From 8086d6f6967797009f31cb6c35d0ec62216b5006 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 24 Sep 2013 13:37:33 -0700 Subject: [PATCH] blake2: remove more declarations in for() for MSVC --- .../crypto_generichash/blake2/ref/blake2b-ref.c | 12 ++++++++---- .../crypto_generichash/blake2/ref/blake2s-ref.c | 11 +++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c b/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c index dcb02398..e98c9f12 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c @@ -138,9 +138,10 @@ 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; } @@ -148,11 +149,13 @@ 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 ) { + size_t i; + blake2b_init0( S ); const uint8_t *p = ( const 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; @@ -217,7 +220,7 @@ static int blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCK { uint64_t m[16]; uint64_t v[16]; - int i; + int i; for( i = 0; i < 16; ++i ) m[i] = load64( block + i * sizeof( m[i] ) ); @@ -311,6 +314,7 @@ int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ) int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ) { uint8_t buffer[BLAKE2B_OUTBYTES]; + int i; if( S->buflen > BLAKE2B_BLOCKBYTES ) { @@ -325,7 +329,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 ); diff --git a/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c b/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c index 910eb10f..03c2bb22 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c @@ -144,11 +144,13 @@ static inline int blake2s_init0( blake2s_state *S ) /* init2 xors IV with input parameter block */ int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) { + size_t i; + blake2s_init0( S ); uint32_t *p = ( uint32_t * )( P ); /* IV XOR ParamBlock */ - for( size_t i = 0; i < 8; ++i ) + for( i = 0; i < 8; ++i ) S->h[i] ^= load32( &p[i] ); return 0; @@ -213,11 +215,12 @@ static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCK { uint32_t m[16]; uint32_t v[16]; + size_t i; - for( size_t i = 0; i < 16; ++i ) + for( i = 0; i < 16; ++i ) m[i] = load32( block + i * sizeof( m[i] ) ); - for( size_t i = 0; i < 8; ++i ) + for( i = 0; i < 8; ++i ) v[i] = S->h[i]; v[ 8] = blake2s_IV[0]; @@ -261,7 +264,7 @@ static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCK ROUND( 8 ); ROUND( 9 ); - for( size_t i = 0; i < 8; ++i ) + for( i = 0; i < 8; ++i ) S->h[i] = S->h[i] ^ v[i] ^ v[i + 8]; #undef G