3
* The DSA publickey algorithm.
6
/* nettle, low-level cryptographics library
8
* Copyright (C) 2002 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_DSA_H_INCLUDED
27
#define NETTLE_DSA_H_INCLUDED
31
#include "nettle-types.h"
35
/* For nettle_random_func */
36
#include "nettle-meta.h"
39
#define dsa_public_key_init nettle_dsa_public_key_init
40
#define dsa_public_key_clear nettle_dsa_public_key_clear
41
#define dsa_private_key_init nettle_dsa_private_key_init
42
#define dsa_private_key_clear nettle_dsa_private_key_clear
43
#define dsa_signature_init nettle_dsa_signature_init
44
#define dsa_signature_clear nettle_dsa_signature_clear
45
#define dsa_sign nettle_dsa_sign
46
#define dsa_verify nettle_dsa_verify
47
#define dsa_sign_digest nettle_dsa_sign_digest
48
#define dsa_verify_digest nettle_dsa_verify_digest
49
#define dsa_generate_keypair nettle_dsa_generate_keypair
50
#define dsa_signature_from_sexp nettle_dsa_signature_from_sexp
51
#define dsa_keypair_from_sexp_alist nettle_dsa_keypair_from_sexp_alist
52
#define dsa_keypair_from_sexp nettle_dsa_keypair_from_sexp
54
#define DSA_MIN_P_BITS 512
55
#define DSA_Q_OCTETS 20
56
#define DSA_Q_BITS 160
73
struct dsa_private_key
75
/* Unlike an rsa public key, private key operations will need both
76
* the private and the public information. */
86
/* Signing a message works as follows:
88
* Store the private key in a dsa_private_key struct.
90
* Initialize a hashing context, by callling
93
* Hash the message by calling
96
* Create the signature by calling
99
* The signature is represented as a struct dsa_signature. This call also
100
* resets the hashing context.
102
* When done with the key and signature, don't forget to call
103
* dsa_signature_clear.
106
/* Calls mpz_init to initialize bignum storage. */
108
dsa_public_key_init(struct dsa_public_key *key);
110
/* Calls mpz_clear to deallocate bignum storage. */
112
dsa_public_key_clear(struct dsa_public_key *key);
115
/* Calls mpz_init to initialize bignum storage. */
117
dsa_private_key_init(struct dsa_private_key *key);
119
/* Calls mpz_clear to deallocate bignum storage. */
121
dsa_private_key_clear(struct dsa_private_key *key);
123
/* Calls mpz_init to initialize bignum storage. */
125
dsa_signature_init(struct dsa_signature *signature);
127
/* Calls mpz_clear to deallocate bignum storage. */
129
dsa_signature_clear(struct dsa_signature *signature);
133
dsa_sign(const struct dsa_public_key *pub,
134
const struct dsa_private_key *key,
135
void *random_ctx, nettle_random_func random,
136
struct sha1_ctx *hash,
137
struct dsa_signature *signature);
141
dsa_verify(const struct dsa_public_key *key,
142
struct sha1_ctx *hash,
143
const struct dsa_signature *signature);
146
dsa_sign_digest(const struct dsa_public_key *pub,
147
const struct dsa_private_key *key,
148
void *random_ctx, nettle_random_func random,
149
const uint8_t *digest,
150
struct dsa_signature *signature);
153
dsa_verify_digest(const struct dsa_public_key *key,
154
const uint8_t *digest,
155
const struct dsa_signature *signature);
160
dsa_generate_keypair(struct dsa_public_key *pub,
161
struct dsa_private_key *key,
163
void *random_ctx, nettle_random_func random,
164
void *progress_ctx, nettle_progress_func progress,
166
/* Size of key, in bits.
167
* Use size = 512 + 64 * l for the official
171
struct sexp_iterator;
174
dsa_signature_from_sexp(struct dsa_signature *rs,
175
struct sexp_iterator *i);
178
dsa_keypair_from_sexp_alist(struct dsa_public_key *pub,
179
struct dsa_private_key *priv,
181
struct sexp_iterator *i);
183
/* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
184
* expect a private key expression and ignore the parts not needed for
186
/* Keys must be initialized before calling this function, as usual. */
188
dsa_keypair_from_sexp(struct dsa_public_key *pub,
189
struct dsa_private_key *priv,
191
unsigned length, const uint8_t *expr);
194
#endif /* NETTLE_DSA_H_INCLUDED */