README.md
+/Makefile
+*.o
+*.app
+*.a
+
--- /dev/null
+/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived from the source code of Encryption for the Masses 2.02a, which is
+ Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
+ Agreement for Encryption for the Masses'. Modifications and additions to
+ the original source code (contained in this file) and all other portions
+ of this file are Copyright (c) 2003-2008 TrueCrypt Developers Association
+ and are governed by the TrueCrypt License 3.0 the full text of which is
+ contained in the file License.txt included in TrueCrypt binary and source
+ code distribution packages. */
+
+#ifndef TC_HEADER_PKCS5
+#define TC_HEADER_PKCS5
+
+#include "Tcdefs.h"
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+void hmac_sha512 (char *k, int lk, char *d, int ld, char *out, int t);
+void derive_u_sha512 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *u, int b);
+void derive_key_sha512 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen);
+void hmac_sha1 (char *k, int lk, char *d, int ld, char *out, int t);
+void derive_u_sha1 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *u, int b);
+void derive_key_sha1 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen);
+void hmac_ripemd160 (char *key, int keylen, char *input, int len, char *digest);
+void derive_u_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *u, int b);
+void derive_key_ripemd160 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen);
+void hmac_whirlpool (char *k, int lk, char *d, int ld, char *out, int t);
+void derive_u_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *u, int b);
+void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen);
+void hmac_blake512 (char *k, int lk, char *d, int ld, char *out, int t);
+void derive_u_blake512 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *u, int b);
+
+void derive_key_blake512 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen);
+int get_pkcs5_iteration_count (int pkcs5_prf_id, BOOL bBoot);
+char *get_pkcs5_prf_name (int pkcs5_prf_id);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif // TC_HEADER_PKCS5
--- /dev/null
+wsmith@abners-MacBook-Air.local.73454
\ No newline at end of file
static Hash Hashes[] =
{ // ID Name Deprecated System Encryption
{ RIPEMD160, "RIPEMD-160", FALSE, TRUE },
-#ifndef TC_WINDOWS_BOOT
+ // #ifndef TC_WINDOWS_BOOT
{ SHA512, "SHA-512", FALSE, FALSE },
{ WHIRLPOOL, "Whirlpool", FALSE, FALSE },
+ { BLAKE512, "Blake-512", FALSE, FALSE },
{ SHA1, "SHA-1", TRUE, FALSE }, // Deprecated/legacy
-#endif
+ //#endif
{ 0, 0, 0 }
};
enum
{
WHIRLPOOL = FIRST_PRF_ID,
+ BLAKE512,
#ifndef TC_WINDOWS_BOOT
SHA512,
RIPEMD160,
#define WHIRLPOOL_BLOCKSIZE 64
#define WHIRLPOOL_DIGESTSIZE 64
+
+#define BLAKE512_BLOCKSIZE 64
+#define BLAKE512_DIGESTSIZE 64
#define MAX_DIGESTSIZE WHIRLPOOL_DIGESTSIZE
# include "Sha1.h"
# include "Sha2.h"
# include "Whirlpool.h"
+# include "blake.h"
+# include "skein.h"
# include "Camellia.h"
#endif
{
BYTE *digest [MAX_DIGESTSIZE];
WHIRLPOOL_CTX wctx;
+ BLAKE512_CTX bctx;
RMD160_CTX rctx;
sha1_ctx sctx;
sha512_ctx s2ctx;
WHIRLPOOL_add (lpTestBuffer, benchmarkBufferSize * 8, &wctx);
WHIRLPOOL_finalize (&wctx, (unsigned char *) digest);
break;
+
+ case BLAKE512:
+ blake512_init (&bctx);
+ blake512_update (&bctx, lpTestBuffer, benchmarkBufferSize * 8);
+ blake512_final (&bctx, (unsigned char *) digest);
+ break;
+
}
if (QueryPerformanceCounter (&performanceCountEnd) == 0)
/* PKCS-5 test with HMAC-Whirlpool used as the PRF */
derive_key_whirlpool ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid, FALSE), dk, MASTER_KEYDATA_SIZE);
break;
+
+ case BLAKE512:
+ /* PKCS-5 test with HMAC-Blake512 used as the PRF */
+ derive_key_blake512 ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid, FALSE), dk, MASTER_KEYDATA_SIZE);
+ break;
+
}
}
workItem->KeyDerivation.IterationCount, workItem->KeyDerivation.DerivedKey, GetMaxPkcs5OutSize());
break;
+ case BLAKE512:
+ derive_key_blake512 (workItem->KeyDerivation.Password, workItem->KeyDerivation.PasswordLength, workItem->KeyDerivation.Salt, PKCS5_SALT_SIZE,
+ workItem->KeyDerivation.IterationCount, workItem->KeyDerivation.DerivedKey, GetMaxPkcs5OutSize());
+ break;
+
case SHA1:
derive_key_sha1 (workItem->KeyDerivation.Password, workItem->KeyDerivation.PasswordLength, workItem->KeyDerivation.Salt, PKCS5_SALT_SIZE,
workItem->KeyDerivation.IterationCount, workItem->KeyDerivation.DerivedKey, GetMaxPkcs5OutSize());
#include <memory.h>
#include "Rmd160.h"
-#ifndef TC_WINDOWS_BOOT
+//#ifndef TC_WINDOWS_BOOT
#include "Sha1.h"
#include "Sha2.h"
#include "Whirlpool.h"
-#endif
+#include "blake.h"
+#include "skein.h"
+//#endif
#include "Pkcs5.h"
#include "Crypto.h"
d2[i] = d1[i];
}
-#ifndef TC_WINDOWS_BOOT
+//#ifndef TC_WINDOWS_BOOT
void hmac_sha512
(
burn (u, sizeof(u));
}
-#endif // TC_WINDOWS_BOOT
+//#endif // TC_WINDOWS_BOOT
void hmac_ripemd160 (char *key, int keylen, char *input, int len, char *digest)
{
burn (u, sizeof(u));
}
-#ifndef TC_WINDOWS_BOOT
+// #ifndef TC_WINDOWS_BOOT
void hmac_whirlpool
(
burn (u, sizeof(u));
}
+// BLAKE-512
+void hmac_blake512
+(
+ char *k, /* secret key */
+ int lk, /* length of the key in bytes */
+ char *d, /* data */
+ int ld, /* length of data in bytes */
+ char *out, /* output buffer, at least "t" bytes */
+ int t
+)
+{
+ BLAKE512_CTX ictx, octx;
+ char iwhi[BLAKE512_DIGESTSIZE], owhi[BLAKE512_DIGESTSIZE];
+ char key[BLAKE512_DIGESTSIZE];
+ char buf[BLAKE512_BLOCKSIZE];
+ int i;
+
+ /* If the key is longer than the hash algorithm block size,
+ let key = whirlpool(key), as per HMAC specifications. */
+ if (lk > BLAKE512_BLOCKSIZE)
+ {
+ BLAKE512_CTX tctx;
+
+ blake512_init (&tctx);
+ blake512_update (&tctx, (unsigned char *) k, lk);
+ blake512_final (&tctx, (unsigned char *) key);
+
+ k = key;
+ lk = BLAKE512_DIGESTSIZE;
+
+ burn (&tctx, sizeof(tctx)); // Prevent leaks
+ }
+
+ /**** Inner Digest ****/
+
+ blake512_init (&ictx);
+
+ /* Pad the key for inner digest */
+ for (i = 0; i < lk; ++i)
+ buf[i] = (char) (k[i] ^ 0x36);
+ for (i = lk; i < BLAKE512_BLOCKSIZE; ++i)
+ buf[i] = 0x36;
+
+ blake512_update (&ictx, (unsigned char *) buf, BLAKE512_BLOCKSIZE);
+ blake512_update (&ictx, (unsigned char *) d, ld);
+
+ blake512_final (&ictx, (unsigned char *) iwhi);
+
+ /**** Outer Digest ****/
+
+ blake512_init (&octx);
+
+ for (i = 0; i < lk; ++i)
+ buf[i] = (char) (k[i] ^ 0x5C);
+ for (i = lk; i < BLAKE512_BLOCKSIZE; ++i)
+ buf[i] = 0x5C;
+
+ blake512_update (&octx, (unsigned char *) buf, BLAKE512_BLOCKSIZE);
+ blake512_update (&octx, (unsigned char *) iwhi, BLAKE512_DIGESTSIZE);
+
+ blake512_final (&octx, (unsigned char *) owhi);
+
+ /* truncate and print the results */
+ t = t > BLAKE512_DIGESTSIZE ? BLAKE512_DIGESTSIZE : t;
+ hmac_truncate (owhi, out, t);
+
+ /* Prevent possible leaks. */
+ burn (&ictx, sizeof(ictx));
+ burn (&octx, sizeof(octx));
+ burn (owhi, sizeof(owhi));
+ burn (iwhi, sizeof(iwhi));
+ burn (buf, sizeof(buf));
+ burn (key, sizeof(key));
+}
+
+void derive_u_blake512 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *u, int b)
+{
+ char j[BLAKE512_DIGESTSIZE], k[BLAKE512_DIGESTSIZE];
+ char init[128];
+ char counter[4];
+ int c, i;
+
+ /* iteration 1 */
+ memset (counter, 0, 4);
+ counter[3] = (char) b;
+ memcpy (init, salt, salt_len); /* salt */
+ memcpy (&init[salt_len], counter, 4); /* big-endian block number */
+ hmac_blake512 (pwd, pwd_len, init, salt_len + 4, j, BLAKE512_DIGESTSIZE);
+ memcpy (u, j, BLAKE512_DIGESTSIZE);
+
+ /* remaining iterations */
+ for (c = 1; c < iterations; c++)
+ {
+ hmac_blake512 (pwd, pwd_len, j, BLAKE512_DIGESTSIZE, k, BLAKE512_DIGESTSIZE);
+ for (i = 0; i < BLAKE512_DIGESTSIZE; i++)
+ {
+ u[i] ^= k[i];
+ j[i] = k[i];
+ }
+ }
+
+ /* Prevent possible leaks. */
+ burn (j, sizeof(j));
+ burn (k, sizeof(k));
+}
+
+void derive_key_blake512 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen)
+{
+ char u[BLAKE512_DIGESTSIZE];
+ int b, l, r;
+
+ if (dklen % BLAKE512_DIGESTSIZE)
+ {
+ l = 1 + dklen / BLAKE512_DIGESTSIZE;
+ }
+ else
+ {
+ l = dklen / BLAKE512_DIGESTSIZE;
+ }
+
+ r = dklen - (l - 1) * BLAKE512_DIGESTSIZE;
+
+ /* first l - 1 blocks */
+ for (b = 1; b < l; b++)
+ {
+ derive_u_blake512 (pwd, pwd_len, salt, salt_len, iterations, u, b);
+ memcpy (dk, u, BLAKE512_DIGESTSIZE);
+ dk += BLAKE512_DIGESTSIZE;
+ }
+
+ /* last block */
+ derive_u_blake512 (pwd, pwd_len, salt, salt_len, iterations, u, b);
+ memcpy (dk, u, r);
+
+
+ /* Prevent possible leaks. */
+ burn (u, sizeof(u));
+}
+
char *get_pkcs5_prf_name (int pkcs5_prf_id)
{
case WHIRLPOOL:
return "HMAC-Whirlpool";
+ case BLAKE512:
+ return "HMAC-Blake-512";
+
default:
return "(Unknown)";
}
}
-#endif //!TC_WINDOWS_BOOT
+// #endif //!TC_WINDOWS_BOOT
int get_pkcs5_iteration_count (int pkcs5_prf_id, BOOL bBoot)
case RIPEMD160:
return (bBoot ? 1000 : 2000);
-#ifndef TC_WINDOWS_BOOT
-
case SHA512:
return 1000;
case WHIRLPOOL:
return 1000;
-#endif
+
+ case BLAKE512:
+ return 2000;
default:
TC_THROW_FATAL_EXCEPTION; // Unknown/wrong ID
void hmac_whirlpool (char *k, int lk, char *d, int ld, char *out, int t);
void derive_u_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *u, int b);
void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen);
+void hmac_blake512 (char *k, int lk, char *d, int ld, char *out, int t);
+void derive_u_blake512 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *u, int b);
+void derive_key_blake512 (char *pwd, int pwd_len, char *salt, int salt_len, int iterations, char *dk, int dklen);
int get_pkcs5_iteration_count (int pkcs5_prf_id, BOOL bBoot);
char *get_pkcs5_prf_name (int pkcs5_prf_id);
{
unsigned char hashOutputBuffer [MAX_DIGESTSIZE];
WHIRLPOOL_CTX wctx;
+ BLAKE512_CTX bctx
RMD160_CTX rctx;
sha512_ctx sctx;
int poolIndex, digestIndex, digestSize;
digestSize = WHIRLPOOL_DIGESTSIZE;
break;
+ case BLAKE512:
+ digestSize = BLAKE512_DIGESTSIZE;
+ break;
+
default:
TC_THROW_FATAL_EXCEPTION;
}
WHIRLPOOL_finalize (&wctx, hashOutputBuffer);
break;
+ case BLAKE512:
+ blake512_init (&bctx);
+ blake512_update (&bctx,pRandPool, RNG_POOL_SIZE * 8);
+ blake512_final (&bctx, hashOutputBuffer);
+ break;
+
default:
// Unknown/wrong ID
TC_THROW_FATAL_EXCEPTION;
burn (&wctx, sizeof(wctx));
break;
+ case BLAKE512:
+ burn (&bctx, sizeof(bctx));
+ break;
+
+
default:
// Unknown/wrong ID
TC_THROW_FATAL_EXCEPTION;
/* RNG defines & pool pointers */
#define RNG_POOL_SIZE 320 // Must be divisible by the size of the output of each of the implemented hash functions. (in bytes)
-#if RNG_POOL_SIZE % SHA512_DIGESTSIZE || RNG_POOL_SIZE % WHIRLPOOL_DIGESTSIZE || RNG_POOL_SIZE % RIPEMD160_DIGESTSIZE
+#if RNG_POOL_SIZE % SHA512_DIGESTSIZE || RNG_POOL_SIZE % WHIRLPOOL_DIGESTSIZE || RNG_POOL_SIZE % RIPEMD160_DIGESTSIZE || RNG_POOL_SIZE % BLAKE512_DIGESTSIZE
#error RNG_POOL_SIZE must be divisible by the size of the output of each of the implemented hash functions.
#endif
typedef unsigned __int16 uint_16t;
typedef unsigned __int32 uint_32t;
#ifndef TC_NO_COMPILER_INT64
-typedef uint64 uint_64t;
+typedef unsigned long long uint_64t;
#endif
typedef union
PKCS5_SALT_SIZE, keyInfo.noIterations, dk, GetMaxPkcs5OutSize());
break;
+ case BLAKE512:
+ derive_key_blake512 (keyInfo.userKey, keyInfo.keyLength, keyInfo.salt,
+ PKCS5_SALT_SIZE, keyInfo.noIterations, dk, GetMaxPkcs5OutSize());
+ break;
+
+
default:
// Unknown/wrong ID
TC_THROW_FATAL_EXCEPTION;
PKCS5_SALT_SIZE, keyInfo.noIterations, dk, GetMaxPkcs5OutSize());
break;
+ case BLAKE512:
+ derive_key_blake512 (keyInfo.userKey, keyInfo.keyLength, keyInfo.salt,
+ PKCS5_SALT_SIZE, keyInfo.noIterations, dk, GetMaxPkcs5OutSize());
+ break;
+
default:
// Unknown/wrong ID
TC_THROW_FATAL_EXCEPTION;
--- /dev/null
+/*
+ BLAKE reference C implementation
+
+ Copyright (c) 2012 Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
+
+ To the extent possible under law, the author(s) have dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+
+ You should have received a copy of the CC0 Public Domain Dedication along with
+ this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+ */
+#include "blake.h"
+
+const uint8_t sigma[][16] =
+{
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
+ {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
+ {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
+ { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
+ { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
+ { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
+ {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
+ {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
+ { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
+ {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
+ {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
+ {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
+ { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
+ { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
+ { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
+};
+
+const uint32_t u256[16] =
+{
+ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
+ 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
+ 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+ 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917
+};
+
+const uint64_t blake_u512[16] =
+{
+ 0x243f6a8885a308d3ULL, 0x13198a2e03707344ULL,
+ 0xa4093822299f31d0ULL, 0x082efa98ec4e6c89ULL,
+ 0x452821e638d01377ULL, 0xbe5466cf34e90c6cULL,
+ 0xc0ac29b7c97c50ddULL, 0x3f84d5b5b5470917ULL,
+ 0x9216d5d98979fb1bULL, 0xd1310ba698dfb5acULL,
+ 0x2ffd72dbd01adfb7ULL, 0xb8e1afed6a267e96ULL,
+ 0xba7c9045f12c7f99ULL, 0x24a19947b3916cf7ULL,
+ 0x0801f2e2858efc16ULL, 0x636920d871574e69ULL
+};
+
+
+static const uint8_t blake_padding[129] =
+{
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+void blake512_compress( BLAKE512_CTX *S, const uint8_t *block )
+{
+ uint64_t v[16], m[16], i;
+#define ROT(x,n) (((x)<<(64-n))|( (x)>>(n)))
+#define G(a,b,c,d,e) \
+ v[a] += (m[sigma[i][e]] ^ blake_u512[sigma[i][e+1]]) + v[b];\
+ v[d] = ROT( v[d] ^ v[a],32); \
+ v[c] += v[d]; \
+ v[b] = ROT( v[b] ^ v[c],25); \
+ v[a] += (m[sigma[i][e+1]] ^ blake_u512[sigma[i][e]])+v[b]; \
+ v[d] = ROT( v[d] ^ v[a],16); \
+ v[c] += v[d]; \
+ v[b] = ROT( v[b] ^ v[c],11);
+
+ for( i = 0; i < 16; ++i ) m[i] = U8TO64_BIG( block + i * 8 );
+
+ for( i = 0; i < 8; ++i ) v[i] = S->h[i];
+
+ v[ 8] = S->s[0] ^ blake_u512[0];
+ v[ 9] = S->s[1] ^ blake_u512[1];
+ v[10] = S->s[2] ^ blake_u512[2];
+ v[11] = S->s[3] ^ blake_u512[3];
+ v[12] = blake_u512[4];
+ v[13] = blake_u512[5];
+ v[14] = blake_u512[6];
+ v[15] = blake_u512[7];
+
+ /* don't xor t when the block is only padding */
+ if ( !S->nullt )
+ {
+ v[12] ^= S->t[0];
+ v[13] ^= S->t[0];
+ v[14] ^= S->t[1];
+ v[15] ^= S->t[1];
+ }
+
+ for( i = 0; i < 16; ++i )
+ {
+ /* column step */
+ G( 0, 4, 8, 12, 0 );
+ G( 1, 5, 9, 13, 2 );
+ G( 2, 6, 10, 14, 4 );
+ G( 3, 7, 11, 15, 6 );
+ /* diagonal step */
+ G( 0, 5, 10, 15, 8 );
+ G( 1, 6, 11, 12, 10 );
+ G( 2, 7, 8, 13, 12 );
+ G( 3, 4, 9, 14, 14 );
+ }
+
+ for( i = 0; i < 16; ++i ) S->h[i % 8] ^= v[i];
+
+ for( i = 0; i < 8 ; ++i ) S->h[i] ^= S->s[i % 4];
+}
+
+
+void blake512_init( BLAKE512_CTX *S )
+{
+ S->h[0] = 0x6a09e667f3bcc908ULL;
+ S->h[1] = 0xbb67ae8584caa73bULL;
+ S->h[2] = 0x3c6ef372fe94f82bULL;
+ S->h[3] = 0xa54ff53a5f1d36f1ULL;
+ S->h[4] = 0x510e527fade682d1ULL;
+ S->h[5] = 0x9b05688c2b3e6c1fULL;
+ S->h[6] = 0x1f83d9abfb41bd6bULL;
+ S->h[7] = 0x5be0cd19137e2179ULL;
+ S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
+ S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
+}
+
+
+void blake512_update( BLAKE512_CTX *S, const uint8_t *in, uint64_t inlen )
+{
+ int left = S->buflen;
+ int fill = 128 - left;
+
+ /* data left and data received fill a block */
+ if( left && ( inlen >= fill ) )
+ {
+ memcpy( ( void * ) ( S->buf + left ), ( void * ) in, fill );
+ S->t[0] += 1024;
+
+ if ( S->t[0] == 0 ) S->t[1]++;
+
+ blake512_compress( S, S->buf );
+ in += fill;
+ inlen -= fill;
+ left = 0;
+ }
+
+ /* compress blocks of data received */
+ while( inlen >= 128 )
+ {
+ S->t[0] += 1024;
+
+ if ( S->t[0] == 0 ) S->t[1]++;
+
+ blake512_compress( S, in );
+ in += 128;
+ inlen -= 128;
+ }
+
+ /* store any data left */
+ if( inlen > 0 )
+ {
+ memcpy( ( void * ) ( S->buf + left ), \
+ ( void * ) in, ( size_t ) inlen );
+ S->buflen = left + ( int )inlen;
+ }
+ else S->buflen = 0;
+}
+
+
+void blake512_final( BLAKE512_CTX *S, uint8_t *out )
+{
+ uint8_t msglen[16], zo = 0x01, oo = 0x81;
+ uint64_t lo = S->t[0] + ( S->buflen << 3 ), hi = S->t[1];
+
+ /* support for hashing more than 2^32 bits */
+ if ( lo < ( S->buflen << 3 ) ) hi++;
+
+ U64TO8_BIG( msglen + 0, hi );
+ U64TO8_BIG( msglen + 8, lo );
+
+ if ( S->buflen == 111 ) /* one padding byte */
+ {
+ S->t[0] -= 8;
+ blake512_update( S, &oo, 1 );
+ }
+ else
+ {
+ if ( S->buflen < 111 ) /* enough space to fill the block */
+ {
+ if ( !S->buflen ) S->nullt = 1;
+
+ S->t[0] -= 888 - ( S->buflen << 3 );
+ blake512_update( S, blake_padding, 111 - S->buflen );
+ }
+ else /* need 2 compressions */
+ {
+ S->t[0] -= 1024 - ( S->buflen << 3 );
+ blake512_update( S, blake_padding, 128 - S->buflen );
+ S->t[0] -= 888;
+ blake512_update( S, blake_padding + 1, 111 );
+ S->nullt = 1;
+ }
+
+ blake512_update( S, &zo, 1 );
+ S->t[0] -= 8;
+ }
+
+ S->t[0] -= 128;
+ blake512_update( S, msglen, 16 );
+ U64TO8_BIG( out + 0, S->h[0] );
+ U64TO8_BIG( out + 8, S->h[1] );
+ U64TO8_BIG( out + 16, S->h[2] );
+ U64TO8_BIG( out + 24, S->h[3] );
+ U64TO8_BIG( out + 32, S->h[4] );
+ U64TO8_BIG( out + 40, S->h[5] );
+ U64TO8_BIG( out + 48, S->h[6] );
+ U64TO8_BIG( out + 56, S->h[7] );
+}
+
+
+void blake512_hash( uint8_t *out, const uint8_t *in, uint64_t inlen )
+{
+ BLAKE512_CTX S;
+ blake512_init( &S );
+ blake512_update( &S, in, inlen );
+ blake512_final( &S, out );
+}
+
+
+void blake512_test()
+{
+ int i, v;
+ uint8_t in[144], out[64];
+ uint8_t test1[] =
+ {
+ 0x97, 0x96, 0x15, 0x87, 0xf6, 0xd9, 0x70, 0xfa, 0xba, 0x6d, 0x24, 0x78, 0x04, 0x5d, 0xe6, 0xd1,
+ 0xfa, 0xbd, 0x09, 0xb6, 0x1a, 0xe5, 0x09, 0x32, 0x05, 0x4d, 0x52, 0xbc, 0x29, 0xd3, 0x1b, 0xe4,
+ 0xff, 0x91, 0x02, 0xb9, 0xf6, 0x9e, 0x2b, 0xbd, 0xb8, 0x3b, 0xe1, 0x3d, 0x4b, 0x9c, 0x06, 0x09,
+ 0x1e, 0x5f, 0xa0, 0xb4, 0x8b, 0xd0, 0x81, 0xb6, 0x34, 0x05, 0x8b, 0xe0, 0xec, 0x49, 0xbe, 0xb3
+ };
+ uint8_t test2[] =
+ {
+ 0x31, 0x37, 0x17, 0xd6, 0x08, 0xe9, 0xcf, 0x75, 0x8d, 0xcb, 0x1e, 0xb0, 0xf0, 0xc3, 0xcf, 0x9f,
+ 0xC1, 0x50, 0xb2, 0xd5, 0x00, 0xfb, 0x33, 0xf5, 0x1c, 0x52, 0xaf, 0xc9, 0x9d, 0x35, 0x8a, 0x2f,
+ 0x13, 0x74, 0xb8, 0xa3, 0x8b, 0xba, 0x79, 0x74, 0xe7, 0xf6, 0xef, 0x79, 0xca, 0xb1, 0x6f, 0x22,
+ 0xCE, 0x1e, 0x64, 0x9d, 0x6e, 0x01, 0xad, 0x95, 0x89, 0xc2, 0x13, 0x04, 0x5d, 0x54, 0x5d, 0xde
+ };
+ memset( in, 0, 144 );
+ blake512_hash( out, in, 1 );
+ v = 0;
+
+ for( i = 0; i < 64; ++i )
+ {
+ if ( out[i] != test1[i] ) v = 1;
+ }
+
+ if ( v ) printf( "test 1 error\n" );
+
+ blake512_hash( out, in, 144 );
+ v = 0;
+
+ for( i = 0; i < 64; ++i )
+ {
+ if ( out[i] != test2[i] ) v = 1;
+ }
+
+ if ( v ) printf( "test 2 error\n" );
+}
+
--- /dev/null
+wsmith@abners-MacBook-Air.local.73454
\ No newline at end of file
Sha2.c \\r
Twofish.c \\r
Whirlpool.c \\r
- Camellia.c\r
+ Camellia.c \\r
+ blake512.c\r
\r
You should have received a copy of the CC0 Public Domain Dedication along with
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#ifndef _BLAKE_H
+#define _BLAKE_H
+
#include <string.h>
#include <stdio.h>
#include <stdint.h>
-
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
#define U8TO32_BIG(p) \
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) ))
U32TO8_BIG((p), (uint32_t)((v) >> 32)); \
U32TO8_BIG((p) + 4, (uint32_t)((v) ));
-typedef struct
-{
- uint32_t h[8], s[4], t[2];
- int buflen, nullt;
- uint8_t buf[64];
-} state256;
-
-typedef state256 state224;
-
typedef struct
{
uint64_t h[8], s[4], t[2];
int buflen, nullt;
uint8_t buf[128];
-} state512;
+} BLAKE512_CTX;
-typedef state512 state384;
+// typedef BLAKE512_CTX BLAKE384_CTX;
-const uint8_t sigma[][16] =
-{
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
- {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
- {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
- { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
- { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
- { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
- {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
- {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
- { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
- {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
- {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
- {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
- { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
- { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
- { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
-};
+void blake512_init( BLAKE512_CTX *S );
+void blake512_final( BLAKE512_CTX *S, uint8_t *out );
+void blake512_hash( uint8_t *out, const uint8_t *in, uint64_t inlen );
+void blake512_update( BLAKE512_CTX *S, const uint8_t *in, uint64_t inlen );
+void blake512_test();
-const uint32_t u256[16] =
-{
- 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
- 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
- 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
- 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917
-};
+#if defined(__cplusplus)
+}
+#endif
-const uint64_t u512[16] =
-{
- 0x243f6a8885a308d3ULL, 0x13198a2e03707344ULL,
- 0xa4093822299f31d0ULL, 0x082efa98ec4e6c89ULL,
- 0x452821e638d01377ULL, 0xbe5466cf34e90c6cULL,
- 0xc0ac29b7c97c50ddULL, 0x3f84d5b5b5470917ULL,
- 0x9216d5d98979fb1bULL, 0xd1310ba698dfb5acULL,
- 0x2ffd72dbd01adfb7ULL, 0xb8e1afed6a267e96ULL,
- 0xba7c9045f12c7f99ULL, 0x24a19947b3916cf7ULL,
- 0x0801f2e2858efc16ULL, 0x636920d871574e69ULL
-};
-
-
-static const uint8_t padding[129] =
-{
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
+#endif
*/
#include "blake.h"
-void blake512_compress( state512 *S, const uint8_t *block )
+const uint8_t sigma[][16] =
+{
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
+ {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
+ {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
+ { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
+ { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
+ { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
+ {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
+ {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
+ { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
+ {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
+ {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
+ {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
+ { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
+ { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
+ { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
+};
+
+const uint32_t u256[16] =
+{
+ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
+ 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
+ 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+ 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917
+};
+
+const uint64_t blake_u512[16] =
+{
+ 0x243f6a8885a308d3ULL, 0x13198a2e03707344ULL,
+ 0xa4093822299f31d0ULL, 0x082efa98ec4e6c89ULL,
+ 0x452821e638d01377ULL, 0xbe5466cf34e90c6cULL,
+ 0xc0ac29b7c97c50ddULL, 0x3f84d5b5b5470917ULL,
+ 0x9216d5d98979fb1bULL, 0xd1310ba698dfb5acULL,
+ 0x2ffd72dbd01adfb7ULL, 0xb8e1afed6a267e96ULL,
+ 0xba7c9045f12c7f99ULL, 0x24a19947b3916cf7ULL,
+ 0x0801f2e2858efc16ULL, 0x636920d871574e69ULL
+};
+
+
+static const uint8_t blake_padding[129] =
+{
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+void blake512_compress( BLAKE512_CTX *S, const uint8_t *block )
{
uint64_t v[16], m[16], i;
#define ROT(x,n) (((x)<<(64-n))|( (x)>>(n)))
#define G(a,b,c,d,e) \
- v[a] += (m[sigma[i][e]] ^ u512[sigma[i][e+1]]) + v[b];\
+ v[a] += (m[sigma[i][e]] ^ blake_u512[sigma[i][e+1]]) + v[b];\
v[d] = ROT( v[d] ^ v[a],32); \
v[c] += v[d]; \
v[b] = ROT( v[b] ^ v[c],25); \
- v[a] += (m[sigma[i][e+1]] ^ u512[sigma[i][e]])+v[b]; \
+ v[a] += (m[sigma[i][e+1]] ^ blake_u512[sigma[i][e]])+v[b]; \
v[d] = ROT( v[d] ^ v[a],16); \
v[c] += v[d]; \
v[b] = ROT( v[b] ^ v[c],11);
for( i = 0; i < 8; ++i ) v[i] = S->h[i];
- v[ 8] = S->s[0] ^ u512[0];
- v[ 9] = S->s[1] ^ u512[1];
- v[10] = S->s[2] ^ u512[2];
- v[11] = S->s[3] ^ u512[3];
- v[12] = u512[4];
- v[13] = u512[5];
- v[14] = u512[6];
- v[15] = u512[7];
+ v[ 8] = S->s[0] ^ blake_u512[0];
+ v[ 9] = S->s[1] ^ blake_u512[1];
+ v[10] = S->s[2] ^ blake_u512[2];
+ v[11] = S->s[3] ^ blake_u512[3];
+ v[12] = blake_u512[4];
+ v[13] = blake_u512[5];
+ v[14] = blake_u512[6];
+ v[15] = blake_u512[7];
/* don't xor t when the block is only padding */
if ( !S->nullt )
}
-void blake512_init( state512 *S )
+void blake512_init( BLAKE512_CTX *S )
{
S->h[0] = 0x6a09e667f3bcc908ULL;
S->h[1] = 0xbb67ae8584caa73bULL;
}
-void blake512_update( state512 *S, const uint8_t *in, uint64_t inlen )
+void blake512_update( BLAKE512_CTX *S, const uint8_t *in, uint64_t inlen )
{
int left = S->buflen;
int fill = 128 - left;
}
-void blake512_final( state512 *S, uint8_t *out )
+void blake512_final( BLAKE512_CTX *S, uint8_t *out )
{
uint8_t msglen[16], zo = 0x01, oo = 0x81;
uint64_t lo = S->t[0] + ( S->buflen << 3 ), hi = S->t[1];
if ( !S->buflen ) S->nullt = 1;
S->t[0] -= 888 - ( S->buflen << 3 );
- blake512_update( S, padding, 111 - S->buflen );
+ blake512_update( S, blake_padding, 111 - S->buflen );
}
else /* need 2 compressions */
{
S->t[0] -= 1024 - ( S->buflen << 3 );
- blake512_update( S, padding, 128 - S->buflen );
+ blake512_update( S, blake_padding, 128 - S->buflen );
S->t[0] -= 888;
- blake512_update( S, padding + 1, 111 );
+ blake512_update( S, blake_padding + 1, 111 );
S->nullt = 1;
}
void blake512_hash( uint8_t *out, const uint8_t *in, uint64_t inlen )
{
- state512 S;
+ BLAKE512_CTX S;
blake512_init( &S );
blake512_update( &S, in, inlen );
blake512_final( &S, out );
if ( v ) printf( "test 2 error\n" );
}
-int main( int argc, char **argv )
-{
-#define BLOCK512 64
- FILE *fp;
- int i, j, bytesread;
- uint8_t in[BLOCK512], out[64];
- state512 S;
- blake512_test();
-
- for( i = 1; i < argc; ++i )
- {
- fp = fopen( *( argv + i ), "r" );
-
- if ( fp == NULL )
- {
- printf( "Error: unable to open %s\n", *( argv + i ) );
- return 1;
- }
-
- blake512_init( &S );
-
- while( 1 )
- {
- bytesread = fread( in, 1, BLOCK512, fp );
-
- if ( bytesread )
- blake512_update( &S, in, bytesread );
- else
- break;
- }
-
- blake512_final( &S, out );
-
- for( j = 0; j < 64; ++j )
- printf( "%02x", out[j] );
-
- printf( " %s\n", *( argv + i ) );
- fclose( fp );
- }
-
- return 0;
-}
# error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h\r
# endif\r
#endif\r
-\r
-#ifndef BRG_UI64\r
-# if defined( __BORLANDC__ ) && !defined( __MSDOS__ )\r
-# define BRG_UI64\r
-# define li_64(h) 0x##h##ui64\r
- typedef unsigned __int64 uint_64t;\r
-# elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */\r
-# define BRG_UI64\r
-# define li_64(h) 0x##h##ui64\r
- typedef unsigned __int64 uint_64t;\r
-# elif defined( __sun ) && defined(ULONG_MAX) && ULONG_MAX == 0xfffffffful\r
-# define BRG_UI64\r
-# define li_64(h) 0x##h##ull\r
- typedef unsigned long long uint_64t;\r
-# elif defined( UINT_MAX ) && UINT_MAX > 4294967295u\r
-# if UINT_MAX == 18446744073709551615u\r
-# define BRG_UI64\r
-# define li_64(h) 0x##h##u\r
- typedef unsigned int uint_64t;\r
-# endif\r
-# elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u\r
-# if ULONG_MAX == 18446744073709551615ul\r
-# define BRG_UI64\r
-# define li_64(h) 0x##h##ul\r
- typedef unsigned long uint_64t;\r
-# endif\r
-# elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u\r
-# if ULLONG_MAX == 18446744073709551615ull\r
-# define BRG_UI64\r
-# define li_64(h) 0x##h##ull\r
- typedef unsigned long long uint_64t;\r
-# endif\r
-# elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u\r
-# if ULONG_LONG_MAX == 18446744073709551615ull\r
-# define BRG_UI64\r
-# define li_64(h) 0x##h##ull\r
- typedef unsigned long long uint_64t;\r
-# endif\r
-# elif defined(__GNUC__) /* DLW: avoid mingw problem with -ansi */\r
-# define BRG_UI64\r
-# define li_64(h) 0x##h##ull\r
- typedef unsigned long long uint_64t;\r
-# endif\r
-#endif\r
-\r
-#if defined( NEED_UINT_64T ) && !defined( BRG_UI64 )\r
-# error Please define uint_64t as an unsigned 64 bit type in brg_types.h\r
-#endif\r
-\r
#ifndef RETURN_VALUES\r
# define RETURN_VALUES\r
# if defined( DLL_EXPORT )\r
--- /dev/null
+/*\r
+ ---------------------------------------------------------------------------\r
+ Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.\r
+\r
+ LICENSE TERMS\r
+\r
+ The free distribution and use of this software in both source and binary\r
+ form is allowed (with or without changes) provided that:\r
+\r
+ 1. distributions of this source code include the above copyright\r
+ notice, this list of conditions and the following disclaimer;\r
+\r
+ 2. distributions in binary form include the above copyright\r
+ notice, this list of conditions and the following disclaimer\r
+ in the documentation and/or other associated materials;\r
+\r
+ 3. the copyright holder's name is not used to endorse products\r
+ built using this software without specific written permission.\r
+\r
+ ALTERNATIVELY, provided that this notice is retained in full, this product\r
+ may be distributed under the terms of the GNU General Public License (GPL),\r
+ in which case the provisions of the GPL apply INSTEAD OF those given above.\r
+\r
+ DISCLAIMER\r
+\r
+ This software is provided 'as is' with no explicit or implied warranties\r
+ in respect of its properties, including, but not limited to, correctness\r
+ and/or fitness for purpose.\r
+ ---------------------------------------------------------------------------\r
+ Issue 09/09/2006\r
+\r
+ The unsigned integer types defined here are of the form uint_<nn>t where\r
+ <nn> is the length of the type; for example, the unsigned 32-bit type is\r
+ 'uint_32t'. These are NOT the same as the 'C99 integer types' that are\r
+ defined in the inttypes.h and stdint.h headers since attempts to use these\r
+ types have shown that support for them is still highly variable. However,\r
+ since the latter are of the form uint<nn>_t, a regular expression search\r
+ and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t')\r
+ can be used to convert the types used here to the C99 standard types.\r
+*/\r
+\r
+#ifndef BRG_TYPES_H\r
+#define BRG_TYPES_H\r
+\r
+#if defined(__cplusplus)\r
+extern "C" {\r
+#endif\r
+\r
+#include <limits.h>\r
+\r
+#ifndef BRG_UI8\r
+# define BRG_UI8\r
+# if UCHAR_MAX == 255u\r
+ typedef unsigned char uint_8t;\r
+# else\r
+# error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h\r
+# endif\r
+#endif\r
+\r
+#ifndef BRG_UI16\r
+# define BRG_UI16\r
+# if USHRT_MAX == 65535u\r
+ typedef unsigned short uint_16t;\r
+# else\r
+# error Please define uint_16t as a 16-bit unsigned short type in brg_types.h\r
+# endif\r
+#endif\r
+\r
+#ifndef BRG_UI32\r
+# define BRG_UI32\r
+# if UINT_MAX == 4294967295u\r
+# define li_32(h) 0x##h##u\r
+ typedef unsigned int uint_32t;\r
+# elif ULONG_MAX == 4294967295u\r
+# define li_32(h) 0x##h##ul\r
+ typedef unsigned long uint_32t;\r
+# elif defined( _CRAY )\r
+# error This code needs 32-bit data types, which Cray machines do not provide\r
+# else\r
+# error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h\r
+# endif\r
+#endif\r
+\r
+#ifndef BRG_UI64\r
+# if defined( __BORLANDC__ ) && !defined( __MSDOS__ )\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ui64\r
+ typedef unsigned __int64 uint_64t;\r
+# elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ui64\r
+ typedef unsigned __int64 uint_64t;\r
+# elif defined( __sun ) && defined(ULONG_MAX) && ULONG_MAX == 0xfffffffful\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ull\r
+ typedef unsigned long long uint_64t;\r
+# elif defined( UINT_MAX ) && UINT_MAX > 4294967295u\r
+# if UINT_MAX == 18446744073709551615u\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##u\r
+ typedef unsigned int uint_64t;\r
+# endif\r
+# elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u\r
+# if ULONG_MAX == 18446744073709551615ul\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ul\r
+ typedef unsigned long uint_64t;\r
+# endif\r
+# elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u\r
+# if ULLONG_MAX == 18446744073709551615ull\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ull\r
+ typedef unsigned long long uint_64t;\r
+# endif\r
+# elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u\r
+# if ULONG_LONG_MAX == 18446744073709551615ull\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ull\r
+ typedef unsigned long long uint_64t;\r
+# endif\r
+# elif defined(__GNUC__) /* DLW: avoid mingw problem with -ansi */\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ull\r
+ typedef unsigned long long uint_64t;\r
+# endif\r
+#endif\r
+\r
+#if defined( NEED_UINT_64T ) && !defined( BRG_UI64 )\r
+# error Please define uint_64t as an unsigned 64 bit type in brg_types.h\r
+#endif\r
+\r
+#ifndef RETURN_VALUES\r
+# define RETURN_VALUES\r
+# if defined( DLL_EXPORT )\r
+# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )\r
+# define VOID_RETURN __declspec( dllexport ) void __stdcall\r
+# define INT_RETURN __declspec( dllexport ) int __stdcall\r
+# elif defined( __GNUC__ )\r
+# define VOID_RETURN __declspec( __dllexport__ ) void\r
+# define INT_RETURN __declspec( __dllexport__ ) int\r
+# else\r
+# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers\r
+# endif\r
+# elif defined( DLL_IMPORT )\r
+# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )\r
+# define VOID_RETURN __declspec( dllimport ) void __stdcall\r
+# define INT_RETURN __declspec( dllimport ) int __stdcall\r
+# elif defined( __GNUC__ )\r
+# define VOID_RETURN __declspec( __dllimport__ ) void\r
+# define INT_RETURN __declspec( __dllimport__ ) int\r
+# else\r
+# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers\r
+# endif\r
+# elif defined( __WATCOMC__ )\r
+# define VOID_RETURN void __cdecl\r
+# define INT_RETURN int __cdecl\r
+# else\r
+# define VOID_RETURN void\r
+# define INT_RETURN int\r
+# endif\r
+#endif\r
+\r
+/* These defines are used to declare buffers in a way that allows\r
+ faster operations on longer variables to be used. In all these\r
+ defines 'size' must be a power of 2 and >= 8\r
+\r
+ dec_unit_type(size,x) declares a variable 'x' of length \r
+ 'size' bits\r
+\r
+ dec_bufr_type(size,bsize,x) declares a buffer 'x' of length 'bsize' \r
+ bytes defined as an array of variables\r
+ each of 'size' bits (bsize must be a \r
+ multiple of size / 8)\r
+\r
+ ptr_cast(x,size) casts a pointer to a pointer to a \r
+ varaiable of length 'size' bits\r
+*/\r
+\r
+#define ui_type(size) uint_##size##t\r
+#define dec_unit_type(size,x) typedef ui_type(size) x\r
+#define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)]\r
+#define ptr_cast(x,size) ((ui_type(size)*)(x))\r
+\r
+#if defined(__cplusplus)\r
+}\r
+#endif\r
+\r
+#endif\r
--- /dev/null
+/*\r
+ ---------------------------------------------------------------------------\r
+ Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.\r
+\r
+ LICENSE TERMS\r
+\r
+ The free distribution and use of this software in both source and binary\r
+ form is allowed (with or without changes) provided that:\r
+\r
+ 1. distributions of this source code include the above copyright\r
+ notice, this list of conditions and the following disclaimer;\r
+\r
+ 2. distributions in binary form include the above copyright\r
+ notice, this list of conditions and the following disclaimer\r
+ in the documentation and/or other associated materials;\r
+\r
+ 3. the copyright holder's name is not used to endorse products\r
+ built using this software without specific written permission.\r
+\r
+ ALTERNATIVELY, provided that this notice is retained in full, this product\r
+ may be distributed under the terms of the GNU General Public License (GPL),\r
+ in which case the provisions of the GPL apply INSTEAD OF those given above.\r
+\r
+ DISCLAIMER\r
+\r
+ This software is provided 'as is' with no explicit or implied warranties\r
+ in respect of its properties, including, but not limited to, correctness\r
+ and/or fitness for purpose.\r
+ ---------------------------------------------------------------------------\r
+ Issue 09/09/2006\r
+\r
+ The unsigned integer types defined here are of the form uint_<nn>t where\r
+ <nn> is the length of the type; for example, the unsigned 32-bit type is\r
+ 'uint_32t'. These are NOT the same as the 'C99 integer types' that are\r
+ defined in the inttypes.h and stdint.h headers since attempts to use these\r
+ types have shown that support for them is still highly variable. However,\r
+ since the latter are of the form uint<nn>_t, a regular expression search\r
+ and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t')\r
+ can be used to convert the types used here to the C99 standard types.\r
+*/\r
+\r
+#ifndef BRG_TYPES_H\r
+#define BRG_TYPES_H\r
+\r
+#if defined(__cplusplus)\r
+extern "C" {\r
+#endif\r
+\r
+#include <limits.h>\r
+\r
+#ifndef BRG_UI8\r
+# define BRG_UI8\r
+# if UCHAR_MAX == 255u\r
+ typedef unsigned char uint_8t;\r
+# else\r
+# error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h\r
+# endif\r
+#endif\r
+\r
+#ifndef BRG_UI16\r
+# define BRG_UI16\r
+# if USHRT_MAX == 65535u\r
+ typedef unsigned short uint_16t;\r
+# else\r
+# error Please define uint_16t as a 16-bit unsigned short type in brg_types.h\r
+# endif\r
+#endif\r
+\r
+#ifndef BRG_UI32\r
+# define BRG_UI32\r
+# if UINT_MAX == 4294967295u\r
+# define li_32(h) 0x##h##u\r
+ typedef unsigned int uint_32t;\r
+# elif ULONG_MAX == 4294967295u\r
+# define li_32(h) 0x##h##ul\r
+ typedef unsigned long uint_32t;\r
+# elif defined( _CRAY )\r
+# error This code needs 32-bit data types, which Cray machines do not provide\r
+# else\r
+# error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h\r
+# endif\r
+#endif\r
+\r
+#ifndef BRG_UI64\r
+# if defined( __BORLANDC__ ) && !defined( __MSDOS__ )\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ui64\r
+ typedef unsigned __int64 uint_64t;\r
+# elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ui64\r
+ typedef unsigned __int64 uint_64t;\r
+# elif defined( __sun ) && defined(ULONG_MAX) && ULONG_MAX == 0xfffffffful\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ull\r
+ typedef unsigned long long uint_64t;\r
+# elif defined( UINT_MAX ) && UINT_MAX > 4294967295u\r
+# if UINT_MAX == 18446744073709551615u\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##u\r
+ typedef unsigned int uint_64t;\r
+# endif\r
+# elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u\r
+# if ULONG_MAX == 18446744073709551615ul\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ul\r
+ typedef unsigned long uint_64t;\r
+# endif\r
+# elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u\r
+# if ULLONG_MAX == 18446744073709551615ull\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ull\r
+ typedef unsigned long long uint_64t;\r
+# endif\r
+# elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u\r
+# if ULONG_LONG_MAX == 18446744073709551615ull\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ull\r
+ typedef unsigned long long uint_64t;\r
+# endif\r
+# elif defined(__GNUC__) /* DLW: avoid mingw problem with -ansi */\r
+# define BRG_UI64\r
+# define li_64(h) 0x##h##ull\r
+ typedef unsigned long long uint_64t;\r
+# endif\r
+#endif\r
+\r
+#if defined( NEED_UINT_64T ) && !defined( BRG_UI64 )\r
+# error Please define uint_64t as an unsigned 64 bit type in brg_types.h\r
+#endif\r
+\r
+#ifndef RETURN_VALUES\r
+# define RETURN_VALUES\r
+# if defined( DLL_EXPORT )\r
+# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )\r
+# define VOID_RETURN __declspec( dllexport ) void __stdcall\r
+# define INT_RETURN __declspec( dllexport ) int __stdcall\r
+# elif defined( __GNUC__ )\r
+# define VOID_RETURN __declspec( __dllexport__ ) void\r
+# define INT_RETURN __declspec( __dllexport__ ) int\r
+# else\r
+# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers\r
+# endif\r
+# elif defined( DLL_IMPORT )\r
+# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )\r
+# define VOID_RETURN __declspec( dllimport ) void __stdcall\r
+# define INT_RETURN __declspec( dllimport ) int __stdcall\r
+# elif defined( __GNUC__ )\r
+# define VOID_RETURN __declspec( __dllimport__ ) void\r
+# define INT_RETURN __declspec( __dllimport__ ) int\r
+# else\r
+# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers\r
+# endif\r
+# elif defined( __WATCOMC__ )\r
+# define VOID_RETURN void __cdecl\r
+# define INT_RETURN int __cdecl\r
+# else\r
+# define VOID_RETURN void\r
+# define INT_RETURN int\r
+# endif\r
+#endif\r
+\r
+/* These defines are used to declare buffers in a way that allows\r
+ faster operations on longer variables to be used. In all these\r
+ defines 'size' must be a power of 2 and >= 8\r
+\r
+ dec_unit_type(size,x) declares a variable 'x' of length \r
+ 'size' bits\r
+\r
+ dec_bufr_type(size,bsize,x) declares a buffer 'x' of length 'bsize' \r
+ bytes defined as an array of variables\r
+ each of 'size' bits (bsize must be a \r
+ multiple of size / 8)\r
+\r
+ ptr_cast(x,size) casts a pointer to a pointer to a \r
+ varaiable of length 'size' bits\r
+*/\r
+\r
+#define ui_type(size) uint_##size##t\r
+#define dec_unit_type(size,x) typedef ui_type(size) x\r
+#define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)]\r
+#define ptr_cast(x,size) ((ui_type(size)*)(x))\r
+\r
+#if defined(__cplusplus)\r
+}\r
+#endif\r
+\r
+#endif\r
export BUILD_INC := $(BASE_DIR)/Build/Include
export NOTEST := 1
export AR ?= ar
-export CC ?= gcc
-export CXX ?= g++
+export CC ?= clang
+export CXX ?= clang++
export AS := nasm
export RANLIB ?= ranlib
export CFLAGS := -Wall
-export CXXFLAGS := -Wall -Wno-unused-parameter
-C_CXX_FLAGS := -MMD -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -I$(BASE_DIR) -I$(BASE_DIR)/Crypto `wx-config --cxxflags`
+export CXXFLAGS := -Wall -Wno-unused-parameter -lstdc++
+C_CXX_FLAGS := -MMD -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -I$(BASE_DIR) -I$(BASE_DIR)/Crypto -I/usr/include `~/projects/wxWidgets-3-patched/wx-config --cxxflags`
export ASFLAGS := -Ox -D __GNUC__
export LFLAGS :=
export LDLIBS += -lX11
export PKG_CONFIG_PATH ?= /usr/local/lib/pkgconfig
-export WX_CONFIG ?= wx-config
+export WX_CONFIG ?= ~/projects/wxWidgets-3-patched/wx-config
export WX_CONFIG_ARGS := --unicode
WX_CONFIGURE_FLAGS :=
export WXCONFIG_CFLAGS :=
export TC_BUILD_CONFIG := Release
+ifeq "$(shell uname -s)" "Darwin"
+ CPU_ARCH = x64
+ ASM_OBJ_FORMAT = macho64
+endif
ifeq "$(origin DEBUG)" "command line"
ifneq "$(DEBUG)" "0"
TC_BUILD_CONFIG := Debug
ifneq "$(origin VERBOSE)" "command line"
MAKEFLAGS += -s
endif
-
+ifeq "$(CPU_ARCH)" "x86"
+ C_CXX_FLAGS += -D TC_ARCH_X86
+else ifeq "$(CPU_ARCH)" "x64"
+ C_CXX_FLAGS += -D TC_ARCH_X64
+endif
#ifeq "$(origin WXSTATIC)" "command line"
# WX_CONFIG = $(WX_BUILD_DIR)/wx-config
#endif
ifeq "$(ARCH)" "unknown"
ARCH = $(shell uname -m)
endif
-
-ifneq (,$(filter i386 i486 i586 i686 x86,$(ARCH)))
+ifeq "$(shell uname -s)" "Darwin"
+ CPU_ARCH = x64
+ ASM_OBJ_FORMAT = macho64
+else ifneq (,$(filter i386 i486 i586 i686 x86,$(ARCH)))
CPU_ARCH = x86
ASM_OBJ_FORMAT = elf32
else ifneq (,$(filter x86_64 x86-64 amd64 x64,$(ARCH)))
else ifeq "$(CPU_ARCH)" "x64"
C_CXX_FLAGS += -D TC_ARCH_X64
endif
+ifeq "$(CPU_ARCH)" "x86"
+ C_CXX_FLAGS += -D TC_ARCH_X86
+else ifeq "$(CPU_ARCH)" "x64"
+ C_CXX_FLAGS += -D TC_ARCH_X64
+endif
#------ Linux configuration ------
PLATFORM := MacOSX
APPNAME := nemesis
- TC_OSX_SDK ?= /Developer/SDKs/MacOSX10.4u.sdk
- CC := gcc-4.0
- CXX := g++-4.0
+ TC_OSX_SDK ?= /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
+ CC := clang
+ CXX := clang++
- C_CXX_FLAGS += -DTC_UNIX -DTC_BSD -DTC_MACOSX -mmacosx-version-min=10.4 -isysroot $(TC_OSX_SDK)
- LFLAGS += -mmacosx-version-min=10.4 -Wl,-syslibroot $(TC_OSX_SDK)
- WX_CONFIGURE_FLAGS += --with-macosx-version-min=10.4 --with-macosx-sdk=$(TC_OSX_SDK)
+ OBJCXXFLAGS += -stdlib=libstdc++ -std=c++11
+ LDFLAGS += -stdlib=libstdc++
+ CXXFLAGS += -stdlib=libstdc++
+ C_CXX_FLAGS += -DTC_UNIX -DTC_BSD -DTC_MACOSX -mmacosx-version-min=10.7 -isysroot $(TC_OSX_SDK)
+# LFLAGS += -mmacosx-version-min=10.4 -Wl,-syslibroot $(TC_OSX_SDK)
+# WX_CONFIGURE_FLAGS += --with-macosx-version-min=10.4 --with-macosx-sdk=$(TC_OSX_SDK)
- ifeq "$(CPU_ARCH)" "x64"
- CPU_ARCH = x86
- endif
-
- ASM_OBJ_FORMAT = macho
+# ifeq "$(CPU_ARCH)" "x64"
+# CPU_ARCH = x86_64
+# endif
+ CPU_ARCH = x64
+ ASM_OBJ_FORMAT = macho64
ASFLAGS += --prefix _
ifeq "$(TC_BUILD_CONFIG)" "Release"
S := $(C_CXX_FLAGS)
C_CXX_FLAGS = $(subst -MMD,,$(S))
- C_CXX_FLAGS += -gfull -arch i386 -arch ppc
- LFLAGS += -Wl,-dead_strip -arch i386 -arch ppc
+ C_CXX_FLAGS += -gfull
+ LFLAGS += -Wl,-dead_strip
WX_CONFIGURE_FLAGS += --enable-universal_binary
WXCONFIG_CFLAGS += -gfull
all clean:
@if pwd | grep -q ' '; then echo 'Error: source code is stored in a path containing spaces' >&2; exit 1; fi
- @$(MAKE) -C $(BASE_DIR)/Core/libntru static-lib
+# $(MAKE) -C $(BASE_DIR)/Core/libntru
@for DIR in $(PROJ_DIRS); do \
PROJ=$$(echo $$DIR | cut -d/ -f1); \
$(MAKE) -C $$DIR -f $$PROJ.make NAME=$$PROJ $(MAKECMDGOALS) || exit $?; \
- export LIBS="$(BASE_DIR)/$$DIR/$$PROJ.a $(BASE_DIR)/Core/libntru/libntru.a $$LIBS "; \
+ export LIBS="$(BASE_DIR)/$$DIR/$$PROJ.a $$LIBS"; \
done
#------ wxWidgets build ------
/*
- Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
-
+ nemesis - https://github.com/adouble42/nemesis-current
+ portions copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
+
Governed by the TrueCrypt License 3.0 the full text of which is contained in
the file License.txt included in TrueCrypt binary and source code distribution
packages.
#include "Crypto/Sha1.h"
#include "Crypto/Sha2.h"
#include "Crypto/Whirlpool.h"
+#include "Crypto/blake.h"
+#include "Crypto/skein.h"
namespace TrueCrypt
{
l.push_back (shared_ptr <Hash> (new Ripemd160 ()));
l.push_back (shared_ptr <Hash> (new Sha512 ()));
l.push_back (shared_ptr <Hash> (new Whirlpool ()));
+ // l.push_back (shared_ptr <Hash> (new Skein1024 ()));
+ l.push_back (shared_ptr <Hash> (new Blake512 ()));
l.push_back (shared_ptr <Hash> (new Sha1 ()));
return l;
// RIPEMD-160
Ripemd160::Ripemd160 ()
{
- Context.Allocate (sizeof (RMD160_CTX));
+ Deprecated = true;
+ Context.Allocate (sizeof (RMD160_CTX));
Init();
}
if_debug (ValidateDataParameters (data));
WHIRLPOOL_add (data.Get(), (int) data.Size() * 8, (WHIRLPOOL_CTX *) Context.Ptr());
}
+ // Skein-1024
+ Skein1024::Skein1024 ()
+ {
+ Context.Allocate (sizeof (WHIRLPOOL_CTX));
+ Init();
+ }
+
+ void Skein1024::GetDigest (const BufferPtr &buffer)
+ {
+ if_debug (ValidateDigestParameters (buffer));
+ WHIRLPOOL_finalize ((WHIRLPOOL_CTX *) Context.Ptr(), buffer);
+ }
+
+ void Skein1024::Init ()
+ {
+ WHIRLPOOL_init ((WHIRLPOOL_CTX *) Context.Ptr());
+ }
+
+ void Skein1024::ProcessData (const ConstBufferPtr &data)
+ {
+ if_debug (ValidateDataParameters (data));
+ WHIRLPOOL_add (data.Get(), (int) data.Size() * 8, (WHIRLPOOL_CTX *) Context.Ptr());
+ }
+ // BLAKE-512
+ Blake512::Blake512 ()
+ {
+ Context.Allocate (sizeof (BLAKE512_CTX));
+ Init();
+ }
+
+ void Blake512::GetDigest (const BufferPtr &buffer)
+ {
+ if_debug (ValidateDigestParameters (buffer));
+ blake512_final ((BLAKE512_CTX *) Context.Ptr(), buffer);
+ }
+
+ void Blake512::Init ()
+ {
+ blake512_init ((BLAKE512_CTX *) Context.Ptr());
+ }
+
+ void Blake512::ProcessData (const ConstBufferPtr &data)
+ {
+ if_debug (ValidateDataParameters (data));
+ blake512_update ((BLAKE512_CTX *) Context.Ptr(), data.Get(), (int) data.Size() * 8);
+ }
+
}
Whirlpool (const Whirlpool &);
Whirlpool &operator= (const Whirlpool &);
};
+
+ // BLAKE-512
+ class Blake512 : public Hash
+ {
+ public:
+ Blake512 ();
+ virtual ~Blake512 () { }
+
+ virtual void GetDigest (const BufferPtr &buffer);
+ virtual size_t GetBlockSize () const { return 128; }
+ virtual size_t GetDigestSize () const { return 512 / 8; }
+ virtual wstring GetName () const { return L"Blake-512"; }
+ virtual shared_ptr <Hash> GetNew () const { return shared_ptr <Hash> (new Blake512); }
+ virtual void Init ();
+ virtual void ProcessData (const ConstBufferPtr &data);
+
+ protected:
+
+ private:
+ Blake512 (const Blake512 &);
+ Blake512 &operator= (const Blake512 &);
+ };
+ // Skein-1024
+ class Skein1024 : public Hash
+ {
+ public:
+ Skein1024 ();
+ virtual ~Skein1024 () { }
+
+ virtual void GetDigest (const BufferPtr &buffer);
+ virtual size_t GetBlockSize () const { return 128; }
+ virtual size_t GetDigestSize () const { return 1024 / 8; }
+ virtual wstring GetName () const { return L"Skein-1024"; }
+ virtual shared_ptr <Hash> GetNew () const { return shared_ptr <Hash> (new Skein1024); }
+ virtual void Init ();
+ virtual void ProcessData (const ConstBufferPtr &data);
+
+ protected:
+
+ private:
+ Skein1024 (const Skein1024 &);
+ Skein1024 &operator= (const Skein1024 &);
+ };
+
}
#endif // TC_HEADER_Encryption_Hash
l.push_back (shared_ptr <Pkcs5Kdf> (new Pkcs5HmacRipemd160 ()));
l.push_back (shared_ptr <Pkcs5Kdf> (new Pkcs5HmacSha512 ()));
l.push_back (shared_ptr <Pkcs5Kdf> (new Pkcs5HmacWhirlpool ()));
+ l.push_back (shared_ptr <Pkcs5Kdf> (new Pkcs5HmacBlake512 ()));
l.push_back (shared_ptr <Pkcs5Kdf> (new Pkcs5HmacSha1 ()));
return l;
ValidateParameters (key, password, salt, iterationCount);
derive_key_whirlpool ((char *) password.DataPtr(), (int) password.Size(), (char *) salt.Get(), (int) salt.Size(), iterationCount, (char *) key.Get(), (int) key.Size());
}
+
+ void Pkcs5HmacBlake512::DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const
+ {
+ ValidateParameters (key, password, salt, iterationCount);
+ derive_key_blake512 ((char *) password.DataPtr(), (int) password.Size(), (char *) salt.Get(), (int) salt.Size(), iterationCount, (char *) key.Get(), (int) key.Size());
+ }
+
}
Pkcs5HmacWhirlpool (const Pkcs5HmacWhirlpool &);
Pkcs5HmacWhirlpool &operator= (const Pkcs5HmacWhirlpool &);
};
+
+ class Pkcs5HmacBlake512 : public Pkcs5Kdf
+ {
+ public:
+ Pkcs5HmacBlake512 () { }
+ virtual ~Pkcs5HmacBlake512 () { }
+
+ virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
+ virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Blake512); }
+ virtual int GetIterationCount () const { return 2000; }
+ virtual wstring GetName () const { return L"HMAC-Blake-512"; }
+
+ private:
+ Pkcs5HmacBlake512 (const Pkcs5HmacBlake512 &);
+ Pkcs5HmacBlake512 &operator= (const Pkcs5HmacBlake512 &);
+ };
}
#endif // TC_HEADER_Encryption_Pkcs5
OBJS += ../Crypto/Sha2.o
OBJS += ../Crypto/Twofish.o
OBJS += ../Crypto/Whirlpool.o
+OBJS += ../Crypto/blake512.o
OBJS += ../Crypto/Camellia.o