Commit 0fb4bd32 authored by Niels Möller's avatar Niels Möller

(rsa_init_public_key): New function.

(rsa_clear_public_key): Likewise.
(rsa_init_private_key): Likewise.
(rsa_clear_private_key): Likewise.

Rev: src/nettle/rsa.c:1.3
Rev: src/nettle/rsa.h:1.4
parent 87e63ab1
......@@ -37,6 +37,24 @@
* one can link in the signature functions without also getting the
* verify functions. */
void
rsa_init_public_key(struct rsa_public_key *key)
{
mpz_init(key->n);
mpz_init(key->e);
/* Not really necessary, but it seems cleaner to initialize all the
* storage. */
key->size = 0;
}
void
rsa_clear_public_key(struct rsa_public_key *key)
{
mpz_clear(key->n);
mpz_clear(key->e);
}
int
rsa_prepare_public_key(struct rsa_public_key *key)
{
......@@ -63,12 +81,39 @@ rsa_prepare_public_key(struct rsa_public_key *key)
}
}
void
rsa_init_private_key(struct rsa_private_key *key)
{
rsa_init_public_key(&key->pub);
mpz_init(key->d);
mpz_init(key->p);
mpz_init(key->q);
mpz_init(key->a);
mpz_init(key->b);
mpz_init(key->c);
}
void
rsa_clear_private_key(struct rsa_private_key *key)
{
rsa_clear_public_key(&key->pub);
mpz_clear(key->d);
mpz_clear(key->p);
mpz_clear(key->q);
mpz_clear(key->a);
mpz_clear(key->b);
mpz_clear(key->c);
}
int
rsa_prepare_private_key(struct rsa_private_key *key)
{
return rsa_prepare_public_key(&key->pub);
}
#ifndef RSA_CRT
#define RSA_CRT 1
#endif
......
......@@ -84,15 +84,33 @@ struct rsa_private_key
* The signature is represented as a mpz_t bignum. This call also
* resets the hashing context.
*
* When done with the key, don't forget to call mpz_clear.
* When done with the key and signature, don't forget to call
* mpz_clear.
*/
/* Calls mpz_init to initialize bignum storage. */
void
rsa_init_public_key(struct rsa_public_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
rsa_clear_public_key(struct rsa_public_key *key);
int
rsa_prepare_public_key(struct rsa_public_key *key);
/* Calls mpz_init to initialize bignum storage. */
void
rsa_init_private_key(struct rsa_private_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
rsa_clear_private_key(struct rsa_private_key *key);
int
rsa_prepare_private_key(struct rsa_private_key *key);
/* PKCS#1 style signatures */
void
rsa_md5_sign(struct rsa_private_key *key,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment