Skip to content

Commit ac16e6f

Browse files
committed
minor fixes
Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
1 parent b2bf6f0 commit ac16e6f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tests/api/test_pkcs7.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,14 @@ int test_wc_PKCS7_EncodeSignedData_RSA_PSS(void)
10141014
if (outLen > 0) {
10151015
int verifyRet = wc_PKCS7_VerifySignedData(pkcs7, output, (word32)outLen);
10161016
ExpectIntEQ(verifyRet, 0);
1017+
1018+
/* Verify decoded RSASSA-PSS parameters match what we encoded:
1019+
* hashAlgorithm = SHA-256
1020+
* maskGenAlgorithm = MGF1-SHA-256
1021+
* saltLength = 32 (== SHA-256 digest length) */
1022+
ExpectIntEQ(pkcs7->pssHashType, (int)WC_HASH_TYPE_SHA256);
1023+
ExpectIntEQ(pkcs7->pssMgf, WC_MGF1SHA256);
1024+
ExpectIntEQ(pkcs7->pssSaltLen, 32);
10171025
}
10181026
}
10191027

wolfcrypt/src/pkcs7.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,11 @@ static int wc_PKCS7_RsaPssSign(wc_PKCS7* pkcs7, byte* digest, word32 digestSz,
21052105
if (ret >= 0)
21062106
#endif
21072107
{
2108-
/* Use same saltLen as encoded in SignerInfo.signatureAlgorithm */
2108+
/* Salt length policy: use hash digest length (RFC 4055 typical).
2109+
* RFC 3447 allows arbitrary salt lengths, but hash-length is the
2110+
* most interoperable choice and matches OpenSSL's default.
2111+
* Must agree with the saltLen encoded in
2112+
* SignerInfo.signatureAlgorithm params above. */
21092113
int saltLen = wc_HashGetDigestSize(wc_OidGetHash(pkcs7->hashOID));
21102114
if (saltLen < 0) {
21112115
ret = saltLen;
@@ -3183,6 +3187,11 @@ static int PKCS7_EncodeSigned(wc_PKCS7* pkcs7,
31833187
}
31843188
#if defined(WC_RSA_PSS)
31853189
if (digEncAlgoId == CTC_RSASSAPSS) {
3190+
/* Salt length policy: always encode as hash digest length.
3191+
* This is the common CMS/RFC 4055 profile and matches OpenSSL
3192+
* defaults. The decoder (pssSaltLen) handles arbitrary values
3193+
* from external blobs. A future pkcs7->pssSaltLen override for
3194+
* encode could be added here if custom salt lengths are needed. */
31863195
int saltLen = wc_HashGetDigestSize(wc_OidGetHash(pkcs7->hashOID));
31873196
if (saltLen < 0) {
31883197
idx = saltLen;

0 commit comments

Comments
 (0)