|
| 1 | +commit cb7c359c1fdc4d15424b8a077416730856f90702 |
| 2 | +Author: nkraetzschmar <9020053+nkraetzschmar@users.noreply.github.com> |
| 3 | +Date: Tue Feb 24 23:35:08 2026 +0100 |
| 4 | + |
| 5 | + rsa: enforce public key validation for RSA key establishment in FIPS mode |
| 6 | + |
| 7 | + Add SP800-56B public key checks to RSA encrypt and RSA-KEM encapsulation paths prior to calling RSA_public_encrypt |
| 8 | + |
| 9 | +diff --git a/providers/implementations/asymciphers/rsa_enc.c b/providers/implementations/asymciphers/rsa_enc.c |
| 10 | +index 4995b00102..466dd0e35a 100644 |
| 11 | +--- a/providers/implementations/asymciphers/rsa_enc.c |
| 12 | ++++ b/providers/implementations/asymciphers/rsa_enc.c |
| 13 | +@@ -179,6 +179,13 @@ static int rsa_encrypt(void *vprsactx, unsigned char *out, size_t *outlen, |
| 14 | + return 1; |
| 15 | + } |
| 16 | + |
| 17 | ++#ifdef FIPS_MODULE |
| 18 | ++ if (!ossl_rsa_validate_public(prsactx->rsa)) { |
| 19 | ++ ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY); |
| 20 | ++ return 0; |
| 21 | ++ } |
| 22 | ++#endif |
| 23 | ++ |
| 24 | + if (outsize < len) { |
| 25 | + ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL); |
| 26 | + return 0; |
| 27 | +diff --git a/providers/implementations/kem/rsa_kem.c b/providers/implementations/kem/rsa_kem.c |
| 28 | +index f7bf368a0d..eaa5cd57cd 100644 |
| 29 | +--- a/providers/implementations/kem/rsa_kem.c |
| 30 | ++++ b/providers/implementations/kem/rsa_kem.c |
| 31 | +@@ -308,6 +308,13 @@ static int rsasve_generate(PROV_RSA_CTX *prsactx, |
| 32 | + return 0; |
| 33 | + } |
| 34 | + |
| 35 | ++#ifdef FIPS_MODULE |
| 36 | ++ if (!ossl_rsa_validate_public(prsactx->rsa)) { |
| 37 | ++ ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY); |
| 38 | ++ return 0; |
| 39 | ++ } |
| 40 | ++#endif |
| 41 | ++ |
| 42 | + /* |
| 43 | + * Step (2): Generate a random byte string z of nlen bytes where |
| 44 | + * 1 < z < n - 1 |
0 commit comments