Skip to content

Commit 90846ba

Browse files
committed
examples/pkcs7: size output buffer for RSA-4096 signatures
MAX_PKCS7_SIZE aliased to MAX_CONTEXT_SIZE (2 KB), which is enough for an RSA-2048 signed blob but overflows at RSA-4096 where the signature alone is 512 B plus a ~1-1.5 KB cert and ASN.1 overhead. wc_PKCS7_EncodeSignedData then returned BUFFER_E (0xffffff7c). Gate on MAX_RSA_KEY_BITS so 2048-bit builds keep the exact same buffer size; 4096-bit builds (Nations NS350, Infineon SLB967x, or anyone overriding) get 4 KB.
1 parent 6942a8e commit 90846ba

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

examples/pkcs7/pkcs7.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@
5757
#endif
5858

5959
#ifndef MAX_PKCS7_SIZE
60-
#define MAX_PKCS7_SIZE MAX_CONTEXT_SIZE
60+
/* Must hold the full SignedData blob (cert + signature + ASN.1 overhead).
61+
* MAX_CONTEXT_SIZE (2 KB) is enough for RSA-2048 but overflows at
62+
* RSA-4096 where the signature alone is 512 B. */
63+
#if MAX_RSA_KEY_BITS >= 4096
64+
#define MAX_PKCS7_SIZE 4096
65+
#else
66+
#define MAX_PKCS7_SIZE MAX_CONTEXT_SIZE
67+
#endif
6168
#endif
6269

6370
/******************************************************************************/

0 commit comments

Comments
 (0)