2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL licenses, (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.openssl.org/source/license.html
8 * or in the file LICENSE in the source distribution.
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);
26 void RSA_meth_free(RSA_METHOD *meth)
29 if (meth->name != NULL)
30 OPENSSL_free(meth->name);
35 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
39 ret = OPENSSL_malloc(sizeof(RSA_METHOD));
42 memcpy(ret, meth, sizeof(*meth));
43 ret->name = OPENSSL_strdup(meth->name);
49 const char *RSA_meth_get0_name(const RSA_METHOD *meth)
54 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
56 OPENSSL_free(meth->name);
57 meth->name = OPENSSL_strdup(name);
59 return meth->name != NULL;
62 int RSA_meth_get_flags(RSA_METHOD *meth)
67 int RSA_meth_set_flags(RSA_METHOD *meth, int flags)
73 void *RSA_meth_get0_app_data(const RSA_METHOD *meth)
75 return meth->app_data;
78 int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data)
80 meth->app_data = app_data;
84 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
85 (int flen, const unsigned char *from,
86 unsigned char *to, RSA *rsa, int padding)
88 return meth->rsa_pub_enc;
91 int RSA_meth_set_pub_enc(RSA_METHOD *meth,
92 int (*pub_enc) (int flen, const unsigned char *from,
93 unsigned char *to, RSA *rsa,
96 meth->rsa_pub_enc = pub_enc;
100 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
101 (int flen, const unsigned char *from,
102 unsigned char *to, RSA *rsa, int padding)
104 return meth->rsa_pub_dec;
107 int RSA_meth_set_pub_dec(RSA_METHOD *meth,
108 int (*pub_dec) (int flen, const unsigned char *from,
109 unsigned char *to, RSA *rsa,
112 meth->rsa_pub_dec = pub_dec;
116 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
117 (int flen, const unsigned char *from,
118 unsigned char *to, RSA *rsa, int padding)
120 return meth->rsa_priv_enc;
123 int RSA_meth_set_priv_enc(RSA_METHOD *meth,
124 int (*priv_enc) (int flen, const unsigned char *from,
125 unsigned char *to, RSA *rsa,
128 meth->rsa_priv_enc = priv_enc;
132 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
133 (int flen, const unsigned char *from,
134 unsigned char *to, RSA *rsa, int padding)
136 return meth->rsa_priv_dec;
139 int RSA_meth_set_priv_dec(RSA_METHOD *meth,
140 int (*priv_dec) (int flen, const unsigned char *from,
141 unsigned char *to, RSA *rsa,
144 meth->rsa_priv_dec = priv_dec;
149 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
150 (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
152 return meth->rsa_mod_exp;
155 int RSA_meth_set_mod_exp(RSA_METHOD *meth,
156 int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,
159 meth->rsa_mod_exp = mod_exp;
164 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
165 (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
166 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
168 return meth->bn_mod_exp;
171 int RSA_meth_set_bn_mod_exp(RSA_METHOD *meth,
172 int (*bn_mod_exp) (BIGNUM *r,
179 meth->bn_mod_exp = bn_mod_exp;
184 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa)
189 int RSA_meth_set_init(RSA_METHOD *meth, int (*init) (RSA *rsa))
196 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa)
201 int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa))
203 meth->finish = finish;
207 int (*RSA_meth_get_sign(const RSA_METHOD *meth))
209 const unsigned char *m, unsigned int m_length,
210 unsigned char *sigret, unsigned int *siglen,
213 return meth->rsa_sign;
216 int RSA_meth_set_sign(RSA_METHOD *meth,
217 int (*sign) (int type, const unsigned char *m,
218 unsigned int m_length,
219 unsigned char *sigret, unsigned int *siglen,
222 meth->rsa_sign = sign;
226 int (*RSA_meth_get_verify(const RSA_METHOD *meth))
227 (int dtype, const unsigned char *m,
228 unsigned int m_length, const unsigned char *sigbuf,
229 unsigned int siglen, const RSA *rsa)
231 return meth->rsa_verify;
234 int RSA_meth_set_verify(RSA_METHOD *meth,
235 int (*verify) (int dtype, const unsigned char *m,
236 unsigned int m_length,
237 const unsigned char *sigbuf,
238 unsigned int siglen, const RSA *rsa))
240 meth->rsa_verify = verify;
244 int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
245 (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
247 return meth->rsa_keygen;
250 int RSA_meth_set_keygen(RSA_METHOD *meth,
251 int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
254 meth->rsa_keygen = keygen;