Skip to content

Commit 1a270cd

Browse files
JakujeNIIBE Yutaka
authored andcommitted
tests: Expect the RSA PKCS #1.5 encryption to fail in FIPS mode
* tests/basic.c (check_pubkey_crypt): Expect RSA PKCS #1.5 encryption to fail in FIPS mode. Expect failure when wrong padding is selected * tests/pkcs1v2.c (check_v15crypt): Expect RSA PKCS #1.5 encryption to fail in FIPS mode -- Applied the master commit of: f736f3c GnuPG-bug-id: 5918 Signed-off-by: Jakub Jelen <jjelen@redhat.com>
1 parent 9c55ba3 commit 1a270cd

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

tests/basic.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15568,14 +15568,16 @@ check_pubkey_crypt (int n, gcry_sexp_t skey, gcry_sexp_t pkey, int algo,
1556815568
NULL,
1556915569
0,
1557015570
0,
15571-
0 },
15571+
0,
15572+
FLAG_NOFIPS },
1557215573
{ GCRY_PK_RSA,
1557315574
"(data\n (flags pkcs1)\n"
1557415575
" (value #11223344556677889900AA#))\n",
1557515576
"(flags pkcs1)",
1557615577
1,
1557715578
0,
15578-
0 },
15579+
0,
15580+
FLAG_NOFIPS },
1557915581
{ GCRY_PK_RSA,
1558015582
"(data\n (flags oaep)\n"
1558115583
" (value #11223344556677889900AA#))\n",
@@ -15677,7 +15679,8 @@ check_pubkey_crypt (int n, gcry_sexp_t skey, gcry_sexp_t pkey, int algo,
1567715679
die ("converting data failed: %s\n", gpg_strerror (rc));
1567815680

1567915681
rc = gcry_pk_encrypt (&ciph, data, pkey);
15680-
if (in_fips_mode && (flags & FLAG_NOFIPS))
15682+
if (in_fips_mode && ((flags & FLAG_NOFIPS) ||
15683+
(datas[dataidx].flags & FLAG_NOFIPS)))
1568115684
{
1568215685
if (!rc)
1568315686
fail ("gcry_pk_encrypt did not fail as expected in FIPS mode\n");
@@ -15726,7 +15729,7 @@ check_pubkey_crypt (int n, gcry_sexp_t skey, gcry_sexp_t pkey, int algo,
1572615729
ciph = list;
1572715730
}
1572815731
rc = gcry_pk_decrypt (&plain, ciph, skey);
15729-
if (!rc && (datas[dataidx].flags & FLAG_SPECIAL))
15732+
if ((!rc || in_fips_mode) && (datas[dataidx].flags & FLAG_SPECIAL))
1573015733
{
1573115734
/* It may happen that OAEP formatted data which is
1573215735
decrypted as pkcs#1 data returns a valid pkcs#1

tests/pkcs1v2.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,19 @@ check_v15crypt (void)
454454
gcry_free (seed);
455455

456456
err = gcry_pk_encrypt (&ciph, plain, pub_key);
457-
if (err)
457+
if (in_fips_mode)
458+
{
459+
if (!err)
460+
{
461+
fail ("gcry_pk_encrypt should have failed in FIPS mode:\n");
462+
}
463+
gcry_sexp_release (plain);
464+
plain = NULL;
465+
gcry_sexp_release (ciph);
466+
ciph = NULL;
467+
continue;
468+
}
469+
else if (err)
458470
{
459471
show_sexp ("plain:\n", ciph);
460472
fail ("gcry_pk_encrypt failed: %s\n", gpg_strerror (err));

0 commit comments

Comments
 (0)