2016-04-07 20:47:20 +08:00
|
|
|
/*
|
2020-04-23 20:55:52 +08:00
|
|
|
* Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2016-04-07 20:47:20 +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
|
2016-04-07 20:47:20 +08:00
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "dh_local.h"
|
2016-04-07 20:47:20 +08:00
|
|
|
#include <string.h>
|
2016-05-17 22:08:43 +08:00
|
|
|
#include <openssl/err.h>
|
2016-04-07 20:47:20 +08:00
|
|
|
|
|
|
|
DH_METHOD *DH_meth_new(const char *name, int flags)
|
|
|
|
{
|
2016-11-10 07:54:03 +08:00
|
|
|
DH_METHOD *dhm = OPENSSL_zalloc(sizeof(*dhm));
|
2016-04-07 20:47:20 +08:00
|
|
|
|
|
|
|
if (dhm != NULL) {
|
|
|
|
dhm->flags = flags;
|
2016-11-10 07:54:03 +08:00
|
|
|
|
|
|
|
dhm->name = OPENSSL_strdup(name);
|
|
|
|
if (dhm->name != NULL)
|
|
|
|
return dhm;
|
|
|
|
|
|
|
|
OPENSSL_free(dhm);
|
2016-04-07 20:47:20 +08:00
|
|
|
}
|
|
|
|
|
2016-11-10 07:54:03 +08:00
|
|
|
return NULL;
|
2016-04-07 20:47:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DH_meth_free(DH_METHOD *dhm)
|
|
|
|
{
|
|
|
|
if (dhm != NULL) {
|
2016-05-08 00:54:01 +08:00
|
|
|
OPENSSL_free(dhm->name);
|
2016-04-07 20:47:20 +08:00
|
|
|
OPENSSL_free(dhm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DH_METHOD *DH_meth_dup(const DH_METHOD *dhm)
|
|
|
|
{
|
2016-11-10 07:54:03 +08:00
|
|
|
DH_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
|
2016-04-07 20:47:20 +08:00
|
|
|
|
|
|
|
if (ret != NULL) {
|
|
|
|
memcpy(ret, dhm, sizeof(*dhm));
|
2016-11-10 07:54:03 +08:00
|
|
|
|
2016-04-07 20:47:20 +08:00
|
|
|
ret->name = OPENSSL_strdup(dhm->name);
|
2016-11-10 07:54:03 +08:00
|
|
|
if (ret->name != NULL)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
OPENSSL_free(ret);
|
2016-04-07 20:47:20 +08:00
|
|
|
}
|
|
|
|
|
2016-11-10 07:54:03 +08:00
|
|
|
return NULL;
|
2016-04-07 20:47:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *DH_meth_get0_name(const DH_METHOD *dhm)
|
|
|
|
{
|
|
|
|
return dhm->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set1_name(DH_METHOD *dhm, const char *name)
|
|
|
|
{
|
2016-11-10 07:54:03 +08:00
|
|
|
char *tmpname = OPENSSL_strdup(name);
|
2016-05-04 18:28:38 +08:00
|
|
|
|
2022-09-29 19:57:34 +08:00
|
|
|
if (tmpname == NULL)
|
2016-05-04 18:28:38 +08:00
|
|
|
return 0;
|
|
|
|
|
2016-04-07 20:47:20 +08:00
|
|
|
OPENSSL_free(dhm->name);
|
2016-05-04 18:28:38 +08:00
|
|
|
dhm->name = tmpname;
|
2016-04-07 20:47:20 +08:00
|
|
|
|
2016-05-04 18:28:38 +08:00
|
|
|
return 1;
|
2016-04-07 20:47:20 +08:00
|
|
|
}
|
|
|
|
|
2017-01-06 00:58:18 +08:00
|
|
|
int DH_meth_get_flags(const DH_METHOD *dhm)
|
2016-04-07 20:47:20 +08:00
|
|
|
{
|
|
|
|
return dhm->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set_flags(DH_METHOD *dhm, int flags)
|
|
|
|
{
|
|
|
|
dhm->flags = flags;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *DH_meth_get0_app_data(const DH_METHOD *dhm)
|
|
|
|
{
|
|
|
|
return dhm->app_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set0_app_data(DH_METHOD *dhm, void *app_data)
|
|
|
|
{
|
|
|
|
dhm->app_data = app_data;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DH_meth_get_generate_key(const DH_METHOD *dhm)) (DH *)
|
|
|
|
{
|
|
|
|
return dhm->generate_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set_generate_key(DH_METHOD *dhm, int (*generate_key) (DH *))
|
|
|
|
{
|
|
|
|
dhm->generate_key = generate_key;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DH_meth_get_compute_key(const DH_METHOD *dhm))
|
|
|
|
(unsigned char *key, const BIGNUM *pub_key, DH *dh)
|
|
|
|
{
|
|
|
|
return dhm->compute_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set_compute_key(DH_METHOD *dhm,
|
|
|
|
int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh))
|
|
|
|
{
|
|
|
|
dhm->compute_key = compute_key;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int (*DH_meth_get_bn_mod_exp(const DH_METHOD *dhm))
|
|
|
|
(const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
|
|
|
|
BN_CTX *, BN_MONT_CTX *)
|
|
|
|
{
|
|
|
|
return dhm->bn_mod_exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set_bn_mod_exp(DH_METHOD *dhm,
|
|
|
|
int (*bn_mod_exp) (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *,
|
|
|
|
const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
|
|
|
|
{
|
|
|
|
dhm->bn_mod_exp = bn_mod_exp;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DH_meth_get_init(const DH_METHOD *dhm))(DH *)
|
|
|
|
{
|
|
|
|
return dhm->init;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set_init(DH_METHOD *dhm, int (*init)(DH *))
|
|
|
|
{
|
|
|
|
dhm->init = init;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DH_meth_get_finish(const DH_METHOD *dhm)) (DH *)
|
|
|
|
{
|
|
|
|
return dhm->finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set_finish(DH_METHOD *dhm, int (*finish) (DH *))
|
|
|
|
{
|
|
|
|
dhm->finish = finish;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int (*DH_meth_get_generate_params(const DH_METHOD *dhm))
|
|
|
|
(DH *, int, int, BN_GENCB *)
|
|
|
|
{
|
|
|
|
return dhm->generate_params;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DH_meth_set_generate_params(DH_METHOD *dhm,
|
|
|
|
int (*generate_params) (DH *, int, int, BN_GENCB *))
|
|
|
|
{
|
|
|
|
dhm->generate_params = generate_params;
|
|
|
|
return 1;
|
|
|
|
}
|