Skip to content

Commit

Permalink
Do not allow PKCS #1.5 padding for encryption in FIPS
Browse files Browse the repository at this point in the history
* cipher/pubkey-util.c (_gcry_pk_util_data_to_mpi): Block PKCS #1.5
  padding for encryption in FIPS mode
* cipher/rsa.c (rsa_decrypt): Block PKCS #1.5 decryption in FIPS mode
--

GnuPG-bug-id: 5918
Signed-off-by: Jakub Jelen <[email protected]>
  • Loading branch information
Jakuje authored and NIIBE Yutaka committed Apr 21, 2022
1 parent f436bf4 commit c7709f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cipher/pubkey-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,10 @@ _gcry_pk_util_data_to_mpi (gcry_sexp_t input, gcry_mpi_t *ret_mpi,
void *random_override = NULL;
size_t random_override_len = 0;

if ( !(value=sexp_nth_data (lvalue, 1, &valuelen)) || !valuelen )
/* The RSA PKCS#1.5 encryption is no longer supported by FIPS */
if (fips_mode ())
rc = GPG_ERR_INV_FLAG;
else if ( !(value=sexp_nth_data (lvalue, 1, &valuelen)) || !valuelen )
rc = GPG_ERR_INV_OBJ;
else
{
Expand Down
5 changes: 5 additions & 0 deletions cipher/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,11 @@ rsa_decrypt (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t keyparms)
rc = GPG_ERR_INV_DATA;
goto leave;
}
if (fips_mode () && (ctx.encoding == PUBKEY_ENC_PKCS1))
{
rc = GPG_ERR_INV_FLAG;
goto leave;
}

/* Extract the key. */
rc = sexp_extract_param (keyparms, NULL, "nedp?q?u?",
Expand Down

0 comments on commit c7709f7

Please sign in to comment.