dh: Add compat function for openssl < 1.1.0

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Simo Sorce
2019-03-18 09:03:57 -04:00
committed by Andreas Schneider
parent 33399e52f0
commit 33ad6bc54e
3 changed files with 66 additions and 0 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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 */