summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rsa/rsa_meth.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_meth.c')
-rw-r--r--src/lib/libcrypto/rsa/rsa_meth.c309
1 files changed, 0 insertions, 309 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_meth.c b/src/lib/libcrypto/rsa/rsa_meth.c
deleted file mode 100644
index 71608caa01..0000000000
--- a/src/lib/libcrypto/rsa/rsa_meth.c
+++ /dev/null
@@ -1,309 +0,0 @@
1/* $OpenBSD: rsa_meth.c,v 1.7 2023/07/08 12:26:45 beck Exp $ */
2/*
3 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19#include <string.h>
20
21#include <openssl/err.h>
22#include <openssl/rsa.h>
23
24#include "rsa_local.h"
25
26RSA_METHOD *
27RSA_meth_new(const char *name, int flags)
28{
29 RSA_METHOD *meth;
30
31 if ((meth = calloc(1, sizeof(*meth))) == NULL)
32 return NULL;
33 if ((meth->name = strdup(name)) == NULL) {
34 free(meth);
35 return NULL;
36 }
37 meth->flags = flags;
38
39 return meth;
40}
41LCRYPTO_ALIAS(RSA_meth_new);
42
43void
44RSA_meth_free(RSA_METHOD *meth)
45{
46 if (meth == NULL)
47 return;
48
49 free(meth->name);
50 free(meth);
51}
52LCRYPTO_ALIAS(RSA_meth_free);
53
54RSA_METHOD *
55RSA_meth_dup(const RSA_METHOD *meth)
56{
57 RSA_METHOD *copy;
58
59 if ((copy = calloc(1, sizeof(*copy))) == NULL)
60 return NULL;
61 memcpy(copy, meth, sizeof(*copy));
62 if ((copy->name = strdup(meth->name)) == NULL) {
63 free(copy);
64 return NULL;
65 }
66
67 return copy;
68}
69LCRYPTO_ALIAS(RSA_meth_dup);
70
71int
72RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
73{
74 char *new_name;
75
76 if ((new_name = strdup(name)) == NULL)
77 return 0;
78 free(meth->name);
79 meth->name = new_name;
80 return 1;
81}
82LCRYPTO_ALIAS(RSA_meth_set1_name);
83
84int
85(*RSA_meth_get_finish(const RSA_METHOD *meth))(RSA *rsa)
86{
87 return meth->finish;
88}
89LCRYPTO_ALIAS(RSA_meth_get_finish);
90
91int
92RSA_meth_set_priv_enc(RSA_METHOD *meth, int (*priv_enc)(int flen,
93 const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
94{
95 meth->rsa_priv_enc = priv_enc;
96 return 1;
97}
98LCRYPTO_ALIAS(RSA_meth_set_priv_enc);
99
100int
101RSA_meth_set_priv_dec(RSA_METHOD *meth, int (*priv_dec)(int flen,
102 const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
103{
104 meth->rsa_priv_dec = priv_dec;
105 return 1;
106}
107LCRYPTO_ALIAS(RSA_meth_set_priv_dec);
108
109int
110RSA_meth_set_finish(RSA_METHOD *meth, int (*finish)(RSA *rsa))
111{
112 meth->finish = finish;
113 return 1;
114}
115LCRYPTO_ALIAS(RSA_meth_set_finish);
116
117int
118RSA_meth_set_pub_enc(RSA_METHOD *meth, int (*pub_enc)(int flen,
119 const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
120{
121 meth->rsa_pub_enc = pub_enc;
122 return 1;
123}
124LCRYPTO_ALIAS(RSA_meth_set_pub_enc);
125
126int
127RSA_meth_set_pub_dec(RSA_METHOD *meth, int (*pub_dec)(int flen,
128 const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
129{
130 meth->rsa_pub_dec = pub_dec;
131 return 1;
132}
133LCRYPTO_ALIAS(RSA_meth_set_pub_dec);
134
135int
136RSA_meth_set_mod_exp(RSA_METHOD *meth, int (*mod_exp)(BIGNUM *r0,
137 const BIGNUM *i, RSA *rsa, BN_CTX *ctx))
138{
139 meth->rsa_mod_exp = mod_exp;
140 return 1;
141}
142LCRYPTO_ALIAS(RSA_meth_set_mod_exp);
143
144int
145RSA_meth_set_bn_mod_exp(RSA_METHOD *meth, int (*bn_mod_exp)(BIGNUM *r,
146 const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
147 BN_MONT_CTX *m_ctx))
148{
149 meth->bn_mod_exp = bn_mod_exp;
150 return 1;
151}
152LCRYPTO_ALIAS(RSA_meth_set_bn_mod_exp);
153
154int
155RSA_meth_set_init(RSA_METHOD *meth, int (*init)(RSA *rsa))
156{
157 meth->init = init;
158 return 1;
159}
160LCRYPTO_ALIAS(RSA_meth_set_init);
161
162int
163RSA_meth_set_keygen(RSA_METHOD *meth, int (*keygen)(RSA *rsa, int bits,
164 BIGNUM *e, BN_GENCB *cb))
165{
166 meth->rsa_keygen = keygen;
167 return 1;
168}
169LCRYPTO_ALIAS(RSA_meth_set_keygen);
170
171int
172RSA_meth_set_flags(RSA_METHOD *meth, int flags)
173{
174 meth->flags = flags;
175 return 1;
176}
177LCRYPTO_ALIAS(RSA_meth_set_flags);
178
179int
180RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data)
181{
182 meth->app_data = app_data;
183 return 1;
184}
185LCRYPTO_ALIAS(RSA_meth_set0_app_data);
186
187const char *
188RSA_meth_get0_name(const RSA_METHOD *meth)
189{
190 return meth->name;
191}
192LCRYPTO_ALIAS(RSA_meth_get0_name);
193
194int
195(*RSA_meth_get_pub_enc(const RSA_METHOD *meth))(int flen,
196 const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
197{
198 return meth->rsa_pub_enc;
199}
200LCRYPTO_ALIAS(RSA_meth_get_pub_enc);
201
202int
203(*RSA_meth_get_pub_dec(const RSA_METHOD *meth))(int flen,
204 const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
205{
206 return meth->rsa_pub_dec;
207}
208LCRYPTO_ALIAS(RSA_meth_get_pub_dec);
209
210int
211(*RSA_meth_get_priv_enc(const RSA_METHOD *meth))(int flen,
212 const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
213{
214 return meth->rsa_priv_enc;
215}
216LCRYPTO_ALIAS(RSA_meth_get_priv_enc);
217
218int
219(*RSA_meth_get_priv_dec(const RSA_METHOD *meth))(int flen,
220 const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
221{
222 return meth->rsa_priv_dec;
223}
224LCRYPTO_ALIAS(RSA_meth_get_priv_dec);
225
226int
227(*RSA_meth_get_mod_exp(const RSA_METHOD *meth))(BIGNUM *r0, const BIGNUM *i,
228 RSA *rsa, BN_CTX *ctx)
229{
230 return meth->rsa_mod_exp;
231}
232LCRYPTO_ALIAS(RSA_meth_get_mod_exp);
233
234int
235(*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))(BIGNUM *r,
236 const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
237 BN_MONT_CTX *m_ctx)
238{
239 return meth->bn_mod_exp;
240}
241LCRYPTO_ALIAS(RSA_meth_get_bn_mod_exp);
242
243int
244(*RSA_meth_get_init(const RSA_METHOD *meth))(RSA *rsa)
245{
246 return meth->init;
247}
248LCRYPTO_ALIAS(RSA_meth_get_init);
249
250int
251(*RSA_meth_get_keygen(const RSA_METHOD *meth))(RSA *rsa, int bits, BIGNUM *e,
252 BN_GENCB *cb)
253{
254 return meth->rsa_keygen;
255}
256LCRYPTO_ALIAS(RSA_meth_get_keygen);
257
258int
259RSA_meth_get_flags(const RSA_METHOD *meth)
260{
261 return meth->flags;
262}
263LCRYPTO_ALIAS(RSA_meth_get_flags);
264
265void *
266RSA_meth_get0_app_data(const RSA_METHOD *meth)
267{
268 return meth->app_data;
269}
270LCRYPTO_ALIAS(RSA_meth_get0_app_data);
271
272int
273(*RSA_meth_get_sign(const RSA_METHOD *meth))(int type,
274 const unsigned char *m, unsigned int m_length,
275 unsigned char *sigret, unsigned int *siglen,
276 const RSA *rsa)
277{
278 return meth->rsa_sign;
279}
280LCRYPTO_ALIAS(RSA_meth_get_sign);
281
282int
283RSA_meth_set_sign(RSA_METHOD *meth, int (*sign)(int type,
284 const unsigned char *m, unsigned int m_length, unsigned char *sigret,
285 unsigned int *siglen, const RSA *rsa))
286{
287 meth->rsa_sign = sign;
288 return 1;
289}
290LCRYPTO_ALIAS(RSA_meth_set_sign);
291
292int
293(*RSA_meth_get_verify(const RSA_METHOD *meth))(int dtype,
294 const unsigned char *m, unsigned int m_length, const unsigned char *sigbuf,
295 unsigned int siglen, const RSA *rsa)
296{
297 return meth->rsa_verify;
298}
299LCRYPTO_ALIAS(RSA_meth_get_verify);
300
301int
302RSA_meth_set_verify(RSA_METHOD *meth, int (*verify)(int dtype,
303 const unsigned char *m, unsigned int m_length, const unsigned char *sigbuf,
304 unsigned int siglen, const RSA *rsa))
305{
306 meth->rsa_verify = verify;
307 return 1;
308}
309LCRYPTO_ALIAS(RSA_meth_set_verify);