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 RSA_METHOD *RSA_meth_new(const char *name, int flags)
16 RSA_METHOD *meth = OPENSSL_zalloc(sizeof(RSA_METHOD));
19 meth->name = OPENSSL_strdup(name);
20 if (meth->name == NULL) {
22 RSAerr(RSA_F_RSA_METH_NEW, ERR_R_MALLOC_FAILURE);
31 void RSA_meth_free(RSA_METHOD *meth)
34 if (meth->name != NULL)
35 OPENSSL_free(meth->name);
40 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
44 ret = OPENSSL_malloc(sizeof(RSA_METHOD));
47 memcpy(ret, meth, sizeof(*meth));
48 ret->name = OPENSSL_strdup(meth->name);
49 if (ret->name == NULL) {
51 RSAerr(RSA_F_RSA_METH_DUP, ERR_R_MALLOC_FAILURE);
59 const char *RSA_meth_get0_name(const RSA_METHOD *meth)
64 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
68 tmpname = OPENSSL_strdup(name);
69 if (tmpname == NULL) {
70 RSAerr(RSA_F_RSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
74 OPENSSL_free(meth->name);
80 int RSA_meth_get_flags(RSA_METHOD *meth)
85 int RSA_meth_set_flags(RSA_METHOD *meth, int flags)
91 void *RSA_meth_get0_app_data(const RSA_METHOD *meth)
93 return meth->app_data;
96 int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data)
98 meth->app_data = app_data;
102 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
103 (int flen, const unsigned char *from,
104 unsigned char *to, RSA *rsa, int padding)
106 return meth->rsa_pub_enc;
109 int RSA_meth_set_pub_enc(RSA_METHOD *meth,
110 int (*pub_enc) (int flen, const unsigned char *from,
111 unsigned char *to, RSA *rsa,
114 meth->rsa_pub_enc = pub_enc;
118 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
119 (int flen, const unsigned char *from,
120 unsigned char *to, RSA *rsa, int padding)
122 return meth->rsa_pub_dec;
125 int RSA_meth_set_pub_dec(RSA_METHOD *meth,
126 int (*pub_dec) (int flen, const unsigned char *from,
127 unsigned char *to, RSA *rsa,
130 meth->rsa_pub_dec = pub_dec;
134 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
135 (int flen, const unsigned char *from,
136 unsigned char *to, RSA *rsa, int padding)
138 return meth->rsa_priv_enc;
141 int RSA_meth_set_priv_enc(RSA_METHOD *meth,
142 int (*priv_enc) (int flen, const unsigned char *from,
143 unsigned char *to, RSA *rsa,
146 meth->rsa_priv_enc = priv_enc;
150 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
151 (int flen, const unsigned char *from,
152 unsigned char *to, RSA *rsa, int padding)
154 return meth->rsa_priv_dec;
157 int RSA_meth_set_priv_dec(RSA_METHOD *meth,
158 int (*priv_dec) (int flen, const unsigned char *from,
159 unsigned char *to, RSA *rsa,
162 meth->rsa_priv_dec = priv_dec;
167 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
168 (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
170 return meth->rsa_mod_exp;
173 int RSA_meth_set_mod_exp(RSA_METHOD *meth,
174 int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,
177 meth->rsa_mod_exp = mod_exp;
182 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
183 (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
184 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
186 return meth->bn_mod_exp;
189 int RSA_meth_set_bn_mod_exp(RSA_METHOD *meth,
190 int (*bn_mod_exp) (BIGNUM *r,
197 meth->bn_mod_exp = bn_mod_exp;
202 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa)
207 int RSA_meth_set_init(RSA_METHOD *meth, int (*init) (RSA *rsa))
214 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa)
219 int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa))
221 meth->finish = finish;
225 int (*RSA_meth_get_sign(const RSA_METHOD *meth))
227 const unsigned char *m, unsigned int m_length,
228 unsigned char *sigret, unsigned int *siglen,
231 return meth->rsa_sign;
234 int RSA_meth_set_sign(RSA_METHOD *meth,
235 int (*sign) (int type, const unsigned char *m,
236 unsigned int m_length,
237 unsigned char *sigret, unsigned int *siglen,
240 meth->rsa_sign = sign;
244 int (*RSA_meth_get_verify(const RSA_METHOD *meth))
245 (int dtype, const unsigned char *m,
246 unsigned int m_length, const unsigned char *sigbuf,
247 unsigned int siglen, const RSA *rsa)
249 return meth->rsa_verify;
252 int RSA_meth_set_verify(RSA_METHOD *meth,
253 int (*verify) (int dtype, const unsigned char *m,
254 unsigned int m_length,
255 const unsigned char *sigbuf,
256 unsigned int siglen, const RSA *rsa))
258 meth->rsa_verify = verify;
262 int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
263 (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
265 return meth->rsa_keygen;
268 int RSA_meth_set_keygen(RSA_METHOD *meth,
269 int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
272 meth->rsa_keygen = keygen;