1 | /* |
2 | * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at |
7 | * https://www.openssl.org/source/license.html |
8 | */ |
9 | |
10 | #include <openssl/dsa.h> |
11 | #include "internal/refcount.h" |
12 | |
13 | struct dsa_st { |
14 | /* |
15 | * This first variable is used to pick up errors where a DSA is passed |
16 | * instead of of a EVP_PKEY |
17 | */ |
18 | int pad; |
19 | int32_t version; |
20 | BIGNUM *p; |
21 | BIGNUM *q; /* == 20 */ |
22 | BIGNUM *g; |
23 | BIGNUM *pub_key; /* y public key */ |
24 | BIGNUM *priv_key; /* x private key */ |
25 | int flags; |
26 | /* Normally used to cache montgomery values */ |
27 | BN_MONT_CTX *method_mont_p; |
28 | CRYPTO_REF_COUNT references; |
29 | CRYPTO_EX_DATA ex_data; |
30 | const DSA_METHOD *meth; |
31 | /* functional reference if 'meth' is ENGINE-provided */ |
32 | ENGINE *engine; |
33 | CRYPTO_RWLOCK *lock; |
34 | |
35 | /* Provider data */ |
36 | size_t dirty_cnt; /* If any key material changes, increment this */ |
37 | }; |
38 | |
39 | struct DSA_SIG_st { |
40 | BIGNUM *r; |
41 | BIGNUM *s; |
42 | }; |
43 | |
44 | struct dsa_method { |
45 | char *name; |
46 | DSA_SIG *(*dsa_do_sign) (const unsigned char *dgst, int dlen, DSA *dsa); |
47 | int (*dsa_sign_setup) (DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, |
48 | BIGNUM **rp); |
49 | int (*dsa_do_verify) (const unsigned char *dgst, int dgst_len, |
50 | DSA_SIG *sig, DSA *dsa); |
51 | int (*dsa_mod_exp) (DSA *dsa, BIGNUM *rr, const BIGNUM *a1, |
52 | const BIGNUM *p1, const BIGNUM *a2, const BIGNUM *p2, |
53 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont); |
54 | /* Can be null */ |
55 | int (*bn_mod_exp) (DSA *dsa, BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
56 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); |
57 | int (*init) (DSA *dsa); |
58 | int (*finish) (DSA *dsa); |
59 | int flags; |
60 | void *app_data; |
61 | /* If this is non-NULL, it is used to generate DSA parameters */ |
62 | int (*dsa_paramgen) (DSA *dsa, int bits, |
63 | const unsigned char *seed, int seed_len, |
64 | int *counter_ret, unsigned long *h_ret, |
65 | BN_GENCB *cb); |
66 | /* If this is non-NULL, it is used to generate DSA keys */ |
67 | int (*dsa_keygen) (DSA *dsa); |
68 | }; |
69 | |
70 | int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, |
71 | const EVP_MD *evpmd, const unsigned char *seed_in, |
72 | size_t seed_len, unsigned char *seed_out, |
73 | int *counter_ret, unsigned long *h_ret, |
74 | BN_GENCB *cb); |
75 | |
76 | int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N, |
77 | const EVP_MD *evpmd, const unsigned char *seed_in, |
78 | size_t seed_len, int idx, unsigned char *seed_out, |
79 | int *counter_ret, unsigned long *h_ret, |
80 | BN_GENCB *cb); |
81 | |