From 1258396d73cf937e4daaf2c35377011b9366f956 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Wed, 30 Mar 2016 15:21:39 +0100 Subject: Make the DSA structure opaque Move the dsa_st structure out of the public header file. Add some accessor functions to enable access to the internal fields, and update all internal usage to use the new functions. Reviewed-by: Richard Levitte Reviewed-by: Stephen Henson --- crypto/dsa/dsa_ameth.c | 2 +- crypto/dsa/dsa_asn1.c | 2 +- crypto/dsa/dsa_key.c | 2 +- crypto/dsa/dsa_lib.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++- crypto/dsa/dsa_locl.h | 23 ++++++++++++++++ crypto/dsa/dsa_ossl.c | 2 +- crypto/dsa/dsa_sign.c | 2 +- crypto/dsa/dsa_vrf.c | 2 +- 8 files changed, 103 insertions(+), 7 deletions(-) (limited to 'crypto/dsa') diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index f0f28bdf2a..54cdb3dae0 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -60,7 +60,7 @@ #include "internal/cryptlib.h" #include #include -#include +#include "dsa_locl.h" #include #include #include "internal/asn1_int.h" diff --git a/crypto/dsa/dsa_asn1.c b/crypto/dsa/dsa_asn1.c index c338b5f3a8..1468fb1e66 100644 --- a/crypto/dsa/dsa_asn1.c +++ b/crypto/dsa/dsa_asn1.c @@ -58,7 +58,7 @@ #include #include "internal/cryptlib.h" -#include +#include "dsa_locl.h" #include #include #include diff --git a/crypto/dsa/dsa_key.c b/crypto/dsa/dsa_key.c index 831c2b1d9b..441588498e 100644 --- a/crypto/dsa/dsa_key.c +++ b/crypto/dsa/dsa_key.c @@ -59,7 +59,7 @@ #include #include "internal/cryptlib.h" #include -#include +#include "dsa_locl.h" #include static int dsa_builtin_keygen(DSA *dsa); diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c index fa8330fd84..08226181f9 100644 --- a/crypto/dsa/dsa_lib.c +++ b/crypto/dsa/dsa_lib.c @@ -60,7 +60,7 @@ #include #include "internal/cryptlib.h" #include -#include +#include "dsa_locl.h" #include #include #include @@ -280,3 +280,76 @@ DH *DSA_dup_DH(const DSA *r) return NULL; } #endif + +BIGNUM *DSA_get0_p(const DSA *d) +{ + return d->p; +} + +BIGNUM *DSA_get0_q(const DSA *d) +{ + return d->q; +} + +BIGNUM *DSA_get0_g(const DSA *d) +{ + return d->g; +} + +int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g) +{ + if (p == NULL || q == NULL || g == NULL) + return 0; + BN_free(d->p); + BN_free(d->q); + BN_free(d->g); + d->p = p; + d->q = q; + d->g = g; + + return 1; +} + +BIGNUM *DSA_get0_priv_key(const DSA *d) +{ + return d->priv_key; +} + +BIGNUM *DSA_get0_pub_key(const DSA *d) +{ + return d->pub_key; +} + +void DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key) +{ + /* Note that it is valid for priv_key to be NULL */ + if (pub_key == NULL) + return 0; + + BN_free(d->pub_key); + BN_free(d->priv_key); + d->pub_key = pub_key; + d->priv_key = priv_key; + + return 1; +} + +void DSA_clear_flags(DSA *d, int flags) +{ + d->flags &= ~flags; +} + +int DSA_test_flags(const DSA *d, int flags) +{ + return d->flags & flags; +} + +void DSA_set_flags(DSA *d, int flags) +{ + d->flags |= flags; +} + +ENGINE *DSA_get0_engine(DSA *d) +{ + return d->engine; +} diff --git a/crypto/dsa/dsa_locl.h b/crypto/dsa/dsa_locl.h index 6182495848..9b25634ae3 100644 --- a/crypto/dsa/dsa_locl.h +++ b/crypto/dsa/dsa_locl.h @@ -54,6 +54,29 @@ #include +struct dsa_st { + /* + * This first variable is used to pick up errors where a DSA is passed + * instead of of a EVP_PKEY + */ + int pad; + long version; + BIGNUM *p; + BIGNUM *q; /* == 20 */ + BIGNUM *g; + BIGNUM *pub_key; /* y public key */ + BIGNUM *priv_key; /* x private key */ + int flags; + /* Normally used to cache montgomery values */ + BN_MONT_CTX *method_mont_p; + int references; + CRYPTO_EX_DATA ex_data; + const DSA_METHOD *meth; + /* functional reference if 'meth' is ENGINE-provided */ + ENGINE *engine; + CRYPTO_RWLOCK *lock; +}; + int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len, unsigned char *seed_out, diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c index 31a6d53c9a..92855537b8 100644 --- a/crypto/dsa/dsa_ossl.c +++ b/crypto/dsa/dsa_ossl.c @@ -61,7 +61,7 @@ #include "internal/cryptlib.h" #include #include -#include +#include "dsa_locl.h" #include #include diff --git a/crypto/dsa/dsa_sign.c b/crypto/dsa/dsa_sign.c index ca712cf201..b9dcd5b28d 100644 --- a/crypto/dsa/dsa_sign.c +++ b/crypto/dsa/dsa_sign.c @@ -58,7 +58,7 @@ /* Original version from Steven Schoch */ #include "internal/cryptlib.h" -#include +#include "dsa_locl.h" #include #include diff --git a/crypto/dsa/dsa_vrf.c b/crypto/dsa/dsa_vrf.c index 6724b7545f..6ce9968eaf 100644 --- a/crypto/dsa/dsa_vrf.c +++ b/crypto/dsa/dsa_vrf.c @@ -58,7 +58,7 @@ /* Original version from Steven Schoch */ #include "internal/cryptlib.h" -#include +#include "dsa_locl.h" int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa) -- cgit v1.2.3