2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-05-17 19:38:09 +00:00
|
|
|
* Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2011-11-13 14:07:36 +00:00
|
|
|
*
|
2016-05-17 19:38:09 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* 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 14:07:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
2016-04-06 16:49:48 +00:00
|
|
|
#include "dh_locl.h"
|
2011-11-13 14:07:36 +00:00
|
|
|
#include <openssl/bn.h>
|
2015-10-03 15:43:21 +00:00
|
|
|
#include "internal/bn_dh.h"
|
2011-11-13 14:07:36 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* Macro to make a DH structure from BIGNUM data. NB: although just copying
|
2015-09-28 21:00:00 +00: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 14:07:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define make_dh(x) \
|
2015-09-28 21:00:00 +00:00
|
|
|
DH *DH_get_##x(void) \
|
|
|
|
{ \
|
|
|
|
DH *dh = DH_new(); \
|
|
|
|
\
|
|
|
|
if (dh == NULL) \
|
|
|
|
return NULL; \
|
|
|
|
dh->p = BN_dup(&_bignum_dh##x##_p); \
|
|
|
|
dh->g = BN_dup(&_bignum_dh##x##_g); \
|
|
|
|
dh->q = BN_dup(&_bignum_dh##x##_q); \
|
|
|
|
if (dh->p == NULL || dh->q == NULL || dh->g == NULL) {\
|
|
|
|
DH_free(dh); \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
return dh; \
|
|
|
|
}
|
2011-11-13 14:07:36 +00:00
|
|
|
|
|
|
|
make_dh(1024_160)
|
|
|
|
make_dh(2048_224)
|
|
|
|
make_dh(2048_256)
|