/* Derived from source code of TrueCrypt 7.1a, which is Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0. Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ #ifndef TC_HEADER_Platform_PlatformBase #define TC_HEADER_Platform_PlatformBase #include #include #include #include #include #include #include #ifndef _MSC_VER #include #endif using namespace std; #ifdef nullptr #undef nullptr #endif #if !(defined(_MSC_VER) && _MSC_VER >= 1600) #define nullptr 0 #endif namespace VeraCrypt { #ifdef _MSC_VER # ifndef TC_INT_TYPES_DEFINED typedef __int8 int8; typedef __int16 int16; typedef __int32 int32; typedef __int64 int64; typedef unsigned __int8 byte; typedef unsigned __int16 uint16; typedef unsigned __int32 uint32; typedef unsigned __int64 uint64; # endif #else typedef int8_t int8; typedef int16_t int16; typedef int32_t int32; typedef int64_t int64; typedef uint8_t byte; typedef uint16_t uint16; typedef uint32_t uint32; typedef uint64_t uint64; #endif } #if (defined(_WIN32) || defined(_WIN64)) && !defined(TC_WINDOWS) # define TC_WINDOWS #endif #if defined(_DEBUG) && !defined(DEBUG) # define DEBUG #endif #ifndef TC_TO_STRING # define TC_TO_STRING2(n) #n # define TC_TO_STRING(n) TC_TO_STRING2(n) #endif #define TC_JOIN_ARGS(a,b) a##b #define TC_JOIN(a,b) TC_JOIN_ARGS(a,b) #ifdef __GNUC__ template string GetFunctionName (T pos) { string s (pos); size_t p = s.find ('('); if (p == string::npos) return s; s = s.substr (0, p); p = s.find_last_of (" "); if (p == string::npos) return s; return s.substr (p + 1); } # define SRC_POS (GetFunctionName (__PRETTY_FUNCTION__) += ":" TC_TO_STRING(__LINE__)) # define TC_UNUSED_VAR __attribute__ ((unused)) #else # define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__)) # define TC_UNUSED_VAR #endif #ifdef trace_point # undef trace_point #endif #ifdef trace_msg # undef trace_msg #endif #ifdef DEBUG # define if_debug(...) __VA_ARGS__ # ifdef TC_WINDOWS # define trace_point OutputDebugStringA ((string (SRC_POS) + "\n").c_str()) # define trace_msg(stream_args) do { stringstream s; s << (SRC_POS) << ": " << stream_args << endl; OutputDebugStringA (s.str().c_str()); } while (0) # define trace_msgw(stream_args) do { wstringstream s; s << (SRC_POS) << L": " << stream_args << endl; OutputDebugStringW (s.str().c_str()); } while (0) # else # include # define trace_point cerr << (SRC_POS) << endl # define trace_msg(stream_args) cerr << (SRC_POS) << ": " << stream_args << endl # define trace_msgw(stream_args) cerr << (SRC_POS); wcerr << L": " << stream_args << endl # endif # include "Platform/SystemLog.h" # define trace_log_point SystemLog::WriteError (SRC_POS) # define trace_log_msg(stream_args) do { stringstream s; s << (SRC_POS) << ": " << stream_args; SystemLog::WriteError (s.str()); } while (0) #else # define if_debug(...) # define trace_point # define trace_msg(...) # define trace_msgw(...) # define trace_log_point # define trace_log_msg(...) #endif #define trace_val(VAL) trace_msg (#VAL << '=' << (VAL)); #define array_capacity(arr) (sizeof (arr) / sizeof ((arr)[0])) #endif // TC_HEADER_Platform_PlatformBase id='n10' href='#n10'>10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
/*
 * Copyright (c) 2013-2017 IDRIX
 * Governed by the Apache License 2.0 the full text of which is contained
 * in the file License.txt included in VeraCrypt binary and source
 * code distribution packages.
 */

#ifndef _SHA2_H
#define _SHA2_H

#include "Common/Tcdefs.h"
#include "Common/Endian.h"
#include "Crypto/config.h"

#if defined(__cplusplus)
extern "C" {
#endif

#define SHA256_DIGEST_SIZE  32
#define SHA256_BLOCK_SIZE   64

#define SHA512_DIGEST_SIZE  64
#define SHA512_BLOCK_SIZE  128

#if CRYPTOPP_BOOL_X64
#define SHA2_ALIGN	CRYPTOPP_ALIGN_DATA(32)
#else
#define SHA2_ALIGN	CRYPTOPP_ALIGN_DATA(16)
#endif

typedef struct
{   uint_64t count[2];
    SHA2_ALIGN uint_64t hash[8];
    SHA2_ALIGN uint_64t wbuf[16];
} sha512_ctx;

typedef struct
{   uint_32t count[2];
    SHA2_ALIGN uint_32t hash[8];
    SHA2_ALIGN uint_32t wbuf[16];
} sha256_ctx;


void sha512_begin(sha512_ctx* ctx);
void sha512_hash(const unsigned char * source, uint_64t sourceLen, sha512_ctx *ctx);
void sha512_end(unsigned char * result, sha512_ctx* ctx);
void sha512(unsigned char * result, const unsigned char* source, uint_64t sourceLen);

void sha256_begin(sha256_ctx* ctx);
void sha256_hash(const unsigned char * source, uint_32t sourceLen, sha256_ctx *ctx);
void sha256_end(unsigned char * result, sha256_ctx* ctx);
void sha256(unsigned char * result, const unsigned char* source, uint_32t sourceLen);

#if defined(__cplusplus)
}
#endif



#endif