Rich Salz | d2e9e32 | 2016-05-17 14:51:26 -0400 | [diff] [blame] | 1 | /* |
Matt Caswell | 8020d79 | 2021-03-11 13:27:36 +0000 | [diff] [blame] | 2 | * Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved. |
Nils Larsch | 357d5de | 2007-02-03 14:41:12 +0000 | [diff] [blame] | 3 | * |
Richard Levitte | 3cdbea6 | 2018-12-06 13:36:26 +0100 | [diff] [blame] | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
Rich Salz | d2e9e32 | 2016-05-17 14:51:26 -0400 | [diff] [blame] | 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 |
Nils Larsch | 357d5de | 2007-02-03 14:41:12 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <openssl/dsa.h> |
Kurt Roeckx | 2f545ae | 2016-08-27 16:01:08 +0200 | [diff] [blame] | 11 | #include "internal/refcount.h" |
Shane Lontis | dc8de3e | 2020-01-24 14:09:33 +1000 | [diff] [blame] | 12 | #include "internal/ffc.h" |
Nils Larsch | 357d5de | 2007-02-03 14:41:12 +0000 | [diff] [blame] | 13 | |
Matt Caswell | 1258396 | 2016-03-30 15:21:39 +0100 | [diff] [blame] | 14 | struct dsa_st { |
| 15 | /* |
| 16 | * This first variable is used to pick up errors where a DSA is passed |
| 17 | * instead of of a EVP_PKEY |
| 18 | */ |
| 19 | int pad; |
Richard Levitte | 6a32a3c | 2017-04-05 13:24:14 +0200 | [diff] [blame] | 20 | int32_t version; |
Shane Lontis | dc8de3e | 2020-01-24 14:09:33 +1000 | [diff] [blame] | 21 | FFC_PARAMS params; |
Matt Caswell | 1258396 | 2016-03-30 15:21:39 +0100 | [diff] [blame] | 22 | BIGNUM *pub_key; /* y public key */ |
| 23 | BIGNUM *priv_key; /* x private key */ |
| 24 | int flags; |
| 25 | /* Normally used to cache montgomery values */ |
| 26 | BN_MONT_CTX *method_mont_p; |
Kurt Roeckx | 2f545ae | 2016-08-27 16:01:08 +0200 | [diff] [blame] | 27 | CRYPTO_REF_COUNT references; |
Richard Levitte | f844f9e | 2020-04-13 22:34:56 +0200 | [diff] [blame] | 28 | #ifndef FIPS_MODULE |
Matt Caswell | 1258396 | 2016-03-30 15:21:39 +0100 | [diff] [blame] | 29 | CRYPTO_EX_DATA ex_data; |
Richard Levitte | a332778 | 2020-01-14 02:32:42 +0100 | [diff] [blame] | 30 | #endif |
Matt Caswell | 1258396 | 2016-03-30 15:21:39 +0100 | [diff] [blame] | 31 | const DSA_METHOD *meth; |
| 32 | /* functional reference if 'meth' is ENGINE-provided */ |
| 33 | ENGINE *engine; |
| 34 | CRYPTO_RWLOCK *lock; |
Dr. Matthias St. Pierre | b425001 | 2020-10-15 12:55:50 +0300 | [diff] [blame] | 35 | OSSL_LIB_CTX *libctx; |
Matt Caswell | 4889dad | 2019-08-30 13:33:37 +0100 | [diff] [blame] | 36 | |
| 37 | /* Provider data */ |
| 38 | size_t dirty_cnt; /* If any key material changes, increment this */ |
Matt Caswell | 1258396 | 2016-03-30 15:21:39 +0100 | [diff] [blame] | 39 | }; |
| 40 | |
Emilia Kasper | 9267c11 | 2016-06-09 23:09:48 +0200 | [diff] [blame] | 41 | struct DSA_SIG_st { |
| 42 | BIGNUM *r; |
| 43 | BIGNUM *s; |
| 44 | }; |
| 45 | |
Matt Caswell | 6e9fa57 | 2016-03-30 17:18:55 +0100 | [diff] [blame] | 46 | struct dsa_method { |
| 47 | char *name; |
| 48 | DSA_SIG *(*dsa_do_sign) (const unsigned char *dgst, int dlen, DSA *dsa); |
| 49 | int (*dsa_sign_setup) (DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, |
| 50 | BIGNUM **rp); |
| 51 | int (*dsa_do_verify) (const unsigned char *dgst, int dgst_len, |
| 52 | DSA_SIG *sig, DSA *dsa); |
Ben Laurie | 24bf6f3 | 2016-06-24 13:34:51 +0100 | [diff] [blame] | 53 | int (*dsa_mod_exp) (DSA *dsa, BIGNUM *rr, const BIGNUM *a1, |
| 54 | const BIGNUM *p1, const BIGNUM *a2, const BIGNUM *p2, |
| 55 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont); |
Matt Caswell | 6e9fa57 | 2016-03-30 17:18:55 +0100 | [diff] [blame] | 56 | /* Can be null */ |
Ben Laurie | 24bf6f3 | 2016-06-24 13:34:51 +0100 | [diff] [blame] | 57 | int (*bn_mod_exp) (DSA *dsa, BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
Matt Caswell | 6e9fa57 | 2016-03-30 17:18:55 +0100 | [diff] [blame] | 58 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); |
| 59 | int (*init) (DSA *dsa); |
| 60 | int (*finish) (DSA *dsa); |
| 61 | int flags; |
| 62 | void *app_data; |
| 63 | /* If this is non-NULL, it is used to generate DSA parameters */ |
| 64 | int (*dsa_paramgen) (DSA *dsa, int bits, |
| 65 | const unsigned char *seed, int seed_len, |
| 66 | int *counter_ret, unsigned long *h_ret, |
| 67 | BN_GENCB *cb); |
| 68 | /* If this is non-NULL, it is used to generate DSA keys */ |
| 69 | int (*dsa_keygen) (DSA *dsa); |
| 70 | }; |
| 71 | |
Shane Lontis | 5af0221 | 2021-02-18 16:30:37 +1000 | [diff] [blame] | 72 | DSA_SIG *ossl_dsa_do_sign_int(const unsigned char *dgst, int dlen, DSA *dsa); |