Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1 | /* 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 Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 67 | #include <openssl/thread.h> |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 68 | |
| 69 | #if defined(__cplusplus) |
| 70 | extern "C" { |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | /* DSA contains functions for signing and verifing with the Digital Signature |
| 75 | * Algorithm. */ |
| 76 | |
| 77 | |
| 78 | /* Allocation and destruction. */ |
| 79 | |
| 80 | /* DSA_new returns a new, empty DSA object or NULL on error. */ |
| 81 | OPENSSL_EXPORT DSA *DSA_new(void); |
| 82 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 83 | /* DSA_free decrements the reference count of |dsa| and frees it if the |
| 84 | * reference count drops to zero. */ |
| 85 | OPENSSL_EXPORT void DSA_free(DSA *dsa); |
| 86 | |
| 87 | /* DSA_up_ref increments the reference count of |dsa|. */ |
| 88 | OPENSSL_EXPORT int DSA_up_ref(DSA *dsa); |
| 89 | |
| 90 | |
| 91 | /* Parameter generation. */ |
| 92 | |
| 93 | /* DSA_generate_parameters_ex generates a set of DSA parameters by following |
| 94 | * the procedure given in FIPS 186-4, appendix A. |
| 95 | * (http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf) |
| 96 | * |
| 97 | * The larger prime will have a length of |bits| (e.g. 2048). The |seed| value |
| 98 | * allows others to generate and verify the same parameters and should be |
| 99 | * random input which is kept for reference. If |out_counter| or |out_h| are |
| 100 | * not NULL then the counter and h value used in the generation are written to |
| 101 | * them. |
| 102 | * |
| 103 | * The |cb| argument is passed to |BN_generate_prime_ex| and is thus called |
| 104 | * during the generation process in order to indicate progress. See the |
| 105 | * comments for that function for details. In addition to the calls made by |
| 106 | * |BN_generate_prime_ex|, |DSA_generate_parameters_ex| will call it with |
| 107 | * |event| equal to 2 and 3 at different stages of the process. |
| 108 | * |
| 109 | * It returns one on success and zero otherwise. */ |
| 110 | OPENSSL_EXPORT int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, |
| 111 | const uint8_t *seed, |
| 112 | size_t seed_len, int *out_counter, |
| 113 | unsigned long *out_h, |
| 114 | BN_GENCB *cb); |
| 115 | |
| 116 | /* DSAparams_dup returns a freshly allocated |DSA| that contains a copy of the |
| 117 | * parameters from |dsa|. It returns NULL on error. */ |
| 118 | OPENSSL_EXPORT DSA *DSAparams_dup(const DSA *dsa); |
| 119 | |
| 120 | |
| 121 | /* Key generation. */ |
| 122 | |
| 123 | /* DSA_generate_key generates a public/private key pair in |dsa|, which must |
| 124 | * already have parameters setup. It returns one on success and zero on |
| 125 | * error. */ |
| 126 | OPENSSL_EXPORT int DSA_generate_key(DSA *dsa); |
| 127 | |
| 128 | |
| 129 | /* Signatures. */ |
| 130 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 131 | /* DSA_SIG_st (aka |DSA_SIG|) contains a DSA signature as a pair of integers. */ |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 132 | typedef struct DSA_SIG_st { |
| 133 | BIGNUM *r, *s; |
| 134 | } DSA_SIG; |
| 135 | |
| 136 | /* DSA_SIG_new returns a freshly allocated, DIG_SIG structure or NULL on error. |
| 137 | * Both |r| and |s| in the signature will be NULL. */ |
| 138 | OPENSSL_EXPORT DSA_SIG *DSA_SIG_new(void); |
| 139 | |
| 140 | /* DSA_SIG_free frees the contents of |sig| and then frees |sig| itself. */ |
| 141 | OPENSSL_EXPORT void DSA_SIG_free(DSA_SIG *sig); |
| 142 | |
| 143 | /* DSA_do_sign returns a signature of the hash in |digest| by the key in |dsa| |
| 144 | * and returns an allocated, DSA_SIG structure, or NULL on error. */ |
| 145 | OPENSSL_EXPORT DSA_SIG *DSA_do_sign(const uint8_t *digest, size_t digest_len, |
| 146 | DSA *dsa); |
| 147 | |
| 148 | /* DSA_do_verify verifies that |sig| is a valid signature, by the public key in |
| 149 | * |dsa|, of the hash in |digest|. It returns one if so, zero if invalid and -1 |
| 150 | * on error. |
| 151 | * |
| 152 | * WARNING: do not use. This function returns -1 for error, 0 for invalid and 1 |
| 153 | * for valid. However, this is dangerously different to the usual OpenSSL |
| 154 | * convention and could be a disaster if a user did |if (DSA_do_verify(...))|. |
| 155 | * Because of this, |DSA_check_signature| is a safer version of this. |
| 156 | * |
| 157 | * TODO(fork): deprecate. */ |
| 158 | OPENSSL_EXPORT int DSA_do_verify(const uint8_t *digest, size_t digest_len, |
| 159 | DSA_SIG *sig, const DSA *dsa); |
| 160 | |
| 161 | /* DSA_do_check_signature sets |*out_valid| to zero. Then it verifies that |sig| |
| 162 | * is a valid signature, by the public key in |dsa| of the hash in |digest| |
| 163 | * and, if so, it sets |*out_valid| to one. |
| 164 | * |
| 165 | * It returns one if it was able to verify the signature as valid or invalid, |
| 166 | * and zero on error. */ |
| 167 | OPENSSL_EXPORT int DSA_do_check_signature(int *out_valid, const uint8_t *digest, |
| 168 | size_t digest_len, DSA_SIG *sig, |
| 169 | const DSA *dsa); |
| 170 | |
| 171 | |
| 172 | /* ASN.1 signatures. |
| 173 | * |
| 174 | * These functions also perform DSA signature operations, but deal with ASN.1 |
| 175 | * encoded signatures as opposed to raw |BIGNUM|s. If you don't know what |
| 176 | * encoding a DSA signature is in, it's probably ASN.1. */ |
| 177 | |
| 178 | /* DSA_sign signs |digest| with the key in |dsa| and writes the resulting |
| 179 | * signature, in ASN.1 form, to |out_sig| and the length of the signature to |
| 180 | * |*out_siglen|. There must be, at least, |DSA_size(dsa)| bytes of space in |
| 181 | * |out_sig|. It returns one on success and zero otherwise. |
| 182 | * |
| 183 | * (The |type| argument is ignored.) */ |
| 184 | OPENSSL_EXPORT int DSA_sign(int type, const uint8_t *digest, size_t digest_len, |
| 185 | uint8_t *out_sig, unsigned int *out_siglen, |
| 186 | DSA *dsa); |
| 187 | |
| 188 | /* DSA_verify verifies that |sig| is a valid, ASN.1 signature, by the public |
| 189 | * key in |dsa|, of the hash in |digest|. It returns one if so, zero if invalid |
| 190 | * and -1 on error. |
| 191 | * |
| 192 | * (The |type| argument is ignored.) |
| 193 | * |
| 194 | * WARNING: do not use. This function returns -1 for error, 0 for invalid and 1 |
| 195 | * for valid. However, this is dangerously different to the usual OpenSSL |
| 196 | * convention and could be a disaster if a user did |if (DSA_do_verify(...))|. |
| 197 | * Because of this, |DSA_check_signature| is a safer version of this. |
| 198 | * |
| 199 | * TODO(fork): deprecate. */ |
| 200 | OPENSSL_EXPORT int DSA_verify(int type, const uint8_t *digest, |
| 201 | size_t digest_len, const uint8_t *sig, |
| 202 | size_t sig_len, const DSA *dsa); |
| 203 | |
| 204 | /* DSA_check_signature sets |*out_valid| to zero. Then it verifies that |sig| |
| 205 | * is a valid, ASN.1 signature, by the public key in |dsa|, of the hash in |
| 206 | * |digest|. If so, it sets |*out_valid| to one. |
| 207 | * |
| 208 | * It returns one if it was able to verify the signature as valid or invalid, |
| 209 | * and zero on error. */ |
| 210 | OPENSSL_EXPORT int DSA_check_signature(int *out_valid, const uint8_t *digest, |
| 211 | size_t digest_len, const uint8_t *sig, |
| 212 | size_t sig_len, const DSA *dsa); |
| 213 | |
| 214 | /* DSA_size returns the size, in bytes, of an ASN.1 encoded, DSA signature |
| 215 | * generated by |dsa|. Parameters must already have been setup in |dsa|. */ |
| 216 | OPENSSL_EXPORT int DSA_size(const DSA *dsa); |
| 217 | |
| 218 | |
| 219 | /* ASN.1 encoding. */ |
| 220 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 221 | /* DSA_SIG_parse parses a DER-encoded DSA-Sig-Value structure from |cbs| and |
| 222 | * advances |cbs|. It returns a newly-allocated |DSA_SIG| or NULL on error. */ |
| 223 | OPENSSL_EXPORT DSA_SIG *DSA_SIG_parse(CBS *cbs); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 224 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 225 | /* DSA_SIG_marshal marshals |sig| as a DER-encoded DSA-Sig-Value and appends the |
| 226 | * result to |cbb|. It returns one on success and zero on error. */ |
| 227 | OPENSSL_EXPORT int DSA_SIG_marshal(CBB *cbb, const DSA_SIG *sig); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 228 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 229 | /* DSA_parse_public_key parses a DER-encoded DSA public key from |cbs| and |
| 230 | * advances |cbs|. It returns a newly-allocated |DSA| or NULL on error. */ |
| 231 | OPENSSL_EXPORT DSA *DSA_parse_public_key(CBS *cbs); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 232 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 233 | /* DSA_marshal_public_key marshals |dsa| as a DER-encoded DSA public key and |
| 234 | * appends the result to |cbb|. It returns one on success and zero on |
| 235 | * failure. */ |
| 236 | OPENSSL_EXPORT int DSA_marshal_public_key(CBB *cbb, const DSA *dsa); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 237 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 238 | /* DSA_parse_private_key parses a DER-encoded DSA private key from |cbs| and |
| 239 | * advances |cbs|. It returns a newly-allocated |DSA| or NULL on error. */ |
| 240 | OPENSSL_EXPORT DSA *DSA_parse_private_key(CBS *cbs); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 241 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 242 | /* DSA_marshal_private_key marshals |dsa| as a DER-encoded DSA private key and |
| 243 | * appends the result to |cbb|. It returns one on success and zero on |
| 244 | * failure. */ |
| 245 | OPENSSL_EXPORT int DSA_marshal_private_key(CBB *cbb, const DSA *dsa); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 246 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 247 | /* DSA_parse_parameters parses a DER-encoded Dss-Parms structure (RFC 3279) |
| 248 | * from |cbs| and advances |cbs|. It returns a newly-allocated |DSA| or NULL on |
| 249 | * error. */ |
| 250 | OPENSSL_EXPORT DSA *DSA_parse_parameters(CBS *cbs); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 251 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 252 | /* DSA_marshal_parameters marshals |dsa| as a DER-encoded Dss-Parms structure |
| 253 | * (RFC 3447) and appends the result to |cbb|. It returns one on success and |
| 254 | * zero on failure. */ |
| 255 | OPENSSL_EXPORT int DSA_marshal_parameters(CBB *cbb, const DSA *dsa); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 256 | |
| 257 | |
| 258 | /* Precomputation. */ |
| 259 | |
| 260 | /* DSA_sign_setup precomputes the message independent part of the DSA signature |
| 261 | * and writes them to |*out_kinv| and |*out_r|. Returns one on success, zero on |
| 262 | * error. |
| 263 | * |
| 264 | * TODO(fork): decide what to do with this. Since making DSA* opaque there's no |
| 265 | * way for the user to install them. Also, it forces the DSA* not to be const |
| 266 | * when passing to the signing function. */ |
| 267 | OPENSSL_EXPORT int DSA_sign_setup(const DSA *dsa, BN_CTX *ctx, |
| 268 | BIGNUM **out_kinv, BIGNUM **out_r); |
| 269 | |
| 270 | |
| 271 | /* Conversion. */ |
| 272 | |
| 273 | /* DSA_dup_DH returns a |DH| constructed from the parameters of |dsa|. This is |
| 274 | * sometimes needed when Diffie-Hellman parameters are stored in the form of |
| 275 | * DSA parameters. It returns an allocated |DH| on success or NULL on error. */ |
| 276 | OPENSSL_EXPORT DH *DSA_dup_DH(const DSA *dsa); |
| 277 | |
| 278 | |
| 279 | /* ex_data functions. |
| 280 | * |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 281 | * See |ex_data.h| for details. */ |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 282 | |
| 283 | OPENSSL_EXPORT int DSA_get_ex_new_index(long argl, void *argp, |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 284 | CRYPTO_EX_unused *unused, |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 285 | CRYPTO_EX_dup *dup_func, |
| 286 | CRYPTO_EX_free *free_func); |
| 287 | OPENSSL_EXPORT int DSA_set_ex_data(DSA *d, int idx, void *arg); |
| 288 | OPENSSL_EXPORT void *DSA_get_ex_data(const DSA *d, int idx); |
| 289 | |
| 290 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 291 | /* Deprecated functions. */ |
| 292 | |
| 293 | /* d2i_DSA_SIG parses an ASN.1, DER-encoded, DSA signature from |len| bytes at |
| 294 | * |*inp|. If |out_sig| is not NULL then, on exit, a pointer to the result is |
| 295 | * in |*out_sig|. Note that, even if |*out_sig| is already non-NULL on entry, it |
| 296 | * will not be written to. Rather, a fresh |DSA_SIG| is allocated and the |
| 297 | * previous one is freed. On successful exit, |*inp| is advanced past the DER |
| 298 | * structure. It returns the result or NULL on error. |
| 299 | * |
| 300 | * Use |DSA_SIG_parse| instead. */ |
| 301 | OPENSSL_EXPORT DSA_SIG *d2i_DSA_SIG(DSA_SIG **out_sig, const uint8_t **inp, |
| 302 | long len); |
| 303 | |
| 304 | /* i2d_DSA_SIG marshals |in| to an ASN.1, DER structure. If |outp| is not NULL |
| 305 | * then the result is written to |*outp| and |*outp| is advanced just past the |
| 306 | * output. It returns the number of bytes in the result, whether written or not, |
| 307 | * or a negative value on error. |
| 308 | * |
| 309 | * Use |DSA_SIG_marshal| instead. */ |
| 310 | OPENSSL_EXPORT int i2d_DSA_SIG(const DSA_SIG *in, uint8_t **outp); |
| 311 | |
| 312 | /* d2i_DSAPublicKey parses an ASN.1, DER-encoded, DSA public key from |len| |
| 313 | * bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the result |
| 314 | * is in |*out|. Note that, even if |*ou| is already non-NULL on entry, it will |
| 315 | * not be written to. Rather, a fresh |DSA| is allocated and the previous one is |
| 316 | * freed. On successful exit, |*inp| is advanced past the DER structure. It |
| 317 | * returns the result or NULL on error. |
| 318 | * |
| 319 | * Use |DSA_parse_public_key| instead. */ |
| 320 | OPENSSL_EXPORT DSA *d2i_DSAPublicKey(DSA **out, const uint8_t **inp, long len); |
| 321 | |
| 322 | /* i2d_DSAPublicKey marshals a public key from |in| to an ASN.1, DER structure. |
| 323 | * If |outp| is not NULL then the result is written to |*outp| and |*outp| is |
| 324 | * advanced just past the output. It returns the number of bytes in the result, |
| 325 | * whether written or not, or a negative value on error. |
| 326 | * |
| 327 | * Use |DSA_marshal_public_key| instead. */ |
| 328 | OPENSSL_EXPORT int i2d_DSAPublicKey(const DSA *in, uint8_t **outp); |
| 329 | |
| 330 | /* d2i_DSAPrivateKey parses an ASN.1, DER-encoded, DSA private key from |len| |
| 331 | * bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the result |
| 332 | * is in |*out|. Note that, even if |*out| is already non-NULL on entry, it will |
| 333 | * not be written to. Rather, a fresh |DSA| is allocated and the previous one is |
| 334 | * freed. On successful exit, |*inp| is advanced past the DER structure. It |
| 335 | * returns the result or NULL on error. |
| 336 | * |
| 337 | * Use |DSA_parse_private_key| instead. */ |
| 338 | OPENSSL_EXPORT DSA *d2i_DSAPrivateKey(DSA **out, const uint8_t **inp, long len); |
| 339 | |
| 340 | /* i2d_DSAPrivateKey marshals a private key from |in| to an ASN.1, DER structure. |
| 341 | * If |outp| is not NULL then the result is written to |*outp| and |*outp| is |
| 342 | * advanced just past the output. It returns the number of bytes in the result, |
| 343 | * whether written or not, or a negative value on error. |
| 344 | * |
| 345 | * Use |DSA_marshal_private_key| instead. */ |
| 346 | OPENSSL_EXPORT int i2d_DSAPrivateKey(const DSA *in, uint8_t **outp); |
| 347 | |
| 348 | /* d2i_DSAparams parses ASN.1, DER-encoded, DSA parameters from |len| bytes at |
| 349 | * |*inp|. If |out| is not NULL then, on exit, a pointer to the result is in |
| 350 | * |*out|. Note that, even if |*out| is already non-NULL on entry, it will not |
| 351 | * be written to. Rather, a fresh |DSA| is allocated and the previous one is |
| 352 | * freed. On successful exit, |*inp| is advanced past the DER structure. It |
| 353 | * returns the result or NULL on error. |
| 354 | * |
| 355 | * Use |DSA_parse_parameters| instead. */ |
| 356 | OPENSSL_EXPORT DSA *d2i_DSAparams(DSA **out, const uint8_t **inp, long len); |
| 357 | |
| 358 | /* i2d_DSAparams marshals DSA parameters from |in| to an ASN.1, DER structure. |
| 359 | * If |outp| is not NULL then the result is written to |*outp| and |*outp| is |
| 360 | * advanced just past the output. It returns the number of bytes in the result, |
| 361 | * whether written or not, or a negative value on error. |
| 362 | * |
| 363 | * Use |DSA_marshal_parameters| instead. */ |
| 364 | OPENSSL_EXPORT int i2d_DSAparams(const DSA *in, uint8_t **outp); |
| 365 | |
| 366 | /* DSA_generate_parameters is a deprecated version of |
| 367 | * |DSA_generate_parameters_ex| that creates and returns a |DSA*|. Don't use |
| 368 | * it. */ |
| 369 | OPENSSL_EXPORT DSA *DSA_generate_parameters(int bits, unsigned char *seed, |
| 370 | int seed_len, int *counter_ret, |
| 371 | unsigned long *h_ret, |
| 372 | void (*callback)(int, int, void *), |
| 373 | void *cb_arg); |
| 374 | |
| 375 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 376 | struct dsa_st { |
| 377 | long version; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 378 | BIGNUM *p; |
| 379 | BIGNUM *q; /* == 20 */ |
| 380 | BIGNUM *g; |
| 381 | |
| 382 | BIGNUM *pub_key; /* y public key */ |
| 383 | BIGNUM *priv_key; /* x private key */ |
| 384 | |
| 385 | BIGNUM *kinv; /* Signing pre-calc */ |
| 386 | BIGNUM *r; /* Signing pre-calc */ |
| 387 | |
| 388 | int flags; |
| 389 | /* Normally used to cache montgomery values */ |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 390 | CRYPTO_MUTEX method_mont_p_lock; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 391 | BN_MONT_CTX *method_mont_p; |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 392 | CRYPTO_refcount_t references; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 393 | CRYPTO_EX_DATA ex_data; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 394 | }; |
| 395 | |
| 396 | |
| 397 | #if defined(__cplusplus) |
| 398 | } /* extern C */ |
| 399 | #endif |
| 400 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 401 | #define DSA_R_BAD_Q_VALUE 100 |
| 402 | #define DSA_R_MISSING_PARAMETERS 101 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 403 | #define DSA_R_MODULUS_TOO_LARGE 102 |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 404 | #define DSA_R_NEED_NEW_SETUP_VALUES 103 |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 405 | #define DSA_R_BAD_VERSION 104 |
| 406 | #define DSA_R_DECODE_ERROR 105 |
| 407 | #define DSA_R_ENCODE_ERROR 106 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 408 | |
| 409 | #endif /* OPENSSL_HEADER_DSA_H */ |