diff --git a/src/3rd_party/blake2.c b/src/3rd_party/blake2.c index 2a3ba59..6bb6df7 100644 --- a/src/3rd_party/blake2.c +++ b/src/3rd_party/blake2.c @@ -258,9 +258,11 @@ static inline int blake2b_param_set_personal( blake2b_param *P, const uint8_t pe static inline int blake2b_init0( blake2b_state *S ) { + int i; + memset( S, 0, sizeof( blake2b_state ) ); - for( int i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i]; + for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i]; return 0; } @@ -268,11 +270,14 @@ static inline int blake2b_init0( blake2b_state *S ) /* init xors IV with input parameter block */ int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) { + uint8_t *p; + size_t i; + blake2b_init0( S ); - uint8_t *p = ( uint8_t * )( P ); + p = ( uint8_t * )( P ); /* IV XOR ParamBlock */ - for( size_t i = 0; i < 8; ++i ) + for( i = 0; i < 8; ++i ) S->h[i] ^= load64( p + sizeof( S->h[i] ) * i ); return 0; @@ -430,6 +435,8 @@ int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ) /* Is this correct? */ int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ) { + int i; + uint8_t buffer[BLAKE2B_OUTBYTES]; if( S->buflen > BLAKE2B_BLOCKBYTES ) @@ -445,7 +452,7 @@ int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ) memset( S->buf + S->buflen, 0, 2 * BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */ blake2b_compress( S, S->buf ); - for( int i = 0; i < 8; ++i ) /* Output full hash to temp buffer */ + for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */ store64( buffer + sizeof( S->h[i] ) * i, S->h[i] ); memcpy( out, buffer, outlen );