Skip to content

Commit 3538c4d

Browse files
authored
Merge pull request #10875 from danielinux/fixes-2026-07-10
Minor bugfixes
2 parents a962793 + 3fed5f9 commit 3538c4d

7 files changed

Lines changed: 65 additions & 12 deletions

File tree

tests/api/test_dsa.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,11 @@ int test_wc_DsaImportParamsRawCheck(void)
426426
/* null param pointers */
427427
ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, NULL, NULL, NULL, trusted,
428428
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
429-
/* illegal p length */
429+
/* illegal p length: the checked path now preserves the specific
430+
* primality failure from p validation instead of overwriting it with
431+
* BAD_FUNC_ARG during the later (L,N) size check. */
430432
ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, invalidP, q, g, trusted, NULL),
431-
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
433+
WC_NO_ERR_TRACE(DH_CHECK_PUB_E));
432434
/* illegal q length */
433435
ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, invalidQ, g, trusted, NULL),
434436
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
@@ -731,4 +733,3 @@ int test_wc_DsaCheckPubKey(void)
731733
#endif
732734
return EXPECT_RESULT();
733735
} /* END test_wc_DsaCheckPubKey */
734-

wolfcrypt/src/curve25519.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ int wc_curve25519_check_public(const byte* pub, word32 pubSz, int endian)
977977
/* Check for order-1 or higher. */
978978
if (pub[0] == 0x7f) {
979979
for (i = 1; i < CURVE25519_KEYSIZE - 1; i++) {
980-
if (pub[i] != 0)
980+
if (pub[i] != 0xff)
981981
break;
982982
}
983983
if (i == CURVE25519_KEYSIZE - 1 && (pub[i] >= 0xec))

wolfcrypt/src/dh.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,13 @@ int wc_FreeDhKey(DhKey* key)
10131013
#ifdef WOLFSSL_KCAPI_DH
10141014
KcapiDh_Free(key);
10151015
#endif
1016+
#ifdef WOLFSSL_CHECK_MEM_ZERO
1017+
/* Deregister any mem-zero entries covering this key (e.g. key->priv
1018+
* registered by wc_DhImportKeyPair) now that its fields are zeroed.
1019+
* Mirrors wc_FreeRsaKey(); mp_forcezero() alone does not remove the
1020+
* registration, so without this the entry leaks into later checks. */
1021+
wc_MemZero_Check(key, sizeof(*key));
1022+
#endif
10161023
}
10171024
return 0;
10181025
}

wolfcrypt/src/dsa.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,17 @@ static int _DsaImportParamsRaw(DsaKey* dsa, const char* p, const char* q,
546546
if (err == MP_OKAY)
547547
err = mp_read_radix(&dsa->g, g, MP_RADIX_HEX);
548548

549-
/* verify (L,N) pair bit lengths */
550-
pSz = mp_unsigned_bin_size(&dsa->p);
551-
qSz = mp_unsigned_bin_size(&dsa->q);
549+
/* verify (L,N) pair bit lengths - only when the reads above succeeded, so
550+
* a more specific earlier error (e.g. DH_CHECK_PUB_E from the primality
551+
* check) is not overwritten and qSz is not read from an unset q. */
552+
if (err == MP_OKAY) {
553+
pSz = mp_unsigned_bin_size(&dsa->p);
554+
qSz = mp_unsigned_bin_size(&dsa->q);
552555

553-
if (CheckDsaLN(pSz * WOLFSSL_BIT_SIZE, qSz * WOLFSSL_BIT_SIZE) != 0) {
554-
WOLFSSL_MSG("Invalid DSA p or q parameter size");
555-
err = BAD_FUNC_ARG;
556+
if (CheckDsaLN(pSz * WOLFSSL_BIT_SIZE, qSz * WOLFSSL_BIT_SIZE) != 0) {
557+
WOLFSSL_MSG("Invalid DSA p or q parameter size");
558+
err = BAD_FUNC_ARG;
559+
}
556560
}
557561

558562
if (err != MP_OKAY) {

wolfcrypt/src/random.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ int wc_InitRngNonce_ex(WC_RNG* rng, byte* nonce, word32 nonceSz,
22342234
return _InitRng(rng, nonce, nonceSz, heap, devId);
22352235
}
22362236

2237-
#ifdef HAVE_HASHDRBG
2237+
#if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
22382238
static int PollAndReSeed(WC_RNG* rng)
22392239
{
22402240
int ret = DRBG_NEED_RESEED;
@@ -5519,7 +5519,10 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
55195519
{
55205520
int ret = 0;
55215521

5522-
if (os == NULL) {
5522+
/* Validate output before any entropy backend dereferences it: some
5523+
* (e.g. glibc's vDSO getrandom()) fault on a NULL buffer rather than
5524+
* returning an error. Mirrors wc_RNG_GenerateBlock's NULL check. */
5525+
if (os == NULL || output == NULL) {
55235526
return BAD_FUNC_ARG;
55245527
}
55255528

wolfcrypt/src/rsa.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5402,6 +5402,23 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
54025402
#endif /* !WOLFSSL_CRYPTOCELL && !WOLFSSL_SE050 */
54035403
int err;
54045404

5405+
#if !defined(WOLFSSL_CRYPTOCELL) && \
5406+
(!defined(WOLFSSL_SE050) || defined(WOLFSSL_SE050_NO_RSA)) && \
5407+
!defined(WOLF_CRYPTO_CB_ONLY_RSA) && \
5408+
!defined(WOLFSSL_MICROCHIP_TA100) && \
5409+
!defined(WOLFSSL_SMALL_STACK) && defined(WOLFSSL_CHECK_MEM_ZERO)
5410+
/* Zero the stack temporaries so the mp_memzero_check() in the 'out'
5411+
* cleanup is safe even when an early argument/size check leaves via
5412+
* 'goto out' before these are mp_init'd - an uninitialized mp_int's size
5413+
* field would otherwise make the check scan an arbitrary stack range.
5414+
* Done here, after all declarations, to satisfy C89. */
5415+
XMEMSET(&p_buf, 0, sizeof(p_buf));
5416+
XMEMSET(&q_buf, 0, sizeof(q_buf));
5417+
XMEMSET(&tmp1_buf, 0, sizeof(tmp1_buf));
5418+
XMEMSET(&tmp2_buf, 0, sizeof(tmp2_buf));
5419+
XMEMSET(&tmp3_buf, 0, sizeof(tmp3_buf));
5420+
#endif
5421+
54055422
if (key == NULL || rng == NULL) {
54065423
err = BAD_FUNC_ARG;
54075424
goto out;

wolfssl/wolfcrypt/fe_operations.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@
4040
#define CURVED25519_ASM_64BIT
4141
#define CURVED25519_ASM
4242
#endif
43+
44+
/* The small (reduced-C) curve25519/ed25519 code and the Intel x64 assembly
45+
* both provide the same fe_, sc_ and curve25519 symbols, so selecting both
46+
* (for example a user_settings.h that keeps CURVE25519_SMALL/ED25519_SMALL
47+
* while USE_INTEL_SPEEDUP enables the x64 assembly) produces duplicate-symbol
48+
* link errors that are hard to diagnose. Detect the incompatible combination
49+
* at compile time with a clear message instead. To keep the small
50+
* implementation define NO_CURVED25519_X64; to use the assembly drop
51+
* CURVE25519_SMALL / ED25519_SMALL. */
52+
#if defined(CURVED25519_X64) && \
53+
(defined(CURVE25519_SMALL) || defined(ED25519_SMALL))
54+
#error "CURVE25519_SMALL/ED25519_SMALL are incompatible with the Intel x64 curve25519/ed25519 assembly (CURVED25519_X64); define NO_CURVED25519_X64 to keep the small implementation, or remove the SMALL settings to use the assembly"
55+
#endif
56+
4357
#if defined(WOLFSSL_ARMASM)
4458
#ifdef __aarch64__
4559
#define CURVED25519_ASM_64BIT
@@ -112,6 +126,13 @@ WOLFSSL_LOCAL int curve25519_nb(byte * q, const byte * n, const byte * p,
112126
WOLFSSL_LOCAL void fe_init(void);
113127

114128
WOLFSSL_LOCAL int curve25519(byte * q, const byte * n, const byte * p);
129+
#if defined(CURVED25519_X64) || (defined(WOLFSSL_ARMASM) && defined(__aarch64__))
130+
/* Fixed-base scalar multiply provided by the x64/aarch64 assembly
131+
* (fe_x25519_asm.S, armv8-curve25519); declared here as no other header
132+
* prototypes it, which otherwise breaks a strict C (implicit-declaration)
133+
* build of curve25519.c. */
134+
WOLFSSL_LOCAL int curve25519_base(byte * q, const byte * n);
135+
#endif
115136
#ifdef WOLFSSL_CURVE25519_BLINDING
116137
WOLFSSL_LOCAL int curve25519_blind(byte* q, const byte* n, const byte* mask,
117138
const byte* p, const byte* rz);

0 commit comments

Comments
 (0)