diff options
author | Moritz Schulte <mo@g10code.com> | 2003-06-18 14:20:45 +0000 |
---|---|---|
committer | Moritz Schulte <mo@g10code.com> | 2003-06-18 14:20:45 +0000 |
commit | d5538dc80d1fdc068c85ccddeb697e401dfad6ac (patch) | |
tree | 13a6e911fda10a2de32f9a0f794c02238dd23258 | |
parent | dea9ff10aa63a0255aea0533fd23a3a57f93ab87 (diff) | |
download | libgcrypt-d5538dc80d1fdc068c85ccddeb697e401dfad6ac.tar.gz |
2003-06-18 Moritz Schulte <moritz@g10code.com>
* arcfour.c, cipher.c, blowfish.c, md.c, cast5.c, pubkey.c, crc.c,
des.c, dsa.c, elgamal.c, md4.c, md5.c, random.c, rijndael.c,
rmd160.c, rsa.c, sha1.c, sha256.c, sha512.c, tiger.c, twofish.c:
Replaced older types GcryDigestSpec, GcryCipherSpec and
GcryPubkeySpec with newer types: gcry_digest_spec_t,
gcry_cipher_spec_t and gcry_pubkey_spec_t.
* md.c (gcry_digest_id_new): Removed function.
(gcry_digest_register): Removed code for generating a new module
ID.
* pubkey.c (gcry_pubkey_id_new): Removed function.
(gcry_pubkey_register): Removed code for generating a new module
ID.
* cipher.c, md.c, pubkey.c: Replace old type GcryModule with newer
one: gcry_module_t.
(gcry_cipher_id_new): Removed function.
(gcry_cipher_register): Removed code for generating a new module
ID.
* cipher.c (gcry_cipher_register): Adjust call to
_gcry_module_add.
(gcry_cipher_register_default): Likewise.
* pubkey.c (gcry_pubkey_register_default): Likewise.
(gcry_pubkey_register): Likewise.
* md.c (gcry_digest_register_default): Likewise.
(gcry_digest_register): Likewise.
* md.c (gcry_digest_lookup_func_id): Removed function.
(gcry_digest_lookup_id): Likewise.
(gcry_digest_id_new): Use _gcry_module_lookup_id instead of
gcry_digest_lookup_id.
(digest_algo_to_string): Likewise.
(check_digest_algo): Likewise.
(md_enable): Likewise.
(md_digest_length): Likewise.
(md_asn_oid): Likewise.
* pubkey.c (gcry_pubkey_lookup_id): Removed function.
(gcry_pubkey_lookup_func_id): Likewise.
(gcry_pubkey_id_new): Use _gcry_module_lookup_id instead of
gcry_pubkey_id_new.
(gcry_pk_algo_name): Likewise.
(disable_pubkey_algo): Likewise.
(check_pubkey_algo): Likewise.
(pubkey_get_npkey): Likewise.
(pubkey_get_nskey): Likewise.
(pubkey_get_nsig): Likewise.
(pubkey_get_nenc): Likewise.
(pubkey_generate): Likewise.
(pubkey_check_secret_key): Likewise.
(pubkey_encrypt): Likewise.
(pubkey_decrypt): Likewise.
(pubkey_sign): Likewise.
(pubkey_verify): Likewise.
(gcry_pk_algo_info): Likewise.
* cipher.c (gcry_cipher_lookup_func_id): Removed function.
(gcry_cipher_lookup_id): Likewise.
(cipher_algo_to_string): use _gcry_module_lookup_id instead of
gcry_cipher_lookup_id.
(disable_cipher_algo): Likewise.
(check_cipher_algo): Likewise.
(cipher_get_blocksize): Likewise.
(gcry_cipher_open): Likewise.
(gcry_cipher_id_new): Likewise.
-rw-r--r-- | cipher/ChangeLog | 70 | ||||
-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 | 115 | ||||
-rw-r--r-- | cipher/crc.c | 6 | ||||
-rw-r--r-- | cipher/des.c | 4 | ||||
-rw-r--r-- | cipher/dsa.c | 2 | ||||
-rw-r--r-- | cipher/elgamal.c | 2 | ||||
-rw-r--r-- | cipher/md.c | 112 | ||||
-rw-r--r-- | cipher/md4.c | 2 | ||||
-rw-r--r-- | cipher/md5.c | 2 | ||||
-rw-r--r-- | cipher/pubkey.c | 242 | ||||
-rw-r--r-- | cipher/rijndael.c | 6 | ||||
-rw-r--r-- | cipher/rmd160.c | 2 | ||||
-rw-r--r-- | cipher/rsa.c | 2 | ||||
-rw-r--r-- | cipher/sha1.c | 2 | ||||
-rw-r--r-- | cipher/sha256.c | 2 | ||||
-rw-r--r-- | cipher/sha512.c | 4 | ||||
-rw-r--r-- | cipher/tiger.c | 2 | ||||
-rw-r--r-- | cipher/twofish.c | 4 |
21 files changed, 268 insertions, 319 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog index b147d670..447251df 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,73 @@ +2003-06-18 Moritz Schulte <moritz@g10code.com> + + * arcfour.c, cipher.c, blowfish.c, md.c, cast5.c, pubkey.c, crc.c, + des.c, dsa.c, elgamal.c, md4.c, md5.c, random.c, rijndael.c, + rmd160.c, rsa.c, sha1.c, sha256.c, sha512.c, tiger.c, twofish.c: + Replaced older types GcryDigestSpec, GcryCipherSpec and + GcryPubkeySpec with newer types: gcry_digest_spec_t, + gcry_cipher_spec_t and gcry_pubkey_spec_t. + + * md.c (gcry_digest_id_new): Removed function. + (gcry_digest_register): Removed code for generating a new module + ID. + + * pubkey.c (gcry_pubkey_id_new): Removed function. + (gcry_pubkey_register): Removed code for generating a new module + ID. + + * cipher.c, md.c, pubkey.c: Replace old type GcryModule with newer + one: gcry_module_t. + (gcry_cipher_id_new): Removed function. + (gcry_cipher_register): Removed code for generating a new module + ID. + + * cipher.c (gcry_cipher_register): Adjust call to + _gcry_module_add. + (gcry_cipher_register_default): Likewise. + * pubkey.c (gcry_pubkey_register_default): Likewise. + (gcry_pubkey_register): Likewise. + * md.c (gcry_digest_register_default): Likewise. + (gcry_digest_register): Likewise. + + * md.c (gcry_digest_lookup_func_id): Removed function. + (gcry_digest_lookup_id): Likewise. + (gcry_digest_id_new): Use _gcry_module_lookup_id instead of + gcry_digest_lookup_id. + (digest_algo_to_string): Likewise. + (check_digest_algo): Likewise. + (md_enable): Likewise. + (md_digest_length): Likewise. + (md_asn_oid): Likewise. + + * pubkey.c (gcry_pubkey_lookup_id): Removed function. + (gcry_pubkey_lookup_func_id): Likewise. + (gcry_pubkey_id_new): Use _gcry_module_lookup_id instead of + gcry_pubkey_id_new. + (gcry_pk_algo_name): Likewise. + (disable_pubkey_algo): Likewise. + (check_pubkey_algo): Likewise. + (pubkey_get_npkey): Likewise. + (pubkey_get_nskey): Likewise. + (pubkey_get_nsig): Likewise. + (pubkey_get_nenc): Likewise. + (pubkey_generate): Likewise. + (pubkey_check_secret_key): Likewise. + (pubkey_encrypt): Likewise. + (pubkey_decrypt): Likewise. + (pubkey_sign): Likewise. + (pubkey_verify): Likewise. + (gcry_pk_algo_info): Likewise. + + * cipher.c (gcry_cipher_lookup_func_id): Removed function. + (gcry_cipher_lookup_id): Likewise. + (cipher_algo_to_string): use _gcry_module_lookup_id instead of + gcry_cipher_lookup_id. + (disable_cipher_algo): Likewise. + (check_cipher_algo): Likewise. + (cipher_get_blocksize): Likewise. + (gcry_cipher_open): Likewise. + (gcry_cipher_id_new): Likewise. + 2003-06-17 Moritz Schulte <moritz@g10code.com> * Makefile.am (GCRYPT_MODULES): Set to @GCRYPT_CIPHERS@, diff --git a/cipher/arcfour.c b/cipher/arcfour.c index d243414f..90d66985 100644 --- a/cipher/arcfour.c +++ b/cipher/arcfour.c @@ -147,7 +147,7 @@ selftest(void) -GcryCipherSpec cipher_spec_arcfour = +gcry_cipher_spec_t cipher_spec_arcfour = { "ARCFOUR", GCRY_CIPHER_ARCFOUR, 1, 128, sizeof (ARCFOUR_context), arcfour_setkey, NULL, NULL, encrypt_stream, encrypt_stream, diff --git a/cipher/blowfish.c b/cipher/blowfish.c index 59ac9001..f5eb513a 100644 --- a/cipher/blowfish.c +++ b/cipher/blowfish.c @@ -585,7 +585,7 @@ bf_setkey (void *context, const byte *key, unsigned keylen) -GcryCipherSpec cipher_spec_blowfish = +gcry_cipher_spec_t cipher_spec_blowfish = { "BLOWFISH", GCRY_CIPHER_BLOWFISH, BLOWFISH_BLOCKSIZE, 128, sizeof (BLOWFISH_context), diff --git a/cipher/cast5.c b/cipher/cast5.c index 8131c405..fb590d0b 100644 --- a/cipher/cast5.c +++ b/cipher/cast5.c @@ -614,7 +614,7 @@ cast_setkey (void *context, const byte *key, unsigned keylen ) } -GcryCipherSpec cipher_spec_cast5 = +gcry_cipher_spec_t cipher_spec_cast5 = { "CAST5", GCRY_CIPHER_CAST5, CAST5_BLOCKSIZE, 128, sizeof (CAST5_context), cast_setkey, encrypt_block, decrypt_block, diff --git a/cipher/cipher.c b/cipher/cipher.c index aa012646..3cc509d8 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -67,7 +67,7 @@ static struct libgcrypt. */ static struct { - GcryCipherSpec *cipher; + gcry_cipher_spec_t *cipher; } cipher_table[] = { #if USE_BLOWFISH @@ -96,7 +96,7 @@ static struct }; /* List of registered ciphers. */ -static GcryModule *ciphers_registered; +static gcry_module_t *ciphers_registered; /* This is the lock protecting CIPHERS_REGISTERED. */ static ath_mutex_t ciphers_registered_lock = ATH_MUTEX_INITIALIZER; @@ -181,6 +181,7 @@ gcry_cipher_register_default (void) cipher_table[i].cipher->stdecrypt = dummy_decrypt_stream; err = _gcry_module_add (&ciphers_registered, + cipher_table[i].cipher->id, (void *) cipher_table[i].cipher, NULL); } @@ -191,41 +192,19 @@ gcry_cipher_register_default (void) /* Internal callback function. Used via _gcry_module_lookup. */ static int -gcry_cipher_lookup_func_id (void *spec, void *data) -{ - GcryCipherSpec *cipher = (GcryCipherSpec *) spec; - int id = *((int *) data); - - return (cipher->id == id); -} - -/* Internal callback function. Used via _gcry_module_lookup. */ -static int gcry_cipher_lookup_func_name (void *spec, void *data) { - GcryCipherSpec *cipher = (GcryCipherSpec *) spec; + gcry_cipher_spec_t *cipher = (gcry_cipher_spec_t *) spec; char *name = (char *) data; return (! stricmp (cipher->name, name)); } -/* Internal function. Lookup a cipher entry by it's ID. */ -static GcryModule * -gcry_cipher_lookup_id (int id) -{ - GcryModule *cipher; - - cipher = _gcry_module_lookup (ciphers_registered, (void *) &id, - gcry_cipher_lookup_func_id); - - return cipher; -} - /* Internal function. Lookup a cipher entry by it's name. */ -static GcryModule * +static gcry_module_t * gcry_cipher_lookup_name (const char *name) { - GcryModule *cipher; + gcry_module_t *cipher; cipher = _gcry_module_lookup (ciphers_registered, (void *) name, gcry_cipher_lookup_func_name); @@ -233,46 +212,26 @@ gcry_cipher_lookup_name (const char *name) return cipher; } -/* Return a new, unused cipher ID for a user-provided cipher - implementation. */ -static int -gcry_cipher_id_new (void) -{ - int id, id_start = 500, id_end = 600; /* FIXME. */ - - for (id = id_start; id < id_end; id++) - if (! gcry_cipher_lookup_id (id)) - return id; - - return 0; -} - /* Public function. Register a provided CIPHER. Returns zero on success, in which case the chosen cipher ID has been stored in CIPHER, or an error code. */ gpg_error_t -gcry_cipher_register (GcryCipherSpec *cipher, - GcryModule **module) +gcry_cipher_register (gcry_cipher_spec_t *cipher, + gcry_module_t **module) { gpg_err_code_t err = 0; - int id; - GcryModule *mod; + gcry_module_t *mod; ath_mutex_lock (&ciphers_registered_lock); - - id = gcry_cipher_id_new (); - if (! id) - err = GPG_ERR_INTERNAL; /* FIXME? */ - else - { - cipher->id = id; - err = _gcry_module_add (&ciphers_registered, (void *) cipher, - &mod); - } + err = _gcry_module_add (&ciphers_registered, 0, + (void *) cipher, &mod); ath_mutex_unlock (&ciphers_registered_lock); if (! err) - *module = mod; + { + *module = mod; + cipher->id = mod->id; + } return gpg_error (err); } @@ -280,7 +239,7 @@ gcry_cipher_register (GcryCipherSpec *cipher, /* Public function. Unregister the cipher identified by MODULE, which must have been registered with gcry_cipher_register. */ void -gcry_cipher_unregister (GcryModule *module) +gcry_cipher_unregister (gcry_module_t *module) { ath_mutex_lock (&ciphers_registered_lock); _gcry_module_release (module); @@ -291,8 +250,8 @@ gcry_cipher_unregister (GcryModule *module) struct gcry_cipher_handle { int magic; - GcryCipherSpec *cipher; - GcryModule *module; + gcry_cipher_spec_t *cipher; + gcry_module_t *module; int mode; unsigned int flags; byte iv[MAX_BLOCKSIZE]; /* (this should be ulong aligned) */ @@ -333,7 +292,7 @@ search_oid (const char *string) int gcry_cipher_map_name( const char *string ) { - GcryModule *cipher; + gcry_module_t *cipher; int i, id = 0; if (!string) @@ -363,7 +322,7 @@ gcry_cipher_map_name( const char *string ) cipher = gcry_cipher_lookup_name (string); if (cipher) { - id = ((GcryCipherSpec *) cipher->spec)->id; + id = ((gcry_cipher_spec_t *) cipher->spec)->id; _gcry_module_release (cipher); } ath_mutex_unlock (&ciphers_registered_lock); @@ -387,16 +346,16 @@ gcry_cipher_mode_from_oid (const char *string) static const char * cipher_algo_to_string (int id) { - GcryModule *cipher; + gcry_module_t *cipher; const char *name = NULL; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); - cipher = gcry_cipher_lookup_id (id); + cipher = _gcry_module_lookup_id (ciphers_registered, id); if (cipher) { - name = ((GcryCipherSpec *) cipher->spec)->name; + name = ((gcry_cipher_spec_t *) cipher->spec)->name; _gcry_module_release (cipher); } ath_mutex_unlock (&ciphers_registered_lock); @@ -419,12 +378,12 @@ gcry_cipher_algo_name (int id) static void disable_cipher_algo (int id) { - GcryModule *cipher; + gcry_module_t *cipher; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); - cipher = gcry_cipher_lookup_id (id); + cipher = _gcry_module_lookup_id (ciphers_registered, id); if (cipher) { if (! (cipher->flags & FLAG_MODULE_DISABLED)) @@ -443,12 +402,12 @@ static gpg_err_code_t check_cipher_algo (int id) { gpg_err_code_t err = GPG_ERR_NO_ERROR; - GcryModule *cipher; + gcry_module_t *cipher; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); - cipher = gcry_cipher_lookup_id (id); + cipher = _gcry_module_lookup_id (ciphers_registered, id); if (cipher) { if (cipher->flags & FLAG_MODULE_DISABLED) @@ -465,16 +424,16 @@ check_cipher_algo (int id) static unsigned cipher_get_keylen (int id) { - GcryModule *cipher; + gcry_module_t *cipher; unsigned len = 0; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); - cipher = gcry_cipher_lookup_id (id); + cipher = _gcry_module_lookup_id (ciphers_registered, id); if (cipher) { - len = ((GcryCipherSpec *) cipher->spec)->keylen; + len = ((gcry_cipher_spec_t *) cipher->spec)->keylen; if (! len) log_bug ("cipher %d w/o key length\n", id); _gcry_module_release (cipher); @@ -489,16 +448,16 @@ cipher_get_keylen (int id) static unsigned cipher_get_blocksize (int id) { - GcryModule *cipher; + gcry_module_t *cipher; unsigned len = 0; REGISTER_DEFAULT_CIPHERS; ath_mutex_lock (&ciphers_registered_lock); - cipher = gcry_cipher_lookup_id (id); + cipher = _gcry_module_lookup_id (ciphers_registered, id); if (cipher) { - len = ((GcryCipherSpec *) cipher->spec)->blocksize; + len = ((gcry_cipher_spec_t *) cipher->spec)->blocksize; if (! len) log_bug ("cipher %d w/o blocksize\n", id); _gcry_module_release (cipher); @@ -521,8 +480,8 @@ gcry_cipher_open (gcry_cipher_hd_t *handle, int algo, int mode, unsigned int flags ) { int secure = (flags & GCRY_CIPHER_SECURE); - GcryCipherSpec *cipher = NULL; - GcryModule *module = NULL; + gcry_cipher_spec_t *cipher = NULL; + gcry_module_t *module = NULL; gcry_cipher_hd_t h = NULL; gpg_err_code_t err = 0; @@ -533,7 +492,7 @@ gcry_cipher_open (gcry_cipher_hd_t *handle, /* Fetch the according module and check wether the cipher is marked available for use. */ ath_mutex_lock (&ciphers_registered_lock); - module = gcry_cipher_lookup_id (algo); + module = _gcry_module_lookup_id (ciphers_registered, algo); if (module) { /* Found module. */ @@ -545,7 +504,7 @@ gcry_cipher_open (gcry_cipher_hd_t *handle, _gcry_module_release (module); } else - cipher = (GcryCipherSpec *) module->spec; + cipher = (gcry_cipher_spec_t *) module->spec; } else err = GPG_ERR_CIPHER_ALGO; diff --git a/cipher/crc.c b/cipher/crc.c index 1f1dc4b8..70546c2e 100644 --- a/cipher/crc.c +++ b/cipher/crc.c @@ -271,14 +271,14 @@ crc24rfc2440_final (void *context) ctx->buf[2] = (ctx->CRC ) & 0xFF; } -GcryDigestSpec digest_spec_crc32 = +gcry_digest_spec_t digest_spec_crc32 = { "CRC32", GCRY_MD_CRC32, NULL, 0, 4, crc32_init, crc32_write, crc32_final, crc32_read, sizeof (CRC_CONTEXT) }; -GcryDigestSpec digest_spec_crc32_rfc1510 = +gcry_digest_spec_t digest_spec_crc32_rfc1510 = { "CRC32RFC1510", GCRY_MD_CRC32_RFC1510, NULL, 0, 4, crc32rfc1510_init, crc32_write, @@ -286,7 +286,7 @@ GcryDigestSpec digest_spec_crc32_rfc1510 = sizeof (CRC_CONTEXT) }; -GcryDigestSpec digest_spec_crc24_rfc2440 = +gcry_digest_spec_t digest_spec_crc24_rfc2440 = { "CRC24RFC2440", GCRY_MD_CRC24_RFC2440, NULL, 0, 3, crc24rfc2440_init, crc24rfc2440_write, diff --git a/cipher/des.c b/cipher/des.c index 73e2290f..9a9555a8 100644 --- a/cipher/des.c +++ b/cipher/des.c @@ -1066,13 +1066,13 @@ do_des_decrypt( void *context, byte *outbuf, const byte *inbuf ) _gcry_burn_stack (32); } -GcryCipherSpec cipher_spec_des = +gcry_cipher_spec_t cipher_spec_des = { "DES", GCRY_CIPHER_DES, 8, 64, sizeof (struct _des_ctx), do_des_setkey, do_des_encrypt, do_des_decrypt }; -GcryCipherSpec cipher_spec_tripledes = +gcry_cipher_spec_t cipher_spec_tripledes = { "3DES", GCRY_CIPHER_3DES, 8, 192, sizeof (struct _tripledes_ctx), do_tripledes_setkey, do_tripledes_encrypt, do_tripledes_decrypt diff --git a/cipher/dsa.c b/cipher/dsa.c index 800313dc..c2a2e519 100644 --- a/cipher/dsa.c +++ b/cipher/dsa.c @@ -456,7 +456,7 @@ static char *dsa_names[] = NULL, }; -GcryPubkeySpec pubkey_spec_dsa = +gcry_pubkey_spec_t pubkey_spec_dsa = { "DSA", dsa_names, GCRY_PK_DSA, "pqgy", "pqgyx", "", "rs", "pqgy", diff --git a/cipher/elgamal.c b/cipher/elgamal.c index 6001e550..dee79da7 100644 --- a/cipher/elgamal.c +++ b/cipher/elgamal.c @@ -641,7 +641,7 @@ static char *elg_names[] = }; -GcryPubkeySpec pubkey_spec_elg = +gcry_pubkey_spec_t pubkey_spec_elg = { "ELG", elg_names, GCRY_PK_ELG, "pgy", "pgyx", "ab", "rs", "pgy", diff --git a/cipher/md.c b/cipher/md.c index 4ee87542..4872e498 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -62,7 +62,7 @@ static struct { static struct { - GcryDigestSpec *digest; + gcry_digest_spec_t *digest; int flags; } digest_table[] = { @@ -97,7 +97,7 @@ static struct }; /* List of registered digests. */ -static GcryModule *digests_registered; +static gcry_module_t *digests_registered; /* This is the lock protecting DIGESTS_REGISTERED. */ static ath_mutex_t digests_registered_lock = ATH_MUTEX_INITIALIZER; @@ -130,6 +130,7 @@ gcry_digest_register_default (void) for (i = 0; (! err) && digest_table[i].digest; i++) err = _gcry_module_add (&digests_registered, + digest_table[i].digest->id, (void *) digest_table[i].digest, NULL); @@ -139,41 +140,19 @@ gcry_digest_register_default (void) /* Internal callback function. */ static int -gcry_digest_lookup_func_id (void *spec, void *data) -{ - GcryDigestSpec *digest = (GcryDigestSpec *) spec; - int id = *((int *) data); - - return (digest->id == id); -} - -/* Internal callback function. */ -static int gcry_digest_lookup_func_name (void *spec, void *data) { - GcryDigestSpec *digest = (GcryDigestSpec *) spec; + gcry_digest_spec_t *digest = (gcry_digest_spec_t *) spec; char *name = (char *) data; return (! stricmp (digest->name, name)); } -/* Internal function. Lookup a digest entry by it's ID. */ -static GcryModule * -gcry_digest_lookup_id (int id) -{ - GcryModule *digest; - - digest = _gcry_module_lookup (digests_registered, (void *) &id, - gcry_digest_lookup_func_id); - - return digest; -} - /* Internal function. Lookup a digest entry by it's name. */ -static GcryModule * +static gcry_module_t * gcry_digest_lookup_name (const char *name) { - GcryModule *digest; + gcry_module_t *digest; digest = _gcry_module_lookup (digests_registered, (void *) name, gcry_digest_lookup_func_name); @@ -181,44 +160,25 @@ gcry_digest_lookup_name (const char *name) return digest; } -/* Return a new, unused digest ID for a user-provided digest - implementation. */ -static int -gcry_digest_id_new (void) -{ - int id, id_start = 500, id_end = 600; /* FIXME. */ - - for (id = id_start; id < id_end; id++) - if (! gcry_digest_lookup_id (id)) - return id; - - return 0; -} - /* Public function. Register a provided DIGEST. Returns zero on success, in which case the chosen digest ID has been stored in DIGEST, or an error code. */ gpg_error_t -gcry_digest_register (GcryDigestSpec *digest, GcryModule **module) +gcry_digest_register (gcry_digest_spec_t *digest, gcry_module_t **module) { gpg_err_code_t err = 0; - int id; - GcryModule *mod; + gcry_module_t *mod; ath_mutex_lock (&digests_registered_lock); - id = gcry_digest_id_new (); - if (! id) - err = GPG_ERR_INTERNAL; /* FIXME. */ - else - { - digest->id = id; - err = _gcry_module_add (&digests_registered, (void *) digest, - &mod); - } + err = _gcry_module_add (&digests_registered, 0, + (void *) digest, &mod); ath_mutex_unlock (&digests_registered_lock); if (! err) - *module = mod; + { + *module = mod; + digest->id = mod->id; + } return gpg_error (err); } @@ -226,7 +186,7 @@ gcry_digest_register (GcryDigestSpec *digest, GcryModule **module) /* Public function. Unregister the digest identified by ID, which must have been registered with gcry_digest_register. */ void -gcry_digest_unregister (GcryModule *module) +gcry_digest_unregister (gcry_module_t *module) { ath_mutex_lock (&digests_registered_lock); _gcry_module_release (module); @@ -235,8 +195,8 @@ gcry_digest_unregister (GcryModule *module) typedef struct gcry_md_list { - GcryDigestSpec *digest; - GcryModule *module; + gcry_digest_spec_t *digest; + gcry_module_t *module; struct gcry_md_list *next; PROPERLY_ALIGNED_TYPE context; } GcryDigestEntry; @@ -277,7 +237,7 @@ static void md_stop_debug( gcry_md_hd_t a ); int gcry_md_map_name (const char *string) { - GcryModule *digest; + gcry_module_t *digest; int id = 0; if (!string) @@ -307,7 +267,7 @@ gcry_md_map_name (const char *string) digest = gcry_digest_lookup_name (string); if (digest) { - id = ((GcryDigestSpec *) digest->spec)->id; + id = ((gcry_digest_spec_t *) digest->spec)->id; _gcry_module_release (digest); } ath_mutex_unlock (&digests_registered_lock); @@ -323,15 +283,15 @@ static const char * digest_algo_to_string (int id) { const char *name = NULL; - GcryModule *digest; + gcry_module_t *digest; REGISTER_DEFAULT_DIGESTS; ath_mutex_lock (&digests_registered_lock); - digest = gcry_digest_lookup_id (id); + digest = _gcry_module_lookup_id (digests_registered, id); if (digest) { - name = ((GcryDigestSpec *) digest->spec)->name; + name = ((gcry_digest_spec_t *) digest->spec)->name; _gcry_module_release (digest); } ath_mutex_unlock (&digests_registered_lock); @@ -357,12 +317,12 @@ static gpg_err_code_t check_digest_algo (int id) { gpg_err_code_t rc = 0; - GcryModule *digest; + gcry_module_t *digest; REGISTER_DEFAULT_DIGESTS; ath_mutex_lock (&digests_registered_lock); - digest = gcry_digest_lookup_id (id); + digest = _gcry_module_lookup_id (digests_registered, id); if (digest) _gcry_module_release (digest); else @@ -486,9 +446,9 @@ static gpg_err_code_t md_enable (gcry_md_hd_t hd, int id) { struct gcry_md_context *h = hd->ctx; - GcryDigestSpec *digest = NULL; + gcry_digest_spec_t *digest = NULL; GcryDigestEntry *entry; - GcryModule *module; + gcry_module_t *module; gpg_err_code_t err = 0; for (entry = h->list; entry; entry = entry->next) @@ -498,7 +458,7 @@ md_enable (gcry_md_hd_t hd, int id) REGISTER_DEFAULT_DIGESTS; ath_mutex_lock (&digests_registered_lock); - module = gcry_digest_lookup_id (id); + module = _gcry_module_lookup_id (digests_registered, id); ath_mutex_unlock (&digests_registered_lock); if (! module) { @@ -506,7 +466,7 @@ md_enable (gcry_md_hd_t hd, int id) err = GPG_ERR_DIGEST_ALGO; } else - digest = (GcryDigestSpec *) module->spec; + digest = (gcry_digest_spec_t *) module->spec; if (! err) { @@ -982,16 +942,16 @@ gcry_md_get_algo (gcry_md_hd_t hd) static int md_digest_length (int id) { - GcryModule *digest; + gcry_module_t *digest; int mdlen = 0; REGISTER_DEFAULT_DIGESTS; ath_mutex_lock (&digests_registered_lock); - digest = gcry_digest_lookup_id (id); + digest = _gcry_module_lookup_id (digests_registered, id); if (digest) { - mdlen = ((GcryDigestSpec *) digest->spec)->mdlen; + mdlen = ((gcry_digest_spec_t *) digest->spec)->mdlen; _gcry_module_release (digest); } ath_mutex_unlock (&digests_registered_lock); @@ -1016,19 +976,19 @@ static const byte * md_asn_oid (int id, size_t *asnlen, size_t *mdlen) { const byte *asnoid = NULL; - GcryModule *digest; + gcry_module_t *digest; REGISTER_DEFAULT_DIGESTS; ath_mutex_lock (&digests_registered_lock); - digest = gcry_digest_lookup_id (id); + digest = _gcry_module_lookup_id (digests_registered, id); if (digest) { if (asnlen) - *asnlen = ((GcryDigestSpec *) digest->spec)->asnlen; + *asnlen = ((gcry_digest_spec_t *) digest->spec)->asnlen; if (mdlen) - *mdlen = ((GcryDigestSpec *) digest->spec)->mdlen; - asnoid = ((GcryDigestSpec *) digest->spec)->asnoid; + *mdlen = ((gcry_digest_spec_t *) digest->spec)->mdlen; + asnoid = ((gcry_digest_spec_t *) digest->spec)->asnoid; _gcry_module_release (digest); } else diff --git a/cipher/md4.c b/cipher/md4.c index bf4f104e..1686675d 100644 --- a/cipher/md4.c +++ b/cipher/md4.c @@ -303,7 +303,7 @@ 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 }; -GcryDigestSpec digest_spec_md4 = +gcry_digest_spec_t digest_spec_md4 = { "MD4", GCRY_MD_MD4, asn, DIM (asn), 16, md4_init, md4_write, md4_final, md4_read, diff --git a/cipher/md5.c b/cipher/md5.c index ca7cfe26..878a250b 100644 --- a/cipher/md5.c +++ b/cipher/md5.c @@ -329,7 +329,7 @@ md5_read( void *context ) 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 }; -GcryDigestSpec digest_spec_md5 = +gcry_digest_spec_t digest_spec_md5 = { "MD5", GCRY_MD_MD5, asn, DIM (asn), 16, md5_init, md5_write, md5_final, md5_read, diff --git a/cipher/pubkey.c b/cipher/pubkey.c index ca3cb238..afc5160a 100644 --- a/cipher/pubkey.c +++ b/cipher/pubkey.c @@ -39,7 +39,7 @@ static gpg_err_code_t pubkey_verify (int algo, gcry_mpi_t hash, gcry_mpi_t *data libgcrypt. */ static struct { - GcryPubkeySpec *pubkey; + gcry_pubkey_spec_t *pubkey; } pubkey_table[] = { #if USE_RSA @@ -55,7 +55,7 @@ static struct }; /* List of registered ciphers. */ -static GcryModule *pubkeys_registered; +static gcry_module_t *pubkeys_registered; /* This is the lock protecting PUBKEYS_REGISTERED. */ static ath_mutex_t pubkeys_registered_lock; @@ -155,6 +155,7 @@ gcry_pubkey_register_default (void) pubkey_use_dummy (get_nbits); err = _gcry_module_add (&pubkeys_registered, + pubkey_table[i].pubkey->id, (void *) pubkey_table[i].pubkey, NULL); } @@ -164,19 +165,9 @@ gcry_pubkey_register_default (void) /* Internal callback function. Used via _gcry_module_lookup. */ static int -gcry_pubkey_lookup_func_id (void *spec, void *data) -{ - GcryPubkeySpec *pubkey = (GcryPubkeySpec *) spec; - int id = *((int *) data); - - return (pubkey->id == id); -} - -/* Internal callback function. Used via _gcry_module_lookup. */ -static int gcry_pubkey_lookup_func_name (void *spec, void *data) { - GcryPubkeySpec *pubkey = (GcryPubkeySpec *) spec; + gcry_pubkey_spec_t *pubkey = (gcry_pubkey_spec_t *) spec; char *name = (char *) data; char **sexp_names = pubkey->sexp_names; int ret = stricmp (name, pubkey->name); @@ -187,23 +178,11 @@ gcry_pubkey_lookup_func_name (void *spec, void *data) return ! ret; } -/* Internal function. Lookup a pubkey entry by it's ID. */ -static GcryModule * -gcry_pubkey_lookup_id (int id) -{ - GcryModule *pubkey; - - pubkey = _gcry_module_lookup (pubkeys_registered, (void *) &id, - gcry_pubkey_lookup_func_id); - - return pubkey; -} - /* Internal function. Lookup a pubkey entry by it's name. */ -static GcryModule * +static gcry_module_t * gcry_pubkey_lookup_name (const char *name) { - GcryModule *pubkey; + gcry_module_t *pubkey; pubkey = _gcry_module_lookup (pubkeys_registered, (void *) name, gcry_pubkey_lookup_func_name); @@ -211,44 +190,25 @@ gcry_pubkey_lookup_name (const char *name) return pubkey; } -/* Return a new, unused pubkey ID for a user-provided pubkey - implementation. */ -static int -gcry_pubkey_id_new (void) -{ - int id, id_start = 500, id_end = 600; /* FIXME. */ - - for (id = id_start; id < id_end; id++) - if (! gcry_pubkey_lookup_id (id)) - return id; - - return 0; -} - /* Public function. Register a provided PUBKEY. Returns zero on success, in which case the chosen pubkey ID has been stored in PUBKEY, or an error code. */ gpg_error_t -gcry_pubkey_register (GcryPubkeySpec *pubkey, GcryModule **module) +gcry_pubkey_register (gcry_pubkey_spec_t *pubkey, gcry_module_t **module) { gpg_err_code_t err = GPG_ERR_NO_ERROR; - int id; - GcryModule *mod; + gcry_module_t *mod; ath_mutex_lock (&pubkeys_registered_lock); - id = gcry_pubkey_id_new (); - if (! id) - err = GPG_ERR_INTERNAL; /* FIXME. */ - else - { - pubkey->id = id; - err = _gcry_module_add (&pubkeys_registered, (void *) pubkey, - &mod); - } + err = _gcry_module_add (&pubkeys_registered, 0, + (void *) pubkey, &mod); ath_mutex_unlock (&pubkeys_registered_lock); if (! err) - *module = mod; + { + *module = mod; + pubkey->id = mod->id; + } return err; } @@ -256,7 +216,7 @@ gcry_pubkey_register (GcryPubkeySpec *pubkey, GcryModule **module) /* Public function. Unregister the pubkey identified by ID, which must have been registered with gcry_pubkey_register. */ void -gcry_pubkey_unregister (GcryModule *module) +gcry_pubkey_unregister (gcry_module_t *module) { ath_mutex_lock (&pubkeys_registered_lock); _gcry_module_release (module); @@ -279,7 +239,7 @@ release_mpi_array (gcry_mpi_t *array) int gcry_pk_map_name (const char *string) { - GcryModule *pubkey; + gcry_module_t *pubkey; int id = 0; REGISTER_DEFAULT_PUBKEYS; @@ -288,7 +248,7 @@ gcry_pk_map_name (const char *string) pubkey = gcry_pubkey_lookup_name (string); if (pubkey) { - id = ((GcryPubkeySpec *) pubkey->spec)->id; + id = ((gcry_pubkey_spec_t *) pubkey->spec)->id; _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); @@ -304,15 +264,15 @@ const char * gcry_pk_algo_name (int id) { const char *name = NULL; - GcryModule *pubkey; + gcry_module_t *pubkey; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { - name = ((GcryPubkeySpec *) pubkey->spec)->name; + name = ((gcry_pubkey_spec_t *) pubkey->spec)->name; _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); @@ -324,10 +284,10 @@ gcry_pk_algo_name (int id) static void disable_pubkey_algo (int id) { - GcryModule *pubkey; + gcry_module_t *pubkey; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { if (! (pubkey-> flags & FLAG_MODULE_DISABLED)) @@ -345,16 +305,16 @@ static gpg_err_code_t check_pubkey_algo (int id, unsigned use) { gpg_err_code_t err = GPG_ERR_NO_ERROR; - GcryPubkeySpec *pubkey; - GcryModule *module; + gcry_pubkey_spec_t *pubkey; + gcry_module_t *module; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - module = gcry_pubkey_lookup_id (id); + module = _gcry_module_lookup_id (pubkeys_registered, id); if (module) { - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; if (((use & GCRY_PK_USAGE_SIGN) && (! (pubkey->use & GCRY_PK_USAGE_SIGN))) @@ -379,16 +339,16 @@ check_pubkey_algo (int id, unsigned use) static int pubkey_get_npkey (int id) { - GcryModule *pubkey; + gcry_module_t *pubkey; int npkey = 0; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { - npkey = strlen (((GcryPubkeySpec *) pubkey->spec)->elements_pkey); + npkey = strlen (((gcry_pubkey_spec_t *) pubkey->spec)->elements_pkey); _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); @@ -402,16 +362,16 @@ pubkey_get_npkey (int id) static int pubkey_get_nskey (int id) { - GcryModule *pubkey; + gcry_module_t *pubkey; int nskey = 0; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { - nskey = strlen (((GcryPubkeySpec *) pubkey->spec)->elements_skey); + nskey = strlen (((gcry_pubkey_spec_t *) pubkey->spec)->elements_skey); _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); @@ -425,16 +385,16 @@ pubkey_get_nskey (int id) static int pubkey_get_nsig (int id) { - GcryModule *pubkey; + gcry_module_t *pubkey; int nsig = 0; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { - nsig = strlen (((GcryPubkeySpec *) pubkey->spec)->elements_sig); + nsig = strlen (((gcry_pubkey_spec_t *) pubkey->spec)->elements_sig); _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); @@ -448,16 +408,16 @@ pubkey_get_nsig (int id) static int pubkey_get_nenc (int id) { - GcryModule *pubkey; + gcry_module_t *pubkey; int nenc = 0; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { - nenc = strlen (((GcryPubkeySpec *) pubkey->spec)->elements_enc); + nenc = strlen (((gcry_pubkey_spec_t *) pubkey->spec)->elements_enc); _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); @@ -471,15 +431,15 @@ pubkey_generate (int id, unsigned int nbits, unsigned long use_e, gcry_mpi_t *skey, gcry_mpi_t **retfactors) { gpg_err_code_t err = GPG_ERR_PUBKEY_ALGO; - GcryModule *pubkey; + gcry_module_t *pubkey; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { - err = (*((GcryPubkeySpec *) pubkey->spec)->generate) (id, nbits, use_e, skey, + err = (*((gcry_pubkey_spec_t *) pubkey->spec)->generate) (id, nbits, use_e, skey, retfactors); _gcry_module_release (pubkey); } @@ -492,15 +452,15 @@ static gpg_err_code_t pubkey_check_secret_key (int id, gcry_mpi_t *skey) { gpg_err_code_t err = GPG_ERR_PUBKEY_ALGO; - GcryModule *pubkey; + gcry_module_t *pubkey; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { - err = (*((GcryPubkeySpec *) pubkey->spec)->check_secret_key) (id, skey); + err = (*((gcry_pubkey_spec_t *) pubkey->spec)->check_secret_key) (id, skey); _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); @@ -519,8 +479,8 @@ static gpg_err_code_t pubkey_encrypt (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey, int flags) { - GcryPubkeySpec *pubkey; - GcryModule *module; + gcry_pubkey_spec_t *pubkey; + gcry_module_t *module; gpg_err_code_t rc; int i; @@ -533,10 +493,10 @@ pubkey_encrypt (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey, } ath_mutex_lock (&pubkeys_registered_lock); - module = gcry_pubkey_lookup_id (id); + module = _gcry_module_lookup_id (pubkeys_registered, id); if (module) { - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; rc = (*pubkey->encrypt) (id, resarr, data, pkey, flags); _gcry_module_release (module); goto ready; @@ -566,8 +526,8 @@ static gpg_err_code_t pubkey_decrypt (int id, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, int flags) { - GcryPubkeySpec *pubkey; - GcryModule *module; + gcry_pubkey_spec_t *pubkey; + gcry_module_t *module; gpg_err_code_t rc; int i; @@ -582,10 +542,10 @@ pubkey_decrypt (int id, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, } ath_mutex_lock (&pubkeys_registered_lock); - module = gcry_pubkey_lookup_id (id); + module = _gcry_module_lookup_id (pubkeys_registered, id); if (module) { - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; rc = (*pubkey->decrypt) (id, result, data, skey, flags); _gcry_module_release (module); goto ready; @@ -612,8 +572,8 @@ pubkey_decrypt (int id, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, static gpg_err_code_t pubkey_sign (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey) { - GcryPubkeySpec *pubkey; - GcryModule *module; + gcry_pubkey_spec_t *pubkey; + gcry_module_t *module; gpg_err_code_t rc; int i; @@ -626,10 +586,10 @@ pubkey_sign (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey) } ath_mutex_lock (&pubkeys_registered_lock); - module = gcry_pubkey_lookup_id (id); + module = _gcry_module_lookup_id (pubkeys_registered, id); if (module) { - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; rc = (*pubkey->sign) (id, resarr, data, skey); _gcry_module_release (module); goto ready; @@ -655,8 +615,8 @@ static gpg_err_code_t pubkey_verify (int id, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey, int (*cmp)(void *, gcry_mpi_t), void *opaquev) { - GcryPubkeySpec *pubkey; - GcryModule *module; + gcry_pubkey_spec_t *pubkey; + gcry_module_t *module; gpg_err_code_t rc; int i; @@ -671,10 +631,10 @@ pubkey_verify (int id, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey, } ath_mutex_lock (&pubkeys_registered_lock); - module = gcry_pubkey_lookup_id (id); + module = _gcry_module_lookup_id (pubkeys_registered, id); if (module) { - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; rc = (*pubkey->verify) (id, hash, data, pkey, cmp, opaquev); _gcry_module_release (module); goto ready; @@ -754,7 +714,7 @@ sexp_elements_extract (gcry_sexp_t key_sexp, const char *element_names, */ static gpg_err_code_t sexp_to_key (gcry_sexp_t sexp, int want_private, gcry_mpi_t **retarray, - GcryModule **retalgo) + gcry_module_t **retalgo) { gcry_sexp_t list, l2; const char *name; @@ -763,8 +723,8 @@ sexp_to_key (gcry_sexp_t sexp, int want_private, gcry_mpi_t **retarray, const char *elems; gcry_mpi_t *array; gpg_err_code_t err = GPG_ERR_NO_ERROR; - GcryModule *module; - GcryPubkeySpec *pubkey; + gcry_module_t *module; + gcry_pubkey_spec_t *pubkey; /* check that the first element is valid */ list = gcry_sexp_find_token( sexp, want_private? "private-key" @@ -798,7 +758,7 @@ sexp_to_key (gcry_sexp_t sexp, int want_private, gcry_mpi_t **retarray, return GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */ } else - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; algo = pubkey->id; elems = want_private ? pubkey->elements_skey : pubkey->elements_pkey; @@ -831,7 +791,7 @@ sexp_to_key (gcry_sexp_t sexp, int want_private, gcry_mpi_t **retarray, static gpg_err_code_t sexp_to_sig (gcry_sexp_t sexp, gcry_mpi_t **retarray, - GcryModule **retalgo) + gcry_module_t **retalgo) { gcry_sexp_t list, l2; const char *name; @@ -840,8 +800,8 @@ sexp_to_sig (gcry_sexp_t sexp, gcry_mpi_t **retarray, const char *elems; gcry_mpi_t *array; gpg_err_code_t err = GPG_ERR_NO_ERROR; - GcryModule *module; - GcryPubkeySpec *pubkey; + gcry_module_t *module; + gcry_pubkey_spec_t *pubkey; /* check that the first element is valid */ list = gcry_sexp_find_token( sexp, "sig-val" , 0 ); @@ -876,7 +836,7 @@ sexp_to_sig (gcry_sexp_t sexp, gcry_mpi_t **retarray, return GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */ } else - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; algo = pubkey->id; elems = pubkey->elements_sig; @@ -922,12 +882,12 @@ sexp_to_sig (gcry_sexp_t sexp, gcry_mpi_t **retarray, * RET_MODERN is set to true when at least an empty flags list has been found. */ static gpg_err_code_t -sexp_to_enc (gcry_sexp_t sexp, gcry_mpi_t **retarray, GcryModule **retalgo, +sexp_to_enc (gcry_sexp_t sexp, gcry_mpi_t **retarray, gcry_module_t **retalgo, int *ret_modern, int *ret_want_pkcs1, int *flags) { gcry_sexp_t list = NULL, l2 = NULL; - GcryPubkeySpec *pubkey = NULL; - GcryModule *module = NULL; + gcry_pubkey_spec_t *pubkey = NULL; + gcry_module_t *module = NULL; const char *name; size_t n; int parsed_flags = 0; @@ -1018,7 +978,7 @@ sexp_to_enc (gcry_sexp_t sexp, gcry_mpi_t **retarray, GcryModule **retalgo, if (! module) err = GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */ else - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; } if (! err) @@ -1330,8 +1290,8 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) const char *algo_name, *algo_elems; int flags; gpg_err_code_t rc; - GcryPubkeySpec *pubkey = NULL; - GcryModule *module = NULL; + gcry_pubkey_spec_t *pubkey = NULL; + gcry_module_t *module = NULL; REGISTER_DEFAULT_PUBKEYS; @@ -1341,7 +1301,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) if (! rc) { assert (module); - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; algo_name = pubkey->name; algo_elems = pubkey->elements_enc; @@ -1453,8 +1413,8 @@ gcry_pk_decrypt (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t s_skey) gcry_mpi_t *skey = NULL, *data = NULL, plain = NULL; int modern, want_pkcs1, flags; gpg_err_code_t rc; - GcryModule *module_enc = NULL, *module_key = NULL; - GcryPubkeySpec *pubkey = NULL; + gcry_module_t *module_enc = NULL, *module_key = NULL; + gcry_pubkey_spec_t *pubkey = NULL; REGISTER_DEFAULT_PUBKEYS; @@ -1466,11 +1426,11 @@ gcry_pk_decrypt (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t s_skey) if (! rc) { - if (((GcryPubkeySpec *) module_key->spec)->id - != ((GcryPubkeySpec *) module_enc->spec)->id) + if (((gcry_pubkey_spec_t *) module_key->spec)->id + != ((gcry_pubkey_spec_t *) module_enc->spec)->id) rc = GPG_ERR_CONFLICT; /* key algo does not match data algo */ else - pubkey = (GcryPubkeySpec *) module_key->spec; + pubkey = (gcry_pubkey_spec_t *) module_key->spec; } if (! rc) @@ -1549,8 +1509,8 @@ gpg_error_t gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) { gcry_mpi_t *skey = NULL, hash = NULL, *result = NULL; - GcryPubkeySpec *pubkey = NULL; - GcryModule *module = NULL; + gcry_pubkey_spec_t *pubkey = NULL; + gcry_module_t *module = NULL; const char *key_algo_name, *algo_name, *algo_elems; int i; gpg_err_code_t rc; @@ -1564,7 +1524,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) if (! rc) { assert (module); - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; algo_name = key_algo_name = pubkey->name; algo_elems = pubkey->elements_sig; @@ -1649,7 +1609,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) gpg_error_t gcry_pk_verify (gcry_sexp_t s_sig, gcry_sexp_t s_hash, gcry_sexp_t s_pkey) { - GcryModule *module_key = NULL, *module_sig = NULL; + gcry_module_t *module_key = NULL, *module_sig = NULL; gcry_mpi_t *pkey = NULL, hash = NULL, *sig = NULL; gpg_err_code_t rc; @@ -1660,15 +1620,15 @@ gcry_pk_verify (gcry_sexp_t s_sig, gcry_sexp_t s_hash, gcry_sexp_t s_pkey) rc = sexp_to_sig (s_sig, &sig, &module_sig); if ((! rc) - && (((GcryPubkeySpec *) module_key->spec)->id - != ((GcryPubkeySpec *) module_sig->spec)->id)) + && (((gcry_pubkey_spec_t *) module_key->spec)->id + != ((gcry_pubkey_spec_t *) module_sig->spec)->id)) rc = GPG_ERR_CONFLICT; if (! rc) rc = sexp_data_to_mpi (s_hash, gcry_pk_get_nbits (s_pkey), &hash, 0, 0); if (! rc) - rc = pubkey_verify (((GcryPubkeySpec *) module_key->spec)->id, + rc = pubkey_verify (((gcry_pubkey_spec_t *) module_key->spec)->id, hash, sig, pkey, NULL, NULL); if (pkey) @@ -1709,7 +1669,7 @@ gcry_pk_verify (gcry_sexp_t s_sig, gcry_sexp_t s_hash, gcry_sexp_t s_pkey) gpg_error_t gcry_pk_testkey (gcry_sexp_t s_key) { - GcryModule *module = NULL; + gcry_module_t *module = NULL; gcry_mpi_t *key = NULL; gpg_err_code_t rc; @@ -1719,7 +1679,7 @@ gcry_pk_testkey (gcry_sexp_t s_key) rc = sexp_to_key (s_key, 1, &key, &module); if (! rc) { - rc = pubkey_check_secret_key (((GcryPubkeySpec *) module->spec)->id, key); + rc = pubkey_check_secret_key (((gcry_pubkey_spec_t *) module->spec)->id, key); release_mpi_array (key); gcry_free (key); } @@ -1764,8 +1724,8 @@ gcry_pk_testkey (gcry_sexp_t s_key) gpg_error_t gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) { - GcryPubkeySpec *pubkey = NULL; - GcryModule *module = NULL; + gcry_pubkey_spec_t *pubkey = NULL; + gcry_module_t *module = NULL; gcry_sexp_t list = NULL, l2 = NULL; const char *name; size_t n; @@ -1818,7 +1778,7 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) rc = GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */ else { - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; algo = pubkey->id; algo_name = pubkey->name; pub_elems = pubkey->elements_pkey; @@ -1988,8 +1948,8 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) unsigned int gcry_pk_get_nbits (gcry_sexp_t key) { - GcryModule *module = NULL; - GcryPubkeySpec *pubkey; + gcry_module_t *module = NULL; + gcry_pubkey_spec_t *pubkey; gcry_mpi_t *keyarr = NULL; unsigned int nbits = 0; gpg_err_code_t rc; @@ -2003,7 +1963,7 @@ gcry_pk_get_nbits (gcry_sexp_t key) return 0; else { - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; nbits = (*pubkey->get_nbits) (pubkey->id, keyarr); ath_mutex_lock (&pubkeys_registered_lock); @@ -2029,8 +1989,8 @@ unsigned char * gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array) { gcry_sexp_t list = NULL, l2 = NULL; - GcryPubkeySpec *pubkey = NULL; - GcryModule *module = NULL; + gcry_pubkey_spec_t *pubkey = NULL; + gcry_module_t *module = NULL; const char *s, *name; size_t n; int idx; @@ -2074,7 +2034,7 @@ gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array) if (! module) goto fail; /* unknown algorithm */ else - pubkey = (GcryPubkeySpec *) module->spec; + pubkey = (gcry_pubkey_spec_t *) module->spec; /* FIXME, special handling should be implemented by the algorithms, not by the libgcrypt core. */ @@ -2202,16 +2162,16 @@ gcry_pk_algo_info (int id, int what, void *buffer, size_t *nbytes) case GCRYCTL_GET_ALGO_USAGE: { - GcryModule *pubkey; + gcry_module_t *pubkey; int use = 0; REGISTER_DEFAULT_PUBKEYS; ath_mutex_lock (&pubkeys_registered_lock); - pubkey = gcry_pubkey_lookup_id (id); + pubkey = _gcry_module_lookup_id (pubkeys_registered, id); if (pubkey) { - use = ((GcryPubkeySpec *) pubkey->spec)->use; + use = ((gcry_pubkey_spec_t *) pubkey->spec)->use; _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); diff --git a/cipher/rijndael.c b/cipher/rijndael.c index 7066da22..3943d9a6 100644 --- a/cipher/rijndael.c +++ b/cipher/rijndael.c @@ -2131,19 +2131,19 @@ selftest (void) -GcryCipherSpec cipher_spec_aes = +gcry_cipher_spec_t cipher_spec_aes = { "AES", GCRY_CIPHER_AES, 16, 128, sizeof (RIJNDAEL_context), rijndael_setkey, rijndael_encrypt, rijndael_decrypt, }; -GcryCipherSpec cipher_spec_aes192 = +gcry_cipher_spec_t cipher_spec_aes192 = { "AES192", GCRY_CIPHER_AES192, 16, 192, sizeof (RIJNDAEL_context), rijndael_setkey, rijndael_encrypt, rijndael_decrypt, }; -GcryCipherSpec cipher_spec_aes256 = +gcry_cipher_spec_t cipher_spec_aes256 = { "AES256", GCRY_CIPHER_AES256, 16, 256, sizeof (RIJNDAEL_context), rijndael_setkey, rijndael_encrypt, rijndael_decrypt, diff --git a/cipher/rmd160.c b/cipher/rmd160.c index a0b11fc6..01df1d2b 100644 --- a/cipher/rmd160.c +++ b/cipher/rmd160.c @@ -543,7 +543,7 @@ 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 }; -GcryDigestSpec digest_spec_rmd160 = +gcry_digest_spec_t digest_spec_rmd160 = { "RIPEMD160", GCRY_MD_RMD160, asn, DIM (asn), 20, _gcry_rmd160_init, rmd160_write, rmd160_final, rmd160_read, diff --git a/cipher/rsa.c b/cipher/rsa.c index ad266588..c16ccc0a 100644 --- a/cipher/rsa.c +++ b/cipher/rsa.c @@ -611,7 +611,7 @@ static char *rsa_names[] = NULL, }; -GcryPubkeySpec pubkey_spec_rsa = +gcry_pubkey_spec_t pubkey_spec_rsa = { "RSA", rsa_names, GCRY_PK_RSA, "ne", "nedpqu", "a", "s", "n", diff --git a/cipher/sha1.c b/cipher/sha1.c index 64f56fb7..1c382a91 100644 --- a/cipher/sha1.c +++ b/cipher/sha1.c @@ -319,7 +319,7 @@ 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 }; -GcryDigestSpec digest_spec_sha1 = +gcry_digest_spec_t digest_spec_sha1 = { "SHA1", GCRY_MD_SHA1, asn, DIM (asn), 20, sha1_init, sha1_write, sha1_final, sha1_read, diff --git a/cipher/sha256.c b/cipher/sha256.c index a33c36ae..6b3b4981 100644 --- a/cipher/sha256.c +++ b/cipher/sha256.c @@ -293,7 +293,7 @@ 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 }; -GcryDigestSpec digest_spec_sha256 = +gcry_digest_spec_t digest_spec_sha256 = { "SHA256", GCRY_MD_SHA256, asn, DIM (asn), 32, sha256_init, sha256_write, sha256_final, sha256_read, diff --git a/cipher/sha512.c b/cipher/sha512.c index 767e92ba..d2e0e3a2 100644 --- a/cipher/sha512.c +++ b/cipher/sha512.c @@ -367,7 +367,7 @@ static byte sha512_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.3 */ 0x00, 0x04, 0x40 }; -GcryDigestSpec digest_spec_sha512 = { +gcry_digest_spec_t digest_spec_sha512 = { "SHA512", GCRY_MD_SHA512, sha512_asn, DIM (sha512_asn), 64, sha512_init, sha512_write, sha512_final, sha512_read, sizeof (SHA512_CONTEXT), @@ -380,7 +380,7 @@ static byte sha384_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.2 */ 0x00, 0x04, 0x30 }; -GcryDigestSpec digest_spec_sha384 = { +gcry_digest_spec_t digest_spec_sha384 = { "SHA384", GCRY_MD_SHA384, sha384_asn, DIM (sha384_asn), 48, sha384_init, sha512_write, sha512_final, sha512_read, sizeof (SHA512_CONTEXT), diff --git a/cipher/tiger.c b/cipher/tiger.c index 5b0ef9a2..2aaeadb4 100644 --- a/cipher/tiger.c +++ b/cipher/tiger.c @@ -827,7 +827,7 @@ static byte asn[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */ 0x05, 0x00, 0x04, 0x18 }; -GcryDigestSpec digest_spec_tiger = +gcry_digest_spec_t digest_spec_tiger = { "TIGER192", GCRY_MD_TIGER, asn, DIM (asn), 24, tiger_init, tiger_write, tiger_final, tiger_read, diff --git a/cipher/twofish.c b/cipher/twofish.c index a1fcef82..a5a2aa4d 100644 --- a/cipher/twofish.c +++ b/cipher/twofish.c @@ -1019,13 +1019,13 @@ main() -GcryCipherSpec cipher_spec_twofish = +gcry_cipher_spec_t cipher_spec_twofish = { "TWOFISH", GCRY_CIPHER_TWOFISH, 16, 256, sizeof (TWOFISH_context), twofish_setkey, twofish_encrypt, twofish_decrypt, }; -GcryCipherSpec cipher_spec_twofish128 = +gcry_cipher_spec_t cipher_spec_twofish128 = { "TWOFISH128", GCRY_CIPHER_TWOFISH, 16, 128, sizeof (TWOFISH_context), twofish_setkey, twofish_encrypt, twofish_decrypt, |