From 371a004f263c7e195b9681f637ecf03caa4dc1fb Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 26 Nov 2021 16:52:07 +0000 Subject: [PATCH] make the bn/mont test compile with opaque DH. --- regress/lib/libcrypto/bn/mont/mont.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/regress/lib/libcrypto/bn/mont/mont.c b/regress/lib/libcrypto/bn/mont/mont.c index 54626b5c38a..2c311af4170 100644 --- a/regress/lib/libcrypto/bn/mont/mont.c +++ b/regress/lib/libcrypto/bn/mont/mont.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mont.c,v 1.4 2021/04/04 19:36:09 tb Exp $ */ +/* $OpenBSD: mont.c,v 1.5 2021/11/26 16:52:07 tb Exp $ */ /* * Copyright (c) 2014 Miodrag Vallat. @@ -35,6 +35,8 @@ int main(int argc, char *argv[]) { DH *dh = NULL; + BIGNUM *priv_key = NULL; + const BIGNUM *pub_key; unsigned char *key = NULL; unsigned char r[32 + 16 * 8]; size_t privsz; @@ -50,16 +52,21 @@ main(int argc, char *argv[]) goto err; /* force private key to be much larger than public one */ - dh->priv_key = BN_bin2bn(r, privsz, NULL); - if (dh->priv_key == NULL) + priv_key = BN_bin2bn(r, privsz, NULL); + if (priv_key == NULL) goto err; + if (!DH_set0_key(dh, NULL, priv_key)) + goto err; + priv_key = NULL; + if (DH_generate_key(dh) == 0) goto err; key = malloc(DH_size(dh)); if (key == NULL) err(1, "malloc"); - if (DH_compute_key(key, dh->pub_key, dh) == -1) + DH_get0_key(dh, &pub_key, NULL); + if (DH_compute_key(key, pub_key, dh) == -1) goto err; free(key); @@ -73,6 +80,7 @@ main(int argc, char *argv[]) err: ERR_print_errors_fp(stderr); free(key); + BN_free(priv_key); DH_free(dh); return 1; } -- 2.20.1