2 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
11 * RSA low level APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
17 #include "rsa_local.h"
18 #include <openssl/err.h>
20 RSA_METHOD *RSA_meth_new(const char *name, int flags)
22 RSA_METHOD *meth = OPENSSL_zalloc(sizeof(*meth));
27 meth->name = OPENSSL_strdup(name);
28 if (meth->name != NULL)
34 RSAerr(RSA_F_RSA_METH_NEW, ERR_R_MALLOC_FAILURE);
38 void RSA_meth_free(RSA_METHOD *meth)
41 OPENSSL_free(meth->name);
46 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
48 RSA_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
51 memcpy(ret, meth, sizeof(*meth));
53 ret->name = OPENSSL_strdup(meth->name);
54 if (ret->name != NULL)
60 RSAerr(RSA_F_RSA_METH_DUP, ERR_R_MALLOC_FAILURE);
64 const char *RSA_meth_get0_name(const RSA_METHOD *meth)
69 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
71 char *tmpname = OPENSSL_strdup(name);
73 if (tmpname == NULL) {
74 RSAerr(RSA_F_RSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
78 OPENSSL_free(meth->name);
84 int RSA_meth_get_flags(const RSA_METHOD *meth)
89 int RSA_meth_set_flags(RSA_METHOD *meth, int flags)
95 void *RSA_meth_get0_app_data(const RSA_METHOD *meth)
97 return meth->app_data;
100 int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data)
102 meth->app_data = app_data;
106 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
107 (int flen, const unsigned char *from,
108 unsigned char *to, RSA *rsa, int padding)
110 return meth->rsa_pub_enc;
113 int RSA_meth_set_pub_enc(RSA_METHOD *meth,
114 int (*pub_enc) (int flen, const unsigned char *from,
115 unsigned char *to, RSA *rsa,
118 meth->rsa_pub_enc = pub_enc;
122 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
123 (int flen, const unsigned char *from,
124 unsigned char *to, RSA *rsa, int padding)
126 return meth->rsa_pub_dec;
129 int RSA_meth_set_pub_dec(RSA_METHOD *meth,
130 int (*pub_dec) (int flen, const unsigned char *from,
131 unsigned char *to, RSA *rsa,
134 meth->rsa_pub_dec = pub_dec;
138 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
139 (int flen, const unsigned char *from,
140 unsigned char *to, RSA *rsa, int padding)
142 return meth->rsa_priv_enc;
145 int RSA_meth_set_priv_enc(RSA_METHOD *meth,
146 int (*priv_enc) (int flen, const unsigned char *from,
147 unsigned char *to, RSA *rsa,
150 meth->rsa_priv_enc = priv_enc;
154 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
155 (int flen, const unsigned char *from,
156 unsigned char *to, RSA *rsa, int padding)
158 return meth->rsa_priv_dec;
161 int RSA_meth_set_priv_dec(RSA_METHOD *meth,
162 int (*priv_dec) (int flen, const unsigned char *from,
163 unsigned char *to, RSA *rsa,
166 meth->rsa_priv_dec = priv_dec;
171 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
172 (BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx)
174 return meth->rsa_mod_exp;
177 int RSA_meth_set_mod_exp(RSA_METHOD *meth,
178 int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa,
181 meth->rsa_mod_exp = mod_exp;
186 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
187 (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
188 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
190 return meth->bn_mod_exp;
193 int RSA_meth_set_bn_mod_exp(RSA_METHOD *meth,
194 int (*bn_mod_exp) (BIGNUM *r,
201 meth->bn_mod_exp = bn_mod_exp;
206 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa)
211 int RSA_meth_set_init(RSA_METHOD *meth, int (*init) (RSA *rsa))
218 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa)
223 int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa))
225 meth->finish = finish;
229 int (*RSA_meth_get_sign(const RSA_METHOD *meth))
231 const unsigned char *m, unsigned int m_length,
232 unsigned char *sigret, unsigned int *siglen,
235 return meth->rsa_sign;
238 int RSA_meth_set_sign(RSA_METHOD *meth,
239 int (*sign) (int type, const unsigned char *m,
240 unsigned int m_length,
241 unsigned char *sigret, unsigned int *siglen,
244 meth->rsa_sign = sign;
248 int (*RSA_meth_get_verify(const RSA_METHOD *meth))
249 (int dtype, const unsigned char *m,
250 unsigned int m_length, const unsigned char *sigbuf,
251 unsigned int siglen, const RSA *rsa)
253 return meth->rsa_verify;
256 int RSA_meth_set_verify(RSA_METHOD *meth,
257 int (*verify) (int dtype, const unsigned char *m,
258 unsigned int m_length,
259 const unsigned char *sigbuf,
260 unsigned int siglen, const RSA *rsa))
262 meth->rsa_verify = verify;
266 int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
267 (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
269 return meth->rsa_keygen;
272 int RSA_meth_set_keygen(RSA_METHOD *meth,
273 int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
276 meth->rsa_keygen = keygen;
280 int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth))
281 (RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb)
283 return meth->rsa_multi_prime_keygen;
286 int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
287 int (*keygen) (RSA *rsa, int bits,
288 int primes, BIGNUM *e,
291 meth->rsa_multi_prime_keygen = keygen;