blob: 2b4c08bacc99e8ca8ba6f56db59cba6bc9b2ec72 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2 * All rights reserved.
3 *
4 * This package is an SSL implementation written
5 * by Eric Young (eay@cryptsoft.com).
6 * The implementation was written so as to conform with Netscapes SSL.
7 *
8 * This library is free for commercial and non-commercial use as long as
9 * the following conditions are aheared to. The following conditions
10 * apply to all code found in this distribution, be it the RC4, RSA,
11 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12 * included with this distribution is covered by the same copyright terms
13 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14 *
15 * Copyright remains Eric Young's, and as such any Copyright notices in
16 * the code are not to be removed.
17 * If this package is used in a product, Eric Young should be given attribution
18 * as the author of the parts of the library used.
19 * This can be in the form of a textual message at program startup or
20 * in documentation (online or textual) provided with the package.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * "This product includes cryptographic software written by
33 * Eric Young (eay@cryptsoft.com)"
34 * The word 'cryptographic' can be left out if the rouines from the library
35 * being used are not cryptographic related :-).
36 * 4. If you include any Windows specific code (or a derivative thereof) from
37 * the apps directory (application code) you must include an acknowledgement:
38 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 *
52 * The licence and distribution terms for any publically available version or
53 * derivative of this code cannot be changed. i.e. this code cannot simply be
54 * copied and put under another distribution licence
55 * [including the GNU Public Licence.]
56 *
57 * The DSS routines are based on patches supplied by
58 * Steven Schoch <schoch@sheba.arc.nasa.gov>. */
59
60#ifndef OPENSSL_HEADER_DSA_H
61#define OPENSSL_HEADER_DSA_H
62
63#include <openssl/base.h>
64
65#include <openssl/engine.h>
66#include <openssl/ex_data.h>
Adam Langley683d7bd2015-04-13 11:04:14 -070067#include <openssl/thread.h>
Adam Langley95c29f32014-06-20 12:00:00 -070068
69#if defined(__cplusplus)
70extern "C" {
71#endif
72
73
David Benjamin4512b792017-08-18 19:21:50 -040074// DSA contains functions for signing and verifying with the Digital Signature
75// Algorithm.
Adam Langley95c29f32014-06-20 12:00:00 -070076
77
David Benjamin4512b792017-08-18 19:21:50 -040078// Allocation and destruction.
Adam Langley95c29f32014-06-20 12:00:00 -070079
David Benjamin4512b792017-08-18 19:21:50 -040080// DSA_new returns a new, empty DSA object or NULL on error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -070081OPENSSL_EXPORT DSA *DSA_new(void);
Adam Langley95c29f32014-06-20 12:00:00 -070082
David Benjamin4512b792017-08-18 19:21:50 -040083// DSA_free decrements the reference count of |dsa| and frees it if the
84// reference count drops to zero.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -070085OPENSSL_EXPORT void DSA_free(DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -070086
David Benjamin4512b792017-08-18 19:21:50 -040087// DSA_up_ref increments the reference count of |dsa| and returns one.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -070088OPENSSL_EXPORT int DSA_up_ref(DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -070089
90
David Benjamin4512b792017-08-18 19:21:50 -040091// Properties.
David Benjamin5a915032016-08-09 11:04:24 -040092
David Benjamin4512b792017-08-18 19:21:50 -040093// DSA_get0_key sets |*out_pub_key| and |*out_priv_key|, if non-NULL, to |dsa|'s
94// public and private key, respectively. If |dsa| is a public key, the private
95// key will be set to NULL.
David Benjamin5a915032016-08-09 11:04:24 -040096OPENSSL_EXPORT void DSA_get0_key(const DSA *dsa, const BIGNUM **out_pub_key,
97 const BIGNUM **out_priv_key);
98
David Benjamin4512b792017-08-18 19:21:50 -040099// DSA_get0_pqg sets |*out_p|, |*out_q|, and |*out_g|, if non-NULL, to |dsa|'s
100// p, q, and g parameters, respectively.
David Benjamin5a915032016-08-09 11:04:24 -0400101OPENSSL_EXPORT void DSA_get0_pqg(const DSA *dsa, const BIGNUM **out_p,
102 const BIGNUM **out_q, const BIGNUM **out_g);
103
104
David Benjamin4512b792017-08-18 19:21:50 -0400105// Parameter generation.
Adam Langley95c29f32014-06-20 12:00:00 -0700106
David Benjamin4512b792017-08-18 19:21:50 -0400107// DSA_generate_parameters_ex generates a set of DSA parameters by following
108// the procedure given in FIPS 186-4, appendix A.
109// (http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf)
110//
111// The larger prime will have a length of |bits| (e.g. 2048). The |seed| value
112// allows others to generate and verify the same parameters and should be
113// random input which is kept for reference. If |out_counter| or |out_h| are
114// not NULL then the counter and h value used in the generation are written to
115// them.
116//
117// The |cb| argument is passed to |BN_generate_prime_ex| and is thus called
118// during the generation process in order to indicate progress. See the
119// comments for that function for details. In addition to the calls made by
120// |BN_generate_prime_ex|, |DSA_generate_parameters_ex| will call it with
121// |event| equal to 2 and 3 at different stages of the process.
122//
123// It returns one on success and zero otherwise.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700124OPENSSL_EXPORT int DSA_generate_parameters_ex(DSA *dsa, unsigned bits,
125 const uint8_t *seed,
126 size_t seed_len, int *out_counter,
127 unsigned long *out_h,
128 BN_GENCB *cb);
Adam Langley95c29f32014-06-20 12:00:00 -0700129
David Benjamin4512b792017-08-18 19:21:50 -0400130// DSAparams_dup returns a freshly allocated |DSA| that contains a copy of the
131// parameters from |dsa|. It returns NULL on error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700132OPENSSL_EXPORT DSA *DSAparams_dup(const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700133
134
David Benjamin4512b792017-08-18 19:21:50 -0400135// Key generation.
Adam Langley95c29f32014-06-20 12:00:00 -0700136
David Benjamin4512b792017-08-18 19:21:50 -0400137// DSA_generate_key generates a public/private key pair in |dsa|, which must
138// already have parameters setup. It returns one on success and zero on
139// error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700140OPENSSL_EXPORT int DSA_generate_key(DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700141
142
David Benjamin4512b792017-08-18 19:21:50 -0400143// Signatures.
Adam Langley95c29f32014-06-20 12:00:00 -0700144
David Benjamin4512b792017-08-18 19:21:50 -0400145// DSA_SIG_st (aka |DSA_SIG|) contains a DSA signature as a pair of integers.
Matt Braithwaiteb9afd512016-07-19 12:41:35 -0700146struct DSA_SIG_st {
Adam Langley95c29f32014-06-20 12:00:00 -0700147 BIGNUM *r, *s;
Matt Braithwaiteb9afd512016-07-19 12:41:35 -0700148};
Adam Langley95c29f32014-06-20 12:00:00 -0700149
David Benjamin4512b792017-08-18 19:21:50 -0400150// DSA_SIG_new returns a freshly allocated, DIG_SIG structure or NULL on error.
151// Both |r| and |s| in the signature will be NULL.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700152OPENSSL_EXPORT DSA_SIG *DSA_SIG_new(void);
Adam Langley95c29f32014-06-20 12:00:00 -0700153
David Benjamin4512b792017-08-18 19:21:50 -0400154// DSA_SIG_free frees the contents of |sig| and then frees |sig| itself.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700155OPENSSL_EXPORT void DSA_SIG_free(DSA_SIG *sig);
Adam Langley95c29f32014-06-20 12:00:00 -0700156
David Benjamin4512b792017-08-18 19:21:50 -0400157// DSA_do_sign returns a signature of the hash in |digest| by the key in |dsa|
158// and returns an allocated, DSA_SIG structure, or NULL on error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700159OPENSSL_EXPORT DSA_SIG *DSA_do_sign(const uint8_t *digest, size_t digest_len,
160 DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700161
David Benjamin4512b792017-08-18 19:21:50 -0400162// DSA_do_verify verifies that |sig| is a valid signature, by the public key in
163// |dsa|, of the hash in |digest|. It returns one if so, zero if invalid and -1
164// on error.
165//
166// WARNING: do not use. This function returns -1 for error, 0 for invalid and 1
167// for valid. However, this is dangerously different to the usual OpenSSL
168// convention and could be a disaster if a user did |if (DSA_do_verify(...))|.
169// Because of this, |DSA_check_signature| is a safer version of this.
170//
171// TODO(fork): deprecate.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700172OPENSSL_EXPORT int DSA_do_verify(const uint8_t *digest, size_t digest_len,
173 DSA_SIG *sig, const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700174
David Benjamin4512b792017-08-18 19:21:50 -0400175// DSA_do_check_signature sets |*out_valid| to zero. Then it verifies that |sig|
176// is a valid signature, by the public key in |dsa| of the hash in |digest|
177// and, if so, it sets |*out_valid| to one.
178//
179// It returns one if it was able to verify the signature as valid or invalid,
180// and zero on error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700181OPENSSL_EXPORT int DSA_do_check_signature(int *out_valid, const uint8_t *digest,
182 size_t digest_len, DSA_SIG *sig,
183 const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700184
185
David Benjamin4512b792017-08-18 19:21:50 -0400186// ASN.1 signatures.
187//
188// These functions also perform DSA signature operations, but deal with ASN.1
189// encoded signatures as opposed to raw |BIGNUM|s. If you don't know what
190// encoding a DSA signature is in, it's probably ASN.1.
Adam Langley95c29f32014-06-20 12:00:00 -0700191
David Benjamin4512b792017-08-18 19:21:50 -0400192// DSA_sign signs |digest| with the key in |dsa| and writes the resulting
193// signature, in ASN.1 form, to |out_sig| and the length of the signature to
194// |*out_siglen|. There must be, at least, |DSA_size(dsa)| bytes of space in
195// |out_sig|. It returns one on success and zero otherwise.
196//
197// (The |type| argument is ignored.)
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700198OPENSSL_EXPORT int DSA_sign(int type, const uint8_t *digest, size_t digest_len,
199 uint8_t *out_sig, unsigned int *out_siglen,
200 DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700201
David Benjamin4512b792017-08-18 19:21:50 -0400202// DSA_verify verifies that |sig| is a valid, ASN.1 signature, by the public
203// key in |dsa|, of the hash in |digest|. It returns one if so, zero if invalid
204// and -1 on error.
205//
206// (The |type| argument is ignored.)
207//
208// WARNING: do not use. This function returns -1 for error, 0 for invalid and 1
209// for valid. However, this is dangerously different to the usual OpenSSL
210// convention and could be a disaster if a user did |if (DSA_do_verify(...))|.
211// Because of this, |DSA_check_signature| is a safer version of this.
212//
213// TODO(fork): deprecate.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700214OPENSSL_EXPORT int DSA_verify(int type, const uint8_t *digest,
215 size_t digest_len, const uint8_t *sig,
216 size_t sig_len, const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700217
David Benjamin4512b792017-08-18 19:21:50 -0400218// DSA_check_signature sets |*out_valid| to zero. Then it verifies that |sig|
219// is a valid, ASN.1 signature, by the public key in |dsa|, of the hash in
220// |digest|. If so, it sets |*out_valid| to one.
221//
222// It returns one if it was able to verify the signature as valid or invalid,
223// and zero on error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700224OPENSSL_EXPORT int DSA_check_signature(int *out_valid, const uint8_t *digest,
225 size_t digest_len, const uint8_t *sig,
226 size_t sig_len, const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700227
David Benjamin4512b792017-08-18 19:21:50 -0400228// DSA_size returns the size, in bytes, of an ASN.1 encoded, DSA signature
229// generated by |dsa|. Parameters must already have been setup in |dsa|.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700230OPENSSL_EXPORT int DSA_size(const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700231
232
David Benjamin4512b792017-08-18 19:21:50 -0400233// ASN.1 encoding.
Adam Langley95c29f32014-06-20 12:00:00 -0700234
David Benjamin4512b792017-08-18 19:21:50 -0400235// DSA_SIG_parse parses a DER-encoded DSA-Sig-Value structure from |cbs| and
236// advances |cbs|. It returns a newly-allocated |DSA_SIG| or NULL on error.
David Benjaminfda22a72016-01-30 01:51:01 -0500237OPENSSL_EXPORT DSA_SIG *DSA_SIG_parse(CBS *cbs);
Adam Langley95c29f32014-06-20 12:00:00 -0700238
David Benjamin4512b792017-08-18 19:21:50 -0400239// DSA_SIG_marshal marshals |sig| as a DER-encoded DSA-Sig-Value and appends the
240// result to |cbb|. It returns one on success and zero on error.
David Benjaminfda22a72016-01-30 01:51:01 -0500241OPENSSL_EXPORT int DSA_SIG_marshal(CBB *cbb, const DSA_SIG *sig);
Adam Langley95c29f32014-06-20 12:00:00 -0700242
David Benjamin4512b792017-08-18 19:21:50 -0400243// DSA_parse_public_key parses a DER-encoded DSA public key from |cbs| and
244// advances |cbs|. It returns a newly-allocated |DSA| or NULL on error.
David Benjaminfda22a72016-01-30 01:51:01 -0500245OPENSSL_EXPORT DSA *DSA_parse_public_key(CBS *cbs);
Adam Langley95c29f32014-06-20 12:00:00 -0700246
David Benjamin4512b792017-08-18 19:21:50 -0400247// DSA_marshal_public_key marshals |dsa| as a DER-encoded DSA public key and
248// appends the result to |cbb|. It returns one on success and zero on
249// failure.
David Benjaminfda22a72016-01-30 01:51:01 -0500250OPENSSL_EXPORT int DSA_marshal_public_key(CBB *cbb, const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700251
David Benjamin4512b792017-08-18 19:21:50 -0400252// DSA_parse_private_key parses a DER-encoded DSA private key from |cbs| and
253// advances |cbs|. It returns a newly-allocated |DSA| or NULL on error.
David Benjaminfda22a72016-01-30 01:51:01 -0500254OPENSSL_EXPORT DSA *DSA_parse_private_key(CBS *cbs);
Adam Langley95c29f32014-06-20 12:00:00 -0700255
David Benjamin4512b792017-08-18 19:21:50 -0400256// DSA_marshal_private_key marshals |dsa| as a DER-encoded DSA private key and
257// appends the result to |cbb|. It returns one on success and zero on
258// failure.
David Benjaminfda22a72016-01-30 01:51:01 -0500259OPENSSL_EXPORT int DSA_marshal_private_key(CBB *cbb, const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700260
David Benjamin4512b792017-08-18 19:21:50 -0400261// DSA_parse_parameters parses a DER-encoded Dss-Parms structure (RFC 3279)
262// from |cbs| and advances |cbs|. It returns a newly-allocated |DSA| or NULL on
263// error.
David Benjaminfda22a72016-01-30 01:51:01 -0500264OPENSSL_EXPORT DSA *DSA_parse_parameters(CBS *cbs);
Adam Langley95c29f32014-06-20 12:00:00 -0700265
David Benjamin4512b792017-08-18 19:21:50 -0400266// DSA_marshal_parameters marshals |dsa| as a DER-encoded Dss-Parms structure
267// (RFC 3447) and appends the result to |cbb|. It returns one on success and
268// zero on failure.
David Benjaminfda22a72016-01-30 01:51:01 -0500269OPENSSL_EXPORT int DSA_marshal_parameters(CBB *cbb, const DSA *dsa);
Adam Langley95c29f32014-06-20 12:00:00 -0700270
271
David Benjamin4512b792017-08-18 19:21:50 -0400272// Precomputation.
Adam Langley95c29f32014-06-20 12:00:00 -0700273
David Benjamin4512b792017-08-18 19:21:50 -0400274// DSA_sign_setup precomputes the message independent part of the DSA signature
275// and writes them to |*out_kinv| and |*out_r|. Returns one on success, zero on
276// error.
277//
278// TODO(fork): decide what to do with this. Since making DSA* opaque there's no
279// way for the user to install them. Also, it forces the DSA* not to be const
280// when passing to the signing function.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700281OPENSSL_EXPORT int DSA_sign_setup(const DSA *dsa, BN_CTX *ctx,
282 BIGNUM **out_kinv, BIGNUM **out_r);
Adam Langley95c29f32014-06-20 12:00:00 -0700283
284
David Benjamin4512b792017-08-18 19:21:50 -0400285// Conversion.
Adam Langleybed8ce72014-09-05 17:04:51 -0700286
David Benjamin4512b792017-08-18 19:21:50 -0400287// DSA_dup_DH returns a |DH| constructed from the parameters of |dsa|. This is
288// sometimes needed when Diffie-Hellman parameters are stored in the form of
289// DSA parameters. It returns an allocated |DH| on success or NULL on error.
Adam Langleybed8ce72014-09-05 17:04:51 -0700290OPENSSL_EXPORT DH *DSA_dup_DH(const DSA *dsa);
291
292
David Benjamin4512b792017-08-18 19:21:50 -0400293// ex_data functions.
294//
295// See |ex_data.h| for details.
Adam Langley95c29f32014-06-20 12:00:00 -0700296
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700297OPENSSL_EXPORT int DSA_get_ex_new_index(long argl, void *argp,
David Benjamin8a589332015-12-04 23:14:35 -0500298 CRYPTO_EX_unused *unused,
David Benjamind94682d2017-05-14 17:10:18 -0400299 CRYPTO_EX_dup *dup_unused,
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700300 CRYPTO_EX_free *free_func);
David Benjamin27e377e2017-07-31 19:09:42 -0400301OPENSSL_EXPORT int DSA_set_ex_data(DSA *dsa, int idx, void *arg);
302OPENSSL_EXPORT void *DSA_get_ex_data(const DSA *dsa, int idx);
Adam Langley95c29f32014-06-20 12:00:00 -0700303
304
David Benjamin4512b792017-08-18 19:21:50 -0400305// Deprecated functions.
David Benjaminfda22a72016-01-30 01:51:01 -0500306
David Benjamin4512b792017-08-18 19:21:50 -0400307// d2i_DSA_SIG parses an ASN.1, DER-encoded, DSA signature from |len| bytes at
308// |*inp|. If |out_sig| is not NULL then, on exit, a pointer to the result is
309// in |*out_sig|. Note that, even if |*out_sig| is already non-NULL on entry, it
310// will not be written to. Rather, a fresh |DSA_SIG| is allocated and the
311// previous one is freed. On successful exit, |*inp| is advanced past the DER
312// structure. It returns the result or NULL on error.
313//
314// Use |DSA_SIG_parse| instead.
David Benjaminfda22a72016-01-30 01:51:01 -0500315OPENSSL_EXPORT DSA_SIG *d2i_DSA_SIG(DSA_SIG **out_sig, const uint8_t **inp,
316 long len);
317
David Benjamin4512b792017-08-18 19:21:50 -0400318// i2d_DSA_SIG marshals |in| to an ASN.1, DER structure. If |outp| is not NULL
319// then the result is written to |*outp| and |*outp| is advanced just past the
320// output. It returns the number of bytes in the result, whether written or not,
321// or a negative value on error.
322//
323// Use |DSA_SIG_marshal| instead.
David Benjaminfda22a72016-01-30 01:51:01 -0500324OPENSSL_EXPORT int i2d_DSA_SIG(const DSA_SIG *in, uint8_t **outp);
325
David Benjamin4512b792017-08-18 19:21:50 -0400326// d2i_DSAPublicKey parses an ASN.1, DER-encoded, DSA public key from |len|
327// bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the result
328// is in |*out|. Note that, even if |*ou| is already non-NULL on entry, it will
329// not be written to. Rather, a fresh |DSA| is allocated and the previous one is
330// freed. On successful exit, |*inp| is advanced past the DER structure. It
331// returns the result or NULL on error.
332//
333// Use |DSA_parse_public_key| instead.
David Benjaminfda22a72016-01-30 01:51:01 -0500334OPENSSL_EXPORT DSA *d2i_DSAPublicKey(DSA **out, const uint8_t **inp, long len);
335
David Benjamin4512b792017-08-18 19:21:50 -0400336// i2d_DSAPublicKey marshals a public key from |in| to an ASN.1, DER structure.
337// If |outp| is not NULL then the result is written to |*outp| and |*outp| is
338// advanced just past the output. It returns the number of bytes in the result,
339// whether written or not, or a negative value on error.
340//
341// Use |DSA_marshal_public_key| instead.
David Benjaminfda22a72016-01-30 01:51:01 -0500342OPENSSL_EXPORT int i2d_DSAPublicKey(const DSA *in, uint8_t **outp);
343
David Benjamin4512b792017-08-18 19:21:50 -0400344// d2i_DSAPrivateKey parses an ASN.1, DER-encoded, DSA private key from |len|
345// bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the result
346// is in |*out|. Note that, even if |*out| is already non-NULL on entry, it will
347// not be written to. Rather, a fresh |DSA| is allocated and the previous one is
348// freed. On successful exit, |*inp| is advanced past the DER structure. It
349// returns the result or NULL on error.
350//
351// Use |DSA_parse_private_key| instead.
David Benjaminfda22a72016-01-30 01:51:01 -0500352OPENSSL_EXPORT DSA *d2i_DSAPrivateKey(DSA **out, const uint8_t **inp, long len);
353
David Benjamin4512b792017-08-18 19:21:50 -0400354// i2d_DSAPrivateKey marshals a private key from |in| to an ASN.1, DER
355// structure. If |outp| is not NULL then the result is written to |*outp| and
356// |*outp| is advanced just past the output. It returns the number of bytes in
357// the result, whether written or not, or a negative value on error.
358//
359// Use |DSA_marshal_private_key| instead.
David Benjaminfda22a72016-01-30 01:51:01 -0500360OPENSSL_EXPORT int i2d_DSAPrivateKey(const DSA *in, uint8_t **outp);
361
David Benjamin4512b792017-08-18 19:21:50 -0400362// d2i_DSAparams parses ASN.1, DER-encoded, DSA parameters from |len| bytes at
363// |*inp|. If |out| is not NULL then, on exit, a pointer to the result is in
364// |*out|. Note that, even if |*out| is already non-NULL on entry, it will not
365// be written to. Rather, a fresh |DSA| is allocated and the previous one is
366// freed. On successful exit, |*inp| is advanced past the DER structure. It
367// returns the result or NULL on error.
368//
369// Use |DSA_parse_parameters| instead.
David Benjaminfda22a72016-01-30 01:51:01 -0500370OPENSSL_EXPORT DSA *d2i_DSAparams(DSA **out, const uint8_t **inp, long len);
371
David Benjamin4512b792017-08-18 19:21:50 -0400372// i2d_DSAparams marshals DSA parameters from |in| to an ASN.1, DER structure.
373// If |outp| is not NULL then the result is written to |*outp| and |*outp| is
374// advanced just past the output. It returns the number of bytes in the result,
375// whether written or not, or a negative value on error.
376//
377// Use |DSA_marshal_parameters| instead.
David Benjaminfda22a72016-01-30 01:51:01 -0500378OPENSSL_EXPORT int i2d_DSAparams(const DSA *in, uint8_t **outp);
379
David Benjamin4512b792017-08-18 19:21:50 -0400380// DSA_generate_parameters is a deprecated version of
381// |DSA_generate_parameters_ex| that creates and returns a |DSA*|. Don't use
382// it.
Adam Langley99a24ba2016-03-07 16:11:01 -0800383OPENSSL_EXPORT DSA *DSA_generate_parameters(int bits, unsigned char *seed,
384 int seed_len, int *counter_ret,
385 unsigned long *h_ret,
386 void (*callback)(int, int, void *),
387 void *cb_arg);
388
David Benjaminfda22a72016-01-30 01:51:01 -0500389
Adam Langley95c29f32014-06-20 12:00:00 -0700390struct dsa_st {
391 long version;
Adam Langley95c29f32014-06-20 12:00:00 -0700392 BIGNUM *p;
David Benjamin4512b792017-08-18 19:21:50 -0400393 BIGNUM *q; // == 20
Adam Langley95c29f32014-06-20 12:00:00 -0700394 BIGNUM *g;
395
David Benjamin4512b792017-08-18 19:21:50 -0400396 BIGNUM *pub_key; // y public key
397 BIGNUM *priv_key; // x private key
Adam Langley95c29f32014-06-20 12:00:00 -0700398
David Benjamin4512b792017-08-18 19:21:50 -0400399 BIGNUM *kinv; // Signing pre-calc
400 BIGNUM *r; // Signing pre-calc
Adam Langley95c29f32014-06-20 12:00:00 -0700401
402 int flags;
David Benjamin4512b792017-08-18 19:21:50 -0400403 // Normally used to cache montgomery values
David Benjamin99c752a2016-06-16 15:13:43 -0400404 CRYPTO_MUTEX method_mont_lock;
Adam Langley95c29f32014-06-20 12:00:00 -0700405 BN_MONT_CTX *method_mont_p;
David Benjamin99c752a2016-06-16 15:13:43 -0400406 BN_MONT_CTX *method_mont_q;
Adam Langley0da323a2015-05-15 12:49:30 -0700407 CRYPTO_refcount_t references;
Adam Langley95c29f32014-06-20 12:00:00 -0700408 CRYPTO_EX_DATA ex_data;
Adam Langley95c29f32014-06-20 12:00:00 -0700409};
410
411
412#if defined(__cplusplus)
David Benjamin4512b792017-08-18 19:21:50 -0400413} // extern C
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700414
415extern "C++" {
416
417namespace bssl {
418
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700419BORINGSSL_MAKE_DELETER(DSA, DSA_free)
420BORINGSSL_MAKE_DELETER(DSA_SIG, DSA_SIG_free)
421
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700422} // namespace bssl
423
David Benjamin4512b792017-08-18 19:21:50 -0400424} // extern C++
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700425
Adam Langley95c29f32014-06-20 12:00:00 -0700426#endif
427
David Benjamin689be0f2015-02-11 15:55:26 -0500428#define DSA_R_BAD_Q_VALUE 100
429#define DSA_R_MISSING_PARAMETERS 101
Adam Langley95c29f32014-06-20 12:00:00 -0700430#define DSA_R_MODULUS_TOO_LARGE 102
David Benjamin689be0f2015-02-11 15:55:26 -0500431#define DSA_R_NEED_NEW_SETUP_VALUES 103
David Benjaminfda22a72016-01-30 01:51:01 -0500432#define DSA_R_BAD_VERSION 104
433#define DSA_R_DECODE_ERROR 105
434#define DSA_R_ENCODE_ERROR 106
Adam Langley95c29f32014-06-20 12:00:00 -0700435
David Benjamin4512b792017-08-18 19:21:50 -0400436#endif // OPENSSL_HEADER_DSA_H