summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Schulte <mo@g10code.com>2003-07-07 16:21:36 +0000
committerMoritz Schulte <mo@g10code.com>2003-07-07 16:21:36 +0000
commit615e7964750d322bfb35fe8c9e8228c12314950c (patch)
tree938ec5c5c053c151f4ec03375e695f5cea1c416d
parentd8e6c13ea72d92ddae184fe210237148d147741b (diff)
downloadlibgcrypt-615e7964750d322bfb35fe8c9e8228c12314950c.tar.gz
2003-07-07 Moritz Schulte <moritz@g10code.com>
* ac.c (gcry_ac_data_set): Only release old MPI value if it is different from the new value. * pubkey.c (gcry_pk_list): New function. * md.c (gcry_md_list): New function. * ac.c (gcry_ac_key_pair_generate): Fix calculation of format string size. 2003-07-05 Moritz Schulte <moritz@g10code.com> * md.c: Named struct of digest_table `digest_table_entry'. (digest_table_entry): New member: algorithm; filled in. (digest_table_entry): Removed unused member: flags. (gcry_md_register): New argument: algorithm_id, filled in. (gcry_md_register_default): Used algorithm ID from module structure. (gcry_md_map_name): Likewise. (md_enable): Likewise. (md_read): Likewise. (gcry_md_info): Likewise. * pubkey.c: Named truct for pubkey_table `pubkey_table_entry'. (pubkey_table_entry): New member: algorithm; filled in. (gcry_pk_register_default): Used algorithm ID from pubkey_table. (gcry_pk_register): New argument: algorithm_id, filled in. (gcry_pk_map_name): Used algorithm ID from module structure. (gcry_pk_decrypt): Likewise. (gcry_pk_encrypt): Likewise. (gcry_pk_verify): Likewise. (gcry_pk_sign): Likewise. (gcry_pk_testkey): Likewise. (gcry_pk_genkey): Likewise. (gcry_pk_get_nbits): Likewise. (sexp_to_key): Removed unused variable: algo. (sexp_to_sig): Likewise. * cipher.c: Named struct for cipher_table `cipher_table_entry'. (cipher_table_entry): New member: algorithm; filled in. (gcry_cipher_register_default): Used algorithm ID from cipher_table. (gcry_cipher_register): New argument: algorithm_id, filled in. (gcry_cipher_map_name): Used algorithm ID from module structure. * arcfour.c (cipher_spec_arcfour): Removed algorithm ID. * blowfish.c (cipher_spec_blowfish): Likewise. * cast5.c (cipher_spec_cast5): Likewise. * crc.c (digest_spec_crc32): Likewise. * crc.c (digest_spec_crc32_rfc1510): Likewise. * crc.c (digest_spec_crc32_rfc2440): Likewise. * des.c (cipher_spec_des): Likewise. * des.c (cipher_spec_tripledes): Likewise. * dsa.c (pubkey_spec_dsa): Likewise. * elgamal.c (pubkey_spec_elg): Likewise. * md4.c (digest_spec_md4): Likewise. * md5.c (digest_spec_md5): Likewise. * aes.c (cipher_spec_aes): Likewise. * aes.c (cipher_spec_aes192): Likewise. * aes.c (cipher_spec_aes256): Likewise. * rsa.c (pubkey_spec_rsa): Likewise. * sha1.c (digest_spec_sha1): Likewise. * sha256.c (digest_spec_sha256): Likewise. * sha512.c (digest_spec_sha512): Likewise. * tiger.c (digest_spec_tiger): Likewise. * twofish.c (cipher_spec_twofish): Likewise. * twofish.c (cipher_spec_twofish128): Likewise. * Makefile.am (EXTRA_libcipher_la_SOURCES): Fix list of source files; reported by Simon Josefsson <jas@extundo.com>. * pubkey.c: Replaced all occurences of `id' with `algorithm', since `id' is a keyword in obj-c. * md.c: Likewise. * cipher.c: Likewise. * crc.c, md4.c, md5.c, rmd160.c, sha1.c, sha256.c, tiger.c: Replaced all occurences of gcry_digest_spec_t with gcry_md_spec_t. * dsa.c, rsa.c, elgamal.c: Replaced all occurencens of gcry_pubkey_spec_t with gcry_pk_spec_t. * md.c: Replaced all occurences of gcry_digest_spec_t with gcry_md_spec_t. (gcry_digest_register_default): Renamed to ... (gcry_md_register_default): ... this; adjusted callers. (gcry_digest_lookup_func_name): Renamed to ... (gcry_md_lookup_func_name): ... this; adjusted callers. (gcry_digest_lookup_name): Renamed to ... (gcry_md_lookup_name): ... this; adjusted callers. (gcry_digest_register): Renamed to ... (gcry_md_register): ... this. (gcry_digest_unregister): Renamed to ... (gcry_md_unregister): ... this. * pubkey.c (gcry_pubkey_register): Renamed to ... (gcry_pk_register): ... this. (gcry_pubkey_unregister): Renamed to ... (gcry_pk_unregister): ... this. Replaced all occurences of gcry_pubkey_spec_t with gcry_pk_spec_t. (gcry_pubkey_register_default): Renamed to ... (gcry_pk_register_default): ... this; adjusted callers. (gcry_pubkey_lookup_func_name): Renamed to ... (gcry_pk_lookup_func_name): ... this; adjusted callers. (gcry_pubkey_lookup_name): Renamed to ... (gcry_pk_lookup_name): ... this; adjusted callers. * md.c (gcry_md_hash_buffer): Fix error checking. Thanks to Simon Josefsson <jas@extunde.com>. 2003-07-04 Moritz Schulte <moritz@g10code.com> * cipher.c (gcry_cipher_list): New function.
-rw-r--r--cipher/ChangeLog131
-rw-r--r--cipher/Makefile.am6
-rw-r--r--cipher/ac.c94
-rw-r--r--cipher/arcfour.c2
-rw-r--r--cipher/blowfish.c2
-rw-r--r--cipher/cast5.c2
-rw-r--r--cipher/cipher.c124
-rw-r--r--cipher/crc.c12
-rw-r--r--cipher/des.c4
-rw-r--r--cipher/dsa.c4
-rw-r--r--cipher/elgamal.c6
-rw-r--r--cipher/md.c171
-rw-r--r--cipher/md4.c4
-rw-r--r--cipher/md5.c4
-rw-r--r--cipher/pubkey.c380
-rw-r--r--cipher/rijndael.c6
-rw-r--r--cipher/rmd160.c4
-rw-r--r--cipher/rsa.c4
-rw-r--r--cipher/sha1.c4
-rw-r--r--cipher/sha256.c4
-rw-r--r--cipher/sha512.c8
-rw-r--r--cipher/tiger.c4
-rw-r--r--cipher/twofish.c4
23 files changed, 593 insertions, 391 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 72cf4f2d..891c91a9 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,134 @@
+2003-07-07 Moritz Schulte <moritz@g10code.com>
+
+ * ac.c (gcry_ac_data_set): Only release old MPI value if it is
+ different from the new value.
+
+ * pubkey.c (gcry_pk_list): New function.
+ * md.c (gcry_md_list): New function.
+
+ * ac.c (gcry_ac_key_pair_generate): Fix calculation of format
+ string size.
+
+2003-07-05 Moritz Schulte <moritz@g10code.com>
+
+ * md.c: Named struct of digest_table `digest_table_entry'.
+ (digest_table_entry): New member: algorithm; filled in.
+ (digest_table_entry): Removed unused member: flags.
+ (gcry_md_register): New argument: algorithm_id, filled in.
+ (gcry_md_register_default): Used algorithm ID from module
+ structure.
+ (gcry_md_map_name): Likewise.
+ (md_enable): Likewise.
+ (md_read): Likewise.
+ (gcry_md_info): Likewise.
+
+ * pubkey.c: Named truct for pubkey_table `pubkey_table_entry'.
+ (pubkey_table_entry): New member: algorithm; filled in.
+ (gcry_pk_register_default): Used algorithm ID from pubkey_table.
+ (gcry_pk_register): New argument: algorithm_id, filled in.
+ (gcry_pk_map_name): Used algorithm ID from module structure.
+ (gcry_pk_decrypt): Likewise.
+ (gcry_pk_encrypt): Likewise.
+ (gcry_pk_verify): Likewise.
+ (gcry_pk_sign): Likewise.
+ (gcry_pk_testkey): Likewise.
+ (gcry_pk_genkey): Likewise.
+ (gcry_pk_get_nbits): Likewise.
+ (sexp_to_key): Removed unused variable: algo.
+ (sexp_to_sig): Likewise.
+
+ * cipher.c: Named struct for cipher_table `cipher_table_entry'.
+ (cipher_table_entry): New member: algorithm; filled in.
+ (gcry_cipher_register_default): Used algorithm ID from
+ cipher_table.
+ (gcry_cipher_register): New argument: algorithm_id, filled in.
+ (gcry_cipher_map_name): Used algorithm ID from module structure.
+
+ * arcfour.c (cipher_spec_arcfour): Removed algorithm ID.
+ * blowfish.c (cipher_spec_blowfish): Likewise.
+ * cast5.c (cipher_spec_cast5): Likewise.
+ * crc.c (digest_spec_crc32): Likewise.
+ * crc.c (digest_spec_crc32_rfc1510): Likewise.
+ * crc.c (digest_spec_crc32_rfc2440): Likewise.
+ * des.c (cipher_spec_des): Likewise.
+ * des.c (cipher_spec_tripledes): Likewise.
+ * dsa.c (pubkey_spec_dsa): Likewise.
+ * elgamal.c (pubkey_spec_elg): Likewise.
+ * md4.c (digest_spec_md4): Likewise.
+ * md5.c (digest_spec_md5): Likewise.
+ * aes.c (cipher_spec_aes): Likewise.
+ * aes.c (cipher_spec_aes192): Likewise.
+ * aes.c (cipher_spec_aes256): Likewise.
+ * rsa.c (pubkey_spec_rsa): Likewise.
+ * sha1.c (digest_spec_sha1): Likewise.
+ * sha256.c (digest_spec_sha256): Likewise.
+ * sha512.c (digest_spec_sha512): Likewise.
+ * tiger.c (digest_spec_tiger): Likewise.
+ * twofish.c (cipher_spec_twofish): Likewise.
+ * twofish.c (cipher_spec_twofish128): Likewise.
+
+ * Makefile.am (EXTRA_libcipher_la_SOURCES): Fix list of source
+ files; reported by Simon Josefsson <jas@extundo.com>.
+
+ * pubkey.c: Replaced all occurences of `id' with `algorithm',
+ since `id' is a keyword in obj-c.
+ * md.c: Likewise.
+ * cipher.c: Likewise.
+
+ * crc.c, md4.c, md5.c, rmd160.c, sha1.c, sha256.c, tiger.c:
+ Replaced all occurences of gcry_digest_spec_t with gcry_md_spec_t.
+
+ * dsa.c, rsa.c, elgamal.c: Replaced all occurencens of
+ gcry_pubkey_spec_t with gcry_pk_spec_t.
+
+ * md.c: Replaced all occurences of gcry_digest_spec_t with
+ gcry_md_spec_t.
+ (gcry_digest_register_default): Renamed to ...
+ (gcry_md_register_default): ... this; adjusted callers.
+ (gcry_digest_lookup_func_name): Renamed to ...
+ (gcry_md_lookup_func_name): ... this; adjusted callers.
+ (gcry_digest_lookup_name): Renamed to ...
+ (gcry_md_lookup_name): ... this; adjusted callers.
+ (gcry_digest_register): Renamed to ...
+ (gcry_md_register): ... this.
+ (gcry_digest_unregister): Renamed to ...
+ (gcry_md_unregister): ... this.
+
+ * pubkey.c (gcry_pubkey_register): Renamed to ...
+ (gcry_pk_register): ... this.
+ (gcry_pubkey_unregister): Renamed to ...
+ (gcry_pk_unregister): ... this.
+ Replaced all occurences of gcry_pubkey_spec_t with gcry_pk_spec_t.
+ (gcry_pubkey_register_default): Renamed to ...
+ (gcry_pk_register_default): ... this; adjusted callers.
+ (gcry_pubkey_lookup_func_name): Renamed to ...
+ (gcry_pk_lookup_func_name): ... this; adjusted callers.
+ (gcry_pubkey_lookup_name): Renamed to ...
+ (gcry_pk_lookup_name): ... this; adjusted callers.
+
+ * md.c (gcry_md_hash_buffer): Fix error checking. Thanks to Simon
+ Josefsson <jas@extunde.com>.
+
+2003-07-04 Moritz Schulte <moritz@g10code.com>
+
+ * cipher.c (gcry_cipher_list): New function.
+
+2003-07-01 Moritz Schulte <moritz@g10code.com>
+
+ * pubkey.c (sexp_to_sig): Accept a `flags' S-expression to be more
+ consistent with sexp_to_enc.
+
+2003-06-30 Moritz Schulte <moritz@g10code.com>
+
+ * Makefile.am (libcipher_la_SOURCES): Added: ac.c.
+
+ * pubkey.c (_gcry_pk_module_lookup): New function.
+ (_gcry_pk_module_release): New function.
+
+2003-06-29 Moritz Schulte <moritz@g10code.com>
+
+ * ac.c: New file.
+
2003-06-18 Werner Koch <wk@gnupg.org>
* cipher.c (gcry_cipher_get_algo_keylen): New.
diff --git a/cipher/Makefile.am b/cipher/Makefile.am
index ad6025b3..8fb5a631 100644
--- a/cipher/Makefile.am
+++ b/cipher/Makefile.am
@@ -49,10 +49,12 @@ md4.c \
md5.c \
rijndael.c \
rmd160.c \
+rndlinux.c \
rndegd.c \
-endunix.c \
-rndnw32.c \
+rndunix.c \
+rndw32.c \
rsa.c \
+sha1.c \
sha256.c \
sha512.c \
tiger.c \
diff --git a/cipher/ac.c b/cipher/ac.c
index ad1574b2..f35a7338 100644
--- a/cipher/ac.c
+++ b/cipher/ac.c
@@ -80,7 +80,7 @@ struct gcry_ac_handle
handle. */
const char *algorithm_name; /* Name of the algorithm. */
unsigned int flags; /* Flags, not used yet. */
- gcry_module_t *module; /* Reference to the algorithm
+ gcry_module_t module; /* Reference to the algorithm
module. */
};
@@ -472,7 +472,7 @@ gcry_ac_data_construct (const char *identifier, unsigned int flags,
* Functions for working with data sets.
*/
-/* Returns a new, empty data set in DATA. */
+/* Creates a new, empty data set and stores it in DATA. */
gpg_error_t
gcry_ac_data_new (gcry_ac_data_t *data)
{
@@ -493,7 +493,7 @@ gcry_ac_data_new (gcry_ac_data_t *data)
return gpg_error (err);
}
-/* Destroy the data set DATA. */
+/* Destroys the data set DATA. */
void
gcry_ac_data_destroy (gcry_ac_data_t data)
{
@@ -508,8 +508,9 @@ gcry_ac_data_destroy (gcry_ac_data_t data)
gcry_free (data);
}
-/* Add the value MPI to DATA with the label NAME. If there is already
- a value with that label, replace it, otherwise add it. */
+/* Adds the value MPI to the data set DATA with the label NAME. If
+ there is already a value with that label, it is replaced, otherwise
+ a new value is added. */
gpg_error_t
gcry_ac_data_set (gcry_ac_data_t data,
const char *name, gcry_mpi_t mpi)
@@ -521,8 +522,11 @@ gcry_ac_data_set (gcry_ac_data_t data,
if (ac_mpi)
{
/* An entry for NAME does already exist, replace it. */
- gcry_mpi_release (ac_mpi->mpi);
- ac_mpi->mpi = mpi;
+ if (ac_mpi->mpi != mpi)
+ {
+ gcry_mpi_release (ac_mpi->mpi);
+ ac_mpi->mpi = mpi;
+ }
}
else
{
@@ -552,7 +556,7 @@ gcry_ac_data_set (gcry_ac_data_t data,
return gpg_error (err);
}
-/* Return the number of named MPI values inside of the data set
+/* Returns the number of named MPI values inside of the data set
DATA. */
unsigned int
gcry_ac_data_length (gcry_ac_data_t data)
@@ -560,8 +564,10 @@ gcry_ac_data_length (gcry_ac_data_t data)
return data->data_n;
}
-/* Store the value labelled with NAME found in DATA in MPI or NULL if
- a value with that label was not found. */
+/* Stores the value labelled with NAME found in the data set DATA in
+ MPI. The returned MPI value will be released in case
+ gcry_ac_data_set is used to associate the label NAME with a
+ different MPI value. */
gpg_error_t
gcry_ac_data_get_name (gcry_ac_data_t data, const char *name,
gcry_mpi_t *mpi)
@@ -583,8 +589,10 @@ gcry_ac_data_get_name (gcry_ac_data_t data, const char *name,
return gpg_error (err);
}
-/* Return the MPI value with index INDEX contained in the data set
- DATA. */
+/* Stores in NAME and MPI the named MPI value contained in the data
+ set DATA with the index INDEX. NAME or MPI may be NULL. The
+ returned MPI value will be released in case gcry_ac_data_set is
+ used to associate the label NAME with a different MPI value. */
gpg_error_t
gcry_ac_data_get_index (gcry_ac_data_t data, unsigned int index,
const char **name, gcry_mpi_t *mpi)
@@ -604,7 +612,7 @@ gcry_ac_data_get_index (gcry_ac_data_t data, unsigned int index,
return gpg_error (err);
}
-/* Destroy any values contained in the data set DATA. */
+/* Destroys any values contained in the data set DATA. */
void
gcry_ac_data_clear (gcry_ac_data_t data)
{
@@ -619,13 +627,14 @@ gcry_ac_data_clear (gcry_ac_data_t data)
* Handle management.
*/
-/* Create a new ac handle. */
+/* Creates a new handle for the algorithm ALGORITHM and store it in
+ HANDLE. FLAGS is not used yet. */
gpg_error_t
gcry_ac_open (gcry_ac_handle_t *handle,
gcry_ac_id_t algorithm, unsigned int flags)
{
gpg_err_code_t err = GPG_ERR_NO_ERROR;
- gcry_module_t *module = NULL;
+ gcry_module_t module = NULL;
gcry_ac_handle_t handle_new;
const char *algorithm_name;
@@ -665,7 +674,7 @@ gcry_ac_open (gcry_ac_handle_t *handle,
return gpg_error (err);
}
-/* Destroy an ac handle. */
+/* Destroys the handle HANDLE. */
void
gcry_ac_close (gcry_ac_handle_t handle)
{
@@ -680,7 +689,8 @@ gcry_ac_close (gcry_ac_handle_t handle)
* Key management.
*/
-/* Initialize a key from a given data set. */
+/* Creates a new key of type TYPE, consisting of the MPI values
+ contained in the data set DATA and stores it in KEY. */
gpg_error_t
gcry_ac_key_init (gcry_ac_key_t *key,
gcry_ac_handle_t handle,
@@ -726,7 +736,10 @@ gcry_ac_key_init (gcry_ac_key_t *key,
return gpg_error (err);
}
-/* Generate a new key pair. */
+/* Generates a new key pair via the handle HANDLE of NBITS bits and
+ stores it in KEY_PAIR. In case non-standard settings are wanted, a
+ pointer to a structure of type gcry_ac_key_spec_<algorithm>_t,
+ matching the selected algorithm, can be given as KEY_SPEC. */
gpg_error_t
gcry_ac_key_pair_generate (gcry_ac_handle_t handle,
gcry_ac_key_pair_t *key_pair,
@@ -776,13 +789,13 @@ gcry_ac_key_pair_generate (gcry_ac_handle_t handle,
{
/* Calculate size of the format string, that is used for
creating the request S-expression. */
- genkey_format_n = 22;
+ genkey_format_n = 23;
/* Respect any relevant algorithm specific commands. */
if (key_spec)
for (i = 0; gcry_ac_key_generate_specs[i].algorithm; i++)
if (handle->algorithm == gcry_ac_key_generate_specs[i].algorithm)
- genkey_format_n += 4;
+ genkey_format_n += 6;
/* Create format string. */
genkey_format = gcry_malloc (genkey_format_n);
@@ -908,7 +921,7 @@ gcry_ac_key_pair_generate (gcry_ac_handle_t handle,
return gpg_error (err);
}
-/* Returns a specified key from a key pair. */
+/* Returns the key of type WHICH out of the key pair KEY_PAIR. */
gcry_ac_key_t
gcry_ac_key_pair_extract (gcry_ac_key_pair_t key_pair,
gcry_ac_key_type_t witch)
@@ -929,7 +942,7 @@ gcry_ac_key_pair_extract (gcry_ac_key_pair_t key_pair,
return key;
}
-/* Destroy a key. */
+/* Destroys the key KEY. */
void
gcry_ac_key_destroy (gcry_ac_key_t key)
{
@@ -947,7 +960,7 @@ gcry_ac_key_destroy (gcry_ac_key_t key)
gcry_free (key);
}
-/* Destroy a key pair. */
+/* Destroys the key pair KEY_PAIR. */
void
gcry_ac_key_pair_destroy (gcry_ac_key_pair_t key_pair)
{
@@ -956,7 +969,7 @@ gcry_ac_key_pair_destroy (gcry_ac_key_pair_t key_pair)
gcry_free (key_pair);
}
-/* Verify that the key KEY is sane. */
+/* Verifies that the key KEY is sane. */
gpg_error_t
gcry_ac_key_test (gcry_ac_key_t key)
{
@@ -967,7 +980,7 @@ gcry_ac_key_test (gcry_ac_key_t key)
return gpg_error (err);
}
-/* Return the number of bits of the key KEY in NBITS. */
+/* Stores the number of bits of the key KEY in NBITS. */
gpg_error_t
gcry_ac_key_get_nbits (gcry_ac_key_t key, unsigned int *nbits)
{
@@ -983,7 +996,7 @@ gcry_ac_key_get_nbits (gcry_ac_key_t key, unsigned int *nbits)
return gpg_error (err);
}
-/* Write the 20 byte long key grip of the key KEY to KEY_GRIP. */
+/* Writes the 20 byte long key grip of the key KEY to KEY_GRIP. */
gpg_error_t
gcry_ac_key_get_grip (gcry_ac_key_t key, unsigned char *key_grip)
{
@@ -1003,9 +1016,9 @@ gcry_ac_key_get_grip (gcry_ac_key_t key, unsigned char *key_grip)
* Functions performing cryptographic operations.
*/
-/* Encrypt the plain text MPI value DATA_PLAIN with the key KEY under
- the control of the flags FLAGS and store the resulting data set
- into DATA_ENCRYPTED. */
+/* Encrypts the plain text MPI value DATA_PLAIN with the key public
+ KEY under the control of the flags FLAGS and stores the resulting
+ data set into DATA_ENCRYPTED. */
gpg_error_t
gcry_ac_data_encrypt (gcry_ac_handle_t handle,
unsigned int flags,
@@ -1081,9 +1094,10 @@ gcry_ac_data_encrypt (gcry_ac_handle_t handle,
return gpg_error (err);
}
-/* Decrypt the decrypted data contained in the data set DATA_ENCRYPTED
- with the key KEY under the control of the flags FLAGS and store the
- resulting plain text MPI value in DATA_PLAIN. */
+/* Decrypts the encrypted data contained in the data set
+ DATA_ENCRYPTED with the secret key KEY under the control of the
+ flags FLAGS and stores the resulting plain text MPI value in
+ DATA_PLAIN. */
gpg_error_t
gcry_ac_data_decrypt (gcry_ac_handle_t handle,
unsigned int flags,
@@ -1143,8 +1157,8 @@ gcry_ac_data_decrypt (gcry_ac_handle_t handle,
}
-/* Sign the data contained in DATA with the key KEY and store the
- resulting signature in the data set DATA_SIGNATURE. */
+/* Signs the data contained in DATA with the secret key KEY and stores
+ the resulting signature data set in DATA_SIGNATURE. */
gpg_error_t
gcry_ac_data_sign (gcry_ac_handle_t handle,
gcry_ac_key_t key,
@@ -1185,9 +1199,9 @@ gcry_ac_data_sign (gcry_ac_handle_t handle,
return gpg_error (err);
}
-/* Verify that the signature contained in the data set DATA_SIGNATURE
- is indeed the result of signing the data contained in DATA with the
- secret key belonging to the public key KEY. */
+/* Verifies that the signature contained in the data set
+ DATA_SIGNATURE is indeed the result of signing the data contained
+ in DATA with the secret key belonging to the public key KEY. */
gpg_error_t
gcry_ac_data_verify (gcry_ac_handle_t handle,
gcry_ac_key_t key,
@@ -1231,8 +1245,8 @@ gcry_ac_data_verify (gcry_ac_handle_t handle,
* General functions.
*/
-/* Store the textual representation of the algorithm whose id is given
- in ALGORITHM in NAME. */
+/* Stores the textual representation of the algorithm whose id is
+ given in ALGORITHM in NAME. */
gpg_error_t
gcry_ac_id_to_name (gcry_ac_id_t algorithm, const char **name)
{
@@ -1248,7 +1262,7 @@ gcry_ac_id_to_name (gcry_ac_id_t algorithm, const char **name)
return gpg_error (err);
}
-/* Store the numeric ID of the algorithm whose textual representation
+/* Stores the numeric ID of the algorithm whose textual representation
is contained in NAME in ALGORITHM. */
gpg_error_t
gcry_ac_name_to_id (const char *name, gcry_ac_id_t *algorithm)
diff --git a/cipher/arcfour.c b/cipher/arcfour.c
index 90d66985..2e3bf22a 100644
--- a/cipher/arcfour.c
+++ b/cipher/arcfour.c
@@ -149,6 +149,6 @@ selftest(void)
gcry_cipher_spec_t cipher_spec_arcfour =
{
- "ARCFOUR", GCRY_CIPHER_ARCFOUR, 1, 128, sizeof (ARCFOUR_context),
+ "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 f5eb513a..97909a5e 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", GCRY_CIPHER_BLOWFISH, BLOWFISH_BLOCKSIZE, 128,
+ "BLOWFISH", BLOWFISH_BLOCKSIZE, 128,
sizeof (BLOWFISH_context),
bf_setkey, encrypt_block, decrypt_block,
};
diff --git a/cipher/cast5.c b/cipher/cast5.c
index fb590d0b..8c036d84 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", GCRY_CIPHER_CAST5, CAST5_BLOCKSIZE, 128, sizeof (CAST5_context),
+ "CAST5", CAST5_BLOCKSIZE, 128, sizeof (CAST5_context),
cast_setkey, encrypt_block, decrypt_block,
};
diff --git a/cipher/cipher.c b/cipher/cipher.c
index 185ac9f7..30cd4f0a 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -65,38 +65,39 @@ static struct
/* This is the list of the default ciphers, which are included in
libgcrypt. */
-static struct
+static struct cipher_table_entry
{
gcry_cipher_spec_t *cipher;
+ unsigned int algorithm;
} cipher_table[] =
{
#if USE_BLOWFISH
- { &cipher_spec_blowfish, },
+ { &cipher_spec_blowfish, GCRY_CIPHER_BLOWFISH },
#endif
#if USE_DES
- { &cipher_spec_des },
- { &cipher_spec_tripledes },
+ { &cipher_spec_des, GCRY_CIPHER_DES },
+ { &cipher_spec_tripledes, GCRY_CIPHER_3DES },
#endif
#if USE_ARCFOUR
- { &cipher_spec_arcfour },
+ { &cipher_spec_arcfour, GCRY_CIPHER_ARCFOUR },
#endif
#if USE_CAST5
- { &cipher_spec_cast5 },
+ { &cipher_spec_cast5, GCRY_CIPHER_CAST5 },
#endif
#if USE_AES
- { &cipher_spec_aes },
- { &cipher_spec_aes192 },
- { &cipher_spec_aes256 },
+ { &cipher_spec_aes, GCRY_CIPHER_AES },
+ { &cipher_spec_aes192, GCRY_CIPHER_AES192 },
+ { &cipher_spec_aes256, GCRY_CIPHER_AES256 },
#endif
#if USE_TWOFISH
- { &cipher_spec_twofish },
- { &cipher_spec_twofish128 },
+ { &cipher_spec_twofish, GCRY_CIPHER_TWOFISH },
+ // { &cipher_spec_twofish128, GCRY_CIPHER_TWOFISH128 },
#endif
{ NULL },
};
/* List of registered ciphers. */
-static gcry_module_t *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,7 +182,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,
+ cipher_table[i].algorithm,
(void *) cipher_table[i].cipher,
NULL);
}
@@ -201,10 +202,10 @@ gcry_cipher_lookup_func_name (void *spec, void *data)
}
/* Internal function. Lookup a cipher entry by it's name. */
-static gcry_module_t *
+static gcry_module_t
gcry_cipher_lookup_name (const char *name)
{
- gcry_module_t *cipher;
+ gcry_module_t cipher;
cipher = _gcry_module_lookup (ciphers_registered, (void *) name,
gcry_cipher_lookup_func_name);
@@ -212,15 +213,16 @@ gcry_cipher_lookup_name (const char *name)
return cipher;
}
-/* 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. */
+/* 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. */
gpg_error_t
gcry_cipher_register (gcry_cipher_spec_t *cipher,
- gcry_module_t **module)
+ unsigned int *algorithm_id,
+ gcry_module_t *module)
{
gpg_err_code_t err = 0;
- gcry_module_t *mod;
+ gcry_module_t mod;
ath_mutex_lock (&ciphers_registered_lock);
err = _gcry_module_add (&ciphers_registered, 0,
@@ -230,16 +232,16 @@ gcry_cipher_register (gcry_cipher_spec_t *cipher,
if (! err)
{
*module = mod;
- cipher->id = mod->id;
+ *algorithm_id = mod->mod_id;
}
return gpg_error (err);
}
-/* Public function. Unregister the cipher identified by MODULE, which
- must have been registered with gcry_cipher_register. */
+/* Unregister the cipher identified by MODULE, which must have been
+ registered with gcry_cipher_register. */
void
-gcry_cipher_unregister (gcry_module_t *module)
+gcry_cipher_unregister (gcry_module_t module)
{
ath_mutex_lock (&ciphers_registered_lock);
_gcry_module_release (module);
@@ -251,7 +253,7 @@ struct gcry_cipher_handle
{
int magic;
gcry_cipher_spec_t *cipher;
- gcry_module_t *module;
+ gcry_module_t module;
int mode;
unsigned int flags;
byte iv[MAX_BLOCKSIZE]; /* (this should be ulong aligned) */
@@ -292,8 +294,8 @@ search_oid (const char *string)
int
gcry_cipher_map_name( const char *string )
{
- gcry_module_t *cipher;
- int i, id = 0;
+ gcry_module_t cipher;
+ int i, algorithm = 0;
if (!string)
return 0;
@@ -322,12 +324,12 @@ gcry_cipher_map_name( const char *string )
cipher = gcry_cipher_lookup_name (string);
if (cipher)
{
- id = ((gcry_cipher_spec_t *) cipher->spec)->id;
+ algorithm = cipher->mod_id;
_gcry_module_release (cipher);
}
ath_mutex_unlock (&ciphers_registered_lock);
- return id;
+ return algorithm;
}
int
@@ -344,15 +346,15 @@ gcry_cipher_mode_from_oid (const char *string)
* Map a cipher algo to a string
*/
static const char *
-cipher_algo_to_string (int id)
+cipher_algo_to_string (int algorithm)
{
- gcry_module_t *cipher;
+ gcry_module_t cipher;
const char *name = NULL;
REGISTER_DEFAULT_CIPHERS;
ath_mutex_lock (&ciphers_registered_lock);
- cipher = _gcry_module_lookup_id (ciphers_registered, id);
+ cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
if (cipher)
{
name = ((gcry_cipher_spec_t *) cipher->spec)->name;
@@ -368,22 +370,22 @@ cipher_algo_to_string (int id)
* string when there is no algo. It will never return NULL.
*/
const char *
-gcry_cipher_algo_name (int id)
+gcry_cipher_algo_name (int algorithm)
{
- const char *s = cipher_algo_to_string (id);
+ const char *s = cipher_algo_to_string (algorithm);
return s ? s : "";
}
static void
-disable_cipher_algo (int id)
+disable_cipher_algo (int algorithm)
{
- gcry_module_t *cipher;
+ gcry_module_t cipher;
REGISTER_DEFAULT_CIPHERS;
ath_mutex_lock (&ciphers_registered_lock);
- cipher = _gcry_module_lookup_id (ciphers_registered, id);
+ cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
if (cipher)
{
if (! (cipher->flags & FLAG_MODULE_DISABLED))
@@ -399,15 +401,15 @@ disable_cipher_algo (int id)
*/
static gpg_err_code_t
-check_cipher_algo (int id)
+check_cipher_algo (int algorithm)
{
gpg_err_code_t err = GPG_ERR_NO_ERROR;
- gcry_module_t *cipher;
+ gcry_module_t cipher;
REGISTER_DEFAULT_CIPHERS;
ath_mutex_lock (&ciphers_registered_lock);
- cipher = _gcry_module_lookup_id (ciphers_registered, id);
+ cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
if (cipher)
{
if (cipher->flags & FLAG_MODULE_DISABLED)
@@ -422,48 +424,48 @@ check_cipher_algo (int id)
}
static unsigned
-cipher_get_keylen (int id)
+cipher_get_keylen (int algorithm)
{
- gcry_module_t *cipher;
+ gcry_module_t cipher;
unsigned len = 0;
REGISTER_DEFAULT_CIPHERS;
ath_mutex_lock (&ciphers_registered_lock);
- cipher = _gcry_module_lookup_id (ciphers_registered, id);
+ cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
if (cipher)
{
len = ((gcry_cipher_spec_t *) cipher->spec)->keylen;
if (! len)
- log_bug ("cipher %d w/o key length\n", id);
+ log_bug ("cipher %d w/o key length\n", algorithm);
_gcry_module_release (cipher);
}
else
- log_bug ("cipher %d not found\n", id);
+ log_bug ("cipher %d not found\n", algorithm);
ath_mutex_unlock (&ciphers_registered_lock);
return len;
}
static unsigned
-cipher_get_blocksize (int id)
+cipher_get_blocksize (int algorithm)
{
- gcry_module_t *cipher;
+ gcry_module_t cipher;
unsigned len = 0;
REGISTER_DEFAULT_CIPHERS;
ath_mutex_lock (&ciphers_registered_lock);
- cipher = _gcry_module_lookup_id (ciphers_registered, id);
+ cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
if (cipher)
{
len = ((gcry_cipher_spec_t *) cipher->spec)->blocksize;
if (! len)
- log_bug ("cipher %d w/o blocksize\n", id);
+ log_bug ("cipher %d w/o blocksize\n", algorithm);
_gcry_module_release (cipher);
}
else
- log_bug ("cipher %d not found\n", id);
+ log_bug ("cipher %d not found\n", algorithm);
ath_mutex_unlock (&ciphers_registered_lock);
return len;
@@ -477,11 +479,11 @@ cipher_get_blocksize (int id)
gpg_error_t
gcry_cipher_open (gcry_cipher_hd_t *handle,
- int algo, int mode, unsigned int flags )
+ int algo, int mode, unsigned int flags)
{
int secure = (flags & GCRY_CIPHER_SECURE);
gcry_cipher_spec_t *cipher = NULL;
- gcry_module_t *module = NULL;
+ gcry_module_t module = NULL;
gcry_cipher_hd_t h = NULL;
gpg_err_code_t err = 0;
@@ -1280,3 +1282,21 @@ _gcry_cipher_init (void)
return err;
}
+
+/* Get a list consisting of the IDs of the loaded cipher modules. If
+ LIST is zero, write the number of loaded cipher modules to
+ LIST_LENGTH and return. If LIST is non-zero, the first
+ *LIST_LENGTH algorithm IDs are stored in LIST, which must be of
+ according size. In case there are less cipher modules than
+ *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */
+gpg_error_t
+gcry_cipher_list (int *list, int *list_length)
+{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
+ ath_mutex_lock (&ciphers_registered_lock);
+ err = _gcry_module_list (ciphers_registered, list, list_length);
+ ath_mutex_unlock (&ciphers_registered_lock);
+
+ return err;
+}
diff --git a/cipher/crc.c b/cipher/crc.c
index 70546c2e..f2116c16 100644
--- a/cipher/crc.c
+++ b/cipher/crc.c
@@ -271,24 +271,24 @@ crc24rfc2440_final (void *context)
ctx->buf[2] = (ctx->CRC ) & 0xFF;
}
-gcry_digest_spec_t digest_spec_crc32 =
+gcry_md_spec_t digest_spec_crc32 =
{
- "CRC32", GCRY_MD_CRC32, NULL, 0, 4,
+ "CRC32", NULL, 0, 4,
crc32_init, crc32_write, crc32_final, crc32_read,
sizeof (CRC_CONTEXT)
};
-gcry_digest_spec_t digest_spec_crc32_rfc1510 =
+gcry_md_spec_t digest_spec_crc32_rfc1510 =
{
- "CRC32RFC1510", GCRY_MD_CRC32_RFC1510, NULL, 0, 4,
+ "CRC32RFC1510", NULL, 0, 4,
crc32rfc1510_init, crc32_write,
crc32rfc1510_final, crc32_read,
sizeof (CRC_CONTEXT)
};
-gcry_digest_spec_t digest_spec_crc24_rfc2440 =
+gcry_md_spec_t digest_spec_crc24_rfc2440 =
{
- "CRC24RFC2440", GCRY_MD_CRC24_RFC2440, NULL, 0, 3,
+ "CRC24RFC2440", NULL, 0, 3,
crc24rfc2440_init, crc24rfc2440_write,
crc24rfc2440_final, crc32_read,
sizeof (CRC_CONTEXT)
diff --git a/cipher/des.c b/cipher/des.c
index 9a9555a8..d9acaaf5 100644
--- a/cipher/des.c
+++ b/cipher/des.c
@@ -1068,12 +1068,12 @@ do_des_decrypt( void *context, byte *outbuf, const byte *inbuf )
gcry_cipher_spec_t cipher_spec_des =
{
- "DES", GCRY_CIPHER_DES, 8, 64, sizeof (struct _des_ctx),
+ "DES", 8, 64, sizeof (struct _des_ctx),
do_des_setkey, do_des_encrypt, do_des_decrypt
};
gcry_cipher_spec_t cipher_spec_tripledes =
{
- "3DES", GCRY_CIPHER_3DES, 8, 192, sizeof (struct _tripledes_ctx),
+ "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 c2a2e519..970002e9 100644
--- a/cipher/dsa.c
+++ b/cipher/dsa.c
@@ -456,9 +456,9 @@ static char *dsa_names[] =
NULL,
};
-gcry_pubkey_spec_t pubkey_spec_dsa =
+gcry_pk_spec_t pubkey_spec_dsa =
{
- "DSA", dsa_names, GCRY_PK_DSA,
+ "DSA", dsa_names,
"pqgy", "pqgyx", "", "rs", "pqgy",
GCRY_PK_USAGE_SIGN,
_gcry_dsa_generate,
diff --git a/cipher/elgamal.c b/cipher/elgamal.c
index dee79da7..e1b20740 100644
--- a/cipher/elgamal.c
+++ b/cipher/elgamal.c
@@ -1,4 +1,4 @@
-/* elgamal.c - ElGamal Public Key encryption
+/* Elgamal.c - ElGamal Public Key encryption
* Copyright (C) 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
@@ -641,9 +641,9 @@ static char *elg_names[] =
};
-gcry_pubkey_spec_t pubkey_spec_elg =
+gcry_pk_spec_t pubkey_spec_elg =
{
- "ELG", elg_names, GCRY_PK_ELG,
+ "ELG", elg_names,
"pgy", "pgyx", "ab", "rs", "pgy",
GCRY_PK_USAGE_SIGN | GCRY_PK_USAGE_ENCR,
_gcry_elg_generate,
diff --git a/cipher/md.c b/cipher/md.c
index 4872e498..82fe1865 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -60,44 +60,44 @@ static struct {
{NULL}
};
-static struct
+static struct digest_table_entry
{
- gcry_digest_spec_t *digest;
- int flags;
+ gcry_md_spec_t *digest;
+ unsigned int algorithm;
} digest_table[] =
{
#if USE_CRC
- { &digest_spec_crc32, 0 },
- { &digest_spec_crc32_rfc1510, 0 },
- { &digest_spec_crc24_rfc2440, 0 },
+ { &digest_spec_crc32, GCRY_MD_CRC32 },
+ { &digest_spec_crc32_rfc1510, GCRY_MD_CRC32_RFC1510 },
+ { &digest_spec_crc24_rfc2440, GCRY_MD_CRC24_RFC2440 },
#endif
#if USE_MD4
- { &digest_spec_md4, 0 },
+ { &digest_spec_md4, GCRY_MD_MD4 },
#endif
#if USE_MD5
- { &digest_spec_md5, 0 },
+ { &digest_spec_md5, GCRY_MD_MD5 },
#endif
#if USE_RMD160
- { &digest_spec_rmd160, 0 },
+ { &digest_spec_rmd160, GCRY_MD_RMD160 },
#endif
#if USE_SHA1
- { &digest_spec_sha1, 0 },
+ { &digest_spec_sha1, GCRY_MD_SHA1 },
#endif
#if USE_SHA256
- { &digest_spec_sha256, 0 },
+ { &digest_spec_sha256, GCRY_MD_SHA256 },
#endif
#if USE_SHA512
- { &digest_spec_sha512, 0 },
- { &digest_spec_sha384, 0 },
+ { &digest_spec_sha512, GCRY_MD_SHA512 },
+ { &digest_spec_sha384, GCRY_MD_SHA384 },
#endif
#if USE_TIGER
- { &digest_spec_tiger, 0 },
+ { &digest_spec_tiger, GCRY_MD_TIGER },
#endif
{ NULL },
};
/* List of registered digests. */
-static gcry_module_t *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;
@@ -113,7 +113,7 @@ static int default_digests_registered;
ath_mutex_lock (&digests_registered_lock); \
if (! default_digests_registered) \
{ \
- gcry_digest_register_default (); \
+ gcry_md_register_default (); \
default_digests_registered = 1; \
} \
ath_mutex_unlock (&digests_registered_lock); \
@@ -123,14 +123,14 @@ static int default_digests_registered;
/* Internal function. Register all the ciphers included in
CIPHER_TABLE. Returns zero on success or an error code. */
static void
-gcry_digest_register_default (void)
+gcry_md_register_default (void)
{
gpg_err_code_t err = 0;
int i;
for (i = 0; (! err) && digest_table[i].digest; i++)
err = _gcry_module_add (&digests_registered,
- digest_table[i].digest->id,
+ digest_table[i].algorithm,
(void *) digest_table[i].digest,
NULL);
@@ -140,34 +140,36 @@ gcry_digest_register_default (void)
/* Internal callback function. */
static int
-gcry_digest_lookup_func_name (void *spec, void *data)
+gcry_md_lookup_func_name (void *spec, void *data)
{
- gcry_digest_spec_t *digest = (gcry_digest_spec_t *) spec;
+ gcry_md_spec_t *digest = (gcry_md_spec_t *) spec;
char *name = (char *) data;
return (! stricmp (digest->name, name));
}
/* Internal function. Lookup a digest entry by it's name. */
-static gcry_module_t *
-gcry_digest_lookup_name (const char *name)
+static gcry_module_t
+gcry_md_lookup_name (const char *name)
{
- gcry_module_t *digest;
+ gcry_module_t digest;
digest = _gcry_module_lookup (digests_registered, (void *) name,
- gcry_digest_lookup_func_name);
+ gcry_md_lookup_func_name);
return digest;
}
-/* 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. */
+/* 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. */
gpg_error_t
-gcry_digest_register (gcry_digest_spec_t *digest, gcry_module_t **module)
+gcry_md_register (gcry_md_spec_t *digest,
+ unsigned int *algorithm_id,
+ gcry_module_t *module)
{
gpg_err_code_t err = 0;
- gcry_module_t *mod;
+ gcry_module_t mod;
ath_mutex_lock (&digests_registered_lock);
err = _gcry_module_add (&digests_registered, 0,
@@ -177,16 +179,16 @@ gcry_digest_register (gcry_digest_spec_t *digest, gcry_module_t **module)
if (! err)
{
*module = mod;
- digest->id = mod->id;
+ *algorithm_id = mod->mod_id;
}
return gpg_error (err);
}
-/* Public function. Unregister the digest identified by ID, which
- must have been registered with gcry_digest_register. */
+/* Unregister the digest identified by ID, which must have been
+ registered with gcry_digest_register. */
void
-gcry_digest_unregister (gcry_module_t *module)
+gcry_md_unregister (gcry_module_t module)
{
ath_mutex_lock (&digests_registered_lock);
_gcry_module_release (module);
@@ -195,8 +197,8 @@ gcry_digest_unregister (gcry_module_t *module)
typedef struct gcry_md_list
{
- gcry_digest_spec_t *digest;
- gcry_module_t *module;
+ gcry_md_spec_t *digest;
+ gcry_module_t module;
struct gcry_md_list *next;
PROPERLY_ALIGNED_TYPE context;
} GcryDigestEntry;
@@ -237,8 +239,8 @@ static void md_stop_debug( gcry_md_hd_t a );
int
gcry_md_map_name (const char *string)
{
- gcry_module_t *digest;
- int id = 0;
+ gcry_module_t digest;
+ int algorithm = 0;
if (!string)
return 0;
@@ -264,15 +266,15 @@ gcry_md_map_name (const char *string)
REGISTER_DEFAULT_DIGESTS;
ath_mutex_lock (&digests_registered_lock);
- digest = gcry_digest_lookup_name (string);
+ digest = gcry_md_lookup_name (string);
if (digest)
{
- id = ((gcry_digest_spec_t *) digest->spec)->id;
+ algorithm = digest->mod_id;
_gcry_module_release (digest);
}
ath_mutex_unlock (&digests_registered_lock);
- return id;
+ return algorithm;
}
@@ -280,18 +282,18 @@ gcry_md_map_name (const char *string)
* Map a digest algo to a string
*/
static const char *
-digest_algo_to_string (int id)
+digest_algo_to_string (int algorithm)
{
const char *name = NULL;
- gcry_module_t *digest;
+ gcry_module_t digest;
REGISTER_DEFAULT_DIGESTS;
ath_mutex_lock (&digests_registered_lock);
- digest = _gcry_module_lookup_id (digests_registered, id);
+ digest = _gcry_module_lookup_id (digests_registered, algorithm);
if (digest)
{
- name = ((gcry_digest_spec_t *) digest->spec)->name;
+ name = ((gcry_md_spec_t *) digest->spec)->name;
_gcry_module_release (digest);
}
ath_mutex_unlock (&digests_registered_lock);
@@ -306,23 +308,23 @@ digest_algo_to_string (int id)
* is valid.
*/
const char *
-gcry_md_algo_name (int id)
+gcry_md_algo_name (int algorithm)
{
- const char *s = digest_algo_to_string (id);
+ const char *s = digest_algo_to_string (algorithm);
return s ? s : "?";
}
static gpg_err_code_t
-check_digest_algo (int id)
+check_digest_algo (int algorithm)
{
gpg_err_code_t rc = 0;
- gcry_module_t *digest;
+ gcry_module_t digest;
REGISTER_DEFAULT_DIGESTS;
ath_mutex_lock (&digests_registered_lock);
- digest = _gcry_module_lookup_id (digests_registered, id);
+ digest = _gcry_module_lookup_id (digests_registered, algorithm);
if (digest)
_gcry_module_release (digest);
else
@@ -443,30 +445,30 @@ gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags)
static gpg_err_code_t
-md_enable (gcry_md_hd_t hd, int id)
+md_enable (gcry_md_hd_t hd, int algorithm)
{
struct gcry_md_context *h = hd->ctx;
- gcry_digest_spec_t *digest = NULL;
+ gcry_md_spec_t *digest = NULL;
GcryDigestEntry *entry;
- gcry_module_t *module;
+ gcry_module_t module;
gpg_err_code_t err = 0;
for (entry = h->list; entry; entry = entry->next)
- if (entry->digest->id == id)
+ if (entry->module->mod_id == algorithm)
return err; /* already enabled */
REGISTER_DEFAULT_DIGESTS;
ath_mutex_lock (&digests_registered_lock);
- module = _gcry_module_lookup_id (digests_registered, id);
+ module = _gcry_module_lookup_id (digests_registered, algorithm);
ath_mutex_unlock (&digests_registered_lock);
if (! module)
{
- log_debug ("md_enable: algorithm %d not available\n", id);
+ log_debug ("md_enable: algorithm %d not available\n", algorithm);
err = GPG_ERR_DIGEST_ALGO;
}
else
- digest = (gcry_digest_spec_t *) module->spec;
+ digest = (gcry_md_spec_t *) module->spec;
if (! err)
{
@@ -509,9 +511,9 @@ md_enable (gcry_md_hd_t hd, int id)
gpg_error_t
-gcry_md_enable (gcry_md_hd_t hd, int id)
+gcry_md_enable (gcry_md_hd_t hd, int algorithm)
{
- gpg_err_code_t err = md_enable (hd, id);
+ gpg_err_code_t err = md_enable (hd, algorithm);
return gpg_error (err);
}
@@ -811,7 +813,7 @@ md_read( gcry_md_hd_t a, int algo )
else
{
for (r = a->ctx->list; r; r = r->next)
- if (r->digest->id == algo)
+ if (r->module->mod_id == algo)
return (*r->digest->read) (&r->context.c);
}
BUG();
@@ -909,7 +911,7 @@ gcry_md_hash_buffer (int algo, void *digest, const void *buffer, size_t length)
normal functions to do it */
gcry_md_hd_t h;
gpg_err_code_t err = md_open (&h, algo, 0, 0);
- if(! err)
+ if (err)
/* FIXME? */
BUG(); /* algo not available */
md_write (h, (byte *) buffer, length);
@@ -926,7 +928,7 @@ md_get_algo (gcry_md_hd_t a)
if (r && r->next)
log_error("WARNING: more than algorithm in md_get_algo()\n");
- return r ? r->digest->id : 0;
+ return r ? r->module->mod_id : 0;
}
int
@@ -940,18 +942,18 @@ gcry_md_get_algo (gcry_md_hd_t hd)
* Return the length of the digest
*/
static int
-md_digest_length (int id)
+md_digest_length (int algorithm)
{
- gcry_module_t *digest;
+ gcry_module_t digest;
int mdlen = 0;
REGISTER_DEFAULT_DIGESTS;
ath_mutex_lock (&digests_registered_lock);
- digest = _gcry_module_lookup_id (digests_registered, id);
+ digest = _gcry_module_lookup_id (digests_registered, algorithm);
if (digest)
{
- mdlen = ((gcry_digest_spec_t *) digest->spec)->mdlen;
+ mdlen = ((gcry_md_spec_t *) digest->spec)->mdlen;
_gcry_module_release (digest);
}
ath_mutex_unlock (&digests_registered_lock);
@@ -964,35 +966,35 @@ md_digest_length (int id)
* This function will return 0 in case of errors.
*/
unsigned int
-gcry_md_get_algo_dlen (int id)
+gcry_md_get_algo_dlen (int algorithm)
{
- return md_digest_length (id);
+ return md_digest_length (algorithm);
}
/* Hmmm: add a mode to enumerate the OIDs
* to make g10/sig-check.c more portable */
static const byte *
-md_asn_oid (int id, size_t *asnlen, size_t *mdlen)
+md_asn_oid (int algorithm, size_t *asnlen, size_t *mdlen)
{
const byte *asnoid = NULL;
- gcry_module_t *digest;
+ gcry_module_t digest;
REGISTER_DEFAULT_DIGESTS;
ath_mutex_lock (&digests_registered_lock);
- digest = _gcry_module_lookup_id (digests_registered, id);
+ digest = _gcry_module_lookup_id (digests_registered, algorithm);
if (digest)
{
if (asnlen)
- *asnlen = ((gcry_digest_spec_t *) digest->spec)->asnlen;
+ *asnlen = ((gcry_md_spec_t *) digest->spec)->asnlen;
if (mdlen)
- *mdlen = ((gcry_digest_spec_t *) digest->spec)->mdlen;
- asnoid = ((gcry_digest_spec_t *) digest->spec)->asnoid;
+ *mdlen = ((gcry_md_spec_t *) digest->spec)->mdlen;
+ asnoid = ((gcry_md_spec_t *) digest->spec)->asnoid;
_gcry_module_release (digest);
}
else
- log_bug ("no asn for md algo %d\n", id);
+ log_bug ("no asn for md algo %d\n", algorithm);
ath_mutex_unlock (&digests_registered_lock);
return asnoid;
@@ -1130,7 +1132,7 @@ gcry_md_info (gcry_md_hd_t h, int cmd, void *buffer, size_t *nbytes)
*nbytes = 0;
for(r=h->ctx->list; r; r = r->next ) {
- if (r->digest->id == algo)
+ if (r->module->mod_id == algo)
{
*nbytes = 1;
break;
@@ -1179,3 +1181,22 @@ gcry_md_is_enabled (gcry_md_hd_t a, int algo)
value = 0;
return value;
}
+
+/* Get a list consisting of the IDs of the loaded message digest
+ modules. If LIST is zero, write the number of loaded message
+ digest modules to LIST_LENGTH and return. If LIST is non-zero, the
+ first *LIST_LENGTH algorithm IDs are stored in LIST, which must be
+ of according size. In case there are less message digest modules
+ than *LIST_LENGTH, *LIST_LENGTH is updated to the correct
+ number. */
+gpg_error_t
+gcry_md_list (int *list, int *list_length)
+{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
+ ath_mutex_lock (&digests_registered_lock);
+ err = _gcry_module_list (digests_registered, list, list_length);
+ ath_mutex_unlock (&digests_registered_lock);
+
+ return err;
+}
diff --git a/cipher/md4.c b/cipher/md4.c
index 1686675d..42f85e38 100644
--- a/cipher/md4.c
+++ b/cipher/md4.c
@@ -303,9 +303,9 @@ 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 };
-gcry_digest_spec_t digest_spec_md4 =
+gcry_md_spec_t digest_spec_md4 =
{
- "MD4", GCRY_MD_MD4, asn, DIM (asn), 16,
+ "MD4", asn, DIM (asn), 16,
md4_init, md4_write, md4_final, md4_read,
sizeof (MD4_CONTEXT)
};
diff --git a/cipher/md5.c b/cipher/md5.c
index 878a250b..31159d2f 100644
--- a/cipher/md5.c
+++ b/cipher/md5.c
@@ -329,9 +329,9 @@ md5_read( void *context )
0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 };
-gcry_digest_spec_t digest_spec_md5 =
+gcry_md_spec_t digest_spec_md5 =
{
- "MD5", GCRY_MD_MD5, asn, DIM (asn), 16,
+ "MD5", asn, DIM (asn), 16,
md5_init, md5_write, md5_final, md5_read,
sizeof (MD5_CONTEXT)
};
diff --git a/cipher/pubkey.c b/cipher/pubkey.c
index 178670de..ff29563e 100644
--- a/cipher/pubkey.c
+++ b/cipher/pubkey.c
@@ -37,25 +37,26 @@ static gpg_err_code_t pubkey_verify (int algo, gcry_mpi_t hash, gcry_mpi_t *data
/* This is the list of the default public-key ciphers included in
libgcrypt. */
-static struct
+static struct pubkey_table_entry
{
- gcry_pubkey_spec_t *pubkey;
+ gcry_pk_spec_t *pubkey;
+ unsigned int algorithm;
} pubkey_table[] =
{
#if USE_RSA
- { &pubkey_spec_rsa },
+ { &pubkey_spec_rsa, GCRY_PK_RSA },
#endif
#if USE_ELGAMAL
- { &pubkey_spec_elg },
+ { &pubkey_spec_elg, GCRY_PK_ELG },
#endif
#if USE_DSA
- { &pubkey_spec_dsa },
+ { &pubkey_spec_dsa, GCRY_PK_DSA },
#endif
{ NULL },
};
/* List of registered ciphers. */
-static gcry_module_t *pubkeys_registered;
+static gcry_module_t pubkeys_registered;
/* This is the lock protecting PUBKEYS_REGISTERED. */
static ath_mutex_t pubkeys_registered_lock;
@@ -71,7 +72,7 @@ static int default_pubkeys_registered;
ath_mutex_lock (&pubkeys_registered_lock); \
if (! default_pubkeys_registered) \
{ \
- gcry_pubkey_register_default (); \
+ gcry_pk_register_default (); \
default_pubkeys_registered = 1; \
} \
ath_mutex_unlock (&pubkeys_registered_lock); \
@@ -82,60 +83,60 @@ static int default_pubkeys_registered;
refuses to provide it's own functions. */
static gpg_err_code_t
-dummy_generate (int id, unsigned int nbits, unsigned long dummy,
+dummy_generate (int algorithm, unsigned int nbits, unsigned long dummy,
gcry_mpi_t *skey, gcry_mpi_t **retfactors)
{
- log_bug ("no generate() for %d\n", id);
+ log_bug ("no generate() for %d\n", algorithm);
return GPG_ERR_PUBKEY_ALGO;
}
static gpg_err_code_t
-dummy_check_secret_key (int id, gcry_mpi_t *skey)
+dummy_check_secret_key (int algorithm, gcry_mpi_t *skey)
{
- log_bug ("no check_secret_key() for %d\n", id);
+ log_bug ("no check_secret_key() for %d\n", algorithm);
return GPG_ERR_PUBKEY_ALGO;
}
static gpg_err_code_t
-dummy_encrypt (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey, int flags)
+dummy_encrypt (int algorithm, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey, int flags)
{
- log_bug ("no encrypt() for %d\n", id);
+ log_bug ("no encrypt() for %d\n", algorithm);
return GPG_ERR_PUBKEY_ALGO;
}
static gpg_err_code_t
-dummy_decrypt (int id, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, int flags)
+dummy_decrypt (int algorithm, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, int flags)
{
- log_bug ("no decrypt() for %d\n", id);
+ log_bug ("no decrypt() for %d\n", algorithm);
return GPG_ERR_PUBKEY_ALGO;
}
static gpg_err_code_t
-dummy_sign (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey)
+dummy_sign (int algorithm, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey)
{
- log_bug ("no sign() for %d\n", id);
+ log_bug ("no sign() for %d\n", algorithm);
return GPG_ERR_PUBKEY_ALGO;
}
static gpg_err_code_t
-dummy_verify (int id, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey,
+dummy_verify (int algorithm, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey,
int (*cmp) (void *, gcry_mpi_t), void *opaquev)
{
- log_bug ("no verify() for %d\n", id);
+ log_bug ("no verify() for %d\n", algorithm);
return GPG_ERR_PUBKEY_ALGO;
}
static unsigned
-dummy_get_nbits (int id, gcry_mpi_t *pkey)
+dummy_get_nbits (int algorithm, gcry_mpi_t *pkey)
{
- log_bug ("no get_nbits() for %d\n", id);
+ log_bug ("no get_nbits() for %d\n", algorithm);
return 0;
}
/* Internal function. Register all the pubkeys included in
PUBKEY_TABLE. Returns zero on success or an error code. */
static void
-gcry_pubkey_register_default (void)
+gcry_pk_register_default (void)
{
gpg_err_code_t err = 0;
int i;
@@ -155,7 +156,7 @@ gcry_pubkey_register_default (void)
pubkey_use_dummy (get_nbits);
err = _gcry_module_add (&pubkeys_registered,
- pubkey_table[i].pubkey->id,
+ pubkey_table[i].algorithm,
(void *) pubkey_table[i].pubkey, NULL);
}
@@ -165,9 +166,9 @@ gcry_pubkey_register_default (void)
/* Internal callback function. Used via _gcry_module_lookup. */
static int
-gcry_pubkey_lookup_func_name (void *spec, void *data)
+gcry_pk_lookup_func_name (void *spec, void *data)
{
- gcry_pubkey_spec_t *pubkey = (gcry_pubkey_spec_t *) spec;
+ gcry_pk_spec_t *pubkey = (gcry_pk_spec_t *) spec;
char *name = (char *) data;
char **sexp_names = pubkey->sexp_names;
int ret = stricmp (name, pubkey->name);
@@ -179,25 +180,27 @@ gcry_pubkey_lookup_func_name (void *spec, void *data)
}
/* Internal function. Lookup a pubkey entry by it's name. */
-static gcry_module_t *
-gcry_pubkey_lookup_name (const char *name)
+static gcry_module_t
+gcry_pk_lookup_name (const char *name)
{
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
pubkey = _gcry_module_lookup (pubkeys_registered, (void *) name,
- gcry_pubkey_lookup_func_name);
+ gcry_pk_lookup_func_name);
return pubkey;
}
-/* 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. */
+/* Register a new pubkey module whose specification can be found in
+ PUBKEY. On success, a new algorithm ID is stored in ALGORITHM_ID
+ and a pointer representhing this module is stored in MODULE. */
gpg_error_t
-gcry_pubkey_register (gcry_pubkey_spec_t *pubkey, gcry_module_t **module)
+gcry_pk_register (gcry_pk_spec_t *pubkey,
+ unsigned int *algorithm_id,
+ gcry_module_t *module)
{
gpg_err_code_t err = GPG_ERR_NO_ERROR;
- gcry_module_t *mod;
+ gcry_module_t mod;
ath_mutex_lock (&pubkeys_registered_lock);
err = _gcry_module_add (&pubkeys_registered, 0,
@@ -207,16 +210,16 @@ gcry_pubkey_register (gcry_pubkey_spec_t *pubkey, gcry_module_t **module)
if (! err)
{
*module = mod;
- pubkey->id = mod->id;
+ *algorithm_id = mod->mod_id;
}
return err;
}
-/* Public function. Unregister the pubkey identified by ID, which
- must have been registered with gcry_pubkey_register. */
+/* Unregister the pubkey identified by ID, which must have been
+ registered with gcry_pk_register. */
void
-gcry_pubkey_unregister (gcry_module_t *module)
+gcry_pk_unregister (gcry_module_t module)
{
ath_mutex_lock (&pubkeys_registered_lock);
_gcry_module_release (module);
@@ -239,21 +242,21 @@ release_mpi_array (gcry_mpi_t *array)
int
gcry_pk_map_name (const char *string)
{
- gcry_module_t *pubkey;
- int id = 0;
+ gcry_module_t pubkey;
+ int algorithm = 0;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = gcry_pubkey_lookup_name (string);
+ pubkey = gcry_pk_lookup_name (string);
if (pubkey)
{
- id = ((gcry_pubkey_spec_t *) pubkey->spec)->id;
+ algorithm = pubkey->mod_id;
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
- return id;
+ return algorithm;
}
@@ -261,18 +264,18 @@ gcry_pk_map_name (const char *string)
* Map a pubkey algo to a string
*/
const char *
-gcry_pk_algo_name (int id)
+gcry_pk_algo_name (int algorithm)
{
const char *name = NULL;
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
- name = ((gcry_pubkey_spec_t *) pubkey->spec)->name;
+ name = ((gcry_pk_spec_t *) pubkey->spec)->name;
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -282,12 +285,12 @@ gcry_pk_algo_name (int id)
static void
-disable_pubkey_algo (int id)
+disable_pubkey_algo (int algorithm)
{
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
if (! (pubkey-> flags & FLAG_MODULE_DISABLED))
@@ -302,19 +305,19 @@ disable_pubkey_algo (int id)
* a use of 0 means: don't care
*/
static gpg_err_code_t
-check_pubkey_algo (int id, unsigned use)
+check_pubkey_algo (int algorithm, unsigned use)
{
gpg_err_code_t err = GPG_ERR_NO_ERROR;
- gcry_pubkey_spec_t *pubkey;
- gcry_module_t *module;
+ gcry_pk_spec_t *pubkey;
+ gcry_module_t module;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- module = _gcry_module_lookup_id (pubkeys_registered, id);
+ module = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (module)
{
- pubkey = (gcry_pubkey_spec_t *) module->spec;
+ pubkey = (gcry_pk_spec_t *) module->spec;
if (((use & GCRY_PK_USAGE_SIGN)
&& (! (pubkey->use & GCRY_PK_USAGE_SIGN)))
@@ -337,18 +340,18 @@ check_pubkey_algo (int id, unsigned use)
* Return the number of public key material numbers
*/
static int
-pubkey_get_npkey (int id)
+pubkey_get_npkey (int algorithm)
{
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
int npkey = 0;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
- npkey = strlen (((gcry_pubkey_spec_t *) pubkey->spec)->elements_pkey);
+ npkey = strlen (((gcry_pk_spec_t *) pubkey->spec)->elements_pkey);
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -360,18 +363,18 @@ pubkey_get_npkey (int id)
* Return the number of secret key material numbers
*/
static int
-pubkey_get_nskey (int id)
+pubkey_get_nskey (int algorithm)
{
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
int nskey = 0;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
- nskey = strlen (((gcry_pubkey_spec_t *) pubkey->spec)->elements_skey);
+ nskey = strlen (((gcry_pk_spec_t *) pubkey->spec)->elements_skey);
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -383,18 +386,18 @@ pubkey_get_nskey (int id)
* Return the number of signature material numbers
*/
static int
-pubkey_get_nsig (int id)
+pubkey_get_nsig (int algorithm)
{
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
int nsig = 0;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
- nsig = strlen (((gcry_pubkey_spec_t *) pubkey->spec)->elements_sig);
+ nsig = strlen (((gcry_pk_spec_t *) pubkey->spec)->elements_sig);
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -406,18 +409,18 @@ pubkey_get_nsig (int id)
* Return the number of encryption material numbers
*/
static int
-pubkey_get_nenc (int id)
+pubkey_get_nenc (int algorithm)
{
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
int nenc = 0;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
- nenc = strlen (((gcry_pubkey_spec_t *) pubkey->spec)->elements_enc);
+ nenc = strlen (((gcry_pk_spec_t *) pubkey->spec)->elements_enc);
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -427,19 +430,19 @@ pubkey_get_nenc (int id)
static gpg_err_code_t
-pubkey_generate (int id, unsigned int nbits, unsigned long use_e,
+pubkey_generate (int algorithm, unsigned int nbits, unsigned long use_e,
gcry_mpi_t *skey, gcry_mpi_t **retfactors)
{
gpg_err_code_t err = GPG_ERR_PUBKEY_ALGO;
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
- err = (*((gcry_pubkey_spec_t *) pubkey->spec)->generate) (id, nbits, use_e, skey,
+ err = (*((gcry_pk_spec_t *) pubkey->spec)->generate) (algorithm, nbits, use_e, skey,
retfactors);
_gcry_module_release (pubkey);
}
@@ -449,18 +452,18 @@ pubkey_generate (int id, unsigned int nbits, unsigned long use_e,
}
static gpg_err_code_t
-pubkey_check_secret_key (int id, gcry_mpi_t *skey)
+pubkey_check_secret_key (int algorithm, gcry_mpi_t *skey)
{
gpg_err_code_t err = GPG_ERR_PUBKEY_ALGO;
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
- err = (*((gcry_pubkey_spec_t *) pubkey->spec)->check_secret_key) (id, skey);
+ err = (*((gcry_pk_spec_t *) pubkey->spec)->check_secret_key) (algorithm, skey);
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -476,28 +479,28 @@ pubkey_check_secret_key (int id, gcry_mpi_t *skey)
* check with pubkey_get_nenc() )
*/
static gpg_err_code_t
-pubkey_encrypt (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey,
+pubkey_encrypt (int algorithm, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey,
int flags)
{
- gcry_pubkey_spec_t *pubkey;
- gcry_module_t *module;
+ gcry_pk_spec_t *pubkey;
+ gcry_module_t module;
gpg_err_code_t rc;
int i;
if (DBG_CIPHER)
{
- log_debug ("pubkey_encrypt: algo=%d\n", id);
- for(i = 0; i < pubkey_get_npkey (id); i++)
+ log_debug ("pubkey_encrypt: algo=%d\n", algorithm);
+ for(i = 0; i < pubkey_get_npkey (algorithm); i++)
log_mpidump (" pkey:", pkey[i]);
log_mpidump (" data:", data);
}
ath_mutex_lock (&pubkeys_registered_lock);
- module = _gcry_module_lookup_id (pubkeys_registered, id);
+ module = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (module)
{
- pubkey = (gcry_pubkey_spec_t *) module->spec;
- rc = (*pubkey->encrypt) (id, resarr, data, pkey, flags);
+ pubkey = (gcry_pk_spec_t *) module->spec;
+ rc = (*pubkey->encrypt) (algorithm, resarr, data, pkey, flags);
_gcry_module_release (module);
goto ready;
}
@@ -508,7 +511,7 @@ pubkey_encrypt (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey,
if (!rc && DBG_CIPHER)
{
- for(i = 0; i < pubkey_get_nenc (id); i++)
+ for(i = 0; i < pubkey_get_nenc (algorithm); i++)
log_mpidump(" encr:", resarr[i] );
}
return rc;
@@ -523,30 +526,30 @@ pubkey_encrypt (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey,
* newly allocated mpi or NULL in case of an error.
*/
static gpg_err_code_t
-pubkey_decrypt (int id, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey,
+pubkey_decrypt (int algorithm, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey,
int flags)
{
- gcry_pubkey_spec_t *pubkey;
- gcry_module_t *module;
+ gcry_pk_spec_t *pubkey;
+ gcry_module_t module;
gpg_err_code_t rc;
int i;
*result = NULL; /* so the caller can always do a mpi_free */
if (DBG_CIPHER)
{
- log_debug ("pubkey_decrypt: algo=%d\n", id);
- for(i = 0; i < pubkey_get_nskey (id); i++)
+ log_debug ("pubkey_decrypt: algo=%d\n", algorithm);
+ for(i = 0; i < pubkey_get_nskey (algorithm); i++)
log_mpidump (" skey:", skey[i]);
- for(i = 0; i < pubkey_get_nenc (id); i++)
+ for(i = 0; i < pubkey_get_nenc (algorithm); i++)
log_mpidump (" data:", data[i]);
}
ath_mutex_lock (&pubkeys_registered_lock);
- module = _gcry_module_lookup_id (pubkeys_registered, id);
+ module = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (module)
{
- pubkey = (gcry_pubkey_spec_t *) module->spec;
- rc = (*pubkey->decrypt) (id, result, data, skey, flags);
+ pubkey = (gcry_pk_spec_t *) module->spec;
+ rc = (*pubkey->decrypt) (algorithm, result, data, skey, flags);
_gcry_module_release (module);
goto ready;
}
@@ -570,27 +573,27 @@ pubkey_decrypt (int id, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey,
* algorithm allows this - check with pubkey_get_nsig() )
*/
static gpg_err_code_t
-pubkey_sign (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey)
+pubkey_sign (int algorithm, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey)
{
- gcry_pubkey_spec_t *pubkey;
- gcry_module_t *module;
+ gcry_pk_spec_t *pubkey;
+ gcry_module_t module;
gpg_err_code_t rc;
int i;
if (DBG_CIPHER)
{
- log_debug ("pubkey_sign: algo=%d\n", id);
- for(i = 0; i < pubkey_get_nskey (id); i++)
+ log_debug ("pubkey_sign: algo=%d\n", algorithm);
+ for(i = 0; i < pubkey_get_nskey (algorithm); i++)
log_mpidump (" skey:", skey[i]);
log_mpidump(" data:", data );
}
ath_mutex_lock (&pubkeys_registered_lock);
- module = _gcry_module_lookup_id (pubkeys_registered, id);
+ module = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (module)
{
- pubkey = (gcry_pubkey_spec_t *) module->spec;
- rc = (*pubkey->sign) (id, resarr, data, skey);
+ pubkey = (gcry_pk_spec_t *) module->spec;
+ rc = (*pubkey->sign) (algorithm, resarr, data, skey);
_gcry_module_release (module);
goto ready;
}
@@ -601,7 +604,7 @@ pubkey_sign (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey)
ath_mutex_unlock (&pubkeys_registered_lock);
if (! rc && DBG_CIPHER)
- for (i = 0; i < pubkey_get_nsig (id); i++)
+ for (i = 0; i < pubkey_get_nsig (algorithm); i++)
log_mpidump (" sig:", resarr[i]);
return rc;
@@ -612,30 +615,30 @@ pubkey_sign (int id, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey)
* Return 0 if the signature is good
*/
static gpg_err_code_t
-pubkey_verify (int id, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey,
+pubkey_verify (int algorithm, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey,
int (*cmp)(void *, gcry_mpi_t), void *opaquev)
{
- gcry_pubkey_spec_t *pubkey;
- gcry_module_t *module;
+ gcry_pk_spec_t *pubkey;
+ gcry_module_t module;
gpg_err_code_t rc;
int i;
if (DBG_CIPHER)
{
- log_debug ("pubkey_verify: algo=%d\n", id);
- for (i = 0; i < pubkey_get_npkey (id); i++)
+ log_debug ("pubkey_verify: algo=%d\n", algorithm);
+ for (i = 0; i < pubkey_get_npkey (algorithm); i++)
log_mpidump (" pkey:", pkey[i]);
- for (i = 0; i < pubkey_get_nsig (id); i++)
+ for (i = 0; i < pubkey_get_nsig (algorithm); i++)
log_mpidump (" sig:", data[i]);
log_mpidump (" hash:", hash);
}
ath_mutex_lock (&pubkeys_registered_lock);
- module = _gcry_module_lookup_id (pubkeys_registered, id);
+ module = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (module)
{
- pubkey = (gcry_pubkey_spec_t *) module->spec;
- rc = (*pubkey->verify) (id, hash, data, pkey, cmp, opaquev);
+ pubkey = (gcry_pk_spec_t *) module->spec;
+ rc = (*pubkey->verify) (algorithm, hash, data, pkey, cmp, opaquev);
_gcry_module_release (module);
goto ready;
}
@@ -714,17 +717,16 @@ 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,
- gcry_module_t **retalgo)
+ gcry_module_t *retalgo)
{
gcry_sexp_t list, l2;
const char *name;
size_t n;
- int algo;
const char *elems;
gcry_mpi_t *array;
gpg_err_code_t err = GPG_ERR_NO_ERROR;
- gcry_module_t *module;
- gcry_pubkey_spec_t *pubkey;
+ gcry_module_t module;
+ gcry_pk_spec_t *pubkey;
/* check that the first element is valid */
list = gcry_sexp_find_token( sexp, want_private? "private-key"
@@ -746,7 +748,7 @@ sexp_to_key (gcry_sexp_t sexp, int want_private, gcry_mpi_t **retarray,
name_terminated[n] = 0;
ath_mutex_lock (&pubkeys_registered_lock);
- module = gcry_pubkey_lookup_name (name_terminated);
+ module = gcry_pk_lookup_name (name_terminated);
ath_mutex_unlock (&pubkeys_registered_lock);
free (name_terminated);
@@ -758,9 +760,8 @@ sexp_to_key (gcry_sexp_t sexp, int want_private, gcry_mpi_t **retarray,
return GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */
}
else
- pubkey = (gcry_pubkey_spec_t *) module->spec;
+ pubkey = (gcry_pk_spec_t *) module->spec;
- algo = pubkey->id;
elems = want_private ? pubkey->elements_skey : pubkey->elements_pkey;
array = gcry_calloc (strlen (elems) + 1, sizeof (*array));
if (! array)
@@ -791,17 +792,16 @@ 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,
- gcry_module_t **retalgo)
+ gcry_module_t *retalgo)
{
gcry_sexp_t list, l2;
const char *name;
size_t n;
- int algo;
const char *elems;
gcry_mpi_t *array;
gpg_err_code_t err = GPG_ERR_NO_ERROR;
- gcry_module_t *module;
- gcry_pubkey_spec_t *pubkey;
+ gcry_module_t module;
+ gcry_pk_spec_t *pubkey;
/* check that the first element is valid */
list = gcry_sexp_find_token( sexp, "sig-val" , 0 );
@@ -838,7 +838,7 @@ sexp_to_sig (gcry_sexp_t sexp, gcry_mpi_t **retarray,
name_terminated[n] = 0;
ath_mutex_lock (&pubkeys_registered_lock);
- module = gcry_pubkey_lookup_name (name_terminated);
+ module = gcry_pk_lookup_name (name_terminated);
ath_mutex_unlock (&pubkeys_registered_lock);
free (name_terminated);
@@ -851,9 +851,8 @@ sexp_to_sig (gcry_sexp_t sexp, gcry_mpi_t **retarray,
return GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */
}
else
- pubkey = (gcry_pubkey_spec_t *) module->spec;
+ pubkey = (gcry_pk_spec_t *) module->spec;
- algo = pubkey->id;
elems = pubkey->elements_sig;
array = gcry_calloc (strlen (elems) + 1 , sizeof (*array));
if (! array)
@@ -897,12 +896,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, gcry_module_t **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;
- gcry_pubkey_spec_t *pubkey = NULL;
- gcry_module_t *module = NULL;
+ gcry_pk_spec_t *pubkey = NULL;
+ gcry_module_t module = NULL;
const char *name;
size_t n;
int parsed_flags = 0;
@@ -985,7 +984,7 @@ sexp_to_enc (gcry_sexp_t sexp, gcry_mpi_t **retarray, gcry_module_t **retalgo,
name_terminated[n] = 0;
ath_mutex_lock (&pubkeys_registered_lock);
- module = gcry_pubkey_lookup_name (name_terminated);
+ module = gcry_pk_lookup_name (name_terminated);
ath_mutex_unlock (&pubkeys_registered_lock);
free (name_terminated);
@@ -993,7 +992,7 @@ sexp_to_enc (gcry_sexp_t sexp, gcry_mpi_t **retarray, gcry_module_t **retalgo,
if (! module)
err = GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */
else
- pubkey = (gcry_pubkey_spec_t *) module->spec;
+ pubkey = (gcry_pk_spec_t *) module->spec;
}
if (! err)
@@ -1305,8 +1304,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;
- gcry_pubkey_spec_t *pubkey = NULL;
- gcry_module_t *module = NULL;
+ gcry_pk_spec_t *pubkey = NULL;
+ gcry_module_t module = NULL;
REGISTER_DEFAULT_PUBKEYS;
@@ -1316,7 +1315,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey)
if (! rc)
{
assert (module);
- pubkey = (gcry_pubkey_spec_t *) module->spec;
+ pubkey = (gcry_pk_spec_t *) module->spec;
algo_name = pubkey->name;
algo_elems = pubkey->elements_enc;
@@ -1329,7 +1328,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey)
{
/* Now we can encrypt data to ciph */
ciph = gcry_xcalloc (strlen (algo_elems) + 1, sizeof (*ciph));
- rc = pubkey_encrypt (pubkey->id, ciph, data, pkey, flags);
+ rc = pubkey_encrypt (module->mod_id, ciph, data, pkey, flags);
mpi_free (data);
}
@@ -1428,8 +1427,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;
- gcry_module_t *module_enc = NULL, *module_key = NULL;
- gcry_pubkey_spec_t *pubkey = NULL;
+ gcry_module_t module_enc = NULL, module_key = NULL;
+ gcry_pk_spec_t *pubkey = NULL;
REGISTER_DEFAULT_PUBKEYS;
@@ -1441,15 +1440,14 @@ gcry_pk_decrypt (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t s_skey)
if (! rc)
{
- if (((gcry_pubkey_spec_t *) module_key->spec)->id
- != ((gcry_pubkey_spec_t *) module_enc->spec)->id)
+ if (module_key->mod_id != module_enc->mod_id)
rc = GPG_ERR_CONFLICT; /* key algo does not match data algo */
else
- pubkey = (gcry_pubkey_spec_t *) module_key->spec;
+ pubkey = (gcry_pk_spec_t *) module_key->spec;
}
if (! rc)
- rc = pubkey_decrypt (pubkey->id, &plain, data, skey, flags);
+ rc = pubkey_decrypt (module_key->mod_id, &plain, data, skey, flags);
if (! rc)
{
@@ -1524,8 +1522,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;
- gcry_pubkey_spec_t *pubkey = NULL;
- gcry_module_t *module = NULL;
+ gcry_pk_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;
@@ -1539,7 +1537,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey)
if (! rc)
{
assert (module);
- pubkey = (gcry_pubkey_spec_t *) module->spec;
+ pubkey = (gcry_pk_spec_t *) module->spec;
algo_name = key_algo_name = pubkey->name;
algo_elems = pubkey->elements_sig;
@@ -1552,7 +1550,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey)
if (! rc)
{
result = gcry_xcalloc (strlen (algo_elems) + 1, sizeof (*result));
- rc = pubkey_sign (pubkey->id, result, hash, skey);
+ rc = pubkey_sign (module->mod_id, result, hash, skey);
}
if (! rc)
@@ -1624,7 +1622,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)
{
- gcry_module_t *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;
@@ -1635,16 +1633,14 @@ 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)
- && (((gcry_pubkey_spec_t *) module_key->spec)->id
- != ((gcry_pubkey_spec_t *) module_sig->spec)->id))
+ && (module_key->mod_id != module_sig->mod_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 (((gcry_pubkey_spec_t *) module_key->spec)->id,
- hash, sig, pkey, NULL, NULL);
+ rc = pubkey_verify (module_key->mod_id, hash, sig, pkey, NULL, NULL);
if (pkey)
{
@@ -1684,7 +1680,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)
{
- gcry_module_t *module = NULL;
+ gcry_module_t module = NULL;
gcry_mpi_t *key = NULL;
gpg_err_code_t rc;
@@ -1694,7 +1690,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 (((gcry_pubkey_spec_t *) module->spec)->id, key);
+ rc = pubkey_check_secret_key (module->mod_id, key);
release_mpi_array (key);
gcry_free (key);
}
@@ -1739,8 +1735,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)
{
- gcry_pubkey_spec_t *pubkey = NULL;
- gcry_module_t *module = NULL;
+ gcry_pk_spec_t *pubkey = NULL;
+ gcry_module_t module = NULL;
gcry_sexp_t list = NULL, l2 = NULL;
const char *name;
size_t n;
@@ -1784,7 +1780,7 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
name_terminated[n] = 0;
ath_mutex_lock (&pubkeys_registered_lock);
- module = gcry_pubkey_lookup_name (name_terminated);
+ module = gcry_pk_lookup_name (name_terminated);
ath_mutex_unlock (&pubkeys_registered_lock);
free (name_terminated);
@@ -1793,8 +1789,8 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
rc = GPG_ERR_PUBKEY_ALGO; /* unknown algorithm */
else
{
- pubkey = (gcry_pubkey_spec_t *) module->spec;
- algo = pubkey->id;
+ pubkey = (gcry_pk_spec_t *) module->spec;
+ algo = module->mod_id;
algo_name = pubkey->name;
pub_elems = pubkey->elements_pkey;
sec_elems = pubkey->elements_skey;
@@ -1849,7 +1845,7 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
}
if (! rc)
- rc = pubkey_generate (pubkey->id, nbits, use_e, skey, &factors);
+ rc = pubkey_generate (module->mod_id, nbits, use_e, skey, &factors);
if (! rc)
{
@@ -1963,8 +1959,8 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
unsigned int
gcry_pk_get_nbits (gcry_sexp_t key)
{
- gcry_module_t *module = NULL;
- gcry_pubkey_spec_t *pubkey;
+ gcry_module_t module = NULL;
+ gcry_pk_spec_t *pubkey;
gcry_mpi_t *keyarr = NULL;
unsigned int nbits = 0;
gpg_err_code_t rc;
@@ -1978,8 +1974,8 @@ gcry_pk_get_nbits (gcry_sexp_t key)
return 0;
else
{
- pubkey = (gcry_pubkey_spec_t *) module->spec;
- nbits = (*pubkey->get_nbits) (pubkey->id, keyarr);
+ pubkey = (gcry_pk_spec_t *) module->spec;
+ nbits = (*pubkey->get_nbits) (module->mod_id, keyarr);
ath_mutex_lock (&pubkeys_registered_lock);
_gcry_module_release (module);
@@ -2004,8 +2000,8 @@ unsigned char *
gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array)
{
gcry_sexp_t list = NULL, l2 = NULL;
- gcry_pubkey_spec_t *pubkey = NULL;
- gcry_module_t *module = NULL;
+ gcry_pk_spec_t *pubkey = NULL;
+ gcry_module_t module = NULL;
const char *s, *name;
size_t n;
int idx;
@@ -2040,7 +2036,7 @@ gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array)
name_terminated[n] = 0;
ath_mutex_lock (&pubkeys_registered_lock);
- module = gcry_pubkey_lookup_name (name_terminated);
+ module = gcry_pk_lookup_name (name_terminated);
ath_mutex_unlock (&pubkeys_registered_lock);
free (name_terminated);
@@ -2049,11 +2045,11 @@ gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array)
if (! module)
goto fail; /* unknown algorithm */
else
- pubkey = (gcry_pubkey_spec_t *) module->spec;
+ pubkey = (gcry_pk_spec_t *) module->spec;
/* FIXME, special handling should be implemented by the algorithms,
not by the libgcrypt core. */
- is_rsa = pubkey->id == GCRY_PK_RSA;
+ is_rsa = module->mod_id == GCRY_PK_RSA;
elems = pubkey->elements_grip;
if (! elems)
goto fail; /* no grip parameter */
@@ -2159,7 +2155,7 @@ gcry_pk_ctl (int cmd, void *buffer, size_t buflen)
* the block size)
*/
gpg_error_t
-gcry_pk_algo_info (int id, int what, void *buffer, size_t *nbytes)
+gcry_pk_algo_info (int algorithm, int what, void *buffer, size_t *nbytes)
{
gpg_err_code_t err = GPG_ERR_NO_ERROR;
@@ -2170,23 +2166,23 @@ gcry_pk_algo_info (int id, int what, void *buffer, size_t *nbytes)
int use = nbytes ? *nbytes : 0;
if (buffer)
err = GPG_ERR_INV_ARG;
- else if (check_pubkey_algo (id, use))
+ else if (check_pubkey_algo (algorithm, use))
err = GPG_ERR_PUBKEY_ALGO;
break;
}
case GCRYCTL_GET_ALGO_USAGE:
{
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
int use = 0;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
{
- use = ((gcry_pubkey_spec_t *) pubkey->spec)->use;
+ use = ((gcry_pk_spec_t *) pubkey->spec)->use;
_gcry_module_release (pubkey);
}
ath_mutex_unlock (&pubkeys_registered_lock);
@@ -2198,28 +2194,28 @@ gcry_pk_algo_info (int id, int what, void *buffer, size_t *nbytes)
case GCRYCTL_GET_ALGO_NPKEY:
{
/* FIXME? */
- int npkey = pubkey_get_npkey (id);
+ int npkey = pubkey_get_npkey (algorithm);
*nbytes = npkey;
break;
}
case GCRYCTL_GET_ALGO_NSKEY:
{
/* FIXME? */
- int nskey = pubkey_get_nskey (id);
+ int nskey = pubkey_get_nskey (algorithm);
*nbytes = nskey;
break;
}
case GCRYCTL_GET_ALGO_NSIGN:
{
/* FIXME? */
- int nsign = pubkey_get_nsig (id);
+ int nsign = pubkey_get_nsig (algorithm);
*nbytes = nsign;
break;
}
case GCRYCTL_GET_ALGO_NENCR:
{
/* FIXME? */
- int nencr = pubkey_get_nenc (id);
+ int nencr = pubkey_get_nenc (algorithm);
*nbytes = nencr;
break;
}
@@ -2242,15 +2238,15 @@ _gcry_pk_init (void)
}
gpg_err_code_t
-_gcry_pk_module_lookup (int id, gcry_module_t **module)
+_gcry_pk_module_lookup (int algorithm, gcry_module_t *module)
{
gpg_err_code_t err = GPG_ERR_NO_ERROR;
- gcry_module_t *pubkey;
+ gcry_module_t pubkey;
REGISTER_DEFAULT_PUBKEYS;
ath_mutex_lock (&pubkeys_registered_lock);
- pubkey = _gcry_module_lookup_id (pubkeys_registered, id);
+ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm);
if (pubkey)
*module = pubkey;
else
@@ -2261,9 +2257,27 @@ _gcry_pk_module_lookup (int id, gcry_module_t **module)
}
void
-_gcry_pk_module_release (gcry_module_t *module)
+_gcry_pk_module_release (gcry_module_t module)
{
ath_mutex_lock (&pubkeys_registered_lock);
_gcry_module_release (module);
ath_mutex_unlock (&pubkeys_registered_lock);
}
+
+/* Get a list consisting of the IDs of the loaded pubkey modules. If
+ LIST is zero, write the number of loaded pubkey modules to
+ LIST_LENGTH and return. If LIST is non-zero, the first
+ *LIST_LENGTH algorithm IDs are stored in LIST, which must be of
+ according size. In case there are less pubkey modules than
+ *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */
+gpg_error_t
+gcry_pk_list (int *list, int *list_length)
+{
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+
+ ath_mutex_lock (&pubkeys_registered_lock);
+ err = _gcry_module_list (pubkeys_registered, list, list_length);
+ ath_mutex_unlock (&pubkeys_registered_lock);
+
+ return err;
+}
diff --git a/cipher/rijndael.c b/cipher/rijndael.c
index 3943d9a6..1aa9e22d 100644
--- a/cipher/rijndael.c
+++ b/cipher/rijndael.c
@@ -2133,18 +2133,18 @@ selftest (void)
gcry_cipher_spec_t cipher_spec_aes =
{
- "AES", GCRY_CIPHER_AES, 16, 128, sizeof (RIJNDAEL_context),
+ "AES", 16, 128, sizeof (RIJNDAEL_context),
rijndael_setkey, rijndael_encrypt, rijndael_decrypt,
};
gcry_cipher_spec_t cipher_spec_aes192 =
{
- "AES192", GCRY_CIPHER_AES192, 16, 192, sizeof (RIJNDAEL_context),
+ "AES192", 16, 192, sizeof (RIJNDAEL_context),
rijndael_setkey, rijndael_encrypt, rijndael_decrypt,
};
gcry_cipher_spec_t cipher_spec_aes256 =
{
- "AES256", GCRY_CIPHER_AES256, 16, 256, sizeof (RIJNDAEL_context),
+ "AES256", 16, 256, sizeof (RIJNDAEL_context),
rijndael_setkey, rijndael_encrypt, rijndael_decrypt,
};
diff --git a/cipher/rmd160.c b/cipher/rmd160.c
index 01df1d2b..b06702b3 100644
--- a/cipher/rmd160.c
+++ b/cipher/rmd160.c
@@ -543,9 +543,9 @@ 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 };
-gcry_digest_spec_t digest_spec_rmd160 =
+gcry_md_spec_t digest_spec_rmd160 =
{
- "RIPEMD160", GCRY_MD_RMD160, asn, DIM (asn), 20,
+ "RIPEMD160", asn, DIM (asn), 20,
_gcry_rmd160_init, rmd160_write, rmd160_final, rmd160_read,
sizeof (RMD160_CONTEXT)
};
diff --git a/cipher/rsa.c b/cipher/rsa.c
index c16ccc0a..1a5a8dc5 100644
--- a/cipher/rsa.c
+++ b/cipher/rsa.c
@@ -611,9 +611,9 @@ static char *rsa_names[] =
NULL,
};
-gcry_pubkey_spec_t pubkey_spec_rsa =
+gcry_pk_spec_t pubkey_spec_rsa =
{
- "RSA", rsa_names, GCRY_PK_RSA,
+ "RSA", rsa_names,
"ne", "nedpqu", "a", "s", "n",
GCRY_PK_USAGE_SIGN | GCRY_PK_USAGE_ENCR,
_gcry_rsa_generate,
diff --git a/cipher/sha1.c b/cipher/sha1.c
index 1c382a91..bb223644 100644
--- a/cipher/sha1.c
+++ b/cipher/sha1.c
@@ -319,9 +319,9 @@ 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 };
-gcry_digest_spec_t digest_spec_sha1 =
+gcry_md_spec_t digest_spec_sha1 =
{
- "SHA1", GCRY_MD_SHA1, asn, DIM (asn), 20,
+ "SHA1", asn, DIM (asn), 20,
sha1_init, sha1_write, sha1_final, sha1_read,
sizeof (SHA1_CONTEXT)
};
diff --git a/cipher/sha256.c b/cipher/sha256.c
index 6b3b4981..8b92d317 100644
--- a/cipher/sha256.c
+++ b/cipher/sha256.c
@@ -293,9 +293,9 @@ 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 };
-gcry_digest_spec_t digest_spec_sha256 =
+gcry_md_spec_t digest_spec_sha256 =
{
- "SHA256", GCRY_MD_SHA256, asn, DIM (asn), 32,
+ "SHA256", asn, DIM (asn), 32,
sha256_init, sha256_write, sha256_final, sha256_read,
sizeof (SHA256_CONTEXT)
};
diff --git a/cipher/sha512.c b/cipher/sha512.c
index d2e0e3a2..7daca350 100644
--- a/cipher/sha512.c
+++ b/cipher/sha512.c
@@ -367,8 +367,8 @@ static byte sha512_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.3 */
0x00, 0x04, 0x40
};
-gcry_digest_spec_t digest_spec_sha512 = {
- "SHA512", GCRY_MD_SHA512, sha512_asn, DIM (sha512_asn), 64,
+gcry_md_spec_t digest_spec_sha512 = {
+ "SHA512", sha512_asn, DIM (sha512_asn), 64,
sha512_init, sha512_write, sha512_final, sha512_read,
sizeof (SHA512_CONTEXT),
};
@@ -380,8 +380,8 @@ static byte sha384_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.2 */
0x00, 0x04, 0x30
};
-gcry_digest_spec_t digest_spec_sha384 = {
- "SHA384", GCRY_MD_SHA384, sha384_asn, DIM (sha384_asn), 48,
+gcry_md_spec_t digest_spec_sha384 = {
+ "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 2aaeadb4..2115e964 100644
--- a/cipher/tiger.c
+++ b/cipher/tiger.c
@@ -827,9 +827,9 @@ static byte asn[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */
0x05, 0x00, 0x04, 0x18 };
-gcry_digest_spec_t digest_spec_tiger =
+gcry_md_spec_t digest_spec_tiger =
{
- "TIGER192", GCRY_MD_TIGER, asn, DIM (asn), 24,
+ "TIGER192", asn, DIM (asn), 24,
tiger_init, tiger_write, tiger_final, tiger_read,
sizeof (TIGER_CONTEXT)
};
diff --git a/cipher/twofish.c b/cipher/twofish.c
index a5a2aa4d..ac70051e 100644
--- a/cipher/twofish.c
+++ b/cipher/twofish.c
@@ -1021,12 +1021,12 @@ main()
gcry_cipher_spec_t cipher_spec_twofish =
{
- "TWOFISH", GCRY_CIPHER_TWOFISH, 16, 256, sizeof (TWOFISH_context),
+ "TWOFISH", 16, 256, sizeof (TWOFISH_context),
twofish_setkey, twofish_encrypt, twofish_decrypt,
};
gcry_cipher_spec_t cipher_spec_twofish128 =
{
- "TWOFISH128", GCRY_CIPHER_TWOFISH, 16, 128, sizeof (TWOFISH_context),
+ "TWOFISH128", 16, 128, sizeof (TWOFISH_context),
twofish_setkey, twofish_encrypt, twofish_decrypt,
};