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
13 RSA_METHOD *RSA_meth_new(const char *name, int flags)
15 RSA_METHOD *meth = OPENSSL_zalloc(sizeof(RSA_METHOD));
18 meth->name = OPENSSL_strdup(name);
19 if (meth->name == NULL) {
29 void RSA_meth_free(RSA_METHOD *meth)
32 if (meth->name != NULL)
33 OPENSSL_free(meth->name);
38 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
42 ret = OPENSSL_malloc(sizeof(RSA_METHOD));
45 memcpy(ret, meth, sizeof(*meth));
46 ret->name = OPENSSL_strdup(meth->name);
47 if (ret->name == NULL) {
56 const char *RSA_meth_get0_name(const RSA_METHOD *meth)
61 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
65 tmpname = OPENSSL_strdup(name);
69 OPENSSL_free(meth->name);
75 int RSA_meth_get_flags(RSA_METHOD *meth)
80 int RSA_meth_set_flags(RSA_METHOD *meth, int flags)
86 void *RSA_meth_get0_app_data(const RSA_METHOD *meth)
88 return meth->app_data;
91 int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data)
93 meth->app_data = app_data;
97 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
98 (int flen, const unsigned char *from,
99 unsigned char *to, RSA *rsa, int padding)
101 return meth->rsa_pub_enc;
104 int RSA_meth_set_pub_enc(RSA_METHOD *meth,
105 int (*pub_enc) (int flen, const unsigned char *from,
106 unsigned char *to, RSA *rsa,
109 meth->rsa_pub_enc = pub_enc;
113 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
114 (int flen, const unsigned char *from,
115 unsigned char *to, RSA *rsa, int padding)
117 return meth->rsa_pub_dec;
120 int RSA_meth_set_pub_dec(RSA_METHOD *meth,
121 int (*pub_dec) (int flen, const unsigned char *from,
122 unsigned char *to, RSA *rsa,
125 meth->rsa_pub_dec = pub_dec;
129 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
130 (int flen, const unsigned char *from,
131 unsigned char *to, RSA *rsa, int padding)
133 return meth->rsa_priv_enc;
136 int RSA_meth_set_priv_enc(RSA_METHOD *meth,
137 int (*priv_enc) (int flen, const unsigned char *from,
138 unsigned char *to, RSA *rsa,
141 meth->rsa_priv_enc = priv_enc;
145 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
146 (int flen, const unsigned char *from,
147 unsigned char *to, RSA *rsa, int padding)
149 return meth->rsa_priv_dec;
152 int RSA_meth_set_priv_dec(RSA_METHOD *meth,
153 int (*priv_dec) (int flen, const unsigned char *from,
154 unsigned char *to, RSA *rsa,
157 meth->rsa_priv_dec = priv_dec;
162 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
163 (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
165 return meth->rsa_mod_exp;
168 int RSA_meth_set_mod_exp(RSA_METHOD *meth,
169 int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,
172 meth->rsa_mod_exp = mod_exp;
177 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
178 (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
179 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
181 return meth->bn_mod_exp;
184 int RSA_meth_set_bn_mod_exp(RSA_METHOD *meth,
185 int (*bn_mod_exp) (BIGNUM *r,
192 meth->bn_mod_exp = bn_mod_exp;
197 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa)
202 int RSA_meth_set_init(RSA_METHOD *meth, int (*init) (RSA *rsa))
209 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa)
214 int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa))
216 meth->finish = finish;
220 int (*RSA_meth_get_sign(const RSA_METHOD *meth))
222 const unsigned char *m, unsigned int m_length,
223 unsigned char *sigret, unsigned int *siglen,
226 return meth->rsa_sign;
229 int RSA_meth_set_sign(RSA_METHOD *meth,
230 int (*sign) (int type, const unsigned char *m,
231 unsigned int m_length,
232 unsigned char *sigret, unsigned int *siglen,
235 meth->rsa_sign = sign;
239 int (*RSA_meth_get_verify(const RSA_METHOD *meth))
240 (int dtype, const unsigned char *m,
241 unsigned int m_length, const unsigned char *sigbuf,
242 unsigned int siglen, const RSA *rsa)
244 return meth->rsa_verify;
247 int RSA_meth_set_verify(RSA_METHOD *meth,
248 int (*verify) (int dtype, const unsigned char *m,
249 unsigned int m_length,
250 const unsigned char *sigbuf,
251 unsigned int siglen, const RSA *rsa))
253 meth->rsa_verify = verify;
257 int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
258 (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
260 return meth->rsa_keygen;
263 int RSA_meth_set_keygen(RSA_METHOD *meth,
264 int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
267 meth->rsa_keygen = keygen;