blob: 9e33fae131ea64aa7d18aeac5c4dbcfc3c7129e5 [file] [log] [blame]
Rich Salzd2e9e322016-05-17 14:51:26 -04001/*
Matt Caswell8020d792021-03-11 13:27:36 +00002 * Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
Nils Larsch357d5de2007-02-03 14:41:12 +00003 *
Richard Levitte3cdbea62018-12-06 13:36:26 +01004 * Licensed under the Apache License 2.0 (the "License"). You may not use
Rich Salzd2e9e322016-05-17 14:51:26 -04005 * 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 Larsch357d5de2007-02-03 14:41:12 +00008 */
9
10#include <openssl/dsa.h>
Kurt Roeckx2f545ae2016-08-27 16:01:08 +020011#include "internal/refcount.h"
Shane Lontisdc8de3e2020-01-24 14:09:33 +100012#include "internal/ffc.h"
Nils Larsch357d5de2007-02-03 14:41:12 +000013
Matt Caswell12583962016-03-30 15:21:39 +010014struct 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 Levitte6a32a3c2017-04-05 13:24:14 +020020 int32_t version;
Shane Lontisdc8de3e2020-01-24 14:09:33 +100021 FFC_PARAMS params;
Matt Caswell12583962016-03-30 15:21:39 +010022 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 Roeckx2f545ae2016-08-27 16:01:08 +020027 CRYPTO_REF_COUNT references;
Richard Levittef844f9e2020-04-13 22:34:56 +020028#ifndef FIPS_MODULE
Matt Caswell12583962016-03-30 15:21:39 +010029 CRYPTO_EX_DATA ex_data;
Richard Levittea3327782020-01-14 02:32:42 +010030#endif
Matt Caswell12583962016-03-30 15:21:39 +010031 const DSA_METHOD *meth;
32 /* functional reference if 'meth' is ENGINE-provided */
33 ENGINE *engine;
34 CRYPTO_RWLOCK *lock;
Dr. Matthias St. Pierreb4250012020-10-15 12:55:50 +030035 OSSL_LIB_CTX *libctx;
Matt Caswell4889dad2019-08-30 13:33:37 +010036
37 /* Provider data */
38 size_t dirty_cnt; /* If any key material changes, increment this */
Matt Caswell12583962016-03-30 15:21:39 +010039};
40
Emilia Kasper9267c112016-06-09 23:09:48 +020041struct DSA_SIG_st {
42 BIGNUM *r;
43 BIGNUM *s;
44};
45
Matt Caswell6e9fa572016-03-30 17:18:55 +010046struct 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 Laurie24bf6f32016-06-24 13:34:51 +010053 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 Caswell6e9fa572016-03-30 17:18:55 +010056 /* Can be null */
Ben Laurie24bf6f32016-06-24 13:34:51 +010057 int (*bn_mod_exp) (DSA *dsa, BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
Matt Caswell6e9fa572016-03-30 17:18:55 +010058 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 Lontis5af02212021-02-18 16:30:37 +100072DSA_SIG *ossl_dsa_do_sign_int(const unsigned char *dgst, int dlen, DSA *dsa);