summaryrefslogtreecommitdiff
path: root/cipher
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2001-12-06 20:42:18 +0000
committerWerner Koch <wk@gnupg.org>2001-12-06 20:42:18 +0000
commitebcbc6ae00e75a25a5ab8308592aed210d8f1668 (patch)
treea817d35eaafe7d83eca6128aa897023cb8f22f50 /cipher
parentaaa6672e8ffa96a62aaf8296ea8b3ae95ca58818 (diff)
downloadlibgcrypt-ebcbc6ae00e75a25a5ab8308592aed210d8f1668.tar.gz
* cipher.c (gcry_cipher_map_name): Look also for OIDs prefixed
with "oid." or "OID.".
Diffstat (limited to 'cipher')
-rw-r--r--cipher/ChangeLog9
-rw-r--r--cipher/cipher.c32
-rw-r--r--cipher/pubkey.c2
-rw-r--r--cipher/rsa.c55
4 files changed, 71 insertions, 27 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 855d1c17..ef5e1e3d 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,12 @@
+2001-12-06 Werner Koch <wk@gnupg.org>
+
+ * cipher.c (gcry_cipher_map_name): Look also for OIDs prefixed
+ with "oid." or "OID.".
+
+2001-12-05 Werner Koch <wk@gnupg.org>
+
+ * pubkey.c (algo_info_table): Fixed entry for openpgp-rsa.
+
2001-11-24 Werner Koch <wk@gnupg.org>
* pubkey.c: Added the rsaEncryption OID to the tables.
diff --git a/cipher/cipher.c b/cipher/cipher.c
index a5afdc01..1cd5a65b 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -38,6 +38,17 @@
#define CTX_MAGIC_NORMAL 0x24091964
#define CTX_MAGIC_SECURE 0x46919042
+#define digitp(p) (*(p) >= 0 && *(p) <= '9')
+
+static struct {
+ const char *oidstring;
+ int algo;
+} oid_table[] = {
+ { "1.2.840.113549.3.7", GCRY_CIPHER_3DES /* des-EDE3-CBC*/},
+ {NULL}
+};
+
+
struct cipher_table_s {
const char *name;
int algo;
@@ -281,6 +292,26 @@ gcry_cipher_map_name( const char *string )
int i;
const char *s;
+ if (!string)
+ return 0;
+
+ /* If the string starts with a digit (optionally prefixed with
+ either "OID." or "oid."), we first look into our table of ASN.1
+ object identifiers to figure out the algorithm */
+ if (digitp (string)
+ || !strncmp (string, "oid.", 4)
+ || !strncmp (string, "OID.", 4) )
+ {
+ int i;
+ const char *s = digitp(string)? string : (string+4);
+
+ for (i=0; oid_table[i].oidstring; i++)
+ {
+ if (!strcmp (s, oid_table[i].oidstring))
+ return oid_table[i].algo;
+ }
+ }
+
do {
for(i=0; (s=cipher_table[i].name); i++ )
if( !stricmp( s, string ) )
@@ -289,6 +320,7 @@ gcry_cipher_map_name( const char *string )
return 0;
}
+
/****************
* Map a cipher algo to a string
*/
diff --git a/cipher/pubkey.c b/cipher/pubkey.c
index 5bc663ad..0e8f2ecd 100644
--- a/cipher/pubkey.c
+++ b/cipher/pubkey.c
@@ -67,7 +67,7 @@ static struct { const char* name; int algo;
{ "rsa" , PUBKEY_ALGO_RSA , "ne", "", "dpqu" },
{ "elg" , PUBKEY_ALGO_ELGAMAL , "pgy", "", "x" },
{ "openpgp-dsa" , PUBKEY_ALGO_DSA , "pqgy", "", "x" },
- { "openpgp-rsa" , PUBKEY_ALGO_RSA , "pqgy", "", "x" },
+ { "openpgp-rsa" , PUBKEY_ALGO_RSA , "ne", "", "dpqu" },
{ "openpgp-elg" , PUBKEY_ALGO_ELGAMAL_E , "pgy", "", "x" },
{ "openpgp-elg-sig", PUBKEY_ALGO_ELGAMAL , "pgy", "", "x" },
{ "oid.1.2.840.113549.1.1.1", PUBKEY_ALGO_RSA , "ne", "", "dpqu" },
diff --git a/cipher/rsa.c b/cipher/rsa.c
index e5ad116c..51310ad6 100644
--- a/cipher/rsa.c
+++ b/cipher/rsa.c
@@ -202,20 +202,22 @@ public(MPI output, MPI input, RSA_public_key *pkey )
static void
stronger_key_check ( RSA_secret_key *skey )
{
- MPI t = mpi_alloc_secure ( 0 );
- MPI t1 = mpi_alloc_secure ( 0 );
- MPI t2 = mpi_alloc_secure ( 0 );
- MPI phi = mpi_alloc_secure ( 0 );
-
- /* check that n == p * q */
- mpi_mul( t, skey->p, skey->q);
- if (mpi_cmp( t, skey->n) )
- log_info ( "RSA Oops: n != p * q\n" );
-
- /* check that p is less than q */
- if( mpi_cmp( skey->p, skey->q ) > 0 )
- log_info ("RSA Oops: p >= q\n");
-
+ MPI t = mpi_alloc_secure ( 0 );
+ MPI t1 = mpi_alloc_secure ( 0 );
+ MPI t2 = mpi_alloc_secure ( 0 );
+ MPI phi = mpi_alloc_secure ( 0 );
+
+ /* check that n == p * q */
+ mpi_mul( t, skey->p, skey->q);
+ if (mpi_cmp( t, skey->n) )
+ log_info ( "RSA Oops: n != p * q\n" );
+
+ /* check that p is less than q */
+ if( mpi_cmp( skey->p, skey->q ) > 0 )
+ {
+ log_info ("RSA Oops: p >= q - fixed\n");
+ _gcry_mpi_swap ( skey->p, skey->q);
+ }
/* check that e divides neither p-1 nor q-1 */
mpi_sub_ui(t, skey->p, 1 );
@@ -231,17 +233,25 @@ stronger_key_check ( RSA_secret_key *skey )
mpi_sub_ui( t1, skey->p, 1 );
mpi_sub_ui( t2, skey->q, 1 );
mpi_mul( phi, t1, t2 );
- mpi_gcd(t, t1, t2);
+ gcry_mpi_gcd(t, t1, t2);
mpi_fdiv_q(t, phi, t);
mpi_invm(t, skey->e, t );
if ( mpi_cmp(t, skey->d ) )
- log_info ( "RSA Oops: d is wrong\n");
+ {
+ log_info ( "RSA Oops: d is wrong - fixed\n");
+ mpi_set (skey->d, t);
+ _gcry_log_mpidump (" fixed d", skey->d);
+ }
- /* check for crrectness of u */
+ /* check for correctness of u */
mpi_invm(t, skey->p, skey->q );
if ( mpi_cmp(t, skey->u ) )
- log_info ( "RSA Oops: u is wrong\n");
-
+ {
+ log_info ( "RSA Oops: u is wrong - fixed\n");
+ mpi_set (skey->u, t);
+ _gcry_log_mpidump (" fixed u", skey->u);
+ }
+
log_info ( "RSA secret key check finished\n");
mpi_free (t);
@@ -459,10 +469,3 @@ _gcry_rsa_get_info( int algo,
default:*usage = 0; return NULL;
}
}
-
-
-
-
-
-
-