]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/dh/dh_meth.c
Deprecate the low level Diffie-Hellman functions.
[thirdparty/openssl.git] / crypto / dh / dh_meth.c
CommitLineData
17e01abb 1/*
c4d3c19b 2 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
17e01abb 3 *
e38873f5 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
aa6bb135
RS
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
17e01abb 7 * https://www.openssl.org/source/license.html
17e01abb
MC
8 */
9
ada66e78
P
10/*
11 * DH low level APIs are deprecated for public use, but still ok for
12 * internal use.
13 */
14#include "internal/deprecated.h"
15
706457b7 16#include "dh_local.h"
17e01abb 17#include <string.h>
569d0646 18#include <openssl/err.h>
17e01abb
MC
19
20DH_METHOD *DH_meth_new(const char *name, int flags)
21{
bad6b116 22 DH_METHOD *dhm = OPENSSL_zalloc(sizeof(*dhm));
17e01abb
MC
23
24 if (dhm != NULL) {
17e01abb 25 dhm->flags = flags;
bad6b116
F
26
27 dhm->name = OPENSSL_strdup(name);
28 if (dhm->name != NULL)
29 return dhm;
30
31 OPENSSL_free(dhm);
17e01abb
MC
32 }
33
bad6b116
F
34 DHerr(DH_F_DH_METH_NEW, ERR_R_MALLOC_FAILURE);
35 return NULL;
17e01abb
MC
36}
37
38void DH_meth_free(DH_METHOD *dhm)
39{
40 if (dhm != NULL) {
aca6dae9 41 OPENSSL_free(dhm->name);
17e01abb
MC
42 OPENSSL_free(dhm);
43 }
44}
45
46DH_METHOD *DH_meth_dup(const DH_METHOD *dhm)
47{
bad6b116 48 DH_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
17e01abb
MC
49
50 if (ret != NULL) {
51 memcpy(ret, dhm, sizeof(*dhm));
bad6b116 52
17e01abb 53 ret->name = OPENSSL_strdup(dhm->name);
bad6b116
F
54 if (ret->name != NULL)
55 return ret;
56
57 OPENSSL_free(ret);
17e01abb
MC
58 }
59
bad6b116
F
60 DHerr(DH_F_DH_METH_DUP, ERR_R_MALLOC_FAILURE);
61 return NULL;
17e01abb
MC
62}
63
64const char *DH_meth_get0_name(const DH_METHOD *dhm)
65{
66 return dhm->name;
67}
68
69int DH_meth_set1_name(DH_METHOD *dhm, const char *name)
70{
bad6b116 71 char *tmpname = OPENSSL_strdup(name);
6ef020c9 72
569d0646
MC
73 if (tmpname == NULL) {
74 DHerr(DH_F_DH_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
6ef020c9 75 return 0;
569d0646 76 }
6ef020c9 77
17e01abb 78 OPENSSL_free(dhm->name);
6ef020c9 79 dhm->name = tmpname;
17e01abb 80
6ef020c9 81 return 1;
17e01abb
MC
82}
83
693be9a2 84int DH_meth_get_flags(const DH_METHOD *dhm)
17e01abb
MC
85{
86 return dhm->flags;
87}
88
89int DH_meth_set_flags(DH_METHOD *dhm, int flags)
90{
91 dhm->flags = flags;
92 return 1;
93}
94
95void *DH_meth_get0_app_data(const DH_METHOD *dhm)
96{
97 return dhm->app_data;
98}
99
100int DH_meth_set0_app_data(DH_METHOD *dhm, void *app_data)
101{
102 dhm->app_data = app_data;
103 return 1;
104}
105
106int (*DH_meth_get_generate_key(const DH_METHOD *dhm)) (DH *)
107{
108 return dhm->generate_key;
109}
110
111int DH_meth_set_generate_key(DH_METHOD *dhm, int (*generate_key) (DH *))
112{
113 dhm->generate_key = generate_key;
114 return 1;
115}
116
117int (*DH_meth_get_compute_key(const DH_METHOD *dhm))
118 (unsigned char *key, const BIGNUM *pub_key, DH *dh)
119{
120 return dhm->compute_key;
121}
122
123int DH_meth_set_compute_key(DH_METHOD *dhm,
124 int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh))
125{
126 dhm->compute_key = compute_key;
127 return 1;
128}
129
130
131int (*DH_meth_get_bn_mod_exp(const DH_METHOD *dhm))
132 (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
133 BN_CTX *, BN_MONT_CTX *)
134{
135 return dhm->bn_mod_exp;
136}
137
138int DH_meth_set_bn_mod_exp(DH_METHOD *dhm,
139 int (*bn_mod_exp) (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *,
140 const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
141{
142 dhm->bn_mod_exp = bn_mod_exp;
143 return 1;
144}
145
146int (*DH_meth_get_init(const DH_METHOD *dhm))(DH *)
147{
148 return dhm->init;
149}
150
151int DH_meth_set_init(DH_METHOD *dhm, int (*init)(DH *))
152{
153 dhm->init = init;
154 return 1;
155}
156
157int (*DH_meth_get_finish(const DH_METHOD *dhm)) (DH *)
158{
159 return dhm->finish;
160}
161
162int DH_meth_set_finish(DH_METHOD *dhm, int (*finish) (DH *))
163{
164 dhm->finish = finish;
165 return 1;
166}
167
168int (*DH_meth_get_generate_params(const DH_METHOD *dhm))
169 (DH *, int, int, BN_GENCB *)
170{
171 return dhm->generate_params;
172}
173
174int DH_meth_set_generate_params(DH_METHOD *dhm,
175 int (*generate_params) (DH *, int, int, BN_GENCB *))
176{
177 dhm->generate_params = generate_params;
178 return 1;
179}