Skip to content

Commit e671337

Browse files
committed
fixes from CI testing and peer review:
wolfcrypt/src/tfm.c and wolfssl/wolfcrypt/tfm.h: fix for -Wdiscarded-qualifiers in ecc_check_order_minus_1(). wolfssl/wolfcrypt/types.h: in WC_BARRIER(), use XFENCE() too, for best possible barrier. fixes an ARM32 -Ofast -Wmaybe-uninitialized in blake2s_init_key(). wolfcrypt/src/asn_orig.c: set Stored flag after each allocation of a member that needs it. wolfcrypt/src/signature.c: in wc_SignatureGetSize(), provide for legacy FIPS non-const-arg wc_ecc_sig_size() and wc_RsaEncryptSize().
1 parent 21c6568 commit e671337

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

wolfcrypt/src/asn_orig.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,7 @@ static int DecodeConstructedOtherName(DecodedCert* cert, const byte* input,
31823182
ret = MEMORY_E;
31833183
}
31843184
else {
3185+
dnsEntry->nameStored = 1;
31853186
XMEMCPY((void *)(wc_ptr_t)dnsEntry->name, &input[*idx],
31863187
(size_t)strLen);
31873188
((char *)(wc_ptr_t)dnsEntry->name)[strLen] = '\0';
@@ -3272,6 +3273,7 @@ static int DecodeAltNames(const byte* input, word32 sz, DecodedCert* cert)
32723273
XFREE(dnsEntry, cert->heap, DYNAMIC_TYPE_ALTNAME);
32733274
return MEMORY_E;
32743275
}
3276+
dnsEntry->nameStored = 1;
32753277
dnsEntry->len = strLen;
32763278
XMEMCPY((void *)(wc_ptr_t)dnsEntry->name, &input[idx],
32773279
(size_t)strLen);
@@ -3317,6 +3319,7 @@ static int DecodeAltNames(const byte* input, word32 sz, DecodedCert* cert)
33173319
XFREE(dirEntry, cert->heap, DYNAMIC_TYPE_ALTNAME);
33183320
return MEMORY_E;
33193321
}
3322+
dirEntry->nameStored = 1;
33203323
dirEntry->len = strLen;
33213324
XMEMCPY((void *)(wc_ptr_t)dirEntry->name, &input[idx],
33223325
(size_t)strLen);
@@ -3346,7 +3349,7 @@ static int DecodeAltNames(const byte* input, word32 sz, DecodedCert* cert)
33463349
WOLFSSL_MSG("\tOut of Memory");
33473350
return MEMORY_E;
33483351
}
3349-
3352+
emailEntry->nameStored = 1;
33503353
emailEntry->type = ASN_RFC822_TYPE;
33513354
emailEntry->name = (char*)XMALLOC((size_t)strLen + 1, cert->heap,
33523355
DYNAMIC_TYPE_ALTNAME);
@@ -3430,7 +3433,7 @@ static int DecodeAltNames(const byte* input, word32 sz, DecodedCert* cert)
34303433
WOLFSSL_MSG("\tOut of Memory");
34313434
return MEMORY_E;
34323435
}
3433-
3436+
uriEntry->nameStored = 1;
34343437
uriEntry->type = ASN_URI_TYPE;
34353438
uriEntry->name = (char*)XMALLOC((size_t)strLen + 1, cert->heap,
34363439
DYNAMIC_TYPE_ALTNAME);
@@ -3474,7 +3477,7 @@ static int DecodeAltNames(const byte* input, word32 sz, DecodedCert* cert)
34743477
WOLFSSL_MSG("\tOut of Memory");
34753478
return MEMORY_E;
34763479
}
3477-
3480+
ipAddr->nameStored = 1;
34783481
ipAddr->type = ASN_IP_TYPE;
34793482
ipAddr->name = (char*)XMALLOC((size_t)strLen + 1, cert->heap,
34803483
DYNAMIC_TYPE_ALTNAME);
@@ -3534,6 +3537,7 @@ static int DecodeAltNames(const byte* input, word32 sz, DecodedCert* cert)
35343537
XFREE(rid, cert->heap, DYNAMIC_TYPE_ALTNAME);
35353538
return MEMORY_E;
35363539
}
3540+
rid->nameStored = 1;
35373541
rid->len = strLen;
35383542
XMEMCPY((void *)(wc_ptr_t)rid->name, &input[idx], strLen);
35393543
((char *)(wc_ptr_t)rid->name)[strLen] = '\0';

wolfcrypt/src/signature.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ int wc_SignatureGetSize(enum wc_SignatureType sig_type,
9595
#ifdef HAVE_ECC
9696
/* Sanity check that void* key is at least ecc_key in size */
9797
if (key_len >= sizeof(ecc_key)) {
98+
#if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && FIPS_VERSION3_LT(5,0,0))
99+
sig_len = wc_ecc_sig_size((ecc_key*)(wc_ptr_t)key);
100+
#else
98101
sig_len = wc_ecc_sig_size((const ecc_key*)key);
102+
#endif
99103
}
100104
else {
101105
WOLFSSL_MSG("wc_SignatureGetSize: Invalid ECC key size");
@@ -110,7 +114,11 @@ int wc_SignatureGetSize(enum wc_SignatureType sig_type,
110114
#ifndef NO_RSA
111115
/* Sanity check that void* key is at least RsaKey in size */
112116
if (key_len >= sizeof(RsaKey)) {
117+
#if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && FIPS_VERSION3_LT(5,0,0))
118+
sig_len = wc_RsaEncryptSize((RsaKey*)(wc_ptr_t)key);
119+
#else
113120
sig_len = wc_RsaEncryptSize((const RsaKey*)key);
121+
#endif
114122
}
115123
else {
116124
WOLFSSL_MSG("wc_SignatureGetSize: Invalid RsaKey key size");

wolfcrypt/src/tfm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,9 +4540,9 @@ int mp_exptmod_nct (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
45404540

45414541

45424542
/* compare two ints (signed)*/
4543-
int mp_cmp (mp_int * a, mp_int * b)
4543+
int mp_cmp (const mp_int * a, const mp_int * b)
45444544
{
4545-
return fp_cmp(a, b);
4545+
return fp_cmp((mp_int *)a, (mp_int *)b);
45464546
}
45474547

45484548
/* compare a digit */

wolfssl/wolfcrypt/tfm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ MP_API int mp_2expt(mp_int* a, int b);
843843

844844
MP_API int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d);
845845

846-
MP_API int mp_cmp(mp_int *a, mp_int *b);
846+
MP_API int mp_cmp(const mp_int *a, const mp_int *b);
847847
#define mp_cmp_ct(a, b, n) mp_cmp(a, b)
848848
MP_API int mp_cmp_d(mp_int *a, mp_digit b);
849849

wolfssl/wolfcrypt/types.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,11 @@ enum {
489489
static WC_INLINE WARN_UNUSED_RESULT int WC_WUR_INT(int x) { return x; }
490490
#endif
491491

492-
#define WC_BARRIER() do { volatile byte _xfence = 0; (void)_xfence; } while(0)
492+
/* XFENCE() is a no-op on some targets. WC_BARRIER() uses C89 intrinsics as an
493+
* additional portable barrier.
494+
*/
495+
#define WC_BARRIER() do { volatile byte _xfence = 0; (void)_xfence; XFENCE(); \
496+
} while(0)
493497

494498
#ifdef WORD64_AVAILABLE
495499
#define WC_MAX_UINT_OF(x) \

0 commit comments

Comments
 (0)