Skip to content

Commit a68176c

Browse files
committed
check if the RSA key is big enough to actually produce an RSA-PSS/SHA-256
1 parent 8250ec3 commit a68176c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/internal.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31062,6 +31062,8 @@ int SetSuitesHashSigAlgo(Suites* suites, const char* list)
3106231062
#endif /* OPENSSL_EXTRA */
3106331063

3106431064
#if !defined(NO_TLS) && (!defined(NO_WOLFSSL_SERVER) || !defined(NO_CERTS))
31065+
/* Smallest RSA key able to make an RSA-PSS/SHA-256 signature: emLen >= 2*hLen+2 = 66 bytes (RFC 8017 9.1.1, salt len = hash len). */
31066+
#define RSA_PSS_SHA256_MIN_SZ 66 /* bytes: 2*WC_SHA256_DIGEST_SIZE + 2 */
3106531067
static int MatchSigAlgo(WOLFSSL* ssl, int sigAlgo)
3106631068
{
3106731069
#ifdef HAVE_ED25519
@@ -31124,9 +31126,14 @@ static int MatchSigAlgo(WOLFSSL* ssl, int sigAlgo)
3112431126
if (IsAtLeastTLSv1_3(ssl->version))
3112531127
return sigAlgo == rsa_pss_sa_algo;
3112631128
#endif
31127-
/* TLS 1.2 and below - RSA-PSS allowed. */
31128-
if (sigAlgo == rsa_pss_sa_algo)
31129+
/* TLS 1.2 and below - RSA-PSS allowed, but only if the RSA key is big
31130+
* enough to actually produce an RSA-PSS/SHA-256 signature. */
31131+
if (sigAlgo == rsa_pss_sa_algo) {
31132+
if (ssl->buffers.keySz != 0 &&
31133+
ssl->buffers.keySz < RSA_PSS_SHA256_MIN_SZ)
31134+
return 0;
3112931135
return 1;
31136+
}
3113031137
}
3113131138
#endif
3113231139
#ifdef HAVE_ECC_BRAINPOOL

0 commit comments

Comments
 (0)