make sure blake2 calls denote it's the 'b' version, blake2b
This commit is contained in:
parent
7279d3bf85
commit
72926b1eed
@ -625,18 +625,18 @@ void bench_ripemd(void)
|
||||
#ifdef HAVE_BLAKE2
|
||||
void bench_blake2(void)
|
||||
{
|
||||
Blake2 b2;
|
||||
byte digest[32];
|
||||
double start, total, persec;
|
||||
int i;
|
||||
Blake2b b2b;
|
||||
byte digest[64];
|
||||
double start, total, persec;
|
||||
int i;
|
||||
|
||||
InitBlake2(&b2, 32);
|
||||
InitBlake2b(&b2b, 64);
|
||||
start = current_time(1);
|
||||
|
||||
for(i = 0; i < numBlocks; i++)
|
||||
Blake2Update(&b2, plain, sizeof(plain));
|
||||
Blake2bUpdate(&b2b, plain, sizeof(plain));
|
||||
|
||||
Blake2Final(&b2, digest, 32);
|
||||
Blake2bFinal(&b2b, digest, 64);
|
||||
|
||||
total = current_time(0) - start;
|
||||
persec = 1 / total * numBlocks;
|
||||
@ -645,7 +645,7 @@ void bench_blake2(void)
|
||||
persec = persec / 1024;
|
||||
#endif
|
||||
|
||||
printf("BLAKE2 %d %s took %5.3f seconds, %6.2f MB/s\n", numBlocks,
|
||||
printf("BLAKE2b %d %s took %5.3f seconds, %6.2f MB/s\n", numBlocks,
|
||||
blockType, total, persec);
|
||||
}
|
||||
#endif
|
||||
|
@ -434,28 +434,28 @@ int main( int argc, char **argv )
|
||||
|
||||
/* CTaoCrypt API */
|
||||
|
||||
/* Init Blake2 digest, track size incase final doesn't want to "remember" */
|
||||
int InitBlake2(Blake2* b2, word32 digestSz)
|
||||
/* Init Blake2b digest, track size incase final doesn't want to "remember" */
|
||||
int InitBlake2b(Blake2b* b2b, word32 digestSz)
|
||||
{
|
||||
b2->digestSz = digestSz;
|
||||
b2b->digestSz = digestSz;
|
||||
|
||||
return blake2b_init(b2->S, (byte)digestSz);
|
||||
return blake2b_init(b2b->S, (byte)digestSz);
|
||||
}
|
||||
|
||||
|
||||
/* Blake2 Update */
|
||||
int Blake2Update(Blake2* b2, const byte* data, word32 sz)
|
||||
/* Blake2b Update */
|
||||
int Blake2bUpdate(Blake2b* b2b, const byte* data, word32 sz)
|
||||
{
|
||||
return blake2b_update(b2->S, data, sz);
|
||||
return blake2b_update(b2b->S, data, sz);
|
||||
}
|
||||
|
||||
|
||||
/* Blake2 Final, if pass in zero size we use init digestSz */
|
||||
int Blake2Final(Blake2* b2, byte* final, word32 requestSz)
|
||||
/* Blake2b Final, if pass in zero size we use init digestSz */
|
||||
int Blake2bFinal(Blake2b* b2b, byte* final, word32 requestSz)
|
||||
{
|
||||
word32 sz = requestSz ? requestSz : b2->digestSz;
|
||||
word32 sz = requestSz ? requestSz : b2b->digestSz;
|
||||
|
||||
return blake2b_final(b2->S, final, (byte)sz);
|
||||
return blake2b_final(b2b->S, final, (byte)sz);
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,7 +146,7 @@ int pbkdf2_test(void);
|
||||
int ecc_test(void);
|
||||
#endif
|
||||
#ifdef HAVE_BLAKE2
|
||||
int blake2_test(void);
|
||||
int blake2b_test(void);
|
||||
#endif
|
||||
#ifdef HAVE_LIBZ
|
||||
int compress_test(void);
|
||||
@ -247,10 +247,10 @@ void ctaocrypt_test(void* args)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BLAKE2
|
||||
if ( (ret = blake2_test()) )
|
||||
err_sys("BLAKE2 test failed!\n", ret);
|
||||
if ( (ret = blake2b_test()) )
|
||||
err_sys("BLAKE2b test failed!\n", ret);
|
||||
else
|
||||
printf( "BLAKE2 test passed!\n");
|
||||
printf( "BLAKE2b test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifndef NO_HMAC
|
||||
@ -835,20 +835,20 @@ static const byte blake2b_vec[BLAKE2_TESTS][BLAKE2B_OUTBYTES] =
|
||||
|
||||
|
||||
|
||||
int blake2_test(void)
|
||||
int blake2b_test(void)
|
||||
{
|
||||
Blake2 b2;
|
||||
byte digest[64];
|
||||
byte input[64];
|
||||
int i;
|
||||
Blake2b b2b;
|
||||
byte digest[64];
|
||||
byte input[64];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int)sizeof(input); i++)
|
||||
input[i] = (byte)i;
|
||||
|
||||
for (i = 0; i < BLAKE2_TESTS; i++) {
|
||||
InitBlake2(&b2, 64);
|
||||
Blake2Update(&b2, input, i);
|
||||
Blake2Final(&b2, digest, 64);
|
||||
InitBlake2b(&b2b, 64);
|
||||
Blake2bUpdate(&b2b, input, i);
|
||||
Blake2bFinal(&b2b, digest, 64);
|
||||
|
||||
if (memcmp(digest, blake2b_vec[i], 64) != 0) {
|
||||
return -300 - i;
|
||||
|
@ -30,20 +30,20 @@
|
||||
|
||||
/* in bytes, variable digest size up to 512 bits (64 bytes) */
|
||||
enum {
|
||||
BLAKE2_ID = 7 /* hash type unique */
|
||||
BLAKE2B_ID = 7 /* hash type unique */
|
||||
};
|
||||
|
||||
|
||||
/* BLAKE2 digest */
|
||||
typedef struct Blake2 {
|
||||
/* BLAKE2b digest */
|
||||
typedef struct Blake2b {
|
||||
blake2b_state S[1]; /* our state */
|
||||
word32 digestSz; /* digest size used on init */
|
||||
} Blake2;
|
||||
} Blake2b;
|
||||
|
||||
|
||||
CYASSL_API int InitBlake2(Blake2*, word32);
|
||||
CYASSL_API int Blake2Update(Blake2*, const byte*, word32);
|
||||
CYASSL_API int Blake2Final(Blake2*, byte*, word32);
|
||||
CYASSL_API int InitBlake2b(Blake2b*, word32);
|
||||
CYASSL_API int Blake2bUpdate(Blake2b*, const byte*, word32);
|
||||
CYASSL_API int Blake2bFinal(Blake2b*, byte*, word32);
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user