diff --git a/src/dh_crypto.c b/src/dh_crypto.c index 5b1ec4b3..bcf0c837 100644 --- a/src/dh_crypto.c +++ b/src/dh_crypto.c @@ -29,6 +29,7 @@ #include "openssl/crypto.h" #include "openssl/dh.h" +#include "libcrypto-compat.h" extern bignum ssh_dh_generator; extern bignum ssh_dh_group1; diff --git a/src/libcrypto-compat.c b/src/libcrypto-compat.c index 261bc518..048d1781 100644 --- a/src/libcrypto-compat.c +++ b/src/libcrypto-compat.c @@ -335,3 +335,62 @@ void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) OPENSSL_free(ctx); } #endif + +void DH_get0_pqg(const DH *dh, + const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) +{ + if (p) { + *p = dh->p; + } + if (q) { + *q = NULL; + } + if (g) { + *g = dh->g; + } +} + +int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) +{ + if (p) { + if (dh->p) { + BN_free(dh->p); + } + dh->p = p; + } + if (g) { + if (dh->g) { + BN_free(dh->g); + } + dh->g = g; + } + return 1; +} + +void DH_get0_key(const DH *dh, + const BIGNUM **pub_key, const BIGNUM **priv_key) +{ + if (pub_key) { + *pub_key = dh->pub_key; + } + if (priv_key) { + *priv_key = dh->priv_key; + } +} + +int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) +{ + if (pub_key) { + if (dh->pub_key) { + BN_free(dh->pub_key); + } + dh->pub_key = pub_key; + } + if (priv_key) { + if (dh->priv_key) { + BN_free(dh->priv_key); + } + dh->priv_key = priv_key; + } + return 1; +} diff --git a/src/libcrypto-compat.h b/src/libcrypto-compat.h index 00e4f2a3..bda0473e 100644 --- a/src/libcrypto-compat.h +++ b/src/libcrypto-compat.h @@ -38,6 +38,12 @@ HMAC_CTX *HMAC_CTX_new(void); int HMAC_CTX_reset(HMAC_CTX *ctx); void HMAC_CTX_free(HMAC_CTX *ctx); +void DH_get0_pqg(const DH *dh, + const BIGNUM **p, const BIGNUM **q, const BIGNUM **g); +int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g); +void DH_get0_key(const DH *dh, + const BIGNUM **pub_key, const BIGNUM **priv_key); +int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key); #endif /* OPENSSL_VERSION_NUMBER */ #endif /* LIBCRYPTO_COMPAT_H */