11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * Copyright 2011-2021 The OpenSSL Project Authors. All Rights Reserved. 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 51cb0ef41Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at 71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html 81cb0ef41Sopenharmony_ci */ 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci/* 111cb0ef41Sopenharmony_ci * DH low level APIs are deprecated for public use, but still ok for 121cb0ef41Sopenharmony_ci * internal use. 131cb0ef41Sopenharmony_ci */ 141cb0ef41Sopenharmony_ci#include "internal/deprecated.h" 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci#include <stdio.h> 171cb0ef41Sopenharmony_ci#include "internal/cryptlib.h" 181cb0ef41Sopenharmony_ci#include "dh_local.h" 191cb0ef41Sopenharmony_ci#include <openssl/bn.h> 201cb0ef41Sopenharmony_ci#include "crypto/bn_dh.h" 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci/* 231cb0ef41Sopenharmony_ci * Macro to make a DH structure from BIGNUM data. NB: although just copying 241cb0ef41Sopenharmony_ci * the BIGNUM static pointers would be more efficient, we can't do that 251cb0ef41Sopenharmony_ci * because they get wiped using BN_clear_free() when DH_free() is called. 261cb0ef41Sopenharmony_ci */ 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci#define make_dh(x) \ 291cb0ef41Sopenharmony_ciDH *DH_get_##x(void) \ 301cb0ef41Sopenharmony_ci{ \ 311cb0ef41Sopenharmony_ci DH *dh = DH_new(); \ 321cb0ef41Sopenharmony_ci\ 331cb0ef41Sopenharmony_ci if (dh == NULL) \ 341cb0ef41Sopenharmony_ci return NULL; \ 351cb0ef41Sopenharmony_ci dh->params.p = BN_dup(&ossl_bignum_dh##x##_p); \ 361cb0ef41Sopenharmony_ci dh->params.g = BN_dup(&ossl_bignum_dh##x##_g); \ 371cb0ef41Sopenharmony_ci dh->params.q = BN_dup(&ossl_bignum_dh##x##_q); \ 381cb0ef41Sopenharmony_ci if (dh->params.p == NULL || dh->params.q == NULL || dh->params.g == NULL) {\ 391cb0ef41Sopenharmony_ci DH_free(dh); \ 401cb0ef41Sopenharmony_ci return NULL; \ 411cb0ef41Sopenharmony_ci } \ 421cb0ef41Sopenharmony_ci return dh; \ 431cb0ef41Sopenharmony_ci} 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_cimake_dh(1024_160) 461cb0ef41Sopenharmony_cimake_dh(2048_224) 471cb0ef41Sopenharmony_cimake_dh(2048_256) 48