1 /* 2 * Copyright 2011-2021 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the Apache License 2.0 (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 /* 11 * DH low level APIs are deprecated for public use, but still ok for 12 * internal use. 13 */ 14 #include "internal/deprecated.h" 15 16 #include <stdio.h> 17 #include "internal/cryptlib.h" 18 #include "dh_local.h" 19 #include <openssl/bn.h> 20 #include "crypto/bn_dh.h" 21 22 /* 23 * Macro to make a DH structure from BIGNUM data. NB: although just copying 24 * the BIGNUM static pointers would be more efficient, we can't do that 25 * because they get wiped using BN_clear_free() when DH_free() is called. 26 */ 27 28 #define make_dh(x) \ 29 DH *DH_get_##x(void) \ 30 { \ 31 DH *dh = DH_new(); \ 32 \ 33 if (dh == NULL) \ 34 return NULL; \ 35 dh->params.p = BN_dup(&ossl_bignum_dh##x##_p); \ 36 dh->params.g = BN_dup(&ossl_bignum_dh##x##_g); \ 37 dh->params.q = BN_dup(&ossl_bignum_dh##x##_q); \ 38 if (dh->params.p == NULL || dh->params.q == NULL || dh->params.g == NULL) {\ 39 DH_free(dh); \ 40 return NULL; \ 41 } \ 42 return dh; \ 43 } 44 45 make_dh(1024_160) 46 make_dh(2048_224) 47 make_dh(2048_256) 48