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 OPENSSL_free(meth->name);
39 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
43 ret = OPENSSL_malloc(sizeof(RSA_METHOD));
46 memcpy(ret, meth, sizeof(*meth));
47 ret->name = OPENSSL_strdup(meth->name);
48 if (ret->name == NULL) {
50 RSAerr(RSA_F_RSA_METH_DUP, ERR_R_MALLOC_FAILURE);
58 const char *RSA_meth_get0_name(const RSA_METHOD *meth)
63 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
67 tmpname = OPENSSL_strdup(name);
68 if (tmpname == NULL) {
69 RSAerr(RSA_F_RSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
73 OPENSSL_free(meth->name);
79 int RSA_meth_get_flags(RSA_METHOD *meth)
84 int RSA_meth_set_flags(RSA_METHOD *meth, int flags)
90 void *RSA_meth_get0_app_data(const RSA_METHOD *meth)
92 return meth->app_data;
95 int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data)
97 meth->app_data = app_data;
101 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
102 (int flen, const unsigned char *from,
103 unsigned char *to, RSA *rsa, int padding)
105 return meth->rsa_pub_enc;
108 int RSA_meth_set_pub_enc(RSA_METHOD *meth,
109 int (*pub_enc) (int flen, const unsigned char *from,
110 unsigned char *to, RSA *rsa,
113 meth->rsa_pub_enc = pub_enc;
117 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
118 (int flen, const unsigned char *from,
119 unsigned char *to, RSA *rsa, int padding)
121 return meth->rsa_pub_dec;
124 int RSA_meth_set_pub_dec(RSA_METHOD *meth,
125 int (*pub_dec) (int flen, const unsigned char *from,
126 unsigned char *to, RSA *rsa,
129 meth->rsa_pub_dec = pub_dec;
133 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
134 (int flen, const unsigned char *from,
135 unsigned char *to, RSA *rsa, int padding)
137 return meth->rsa_priv_enc;
140 int RSA_meth_set_priv_enc(RSA_METHOD *meth,
141 int (*priv_enc) (int flen, const unsigned char *from,
142 unsigned char *to, RSA *rsa,
145 meth->rsa_priv_enc = priv_enc;
149 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
150 (int flen, const unsigned char *from,
151 unsigned char *to, RSA *rsa, int padding)
153 return meth->rsa_priv_dec;
156 int RSA_meth_set_priv_dec(RSA_METHOD *meth,
157 int (*priv_dec) (int flen, const unsigned char *from,
158 unsigned char *to, RSA *rsa,
161 meth->rsa_priv_dec = priv_dec;
166 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
167 (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
169 return meth->rsa_mod_exp;
172 int RSA_meth_set_mod_exp(RSA_METHOD *meth,
173 int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,
176 meth->rsa_mod_exp = mod_exp;
181 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
182 (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
183 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
185 return meth->bn_mod_exp;
188 int RSA_meth_set_bn_mod_exp(RSA_METHOD *meth,
189 int (*bn_mod_exp) (BIGNUM *r,
196 meth->bn_mod_exp = bn_mod_exp;
201 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa)
206 int RSA_meth_set_init(RSA_METHOD *meth, int (*init) (RSA *rsa))
213 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa)
218 int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa))
220 meth->finish = finish;
224 int (*RSA_meth_get_sign(const RSA_METHOD *meth))
226 const unsigned char *m, unsigned int m_length,
227 unsigned char *sigret, unsigned int *siglen,
230 return meth->rsa_sign;
233 int RSA_meth_set_sign(RSA_METHOD *meth,
234 int (*sign) (int type, const unsigned char *m,
235 unsigned int m_length,
236 unsigned char *sigret, unsigned int *siglen,
239 meth->rsa_sign = sign;
243 int (*RSA_meth_get_verify(const RSA_METHOD *meth))
244 (int dtype, const unsigned char *m,
245 unsigned int m_length, const unsigned char *sigbuf,
246 unsigned int siglen, const RSA *rsa)
248 return meth->rsa_verify;
251 int RSA_meth_set_verify(RSA_METHOD *meth,
252 int (*verify) (int dtype, const unsigned char *m,
253 unsigned int m_length,
254 const unsigned char *sigbuf,
255 unsigned int siglen, const RSA *rsa))
257 meth->rsa_verify = verify;
261 int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
262 (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
264 return meth->rsa_keygen;
267 int RSA_meth_set_keygen(RSA_METHOD *meth,
268 int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
271 meth->rsa_keygen = keygen;