]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/rsa/rsa_meth.c
2 * Copyright 2016-2018 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(*meth
));
21 meth
->name
= OPENSSL_strdup(name
);
22 if (meth
->name
!= NULL
)
28 RSAerr(RSA_F_RSA_METH_NEW
, ERR_R_MALLOC_FAILURE
);
32 void RSA_meth_free(RSA_METHOD
*meth
)
35 OPENSSL_free(meth
->name
);
40 RSA_METHOD
*RSA_meth_dup(const RSA_METHOD
*meth
)
42 RSA_METHOD
*ret
= OPENSSL_malloc(sizeof(*ret
));
45 memcpy(ret
, meth
, sizeof(*meth
));
47 ret
->name
= OPENSSL_strdup(meth
->name
);
48 if (ret
->name
!= NULL
)
54 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
)
65 char *tmpname
= OPENSSL_strdup(name
);
67 if (tmpname
== NULL
) {
68 RSAerr(RSA_F_RSA_METH_SET1_NAME
, ERR_R_MALLOC_FAILURE
);
72 OPENSSL_free(meth
->name
);
78 int RSA_meth_get_flags(const RSA_METHOD
*meth
)
83 int RSA_meth_set_flags(RSA_METHOD
*meth
, int flags
)
89 void *RSA_meth_get0_app_data(const RSA_METHOD
*meth
)
91 return meth
->app_data
;
94 int RSA_meth_set0_app_data(RSA_METHOD
*meth
, void *app_data
)
96 meth
->app_data
= app_data
;
100 int (*RSA_meth_get_pub_enc(const RSA_METHOD
*meth
))
101 (int flen
, const unsigned char *from
,
102 unsigned char *to
, RSA
*rsa
, int padding
)
104 return meth
->rsa_pub_enc
;
107 int RSA_meth_set_pub_enc(RSA_METHOD
*meth
,
108 int (*pub_enc
) (int flen
, const unsigned char *from
,
109 unsigned char *to
, RSA
*rsa
,
112 meth
->rsa_pub_enc
= pub_enc
;
116 int (*RSA_meth_get_pub_dec(const RSA_METHOD
*meth
))
117 (int flen
, const unsigned char *from
,
118 unsigned char *to
, RSA
*rsa
, int padding
)
120 return meth
->rsa_pub_dec
;
123 int RSA_meth_set_pub_dec(RSA_METHOD
*meth
,
124 int (*pub_dec
) (int flen
, const unsigned char *from
,
125 unsigned char *to
, RSA
*rsa
,
128 meth
->rsa_pub_dec
= pub_dec
;
132 int (*RSA_meth_get_priv_enc(const RSA_METHOD
*meth
))
133 (int flen
, const unsigned char *from
,
134 unsigned char *to
, RSA
*rsa
, int padding
)
136 return meth
->rsa_priv_enc
;
139 int RSA_meth_set_priv_enc(RSA_METHOD
*meth
,
140 int (*priv_enc
) (int flen
, const unsigned char *from
,
141 unsigned char *to
, RSA
*rsa
,
144 meth
->rsa_priv_enc
= priv_enc
;
148 int (*RSA_meth_get_priv_dec(const RSA_METHOD
*meth
))
149 (int flen
, const unsigned char *from
,
150 unsigned char *to
, RSA
*rsa
, int padding
)
152 return meth
->rsa_priv_dec
;
155 int RSA_meth_set_priv_dec(RSA_METHOD
*meth
,
156 int (*priv_dec
) (int flen
, const unsigned char *from
,
157 unsigned char *to
, RSA
*rsa
,
160 meth
->rsa_priv_dec
= priv_dec
;
165 int (*RSA_meth_get_mod_exp(const RSA_METHOD
*meth
))
166 (BIGNUM
*r0
, const BIGNUM
*I
, RSA
*rsa
, BN_CTX
*ctx
)
168 return meth
->rsa_mod_exp
;
171 int RSA_meth_set_mod_exp(RSA_METHOD
*meth
,
172 int (*mod_exp
) (BIGNUM
*r0
, const BIGNUM
*I
, RSA
*rsa
,
175 meth
->rsa_mod_exp
= mod_exp
;
180 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD
*meth
))
181 (BIGNUM
*r
, const BIGNUM
*a
, const BIGNUM
*p
,
182 const BIGNUM
*m
, BN_CTX
*ctx
, BN_MONT_CTX
*m_ctx
)
184 return meth
->bn_mod_exp
;
187 int RSA_meth_set_bn_mod_exp(RSA_METHOD
*meth
,
188 int (*bn_mod_exp
) (BIGNUM
*r
,
195 meth
->bn_mod_exp
= bn_mod_exp
;
200 int (*RSA_meth_get_init(const RSA_METHOD
*meth
)) (RSA
*rsa
)
205 int RSA_meth_set_init(RSA_METHOD
*meth
, int (*init
) (RSA
*rsa
))
212 int (*RSA_meth_get_finish(const RSA_METHOD
*meth
)) (RSA
*rsa
)
217 int RSA_meth_set_finish(RSA_METHOD
*meth
, int (*finish
) (RSA
*rsa
))
219 meth
->finish
= finish
;
223 int (*RSA_meth_get_sign(const RSA_METHOD
*meth
))
225 const unsigned char *m
, unsigned int m_length
,
226 unsigned char *sigret
, unsigned int *siglen
,
229 return meth
->rsa_sign
;
232 int RSA_meth_set_sign(RSA_METHOD
*meth
,
233 int (*sign
) (int type
, const unsigned char *m
,
234 unsigned int m_length
,
235 unsigned char *sigret
, unsigned int *siglen
,
238 meth
->rsa_sign
= sign
;
242 int (*RSA_meth_get_verify(const RSA_METHOD
*meth
))
243 (int dtype
, const unsigned char *m
,
244 unsigned int m_length
, const unsigned char *sigbuf
,
245 unsigned int siglen
, const RSA
*rsa
)
247 return meth
->rsa_verify
;
250 int RSA_meth_set_verify(RSA_METHOD
*meth
,
251 int (*verify
) (int dtype
, const unsigned char *m
,
252 unsigned int m_length
,
253 const unsigned char *sigbuf
,
254 unsigned int siglen
, const RSA
*rsa
))
256 meth
->rsa_verify
= verify
;
260 int (*RSA_meth_get_keygen(const RSA_METHOD
*meth
))
261 (RSA
*rsa
, int bits
, BIGNUM
*e
, BN_GENCB
*cb
)
263 return meth
->rsa_keygen
;
266 int RSA_meth_set_keygen(RSA_METHOD
*meth
,
267 int (*keygen
) (RSA
*rsa
, int bits
, BIGNUM
*e
,
270 meth
->rsa_keygen
= keygen
;
274 int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD
*meth
))
275 (RSA
*rsa
, int bits
, int primes
, BIGNUM
*e
, BN_GENCB
*cb
)
277 return meth
->rsa_multi_prime_keygen
;
280 int RSA_meth_set_multi_prime_keygen(RSA_METHOD
*meth
,
281 int (*keygen
) (RSA
*rsa
, int bits
,
282 int primes
, BIGNUM
*e
,
285 meth
->rsa_multi_prime_keygen
= keygen
;