From f8023b808fa3086eb85352dcddb36eb8b5da27e5 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Mon, 15 May 2017 09:47:11 +1000 Subject: [PATCH] Blake2b fix for GCC 5.4 Memsetting P and then setting non-zero fields works with GCC 5.4. --- wolfcrypt/src/blake2b.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wolfcrypt/src/blake2b.c b/wolfcrypt/src/blake2b.c index 4ed71b44a..f30b685af 100644 --- a/wolfcrypt/src/blake2b.c +++ b/wolfcrypt/src/blake2b.c @@ -126,6 +126,7 @@ int blake2b_init( blake2b_state *S, const byte outlen ) if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1; +#ifdef WOLFSSL_BLAKE2B_INIT_EACH_FIELD P->digest_length = outlen; P->key_length = 0; P->fanout = 1; @@ -137,6 +138,12 @@ int blake2b_init( blake2b_state *S, const byte outlen ) XMEMSET( P->reserved, 0, sizeof( P->reserved ) ); XMEMSET( P->salt, 0, sizeof( P->salt ) ); XMEMSET( P->personal, 0, sizeof( P->personal ) ); +#else + XMEMSET( P, 0, sizeof( *P ) ); + P->digest_length = outlen; + P->fanout = 1; + P->depth = 1; +#endif return blake2b_init_param( S, P ); } @@ -150,6 +157,7 @@ int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key, if ( !key || !keylen || keylen > BLAKE2B_KEYBYTES ) return -1; +#ifdef WOLFSSL_BLAKE2B_INIT_EACH_FIELD P->digest_length = outlen; P->key_length = keylen; P->fanout = 1; @@ -161,6 +169,13 @@ int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key, XMEMSET( P->reserved, 0, sizeof( P->reserved ) ); XMEMSET( P->salt, 0, sizeof( P->salt ) ); XMEMSET( P->personal, 0, sizeof( P->personal ) ); +#else + XMEMSET( P, 0, sizeof( *P ) ); + P->digest_length = outlen; + P->key_length = keylen; + P->fanout = 1; + P->depth = 1; +#endif if( blake2b_init_param( S, P ) < 0 ) return -1;