]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/dh/dh_meth.c
Copyright consolidation 09/10
[thirdparty/openssl.git] / crypto / dh / dh_meth.c
CommitLineData
17e01abb
MC
1/*
2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL licenses, (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.openssl.org/source/license.html
8 * or in the file LICENSE in the source distribution.
9 */
10
11
12#include "dh_locl.h"
13#include <string.h>
14
15DH_METHOD *DH_meth_new(const char *name, int flags)
16{
17 DH_METHOD *dhm = OPENSSL_zalloc(sizeof(DH_METHOD));
18
19 if (dhm != NULL) {
20 dhm->name = OPENSSL_strdup(name);
21 dhm->flags = flags;
22 }
23
24 return dhm;
25}
26
27void DH_meth_free(DH_METHOD *dhm)
28{
29 if (dhm != NULL) {
30 if (dhm->name != NULL)
31 OPENSSL_free(dhm->name);
32 OPENSSL_free(dhm);
33 }
34}
35
36DH_METHOD *DH_meth_dup(const DH_METHOD *dhm)
37{
38 DH_METHOD *ret;
39
40 ret = OPENSSL_malloc(sizeof(DH_METHOD));
41
42 if (ret != NULL) {
43 memcpy(ret, dhm, sizeof(*dhm));
44 ret->name = OPENSSL_strdup(dhm->name);
45 }
46
47 return ret;
48}
49
50const char *DH_meth_get0_name(const DH_METHOD *dhm)
51{
52 return dhm->name;
53}
54
55int DH_meth_set1_name(DH_METHOD *dhm, const char *name)
56{
57 OPENSSL_free(dhm->name);
58 dhm->name = OPENSSL_strdup(name);
59
60 return dhm->name != NULL;
61}
62
63int DH_meth_get_flags(DH_METHOD *dhm)
64{
65 return dhm->flags;
66}
67
68int DH_meth_set_flags(DH_METHOD *dhm, int flags)
69{
70 dhm->flags = flags;
71 return 1;
72}
73
74void *DH_meth_get0_app_data(const DH_METHOD *dhm)
75{
76 return dhm->app_data;
77}
78
79int DH_meth_set0_app_data(DH_METHOD *dhm, void *app_data)
80{
81 dhm->app_data = app_data;
82 return 1;
83}
84
85int (*DH_meth_get_generate_key(const DH_METHOD *dhm)) (DH *)
86{
87 return dhm->generate_key;
88}
89
90int DH_meth_set_generate_key(DH_METHOD *dhm, int (*generate_key) (DH *))
91{
92 dhm->generate_key = generate_key;
93 return 1;
94}
95
96int (*DH_meth_get_compute_key(const DH_METHOD *dhm))
97 (unsigned char *key, const BIGNUM *pub_key, DH *dh)
98{
99 return dhm->compute_key;
100}
101
102int DH_meth_set_compute_key(DH_METHOD *dhm,
103 int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh))
104{
105 dhm->compute_key = compute_key;
106 return 1;
107}
108
109
110int (*DH_meth_get_bn_mod_exp(const DH_METHOD *dhm))
111 (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
112 BN_CTX *, BN_MONT_CTX *)
113{
114 return dhm->bn_mod_exp;
115}
116
117int DH_meth_set_bn_mod_exp(DH_METHOD *dhm,
118 int (*bn_mod_exp) (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *,
119 const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
120{
121 dhm->bn_mod_exp = bn_mod_exp;
122 return 1;
123}
124
125int (*DH_meth_get_init(const DH_METHOD *dhm))(DH *)
126{
127 return dhm->init;
128}
129
130int DH_meth_set_init(DH_METHOD *dhm, int (*init)(DH *))
131{
132 dhm->init = init;
133 return 1;
134}
135
136int (*DH_meth_get_finish(const DH_METHOD *dhm)) (DH *)
137{
138 return dhm->finish;
139}
140
141int DH_meth_set_finish(DH_METHOD *dhm, int (*finish) (DH *))
142{
143 dhm->finish = finish;
144 return 1;
145}
146
147int (*DH_meth_get_generate_params(const DH_METHOD *dhm))
148 (DH *, int, int, BN_GENCB *)
149{
150 return dhm->generate_params;
151}
152
153int DH_meth_set_generate_params(DH_METHOD *dhm,
154 int (*generate_params) (DH *, int, int, BN_GENCB *))
155{
156 dhm->generate_params = generate_params;
157 return 1;
158}