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