diff options
author | Werner Koch <wk@gnupg.org> | 2008-08-29 15:40:24 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2008-08-29 15:40:24 +0000 |
commit | 936035b491fab2e32f651ed201bc10a6731ebe05 (patch) | |
tree | 0669310cd08811970b466f1308c37b63a0834602 /cipher/rsa.c | |
parent | 78a1f612bf65d3c1a445c43b456cb28e98a3a6ea (diff) | |
download | libgcrypt-936035b491fab2e32f651ed201bc10a6731ebe05.tar.gz |
Overhauled the keygrip computation.
Diffstat (limited to 'cipher/rsa.c')
-rw-r--r-- | cipher/rsa.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/cipher/rsa.c b/cipher/rsa.c index 8ca8f314..9a7b94df 100644 --- a/cipher/rsa.c +++ b/cipher/rsa.c @@ -686,6 +686,44 @@ _gcry_rsa_get_nbits (int algo, gcry_mpi_t *pkey) } +/* Compute a keygrip. MD is the hash context which we are going to + update. KEYPARAM is an S-expression with the key parameters, this + is usually a public key but may also be a secret key. An example + of such an S-expression is: + + (rsa + (n #00B...#) + (e #010001#)) + + PKCS-15 says that for RSA only the modulus should be hashed - + however, it is not clear wether this is meant to use the raw bytes + (assuming this is an unsigned integer) or whether the DER required + 0 should be prefixed. We hash the raw bytes. */ +static gpg_err_code_t +compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparam) +{ + gcry_sexp_t l1; + const char *data; + size_t datalen; + + l1 = gcry_sexp_find_token (keyparam, "n", 1); + if (!l1) + return GPG_ERR_NO_OBJ; + + data = gcry_sexp_nth_data (l1, 1, &datalen); + if (!data) + { + gcry_sexp_release (l1); + return GPG_ERR_NO_OBJ; + } + + gcry_md_write (md, data, datalen); + gcry_sexp_release (l1); + + return 0; +} + + /* @@ -761,6 +799,7 @@ gcry_pk_spec_t _gcry_pubkey_spec_rsa = pk_extra_spec_t _gcry_pubkey_extraspec_rsa = { run_selftests, - rsa_generate + rsa_generate, + compute_keygrip }; |