2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #include <openssl/err.h>
14 DH_METHOD *DH_meth_new(const char *name, int flags)
16 DH_METHOD *dhm = OPENSSL_zalloc(sizeof(DH_METHOD));
19 dhm->name = OPENSSL_strdup(name);
20 if (dhm->name == NULL) {
22 DHerr(DH_F_DH_METH_NEW, ERR_R_MALLOC_FAILURE);
31 void DH_meth_free(DH_METHOD *dhm)
34 OPENSSL_free(dhm->name);
39 DH_METHOD *DH_meth_dup(const DH_METHOD *dhm)
43 ret = OPENSSL_malloc(sizeof(DH_METHOD));
46 memcpy(ret, dhm, sizeof(*dhm));
47 ret->name = OPENSSL_strdup(dhm->name);
48 if (ret->name == NULL) {
50 DHerr(DH_F_DH_METH_DUP, ERR_R_MALLOC_FAILURE);
58 const char *DH_meth_get0_name(const DH_METHOD *dhm)
63 int DH_meth_set1_name(DH_METHOD *dhm, const char *name)
67 tmpname = OPENSSL_strdup(name);
68 if (tmpname == NULL) {
69 DHerr(DH_F_DH_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
73 OPENSSL_free(dhm->name);
79 int DH_meth_get_flags(DH_METHOD *dhm)
84 int DH_meth_set_flags(DH_METHOD *dhm, int flags)
90 void *DH_meth_get0_app_data(const DH_METHOD *dhm)
95 int DH_meth_set0_app_data(DH_METHOD *dhm, void *app_data)
97 dhm->app_data = app_data;
101 int (*DH_meth_get_generate_key(const DH_METHOD *dhm)) (DH *)
103 return dhm->generate_key;
106 int DH_meth_set_generate_key(DH_METHOD *dhm, int (*generate_key) (DH *))
108 dhm->generate_key = generate_key;
112 int (*DH_meth_get_compute_key(const DH_METHOD *dhm))
113 (unsigned char *key, const BIGNUM *pub_key, DH *dh)
115 return dhm->compute_key;
118 int DH_meth_set_compute_key(DH_METHOD *dhm,
119 int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh))
121 dhm->compute_key = compute_key;
126 int (*DH_meth_get_bn_mod_exp(const DH_METHOD *dhm))
127 (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
128 BN_CTX *, BN_MONT_CTX *)
130 return dhm->bn_mod_exp;
133 int DH_meth_set_bn_mod_exp(DH_METHOD *dhm,
134 int (*bn_mod_exp) (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *,
135 const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
137 dhm->bn_mod_exp = bn_mod_exp;
141 int (*DH_meth_get_init(const DH_METHOD *dhm))(DH *)
146 int DH_meth_set_init(DH_METHOD *dhm, int (*init)(DH *))
152 int (*DH_meth_get_finish(const DH_METHOD *dhm)) (DH *)
157 int DH_meth_set_finish(DH_METHOD *dhm, int (*finish) (DH *))
159 dhm->finish = finish;
163 int (*DH_meth_get_generate_params(const DH_METHOD *dhm))
164 (DH *, int, int, BN_GENCB *)
166 return dhm->generate_params;
169 int DH_meth_set_generate_params(DH_METHOD *dhm,
170 int (*generate_params) (DH *, int, int, BN_GENCB *))
172 dhm->generate_params = generate_params;