diff options
-rw-r--r-- | cipher/ChangeLog | 62 | ||||
-rw-r--r-- | cipher/ac.c | 7 | ||||
-rw-r--r-- | cipher/arcfour.c | 2 | ||||
-rw-r--r-- | cipher/blowfish.c | 2 | ||||
-rw-r--r-- | cipher/cast5.c | 2 | ||||
-rw-r--r-- | cipher/cipher.c | 145 | ||||
-rw-r--r-- | cipher/crc.c | 6 | ||||
-rw-r--r-- | cipher/des.c | 12 | ||||
-rw-r--r-- | cipher/md.c | 128 | ||||
-rw-r--r-- | cipher/md4.c | 9 | ||||
-rw-r--r-- | cipher/md5.c | 16 | ||||
-rw-r--r-- | cipher/pubkey.c | 6 | ||||
-rw-r--r-- | cipher/rijndael.c | 33 | ||||
-rw-r--r-- | cipher/rmd160.c | 9 | ||||
-rw-r--r-- | cipher/sha1.c | 15 | ||||
-rw-r--r-- | cipher/sha256.c | 9 | ||||
-rw-r--r-- | cipher/sha512.c | 16 | ||||
-rw-r--r-- | cipher/tiger.c | 8 | ||||
-rw-r--r-- | cipher/twofish.c | 4 |
19 files changed, 349 insertions, 142 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog index 1302803e..51b745ab 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,65 @@ +2003-07-21 Moritz Schulte <moritz@g10code.com> + + * pubkey.c (gcry_pk_lookup_func_name): Use new member name + `aliases' instead of `sexp_names'. + + * ac.c (gcry_ac_key_data_get): New function. + + * cipher.c (gcry_cipher_lookup_func_name): Fix return value. + +2003-07-20 Moritz Schulte <moritz@g10code.com> + + * blowfish.c: Adjusted for new gcry_cipher_spec_t structure. + * cast5.c: Likewise. + * twofish.c: Likewise. + * arcfour.c: Likewise. + * rijndael.c (rijndael_oids, rijndael192_oids, rijndael256_oids): + New variables, adjust for new gcry_cipher_spec_t structure. + * des.c (oids_tripledes): New variable, adjust for new + gcry_cipher_spec_t structure. + + * md.c (oid_table): Removed. + + * tiger.c (oid_spec_tiger): New variable. + (digest_spec_tiger): Adjusted for new gry_md_spec_t structure. + + * sha512.c (oid_spec_sha512): New variable. + (digest_spec_sha512): Adjusted for new gry_md_spec_t structure. + + * sha512.c (oid_spec_sha384): New variable. + (digest_spec_sha384): Adjusted for new gry_md_spec_t structure. + + * sha256.c (oid_spec_sha256): New variable. + (digest_spec_sha256): Adjusted for new gry_md_spec_t structure. + + * sha1.c (oid_spec_sha1): New variable. + (digest_spec_sha1): Adjusted for new gry_md_spec_t structure. + + * rmd160.c (oid_spec_rmd160): New variable. + (digest_spec_rnd160): Adjusted for new gry_md_spec_t structure. + + * md5.c (oid_spec_md5): New variable. + (digest_spec_md5): Adjusted for new gry_md_spec_t structure. + + * md4.c (oid_spec_md4): New variable. + (digest_spec_md4): Adjusted for new gry_md_spec_t structure. + + * crc.c (digest_spec_crc32, digest_spec_crc32_rfc1510, + digest_spec_crc32_rfc2440): Adjusted for new gry_md_spec_t + structure. + +2003-07-19 Moritz Schulte <moritz@g10code.com> + + * md.c (gcry_md_lookup_func_oid): New function. + (search_oid): New function, copied from cipher.c. + (gcry_md_map_name): Adjust for new search_oid_interface. + + * cipher.c (oid_table): Removed table. + (gcry_cipher_lookup_func_oid): New function. + (search_oid): Rewritten to use the module functions. + (gcry_cipher_map_name): Adjust for new search_oid interface. + (gcry_cipher_mode_from_oid): Likewise. + 2003-07-18 Werner Koch <wk@gnupg.org> * md.c (gcry_md_hash_buffer): Convert ERR to gpg_error_t in diff --git a/cipher/ac.c b/cipher/ac.c index a14a6ef9..3da7ba41 100644 --- a/cipher/ac.c +++ b/cipher/ac.c @@ -1013,6 +1013,13 @@ gcry_ac_key_pair_destroy (gcry_ac_key_pair_t key_pair) gcry_free (key_pair); } +/* Returns the data set contained in the key KEY. */ +gcry_ac_data_t +gcry_ac_key_data_get (gcry_ac_key_t key) +{ + return key->data; +} + /* Verifies that the key KEY is sane. */ gcry_error_t gcry_ac_key_test (gcry_ac_key_t key) diff --git a/cipher/arcfour.c b/cipher/arcfour.c index 926d2f61..57c439c4 100644 --- a/cipher/arcfour.c +++ b/cipher/arcfour.c @@ -149,6 +149,6 @@ selftest(void) gcry_cipher_spec_t cipher_spec_arcfour = { - "ARCFOUR", NULL, 1, 128, sizeof (ARCFOUR_context), + "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context), arcfour_setkey, NULL, NULL, encrypt_stream, encrypt_stream, }; diff --git a/cipher/blowfish.c b/cipher/blowfish.c index 54d54f62..84d8fd6b 100644 --- a/cipher/blowfish.c +++ b/cipher/blowfish.c @@ -587,7 +587,7 @@ bf_setkey (void *context, const byte *key, unsigned keylen) gcry_cipher_spec_t cipher_spec_blowfish = { - "BLOWFISH", NULL, BLOWFISH_BLOCKSIZE, 128, + "BLOWFISH", NULL, NULL, BLOWFISH_BLOCKSIZE, 128, sizeof (BLOWFISH_context), bf_setkey, encrypt_block, decrypt_block, }; diff --git a/cipher/cast5.c b/cipher/cast5.c index 12e0d2af..01840891 100644 --- a/cipher/cast5.c +++ b/cipher/cast5.c @@ -616,6 +616,6 @@ cast_setkey (void *context, const byte *key, unsigned keylen ) gcry_cipher_spec_t cipher_spec_cast5 = { - "CAST5", NULL, CAST5_BLOCKSIZE, 128, sizeof (CAST5_context), + "CAST5", NULL, NULL, CAST5_BLOCKSIZE, 128, sizeof (CAST5_context), cast_setkey, encrypt_block, decrypt_block, }; diff --git a/cipher/cipher.c b/cipher/cipher.c index 1f2bbced..13b50403 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -34,35 +34,6 @@ #define CTX_MAGIC_NORMAL 0x24091964 #define CTX_MAGIC_SECURE 0x46919042 -static struct -{ - const char *oidstring; - int algo; - int mode; -} oid_table[] = - { - { "1.2.840.113549.3.7", GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC }, - - /* OIDs from NIST. See http://csrc.nist.gov.csor/ */ - { "2.16.840.1.101.3.4.1.1", GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB }, - { "2.16.840.1.101.3.4.1.2", GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC }, - { "2.16.840.1.101.3.4.1.3", GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_OFB }, - { "2.16.840.1.101.3.4.1.4", GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CFB }, - { "2.16.840.1.101.3.4.1.21", GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_ECB }, - { "2.16.840.1.101.3.4.1.22", GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC }, - { "2.16.840.1.101.3.4.1.23", GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_OFB }, - { "2.16.840.1.101.3.4.1.24", GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CFB }, - { "2.16.840.1.101.3.4.1.41", GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_ECB }, - { "2.16.840.1.101.3.4.1.42", GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC }, - { "2.16.840.1.101.3.4.1.43", GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_OFB }, - { "2.16.840.1.101.3.4.1.44", GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB }, - - /* Teletrust specific OID for 3DES. */ - { "1.3.36.3.1.3.2.1", GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC }, - - { NULL } - }; - /* This is the list of the default ciphers, which are included in libgcrypt. */ static struct cipher_table_entry @@ -212,11 +183,28 @@ gcry_cipher_lookup_func_name (void *spec, void *data) gcry_cipher_spec_t *cipher = (gcry_cipher_spec_t *) spec; char *name = (char *) data; const char **aliases = cipher->aliases; - int ret = stricmp (name, cipher->name), i; + int i, ret = ! stricmp (name, cipher->name); - if (ret && aliases) - for (i = 0; aliases[i] && ret; i++) - ret = stricmp (name, aliases[i]); + if (aliases) + for (i = 0; aliases[i] && (! ret); i++) + ret = ! stricmp (name, aliases[i]); + + return ret; +} + +/* Internal callback function. Used via _gcry_module_lookup. */ +static int +gcry_cipher_lookup_func_oid (void *spec, void *data) +{ + gcry_cipher_spec_t *cipher = (gcry_cipher_spec_t *) spec; + char *oid = (char *) data; + gcry_cipher_oid_spec_t *oid_specs = cipher->oids; + int ret = 0, i; + + if (oid_specs) + for (i = 0; oid_specs[i].oid && (! ret); i++) + if (! stricmp (oid, oid_specs[i].oid)) + ret = 1; return ret; } @@ -233,6 +221,18 @@ gcry_cipher_lookup_name (const char *name) return cipher; } +/* Internal function. Lookup a cipher entry by it's oid. */ +static gcry_module_t +gcry_cipher_lookup_oid (const char *oid) +{ + gcry_module_t cipher; + + cipher = _gcry_module_lookup (ciphers_registered, (void *) oid, + gcry_cipher_lookup_func_oid); + + return cipher; +} + /* Register a new cipher module whose specification can be found in CIPHER. On success, a new algorithm ID is stored in ALGORITHM_ID and a pointer representhing this module is stored in MODULE. */ @@ -271,24 +271,34 @@ gcry_cipher_unregister (gcry_module_t module) /* locate the OID in the oid table and return the index or -1 when not found */ static int -search_oid (const char *string) +search_oid (const char *oid, int *algorithm, gcry_cipher_oid_spec_t *oid_spec) { - const char *s; - int i; + gcry_module_t module; + int ret = 0; - if (string && (digitp (string) - || !strncmp (string, "oid.", 4) - || !strncmp (string, "OID.", 4) )) - { - s = digitp(string)? string : (string+4); + if (oid && ((! strncmp (oid, "oid.", 4)) + || (! strncmp (oid, "OID.", 4)))) + oid += 4; - for (i=0; oid_table[i].oidstring; i++) - { - if (!strcmp (s, oid_table[i].oidstring)) - return i; - } + module = gcry_cipher_lookup_oid (oid); + if (module) + { + gcry_cipher_spec_t *cipher = module->spec; + int i; + + for (i = 0; cipher->oids[i].oid && (! ret); i++) + if (! stricmp (oid, cipher->oids[i].oid)) + { + if (algorithm) + *algorithm = module->mod_id; + if (oid_spec) + *oid_spec = cipher->oids[i]; + ret = 1; + } + _gcry_module_release (module); } - return -1; + + return ret; } /**************** @@ -297,30 +307,33 @@ search_oid (const char *string) * 0 if the name is not known. */ int -gcry_cipher_map_name( const char *string ) +gcry_cipher_map_name (const char *string) { gcry_module_t cipher; - int i, algorithm = 0; - - if (!string) + int ret, algorithm = 0; + + if (! string) return 0; + REGISTER_DEFAULT_CIPHERS; + /* 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 */ - i = search_oid (string); - if (i != -1) - return oid_table[i].algo; - - REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); - cipher = gcry_cipher_lookup_name (string); - if (cipher) + + ret = search_oid (string, &algorithm, NULL); + if (! ret) { - algorithm = cipher->mod_id; - _gcry_module_release (cipher); + cipher = gcry_cipher_lookup_name (string); + if (cipher) + { + algorithm = cipher->mod_id; + _gcry_module_release (cipher); + } } + ath_mutex_unlock (&ciphers_registered_lock); return algorithm; @@ -329,10 +342,16 @@ gcry_cipher_map_name( const char *string ) int gcry_cipher_mode_from_oid (const char *string) { - int i; + gcry_cipher_oid_spec_t oid_spec; + int ret = 0, mode = 0; + + ath_mutex_lock (&ciphers_registered_lock); + ret = search_oid (string, NULL, &oid_spec); + if (ret) + mode = oid_spec.mode; + ath_mutex_unlock (&ciphers_registered_lock); - i = search_oid (string); - return i == -1? 0 : oid_table[i].mode; + return mode; } diff --git a/cipher/crc.c b/cipher/crc.c index f2116c16..8769a8da 100644 --- a/cipher/crc.c +++ b/cipher/crc.c @@ -273,14 +273,14 @@ crc24rfc2440_final (void *context) gcry_md_spec_t digest_spec_crc32 = { - "CRC32", NULL, 0, 4, + "CRC32", NULL, 0, NULL, 4, crc32_init, crc32_write, crc32_final, crc32_read, sizeof (CRC_CONTEXT) }; gcry_md_spec_t digest_spec_crc32_rfc1510 = { - "CRC32RFC1510", NULL, 0, 4, + "CRC32RFC1510", NULL, 0, NULL, 4, crc32rfc1510_init, crc32_write, crc32rfc1510_final, crc32_read, sizeof (CRC_CONTEXT) @@ -288,7 +288,7 @@ gcry_md_spec_t digest_spec_crc32_rfc1510 = gcry_md_spec_t digest_spec_crc24_rfc2440 = { - "CRC24RFC2440", NULL, 0, 3, + "CRC24RFC2440", NULL, 0, NULL, 3, crc24rfc2440_init, crc24rfc2440_write, crc24rfc2440_final, crc32_read, sizeof (CRC_CONTEXT) diff --git a/cipher/des.c b/cipher/des.c index a38b4f46..c408d851 100644 --- a/cipher/des.c +++ b/cipher/des.c @@ -1068,12 +1068,20 @@ do_des_decrypt( void *context, byte *outbuf, const byte *inbuf ) gcry_cipher_spec_t cipher_spec_des = { - "DES", NULL, 8, 64, sizeof (struct _des_ctx), + "DES", NULL, NULL, 8, 64, sizeof (struct _des_ctx), do_des_setkey, do_des_encrypt, do_des_decrypt }; +static gcry_cipher_oid_spec_t oids_tripledes[] = + { + { "1.2.840.113549.3.7", GCRY_CIPHER_MODE_CBC }, + /* Teletrust specific OID for 3DES. */ + { "1.3.36.3.1.3.2.1", GCRY_CIPHER_MODE_CBC }, + { NULL } + }; + gcry_cipher_spec_t cipher_spec_tripledes = { - "3DES", NULL, 8, 192, sizeof (struct _tripledes_ctx), + "3DES", NULL, oids_tripledes, 8, 192, sizeof (struct _tripledes_ctx), do_tripledes_setkey, do_tripledes_encrypt, do_tripledes_decrypt }; diff --git a/cipher/md.c b/cipher/md.c index 461fe9a8..92994b49 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -31,35 +31,6 @@ #include "rmd.h" -static struct { - const char *oidstring; - int algo; -} oid_table[] = { - /* iso.member-body.us.rsadsi.pkcs.pkcs-1.5 (sha1WithRSAEncryption) */ - { "1.2.840.113549.1.1.5", GCRY_MD_SHA1 }, - /* iso.member-body.us.rsadsi.pkcs.pkcs-1.4 (md5WithRSAEncryption) */ - { "1.2.840.113549.1.1.4", GCRY_MD_MD5 }, - /* iso.member-body.us.x9-57.x9cm.3 (dsaWithSha1)*/ - { "1.2.840.10040.4.3", GCRY_MD_SHA1 }, - /* from NIST's OIW (sha1) */ - { "1.3.14.3.2.26", GCRY_MD_SHA1 }, - /* rsaSignatureWithripemd160 */ - { "1.3.36.3.3.1.2", GCRY_MD_RMD160 }, - /* RSADSI digestAlgorithm MD5 */ - { "1.2.840.113549.2.5", GCRY_MD_MD5 }, - /* GNU.digestAlgorithm TIGER */ - { "1.3.6.1.4.1.11591.12.2", GCRY_MD_TIGER }, - /* iso.member-body.us.rsadsi.digestAlgorithm.md4 */ - { "1.2.840.113549.2.4", GCRY_MD_MD4 }, - /* from NIST OIW (sha-1WithRSAEncryption) */ - { "1.3.14.3.2.29", GCRY_MD_SHA1 }, - /* According to the OpenPGG draft rfc2440-bis06 */ - { "2.16.840.1.101.3.4.2.1", GCRY_MD_SHA256 }, - { "2.16.840.1.101.3.4.2.2", GCRY_MD_SHA384 }, - { "2.16.840.1.101.3.4.2.3", GCRY_MD_SHA512 }, - {NULL} -}; - static struct digest_table_entry { gcry_md_spec_t *digest; @@ -148,6 +119,22 @@ gcry_md_lookup_func_name (void *spec, void *data) return (! stricmp (digest->name, name)); } +/* Internal callback function. Used via _gcry_module_lookup. */ +static int +gcry_md_lookup_func_oid (void *spec, void *data) +{ + gcry_md_spec_t *digest = (gcry_md_spec_t *) spec; + char *oid = (char *) data; + gcry_md_oid_spec_t *oid_specs = digest->oids; + int ret = 0, i; + + for (i = 0; oid_specs[i].oidstring && (! ret); i++) + if (! stricmp (oid, oid_specs[i].oidstring)) + ret = 1; + + return ret; +} + /* Internal function. Lookup a digest entry by it's name. */ static gcry_module_t gcry_md_lookup_name (const char *name) @@ -160,6 +147,18 @@ gcry_md_lookup_name (const char *name) return digest; } +/* Internal function. Lookup a cipher entry by it's oid. */ +static gcry_module_t +gcry_md_lookup_oid (const char *oid) +{ + gcry_module_t digest; + + digest = _gcry_module_lookup (digests_registered, (void *) oid, + gcry_md_lookup_func_oid); + + return digest; +} + /* Register a new digest module whose specification can be found in DIGEST. On success, a new algorithm ID is stored in ALGORITHM_ID and a pointer representhing this module is stored in MODULE. */ @@ -233,6 +232,37 @@ static const byte *md_asn_oid( int algo, size_t *asnlen, size_t *mdlen ); static void md_start_debug( gcry_md_hd_t a, const char *suffix ); static void md_stop_debug( gcry_md_hd_t a ); +static int +search_oid (const char *oid, int *algorithm, gcry_md_oid_spec_t *oid_spec) +{ + gcry_module_t module; + int ret = 0; + + if (oid && ((! strncmp (oid, "oid.", 4)) + || (! strncmp (oid, "OID.", 4)))) + oid += 4; + + module = gcry_md_lookup_oid (oid); + if (module) + { + gcry_md_spec_t *digest = module->spec; + int i; + + for (i = 0; digest->oids[i].oidstring && (! ret); i++) + if (! stricmp (oid, digest->oids[i].oidstring)) + { + if (algorithm) + *algorithm = module->mod_id; + if (oid_spec) + *oid_spec = digest->oids[i]; + ret = 1; + } + _gcry_module_release (module); + } + + return ret; +} + /**************** * Map a string to the digest algo */ @@ -240,37 +270,29 @@ int gcry_md_map_name (const char *string) { gcry_module_t digest; - int algorithm = 0; + int ret, algorithm = 0; - if (!string) + if (! string) return 0; + REGISTER_DEFAULT_DIGESTS; + /* 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; - } - } - - - REGISTER_DEFAULT_DIGESTS; ath_mutex_lock (&digests_registered_lock); - digest = gcry_md_lookup_name (string); - if (digest) + + ret = search_oid (string, &algorithm, NULL); + if (! ret) { - algorithm = digest->mod_id; - _gcry_module_release (digest); + /* Not found, search for an acording diget name. */ + digest = gcry_md_lookup_name (string); + if (digest) + { + algorithm = digest->mod_id; + _gcry_module_release (digest); + } } ath_mutex_unlock (&digests_registered_lock); @@ -1035,8 +1057,10 @@ gcry_md_algo_info (int algo, int what, void *buffer, size_t *nbytes) case GCRYCTL_GET_ASNOID: { + const char unsigned *asn; size_t asnlen; - const char *asn = md_asn_oid (algo, &asnlen, NULL); + + asn = md_asn_oid (algo, &asnlen, NULL); if (buffer && (*nbytes >= asnlen)) { memcpy (buffer, asn, asnlen); diff --git a/cipher/md4.c b/cipher/md4.c index 42f85e38..4a3edd76 100644 --- a/cipher/md4.c +++ b/cipher/md4.c @@ -303,9 +303,16 @@ static byte asn[18] = /* Object ID is 1.2.840.113549.2.4 */ { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48, 0x86, 0xf7, 0x0d, 0x02, 0x04, 0x05, 0x00, 0x04, 0x10 }; +static gcry_md_oid_spec_t oid_spec_md4[] = + { + /* iso.member-body.us.rsadsi.digestAlgorithm.md4 */ + { "1.2.840.113549.2.4" }, + { NULL }, + }; + gcry_md_spec_t digest_spec_md4 = { - "MD4", asn, DIM (asn), 16, + "MD4", asn, DIM (asn), oid_spec_md4,16, md4_init, md4_write, md4_final, md4_read, sizeof (MD4_CONTEXT) }; diff --git a/cipher/md5.c b/cipher/md5.c index 31159d2f..808cfba0 100644 --- a/cipher/md5.c +++ b/cipher/md5.c @@ -324,14 +324,22 @@ md5_read( void *context ) return hd->buf; } - static byte asn[18] = /* Object ID is 1.2.840.113549.2.5 */ - { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48, - 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 }; +static byte asn[18] = /* Object ID is 1.2.840.113549.2.5 */ + { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48, + 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 }; +static gcry_md_oid_spec_t oid_spec_md5[] = + { + /* iso.member-body.us.rsadsi.pkcs.pkcs-1.4 (md5WithRSAEncryption) */ + { "1.2.840.113549.1.1.4" }, + /* RSADSI digestAlgorithm MD5 */ + { "1.2.840.113549.2.5" }, + { NULL }, + }; gcry_md_spec_t digest_spec_md5 = { - "MD5", asn, DIM (asn), 16, + "MD5", asn, DIM (asn), oid_spec_md5, 16, md5_init, md5_write, md5_final, md5_read, sizeof (MD5_CONTEXT) }; diff --git a/cipher/pubkey.c b/cipher/pubkey.c index 2dcfb239..eb760399 100644 --- a/cipher/pubkey.c +++ b/cipher/pubkey.c @@ -170,11 +170,11 @@ gcry_pk_lookup_func_name (void *spec, void *data) { gcry_pk_spec_t *pubkey = (gcry_pk_spec_t *) spec; char *name = (char *) data; - char **sexp_names = pubkey->sexp_names; + char **aliases = pubkey->aliases; int ret = stricmp (name, pubkey->name); - while (ret && *sexp_names) - ret = stricmp (name, *sexp_names++); + while (ret && *aliases) + ret = stricmp (name, *aliases++); return ! ret; } diff --git a/cipher/rijndael.c b/cipher/rijndael.c index 4e57d6b9..b2b50d89 100644 --- a/cipher/rijndael.c +++ b/cipher/rijndael.c @@ -2137,9 +2137,18 @@ static const char *rijndael_names[] = NULL, }; +static gcry_cipher_oid_spec_t rijndael_oids[] = + { + { "2.16.840.1.101.3.4.1.1", GCRY_CIPHER_MODE_ECB }, + { "2.16.840.1.101.3.4.1.2", GCRY_CIPHER_MODE_CBC }, + { "2.16.840.1.101.3.4.1.3", GCRY_CIPHER_MODE_OFB }, + { "2.16.840.1.101.3.4.1.4", GCRY_CIPHER_MODE_CFB }, + { NULL } + }; + gcry_cipher_spec_t cipher_spec_aes = { - "AES", rijndael_names, 16, 128, sizeof (RIJNDAEL_context), + "AES", rijndael_names, rijndael_oids, 16, 128, sizeof (RIJNDAEL_context), rijndael_setkey, rijndael_encrypt, rijndael_decrypt, }; @@ -2149,9 +2158,18 @@ static const char *rijndael192_names[] = NULL, }; +static gcry_cipher_oid_spec_t rijndael192_oids[] = + { + { "2.16.840.1.101.3.4.1.21", GCRY_CIPHER_MODE_ECB }, + { "2.16.840.1.101.3.4.1.22", GCRY_CIPHER_MODE_CBC }, + { "2.16.840.1.101.3.4.1.23", GCRY_CIPHER_MODE_OFB }, + { "2.16.840.1.101.3.4.1.24", GCRY_CIPHER_MODE_CFB }, + { NULL } + }; + gcry_cipher_spec_t cipher_spec_aes192 = { - "AES192", rijndael192_names, 16, 192, sizeof (RIJNDAEL_context), + "AES192", rijndael192_names, rijndael192_oids, 16, 192, sizeof (RIJNDAEL_context), rijndael_setkey, rijndael_encrypt, rijndael_decrypt, }; @@ -2161,8 +2179,17 @@ static const char *rijndael256_names[] = NULL, }; +static gcry_cipher_oid_spec_t rijndael256_oids[] = + { + { "2.16.840.1.101.3.4.1.41", GCRY_CIPHER_MODE_ECB }, + { "2.16.840.1.101.3.4.1.42", GCRY_CIPHER_MODE_CBC }, + { "2.16.840.1.101.3.4.1.43", GCRY_CIPHER_MODE_OFB }, + { "2.16.840.1.101.3.4.1.44", GCRY_CIPHER_MODE_CFB }, + { NULL } + }; + gcry_cipher_spec_t cipher_spec_aes256 = { - "AES256", rijndael256_names, 16, 256, sizeof (RIJNDAEL_context), + "AES256", rijndael256_names, rijndael256_oids, 16, 256, sizeof (RIJNDAEL_context), rijndael_setkey, rijndael_encrypt, rijndael_decrypt, }; diff --git a/cipher/rmd160.c b/cipher/rmd160.c index b06702b3..5b3ea2dd 100644 --- a/cipher/rmd160.c +++ b/cipher/rmd160.c @@ -543,9 +543,16 @@ static byte asn[15] = /* Object ID is 1.3.36.3.2.1 */ { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 }; +static gcry_md_oid_spec_t oid_spec_rmd160[] = + { + /* rsaSignatureWithripemd160 */ + { "1.3.36.3.3.1.2" }, + { NULL }, + }; + gcry_md_spec_t digest_spec_rmd160 = { - "RIPEMD160", asn, DIM (asn), 20, + "RIPEMD160", asn, DIM (asn), oid_spec_rmd160, 20, _gcry_rmd160_init, rmd160_write, rmd160_final, rmd160_read, sizeof (RMD160_CONTEXT) }; diff --git a/cipher/sha1.c b/cipher/sha1.c index bb223644..ae584864 100644 --- a/cipher/sha1.c +++ b/cipher/sha1.c @@ -319,9 +319,22 @@ static byte asn[15] = /* Object ID is 1.3.14.3.2.26 */ { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 }; +static gcry_md_oid_spec_t oid_spec_sha1[] = + { + /* iso.member-body.us.rsadsi.pkcs.pkcs-1.5 (sha1WithRSAEncryption) */ + { "1.2.840.113549.1.1.5" }, + /* iso.member-body.us.x9-57.x9cm.3 (dsaWithSha1)*/ + { "1.2.840.10040.4.3" }, + /* from NIST's OIW (sha1) */ + { "1.3.14.3.2.26" }, + /* from NIST OIW (sha-1WithRSAEncryption) */ + { "1.3.14.3.2.29" }, + { NULL }, + }; + gcry_md_spec_t digest_spec_sha1 = { - "SHA1", asn, DIM (asn), 20, + "SHA1", asn, DIM (asn), oid_spec_sha1, 20, sha1_init, sha1_write, sha1_final, sha1_read, sizeof (SHA1_CONTEXT) }; diff --git a/cipher/sha256.c b/cipher/sha256.c index 8b92d317..b1a0d87e 100644 --- a/cipher/sha256.c +++ b/cipher/sha256.c @@ -293,9 +293,16 @@ static byte asn[19] = /* Object ID is 2.16.840.1.101.3.4.2.1 */ 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 }; +static gcry_md_oid_spec_t oid_spec_sha256[] = + { + /* According to the OpenPGG draft rfc2440-bis06 */ + { "2.16.840.1.101.3.4.2.1" }, + { NULL }, + }; + gcry_md_spec_t digest_spec_sha256 = { - "SHA256", asn, DIM (asn), 32, + "SHA256", asn, DIM (asn), oid_spec_sha256, 32, sha256_init, sha256_write, sha256_final, sha256_read, sizeof (SHA256_CONTEXT) }; diff --git a/cipher/sha512.c b/cipher/sha512.c index 7daca350..cdb6c392 100644 --- a/cipher/sha512.c +++ b/cipher/sha512.c @@ -367,8 +367,14 @@ static byte sha512_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.3 */ 0x00, 0x04, 0x40 }; +static gcry_md_oid_spec_t oid_spec_sha512[] = + { + { "2.16.840.1.101.3.4.2.3" }, + { NULL } + }; + gcry_md_spec_t digest_spec_sha512 = { - "SHA512", sha512_asn, DIM (sha512_asn), 64, + "SHA512", sha512_asn, DIM (sha512_asn), oid_spec_sha512, 64, sha512_init, sha512_write, sha512_final, sha512_read, sizeof (SHA512_CONTEXT), }; @@ -380,8 +386,14 @@ static byte sha384_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.2 */ 0x00, 0x04, 0x30 }; +static gcry_md_oid_spec_t oid_spec_sha384[] = + { + { "2.16.840.1.101.3.4.2.2" }, + { NULL }, + }; + gcry_md_spec_t digest_spec_sha384 = { - "SHA384", sha384_asn, DIM (sha384_asn), 48, + "SHA384", sha384_asn, DIM (sha384_asn), oid_spec_sha384, 48, sha384_init, sha512_write, sha512_final, sha512_read, sizeof (SHA512_CONTEXT), }; diff --git a/cipher/tiger.c b/cipher/tiger.c index 2115e964..9ec3a769 100644 --- a/cipher/tiger.c +++ b/cipher/tiger.c @@ -826,10 +826,16 @@ static byte asn[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */ 0x01, 0x04, 0x01, 0xda, 0x47, 0x0c, 0x02, 0x05, 0x00, 0x04, 0x18 }; +static gcry_md_oid_spec_t oid_spec_tiger[] = + { + /* GNU.digestAlgorithm TIGER */ + { "1.3.6.1.4.1.11591.12.2" }, + { NULL } + }; gcry_md_spec_t digest_spec_tiger = { - "TIGER192", asn, DIM (asn), 24, + "TIGER192", asn, DIM (asn), oid_spec_tiger, 24, tiger_init, tiger_write, tiger_final, tiger_read, sizeof (TIGER_CONTEXT) }; diff --git a/cipher/twofish.c b/cipher/twofish.c index 704c45c5..157aa43a 100644 --- a/cipher/twofish.c +++ b/cipher/twofish.c @@ -1021,12 +1021,12 @@ main() gcry_cipher_spec_t cipher_spec_twofish = { - "TWOFISH", NULL, 16, 256, sizeof (TWOFISH_context), + "TWOFISH", NULL, NULL, 16, 256, sizeof (TWOFISH_context), twofish_setkey, twofish_encrypt, twofish_decrypt, }; gcry_cipher_spec_t cipher_spec_twofish128 = { - "TWOFISH128", NULL, 16, 128, sizeof (TWOFISH_context), + "TWOFISH128", NULL, NULL, 16, 128, sizeof (TWOFISH_context), twofish_setkey, twofish_encrypt, twofish_decrypt, }; |