17bded2dbSJung-uk Kim /* 2*b077aed3SPierre Pronchery * Copyright 2011-2021 The OpenSSL Project Authors. All Rights Reserved. 37bded2dbSJung-uk Kim * 4*b077aed3SPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use 5e71b7053SJung-uk Kim * this file except in compliance with the License. You can obtain a copy 6e71b7053SJung-uk Kim * in the file LICENSE in the source distribution or at 7e71b7053SJung-uk Kim * https://www.openssl.org/source/license.html 87bded2dbSJung-uk Kim */ 97bded2dbSJung-uk Kim 10*b077aed3SPierre Pronchery /* 11*b077aed3SPierre Pronchery * DH low level APIs are deprecated for public use, but still ok for 12*b077aed3SPierre Pronchery * internal use. 13*b077aed3SPierre Pronchery */ 14*b077aed3SPierre Pronchery #include "internal/deprecated.h" 15*b077aed3SPierre Pronchery 167bded2dbSJung-uk Kim #include <stdio.h> 17e71b7053SJung-uk Kim #include "internal/cryptlib.h" 1817f01e99SJung-uk Kim #include "dh_local.h" 197bded2dbSJung-uk Kim #include <openssl/bn.h> 2017f01e99SJung-uk Kim #include "crypto/bn_dh.h" 217bded2dbSJung-uk Kim 227bded2dbSJung-uk Kim /* 237bded2dbSJung-uk Kim * Macro to make a DH structure from BIGNUM data. NB: although just copying 24e71b7053SJung-uk Kim * the BIGNUM static pointers would be more efficient, we can't do that 25e71b7053SJung-uk Kim * because they get wiped using BN_clear_free() when DH_free() is called. 267bded2dbSJung-uk Kim */ 277bded2dbSJung-uk Kim 287bded2dbSJung-uk Kim #define make_dh(x) \ 297bded2dbSJung-uk Kim DH *DH_get_##x(void) \ 307bded2dbSJung-uk Kim { \ 31e71b7053SJung-uk Kim DH *dh = DH_new(); \ 32e71b7053SJung-uk Kim \ 33e71b7053SJung-uk Kim if (dh == NULL) \ 347bded2dbSJung-uk Kim return NULL; \ 35*b077aed3SPierre Pronchery dh->params.p = BN_dup(&ossl_bignum_dh##x##_p); \ 36*b077aed3SPierre Pronchery dh->params.g = BN_dup(&ossl_bignum_dh##x##_g); \ 37*b077aed3SPierre Pronchery dh->params.q = BN_dup(&ossl_bignum_dh##x##_q); \ 38*b077aed3SPierre Pronchery if (dh->params.p == NULL || dh->params.q == NULL || dh->params.g == NULL) {\ 397bded2dbSJung-uk Kim DH_free(dh); \ 407bded2dbSJung-uk Kim return NULL; \ 417bded2dbSJung-uk Kim } \ 427bded2dbSJung-uk Kim return dh; \ 437bded2dbSJung-uk Kim } 447bded2dbSJung-uk Kim 457bded2dbSJung-uk Kim make_dh(1024_160) 467bded2dbSJung-uk Kim make_dh(2048_224) 477bded2dbSJung-uk Kim make_dh(2048_256) 48