3 * The RSA publickey algorithm.
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001 Niels Möller
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26 #ifndef NETTLE_RSA_H_INCLUDED
27 #define NETTLE_RSA_H_INCLUDED
37 /* Size of the modulo, in octets. This is also the size of all
38 * signatures that are created or verified with this key. */
48 struct rsa_private_key
50 struct rsa_public_key pub;
58 /* d % (p-1), i.e. a e = 1 (mod (p-1)) */
61 /* d % (q-1), i.e. b e = 1 (mod (q-1)) */
64 /* modular inverse of q , i.e. c q = 1 (mod p) */
68 /* Signing a message works as follows:
70 * Store the private key in a rsa_private_key struct.
72 * Call rsa_prepare_private_key. This initializes the size attribute
73 * to the length of a signature.
75 * Initialize a hashing context, by callling
78 * Hash the message by calling
81 * Create the signature by calling
84 * The signature is represented as a mpz_t bignum. This call also
85 * resets the hashing context.
87 * When done with the key and signature, don't forget to call
91 /* Calls mpz_init to initialize bignum storage. */
93 rsa_init_public_key(struct rsa_public_key *key);
95 /* Calls mpz_clear to deallocate bignum storage. */
97 rsa_clear_public_key(struct rsa_public_key *key);
100 rsa_prepare_public_key(struct rsa_public_key *key);
102 /* Calls mpz_init to initialize bignum storage. */
104 rsa_init_private_key(struct rsa_private_key *key);
106 /* Calls mpz_clear to deallocate bignum storage. */
108 rsa_clear_private_key(struct rsa_private_key *key);
111 rsa_prepare_private_key(struct rsa_private_key *key);
114 /* PKCS#1 style signatures */
116 rsa_md5_sign(struct rsa_private_key *key,
117 struct md5_ctx *hash,
122 rsa_md5_verify(struct rsa_public_key *key,
123 struct md5_ctx *hash,
124 const mpz_t signature);
127 rsa_sha1_sign(struct rsa_private_key *key,
128 struct sha1_ctx *hash,
132 rsa_sha1_verify(struct rsa_public_key *key,
133 struct sha1_ctx *hash,
134 const mpz_t signature);
136 /* Compute x, the d:th root of m. Calling it with x == m is allowed. */
138 rsa_compute_root(struct rsa_private_key *key, mpz_t x, const mpz_t m);
141 #endif /* NETTLE_RSA_H_INCLUDED */