From 30ec869b8c63f1edcc58110ed20b83b0e77248f8 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 11 Jan 2012 20:15:47 +0100 Subject: [PATCH] gpg: Fix segv with RSA_S keys. * g10/misc.c (pubkey_get_npkey, pubkey_get_nskey) (pubkey_get_nsig, pubkey_get_nenc): Map all RSA algo ids to GCRY_PK_RSA. -- The problem is that Libgcrypt has no more support for the alternate RSA ids and thus if asking for the number of parameters, they will return zero. Now, this leads to packing the key parameters into an opaque MPI but because the algorithm id is actually known to GPG, it assumes valid RSA parameters. An example key with RSA_S is 0x5434509D. --- g10/misc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/g10/misc.c b/g10/misc.c index e0c57a145..c49945a6f 100644 --- a/g10/misc.c +++ b/g10/misc.c @@ -1377,6 +1377,8 @@ pubkey_get_npkey (int algo) /* All other algorithms match those of Libgcrypt. */ if (algo == GCRY_PK_ELG_E) algo = GCRY_PK_ELG; + else if (is_RSA (algo)) + algo = GCRY_PK_RSA; if (gcry_pk_algo_info (algo, GCRYCTL_GET_ALGO_NPKEY, NULL, &n)) n = 0; @@ -1399,6 +1401,8 @@ pubkey_get_nskey (int algo) /* All other algorithms match those of Libgcrypt. */ if (algo == GCRY_PK_ELG_E) algo = GCRY_PK_ELG; + else if (is_RSA (algo)) + algo = GCRY_PK_RSA; if (gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NSKEY, NULL, &n )) n = 0; @@ -1419,6 +1423,8 @@ pubkey_get_nsig (int algo) if (algo == GCRY_PK_ELG_E) algo = GCRY_PK_ELG; + else if (is_RSA (algo)) + algo = GCRY_PK_RSA; if (gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NSIGN, NULL, &n)) n = 0; @@ -1440,6 +1446,8 @@ pubkey_get_nenc (int algo) if (algo == GCRY_PK_ELG_E) algo = GCRY_PK_ELG; + else if (is_RSA (algo)) + algo = GCRY_PK_RSA; if (gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NENCR, NULL, &n )) n = 0;