fixes for clang -Os on clang >= 12.0.0; fixes for bugs in blake2s.

This commit is contained in:
Daniel Pouzzner
2022-02-10 15:54:10 -06:00
parent 34c87b83e2
commit 91578df19d
5 changed files with 32 additions and 13 deletions

View File

@@ -7354,7 +7354,7 @@ then
AM_CFLAGS="$AM_CFLAGS $OPTIMIZE_HUGE_CFLAGS"
fi
else
if test "$ENABLED_SP" = "yes" && test "$ENABLED_SP_SMALL" = "no"
if (test "$ENABLED_SP" = "yes" || test "$ENABLED_SP_MATH_ALL" = "yes") && test "$ENABLED_SP_SMALL" = "no"
then
AM_CFLAGS="$AM_CFLAGS $OPTIMIZE_FAST_CFLAGS"
if test "$ENABLED_FASTHUGEMATH" = "yes"

View File

@@ -120,10 +120,13 @@ int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
}
int blake2b_init( blake2b_state *S, const byte outlen )
{
#ifdef WOLFSSL_BLAKE2B_INIT_EACH_FIELD
blake2b_param P[1];
#else
volatile blake2b_param P[1];
#endif
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return BAD_FUNC_ARG;
@@ -140,12 +143,12 @@ int blake2b_init( blake2b_state *S, const byte outlen )
XMEMSET( P->salt, 0, sizeof( P->salt ) );
XMEMSET( P->personal, 0, sizeof( P->personal ) );
#else
XMEMSET( P, 0, sizeof( *P ) );
XMEMSET( (blake2b_param *)P, 0, sizeof( *P ) );
P->digest_length = outlen;
P->fanout = 1;
P->depth = 1;
#endif
return blake2b_init_param( S, P );
return blake2b_init_param( S, (blake2b_param *)P );
}
@@ -153,7 +156,11 @@ int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key,
const byte keylen )
{
int ret = 0;
#ifdef WOLFSSL_BLAKE2B_INIT_EACH_FIELD
blake2b_param P[1];
#else
volatile blake2b_param P[1];
#endif
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return BAD_FUNC_ARG;
@@ -172,14 +179,14 @@ int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key,
XMEMSET( P->salt, 0, sizeof( P->salt ) );
XMEMSET( P->personal, 0, sizeof( P->personal ) );
#else
XMEMSET( P, 0, sizeof( *P ) );
XMEMSET( (blake2b_param *)P, 0, sizeof( *P ) );
P->digest_length = outlen;
P->key_length = keylen;
P->fanout = 1;
P->depth = 1;
#endif
ret = blake2b_init_param( S, P );
ret = blake2b_init_param( S, (blake2b_param *)P );
if ( ret < 0 ) return ret;
{

View File

@@ -119,7 +119,11 @@ int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
int blake2s_init( blake2s_state *S, const byte outlen )
{
#ifdef WOLFSSL_BLAKE2S_INIT_EACH_FIELD
blake2s_param P[1];
#else
volatile blake2s_param P[1];
#endif
if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return BAD_FUNC_ARG;
@@ -132,16 +136,15 @@ int blake2s_init( blake2s_state *S, const byte outlen )
store32( &P->node_offset, 0 );
P->node_depth = 0;
P->inner_length = 0;
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 ) );
XMEMSET( (blake2s_param *)P, 0, sizeof( *P ) );
P->digest_length = outlen;
P->fanout = 1;
P->depth = 1;
#endif
return blake2s_init_param( S, P );
return blake2s_init_param( S, (blake2s_param *)P );
}
@@ -149,7 +152,11 @@ int blake2s_init_key( blake2s_state *S, const byte outlen, const void *key,
const byte keylen )
{
int ret = 0;
#ifdef WOLFSSL_BLAKE2S_INIT_EACH_FIELD
blake2s_param P[1];
#else
volatile blake2s_param P[1];
#endif
if ( ( !outlen ) || ( outlen > BLAKE2S_OUTBYTES ) ) return BAD_FUNC_ARG;
@@ -164,18 +171,17 @@ int blake2s_init_key( blake2s_state *S, const byte outlen, const void *key,
store64( &P->node_offset, 0 );
P->node_depth = 0;
P->inner_length = 0;
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 ) );
XMEMSET( (blake2s_param *)P, 0, sizeof( *P ) );
P->digest_length = outlen;
P->key_length = keylen;
P->fanout = 1;
P->depth = 1;
#endif
ret = blake2s_init_param( S, P );
ret = blake2s_init_param( S, (blake2s_param *)P );
if (ret < 0)
return ret;

View File

@@ -93,6 +93,12 @@ This library provides single precision (SP) integer math functions.
* WOLFSSL_SP_FAST_MODEXP Allow fast mod_exp with small C code
*/
/* WOLFSSL_SP_SMALL is incompatibile with clang-12+ -Os. */
#if defined(__clang__) && defined(__clang_major__) && \
(__clang_major__ >= 12) && defined(WOLFSSL_SP_SMALL)
#undef WOLFSSL_SP_SMALL
#endif
#include <wolfssl/wolfcrypt/sp_int.h>
/* DECL_SP_INT: Declare one variable of type 'sp_int'. */

View File

@@ -73,7 +73,7 @@
byte node_depth; /* 15 */
byte inner_length; /* 16 */
/* byte reserved[0]; */
byte salt[BLAKE2B_SALTBYTES]; /* 24 */
byte salt[BLAKE2S_SALTBYTES]; /* 24 */
byte personal[BLAKE2S_PERSONALBYTES]; /* 32 */
} blake2s_param;