From 336fc90c19039f5ccd818fc9fccd5b1163a2e45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Tue, 30 Oct 2001 16:36:25 +0100 Subject: *** empty log message *** Rev: src/nettle/ChangeLog:1.43 Rev: src/nettle/rsa.h:1.2 Rev: src/nettle/testsuite/.cvsignore:1.11 --- rsa.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) (limited to 'rsa.h') diff --git a/rsa.h b/rsa.h index 105970ef..52c6d94c 100644 --- a/rsa.h +++ b/rsa.h @@ -27,19 +27,95 @@ #define NETTLE_RSA_H_INCLUDED #include - #include +#include "md5.h" +#include "sha.h" + struct rsa_public_key { + /* Size of the modulo, in octets. This is also the size of all + * signatures that are created or verified with this key. */ + unsigned size; + + /* Modulo */ mpz_t n; + + /* Public exponent */ mpz_t e; }; struct rsa_private_key { + struct rsa_public_key pub; + /* Secret exponent */ + mpz_t d; + + /* The two factors */ + mpz_t p; mpz_t q; + + /* d % (p-1), i.e. a e = 1 (mod (p-1)) */ + mpz_t a; + + /* d % (q-1), i.e. b e = 1 (mod (q-1)) */ + mpz_t b; + + /* modular inverse of q , i.e. c q = 1 (mod p) */ + mpz_t c; }; +/* Signing a message works as follows: + * + * Store the private key in a rsa_private_key struct. + * + * Call rsa_init_private_key. This initializes the size attribute + * to the length of a signature. + * + * Initialize a hashing context, by callling + * md5_init + * + * Hash the message by calling + * md5_update + * + * Finally, call + * rsa_md5_sign + * + * The final call stores the signature, of length size, in the supplied buffer, + * and resets the hashing context. + */ + +int +rsa_init_public_key(struct rsa_public_key *key); + +int +rsa_init_private_key(struct rsa_private_key *key); + +/* PKCS#1 style signatures */ +void +rsa_md5_sign(struct rsa_private_key *key, + struct md5_ctx *hash, + uint8_t *signature); + + +int +rsa_md5_verify(struct rsa_public_key *key, + struct md5_ctx *hash, + const uint8_t *signature); + +void +rsa_sha1_sign(struct rsa_private_key *key, + struct sha1_ctx *hash, + uint8_t *signature); + +int +rsa_sha1_verify(struct rsa_public_key *key, + struct sha1_ctx *hash, + const uint8_t *signature); + +/* Compute x, the d:th root of m. Calling it with x == m is allowed. */ +void +rsa_compute_root(struct rsa_private_key *key, mpz_t x, mpz_t m); + -#endif NETTLE_RSA_H_INCLUDED +#endif /* NETTLE_RSA_H_INCLUDED */ -- cgit v1.2.1