Skip to content

Commit 6ac0f82

Browse files
authored
Merge pull request #10204 from mattia-moffa/20260413-fixes
SetSuitesHashSigAlgo fix
2 parents 5ad6097 + e10ff38 commit 6ac0f82

2 files changed

Lines changed: 42 additions & 27 deletions

File tree

src/internal.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29549,6 +29549,17 @@ int SetSuitesHashSigAlgo(Suites* suites, const char* list)
2954929549
break;
2955029550
}
2955129551
}
29552+
{
29553+
word32 needed = 2;
29554+
#if defined(WC_RSA_PSS) && defined(WOLFSSL_TLS13)
29555+
if (sig_alg == rsa_pss_sa_algo)
29556+
needed = 4;
29557+
#endif
29558+
if ((word32)idx + needed > WOLFSSL_MAX_SIGALGO) {
29559+
ret = 0;
29560+
break;
29561+
}
29562+
}
2955229563
AddSuiteHashSigAlgo(suites->hashSigAlgo, mac_alg, sig_alg, 0, &idx);
2955329564
sig_alg = 0;
2955429565
mac_alg = no_mac;

tests/api.c

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16007,6 +16007,33 @@ static int test_wolfSSL_set1_sigalgs_list(void)
1600716007
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
1600816008
ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256+RSA"),
1600916009
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
16010+
16011+
{
16012+
const char entry[] = "RSA+SHA256";
16013+
const int entryLen = (int)sizeof(entry) - 1;
16014+
const int entries = WOLFSSL_MAX_SIGALGO + 1;
16015+
int listSz = entries * (entryLen + 1);
16016+
char* longList = (char*)XMALLOC(listSz, NULL,
16017+
DYNAMIC_TYPE_TMP_BUFFER);
16018+
int i;
16019+
int pos = 0;
16020+
16021+
ExpectNotNull(longList);
16022+
if (longList != NULL) {
16023+
for (i = 0; i < entries; i++) {
16024+
if (i != 0)
16025+
longList[pos++] = ':';
16026+
XMEMCPY(longList + pos, entry, entryLen);
16027+
pos += entryLen;
16028+
}
16029+
longList[pos] = '\0';
16030+
ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, longList),
16031+
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
16032+
ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, longList),
16033+
WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
16034+
XFREE(longList, NULL, DYNAMIC_TYPE_TMP_BUFFER);
16035+
}
16036+
}
1601016037
#endif
1601116038
#endif
1601216039
#ifdef HAVE_ECC
@@ -35177,7 +35204,6 @@ static int test_pkcs7_padding(void)
3517735204
int outSz;
3517835205
int ctOff = -1;
3517935206
int ctLen = 0;
35180-
int i;
3518135207

3518235208
XMEMSET(key, 0xAA, sizeof(key));
3518335209
XMEMSET(plaintext, 'X', sizeof(plaintext));
@@ -35200,32 +35226,10 @@ static int test_pkcs7_padding(void)
3520035226
(word32)encodedSz, output, sizeof(output)), (int)sizeof(plaintext));
3520135227
wc_PKCS7_Free(&pkcs7);
3520235228

35203-
/* Find ciphertext block in encoded DER */
35204-
if (EXPECT_SUCCESS()) {
35205-
for (i = encodedSz - 10; i > 10; i--) {
35206-
if (encoded[i] == 0x04 || encoded[i] == 0x80) {
35207-
int len, lbytes;
35208-
35209-
if (encoded[i+1] < 0x80) {
35210-
len = encoded[i+1]; lbytes = 1;
35211-
}
35212-
else if (encoded[i+1] == 0x81) {
35213-
len = encoded[i+2]; lbytes = 2;
35214-
}
35215-
else {
35216-
continue;
35217-
}
35218-
if (len > 0 && len % 16 == 0 &&
35219-
i + 1 + lbytes + len <= encodedSz) {
35220-
ctOff = i + 1 + lbytes;
35221-
ctLen = len;
35222-
break;
35223-
}
35224-
}
35225-
}
35226-
}
35227-
ExpectIntGT(ctOff, 0);
35228-
ExpectIntGE(ctLen, 32);
35229+
/* encryptedContent is the last element in the DER, so it ends at encodedSz;
35230+
* 27-byte plaintext -> 32-byte AES-256-CBC ciphertext. */
35231+
ctLen = 32;
35232+
ctOff = encodedSz - ctLen;
3522935233

3523035234
/* Corrupt an interior padding byte via CBC bit-flip */
3523135235
if (EXPECT_SUCCESS()) {

0 commit comments

Comments
 (0)