2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2021-03-11 21:27:36 +08:00
|
|
|
* Copyright 2011-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2011-11-13 22:07:36 +08:00
|
|
|
*
|
2018-12-06 20:36:05 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 03:38:09 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2011-11-13 22:07:36 +08:00
|
|
|
*/
|
|
|
|
|
2020-02-03 17:05:31 +08:00
|
|
|
/*
|
|
|
|
* DH low level APIs are deprecated for public use, but still ok for
|
|
|
|
* internal use.
|
|
|
|
*/
|
|
|
|
#include "internal/deprecated.h"
|
|
|
|
|
2011-11-13 22:07:36 +08:00
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "dh_local.h"
|
2011-11-13 22:07:36 +08:00
|
|
|
#include <openssl/bn.h>
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/bn_dh.h"
|
2011-11-13 22:07:36 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* Macro to make a DH structure from BIGNUM data. NB: although just copying
|
2015-09-29 05:00:00 +08:00
|
|
|
* the BIGNUM static pointers would be more efficient, we can't do that
|
|
|
|
* because they get wiped using BN_clear_free() when DH_free() is called.
|
2011-11-13 22:07:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define make_dh(x) \
|
2015-09-29 05:00:00 +08:00
|
|
|
DH *DH_get_##x(void) \
|
|
|
|
{ \
|
|
|
|
DH *dh = DH_new(); \
|
|
|
|
\
|
|
|
|
if (dh == NULL) \
|
|
|
|
return NULL; \
|
2021-02-19 17:15:41 +08:00
|
|
|
dh->params.p = BN_dup(&ossl_bignum_dh##x##_p); \
|
|
|
|
dh->params.g = BN_dup(&ossl_bignum_dh##x##_g); \
|
|
|
|
dh->params.q = BN_dup(&ossl_bignum_dh##x##_q); \
|
2020-01-24 12:09:33 +08:00
|
|
|
if (dh->params.p == NULL || dh->params.q == NULL || dh->params.g == NULL) {\
|
2015-09-29 05:00:00 +08:00
|
|
|
DH_free(dh); \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
return dh; \
|
|
|
|
}
|
2011-11-13 22:07:36 +08:00
|
|
|
|
|
|
|
make_dh(1024_160)
|
|
|
|
make_dh(2048_224)
|
|
|
|
make_dh(2048_256)
|