diff options
author | Matt Caswell <matt@openssl.org> | 2016-04-06 17:49:48 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-04-09 10:10:55 +0100 |
commit | 0aeddcfa61250a6c474c4f8b3533772a63192f1b (patch) | |
tree | d8ac8b14fc1bd8a365d522a0ecf0fc9999c01575 /crypto/dh | |
parent | b9aec69ace2ae84b2b4494cc49725945805d5a29 (diff) | |
download | openssl-0aeddcfa61250a6c474c4f8b3533772a63192f1b.tar.gz |
Make DH opaque
Move the dh_st structure into an internal header file and provide
relevant accessors for the internal fields.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/dh')
-rw-r--r-- | crypto/dh/dh_ameth.c | 2 | ||||
-rw-r--r-- | crypto/dh/dh_asn1.c | 2 | ||||
-rw-r--r-- | crypto/dh/dh_check.c | 2 | ||||
-rw-r--r-- | crypto/dh/dh_gen.c | 2 | ||||
-rw-r--r-- | crypto/dh/dh_key.c | 2 | ||||
-rw-r--r-- | crypto/dh/dh_lib.c | 85 | ||||
-rw-r--r-- | crypto/dh/dh_locl.h | 38 | ||||
-rw-r--r-- | crypto/dh/dh_pmeth.c | 2 | ||||
-rw-r--r-- | crypto/dh/dh_rfc5114.c | 2 |
9 files changed, 129 insertions, 8 deletions
diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index fc03d8fb0d..54d5ba5d34 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -60,7 +60,7 @@ #include "internal/cryptlib.h" #include <openssl/x509.h> #include <openssl/asn1.h> -#include <openssl/dh.h> +#include "dh_locl.h" #include <openssl/bn.h> #include "internal/asn1_int.h" #include "internal/evp_int.h" diff --git a/crypto/dh/dh_asn1.c b/crypto/dh/dh_asn1.c index 8ea9550000..aa802915a8 100644 --- a/crypto/dh/dh_asn1.c +++ b/crypto/dh/dh_asn1.c @@ -59,7 +59,7 @@ #include <stdio.h> #include "internal/cryptlib.h" #include <openssl/bn.h> -#include <openssl/dh.h> +#include "dh_locl.h" #include <openssl/objects.h> #include <openssl/asn1t.h> diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c index 2cc218dbdc..5d14265802 100644 --- a/crypto/dh/dh_check.c +++ b/crypto/dh/dh_check.c @@ -58,7 +58,7 @@ #include <stdio.h> #include "internal/cryptlib.h" #include <openssl/bn.h> -#include <openssl/dh.h> +#include "dh_locl.h" /*- * Check that p is a safe prime and diff --git a/crypto/dh/dh_gen.c b/crypto/dh/dh_gen.c index bfa2376c39..5c96dacdba 100644 --- a/crypto/dh/dh_gen.c +++ b/crypto/dh/dh_gen.c @@ -63,7 +63,7 @@ #include <stdio.h> #include "internal/cryptlib.h" #include <openssl/bn.h> -#include <openssl/dh.h> +#include "dh_locl.h" static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb); diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 558ec8c3cd..d9575503d1 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -58,7 +58,7 @@ #include <stdio.h> #include "internal/cryptlib.h" #include <openssl/rand.h> -#include <openssl/dh.h> +#include "dh_locl.h" #include "internal/bn_int.h" static int generate_key(DH *dh); diff --git a/crypto/dh/dh_lib.c b/crypto/dh/dh_lib.c index 1a0c054eeb..bf9f8d3317 100644 --- a/crypto/dh/dh_lib.c +++ b/crypto/dh/dh_lib.c @@ -58,7 +58,7 @@ #include <stdio.h> #include "internal/cryptlib.h" #include <openssl/bn.h> -#include <openssl/dh.h> +#include "dh_locl.h" #include <openssl/engine.h> static const DH_METHOD *default_DH_method = NULL; @@ -231,3 +231,86 @@ int DH_security_bits(const DH *dh) N = -1; return BN_security_bits(BN_num_bits(dh->p), N); } + + +void DH_get0_pqg(const DH *dh, BIGNUM **p, BIGNUM **q, BIGNUM **g) +{ + if (p != NULL) + *p = dh->p; + if (q != NULL) + *q = dh->q; + if (g != NULL) + *g = dh->g; +} + +int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) +{ + /* q is optional */ + if (p == NULL || g == NULL) + return 0; + BN_free(dh->p); + BN_free(dh->q); + BN_free(dh->g); + dh->p = p; + dh->q = q; + dh->g = g; + + if (q != NULL) { + dh->length = BN_num_bits(q); + } + + return 1; +} + +long DH_get_length(const DH *dh) +{ + return dh->length; +} + +int DH_set_length(DH *dh, long length) +{ + dh->length = length; + return 1; +} + +void DH_get0_key(const DH *dh, BIGNUM **pub_key, BIGNUM **priv_key) +{ + if (pub_key != NULL) + *pub_key = dh->pub_key; + if (priv_key != NULL) + *priv_key = dh->priv_key; +} + +int DH_set0_key(DH *dh, 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(dh->pub_key); + BN_free(dh->priv_key); + dh->pub_key = pub_key; + dh->priv_key = priv_key; + + return 1; +} + +void DH_clear_flags(DH *dh, int flags) +{ + dh->flags &= ~flags; +} + +int DH_test_flags(const DH *dh, int flags) +{ + return dh->flags & flags; +} + +void DH_set_flags(DH *dh, int flags) +{ + dh->flags |= flags; +} + +ENGINE *DH_get0_engine(DH *dh) +{ + return dh->engine; +} diff --git a/crypto/dh/dh_locl.h b/crypto/dh/dh_locl.h new file mode 100644 index 0000000000..5d51e591fe --- /dev/null +++ b/crypto/dh/dh_locl.h @@ -0,0 +1,38 @@ +/* + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL licenses, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.openssl.org/source/license.html + * or in the file LICENSE in the source distribution. + */ + +#include <openssl/dh.h> + +struct dh_st { + /* + * This first argument is used to pick up errors when a DH is passed + * instead of a EVP_PKEY + */ + int pad; + int version; + BIGNUM *p; + BIGNUM *g; + long length; /* optional */ + BIGNUM *pub_key; /* g^x % p */ + BIGNUM *priv_key; /* x */ + int flags; + BN_MONT_CTX *method_mont_p; + /* Place holders if we want to do X9.42 DH */ + BIGNUM *q; + BIGNUM *j; + unsigned char *seed; + int seedlen; + BIGNUM *counter; + int references; + CRYPTO_EX_DATA ex_data; + const DH_METHOD *meth; + ENGINE *engine; + CRYPTO_RWLOCK *lock; +}; diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index 93bada0058..5d357a3801 100644 --- a/crypto/dh/dh_pmeth.c +++ b/crypto/dh/dh_pmeth.c @@ -61,7 +61,7 @@ #include <openssl/asn1t.h> #include <openssl/x509.h> #include <openssl/evp.h> -#include <openssl/dh.h> +#include "dh_locl.h" #include <openssl/bn.h> #include <openssl/dsa.h> #include <openssl/objects.h> diff --git a/crypto/dh/dh_rfc5114.c b/crypto/dh/dh_rfc5114.c index da998f574f..48b199dfce 100644 --- a/crypto/dh/dh_rfc5114.c +++ b/crypto/dh/dh_rfc5114.c @@ -58,7 +58,7 @@ #include <stdio.h> #include "internal/cryptlib.h" -#include <openssl/dh.h> +#include "dh_locl.h" #include <openssl/bn.h> #include "internal/bn_dh.h" |