]>
Commit | Line | Data |
---|---|---|
21dcbebc | 1 | /* |
a28d06f3 | 2 | * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. |
d02b48c6 | 3 | * |
48f4ad77 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
21dcbebc RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
ae4186b0 DMSP |
10 | #ifndef OPENSSL_RSA_H |
11 | # define OPENSSL_RSA_H | |
d86167ec DMSP |
12 | # pragma once |
13 | ||
14 | # include <openssl/macros.h> | |
936c2b9e | 15 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
d86167ec DMSP |
16 | # define HEADER_RSA_H |
17 | # endif | |
d02b48c6 | 18 | |
98186eb4 | 19 | # include <openssl/opensslconf.h> |
78d3b819 | 20 | |
3a1ee3c1 RL |
21 | # include <openssl/asn1.h> |
22 | # include <openssl/bio.h> | |
23 | # include <openssl/crypto.h> | |
24 | # include <openssl/types.h> | |
25 | # ifndef OPENSSL_NO_DEPRECATED_1_1_0 | |
26 | # include <openssl/bn.h> | |
27 | # endif | |
28 | # include <openssl/rsaerr.h> | |
29 | # include <openssl/safestack.h> | |
f93107d8 | 30 | |
3a1ee3c1 | 31 | # ifdef __cplusplus |
82271cee | 32 | extern "C" { |
3a1ee3c1 | 33 | # endif |
03f8b042 | 34 | |
3a1ee3c1 RL |
35 | # ifndef OPENSSL_RSA_MAX_MODULUS_BITS |
36 | # define OPENSSL_RSA_MAX_MODULUS_BITS 16384 | |
37 | # endif | |
0f113f3e | 38 | |
3a1ee3c1 RL |
39 | # define RSA_3 0x3L |
40 | # define RSA_F4 0x10001L | |
d7e498ac | 41 | |
3a1ee3c1 | 42 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
c5f87134 | 43 | /* The types RSA and RSA_METHOD are defined in ossl_typ.h */ |
0f113f3e | 44 | |
3a1ee3c1 | 45 | # define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 2048 |
c5f87134 | 46 | |
3a1ee3c1 RL |
47 | # ifndef OPENSSL_RSA_SMALL_MODULUS_BITS |
48 | # define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 | |
49 | # endif | |
dbd87ffc MC |
50 | |
51 | /* exponent limit enforced for "large" modulus only */ | |
3a1ee3c1 RL |
52 | # ifndef OPENSSL_RSA_MAX_PUBEXP_BITS |
53 | # define OPENSSL_RSA_MAX_PUBEXP_BITS 64 | |
54 | # endif | |
665d899f | 55 | /* based on RFC 8017 appendix A.1.2 */ |
3a1ee3c1 RL |
56 | # define RSA_ASN1_VERSION_DEFAULT 0 |
57 | # define RSA_ASN1_VERSION_MULTI 1 | |
665d899f | 58 | |
3a1ee3c1 | 59 | # define RSA_DEFAULT_PRIME_NUM 2 |
665d899f | 60 | |
3a1ee3c1 RL |
61 | # define RSA_METHOD_FLAG_NO_CHECK 0x0001 |
62 | # define RSA_FLAG_CACHE_PUBLIC 0x0002 | |
63 | # define RSA_FLAG_CACHE_PRIVATE 0x0004 | |
64 | # define RSA_FLAG_BLINDING 0x0008 | |
65 | # define RSA_FLAG_THREAD_SAFE 0x0010 | |
0f113f3e MC |
66 | /* |
67 | * This flag means the private key operations will be handled by rsa_mod_exp | |
770d19b8 | 68 | * and that they do not depend on the private key components being present: |
0f113f3e MC |
69 | * for example a key stored in external hardware. Without this flag |
70 | * bn_mod_exp gets called when private key components are absent. | |
770d19b8 | 71 | */ |
3a1ee3c1 | 72 | # define RSA_FLAG_EXT_PKEY 0x0020 |
58964a49 | 73 | |
dbd87ffc MC |
74 | /* |
75 | * new with 0.9.6j and 0.9.7b; the built-in | |
76 | * RSA implementation now uses blinding by | |
77 | * default (ignoring RSA_FLAG_BLINDING), | |
78 | * but other engines might not need it | |
79 | */ | |
3a1ee3c1 RL |
80 | # define RSA_FLAG_NO_BLINDING 0x0080 |
81 | # endif /* OPENSSL_NO_DEPRECATED_3_0 */ | |
dbd87ffc | 82 | /* |
5584f65a | 83 | * Does nothing. Previously this switched off constant time behaviour. |
0f113f3e | 84 | */ |
3a1ee3c1 RL |
85 | # ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
86 | # define RSA_FLAG_NO_CONSTTIME 0x0000 | |
87 | # endif | |
dbd87ffc MC |
88 | /* deprecated name for the flag*/ |
89 | /* | |
90 | * new with 0.9.7h; the built-in RSA | |
91 | * implementation now uses constant time | |
92 | * modular exponentiation for secret exponents | |
93 | * by default. This flag causes the | |
94 | * faster variable sliding window method to | |
95 | * be used for all exponents. | |
96 | */ | |
3a1ee3c1 RL |
97 | # ifndef OPENSSL_NO_DEPRECATED_0_9_8 |
98 | # define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME | |
99 | # endif | |
0f113f3e | 100 | |
484d1a73 RL |
101 | /*- |
102 | * New with 3.0: use part of the flags to denote exact type of RSA key, | |
103 | * some of which are limited to specific signature and encryption schemes. | |
104 | * These different types share the same RSA structure, but indicate the | |
105 | * use of certain fields in that structure. | |
106 | * Currently known are: | |
107 | * RSA - this is the "normal" unlimited RSA structure (typenum 0) | |
108 | * RSASSA-PSS - indicates that the PSS parameters are used. | |
109 | * RSAES-OAEP - no specific field used for the moment, but OAEP padding | |
110 | * is expected. (currently unused) | |
111 | * | |
112 | * 4 bits allow for 16 types | |
113 | */ | |
3a1ee3c1 RL |
114 | # define RSA_FLAG_TYPE_MASK 0xF000 |
115 | # define RSA_FLAG_TYPE_RSA 0x0000 | |
116 | # define RSA_FLAG_TYPE_RSASSAPSS 0x1000 | |
117 | # define RSA_FLAG_TYPE_RSAESOAEP 0x2000 | |
484d1a73 | 118 | |
89abd1b6 MC |
119 | int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad_mode); |
120 | int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, int *pad_mode); | |
0f113f3e | 121 | |
6f4b7663 RL |
122 | int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen); |
123 | int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int *saltlen); | |
124 | ||
2972af10 | 125 | int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int bits); |
3786d748 | 126 | int EVP_PKEY_CTX_set1_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp); |
2972af10 | 127 | int EVP_PKEY_CTX_set_rsa_keygen_primes(EVP_PKEY_CTX *ctx, int primes); |
e25761b1 | 128 | int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX *ctx, int saltlen); |
3a1ee3c1 | 129 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
d7e498ac RL |
130 | OSSL_DEPRECATEDIN_3_0 |
131 | int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp); | |
3a1ee3c1 | 132 | # endif |
2972af10 | 133 | |
137096a7 | 134 | /* Salt length matches digest */ |
3a1ee3c1 | 135 | # define RSA_PSS_SALTLEN_DIGEST -1 |
137096a7 | 136 | /* Verify only: auto detect salt length */ |
3a1ee3c1 | 137 | # define RSA_PSS_SALTLEN_AUTO -2 |
137096a7 | 138 | /* Set salt length to maximum possible */ |
3a1ee3c1 | 139 | # define RSA_PSS_SALTLEN_MAX -3 |
137096a7 | 140 | /* Old compatible max salt length for sign only */ |
3a1ee3c1 | 141 | # define RSA_PSS_SALTLEN_MAX_SIGN -2 |
0f113f3e | 142 | |
89abd1b6 MC |
143 | int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); |
144 | int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname, | |
145 | const char *mdprops); | |
146 | int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD **md); | |
147 | int EVP_PKEY_CTX_get_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, char *name, | |
148 | size_t namelen); | |
e25761b1 RL |
149 | int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); |
150 | int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name(EVP_PKEY_CTX *ctx, | |
151 | const char *mdname); | |
e64b2b5c | 152 | |
e947a064 DB |
153 | int EVP_PKEY_CTX_set_rsa_pss_keygen_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); |
154 | int EVP_PKEY_CTX_set_rsa_pss_keygen_md_name(EVP_PKEY_CTX *ctx, | |
155 | const char *mdname, | |
156 | const char *mdprops); | |
157 | ||
89abd1b6 MC |
158 | int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); |
159 | int EVP_PKEY_CTX_set_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, const char *mdname, | |
160 | const char *mdprops); | |
161 | int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD **md); | |
162 | int EVP_PKEY_CTX_get_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, char *name, | |
163 | size_t namelen); | |
c5f87134 | 164 | int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, void *label, int llen); |
89abd1b6 | 165 | int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, unsigned char **label); |
0f113f3e | 166 | |
3a1ee3c1 RL |
167 | # define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1) |
168 | # define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2) | |
0f113f3e | 169 | |
3a1ee3c1 RL |
170 | # define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3) |
171 | # define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4) | |
172 | # define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5) | |
0f113f3e | 173 | |
3a1ee3c1 RL |
174 | # define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6) |
175 | # define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7) | |
176 | # define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8) | |
0f113f3e | 177 | |
3a1ee3c1 RL |
178 | # define EVP_PKEY_CTRL_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 9) |
179 | # define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 10) | |
0f113f3e | 180 | |
3a1ee3c1 RL |
181 | # define EVP_PKEY_CTRL_GET_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 11) |
182 | # define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12) | |
0f113f3e | 183 | |
3a1ee3c1 | 184 | # define EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES (EVP_PKEY_ALG_CTRL + 13) |
665d899f | 185 | |
3a1ee3c1 | 186 | # define RSA_PKCS1_PADDING 1 |
3a1ee3c1 RL |
187 | # define RSA_NO_PADDING 3 |
188 | # define RSA_PKCS1_OAEP_PADDING 4 | |
189 | # define RSA_X931_PADDING 5 | |
d9a75107 | 190 | |
29db322e | 191 | /* EVP_PKEY_ only */ |
3a1ee3c1 RL |
192 | # define RSA_PKCS1_PSS_PADDING 6 |
193 | # define RSA_PKCS1_WITH_TLS_PADDING 7 | |
58964a49 | 194 | |
3a1ee3c1 | 195 | # define RSA_PKCS1_PADDING_SIZE 11 |
ba8ad074 | 196 | |
3a1ee3c1 RL |
197 | # define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) |
198 | # define RSA_get_app_data(s) RSA_get_ex_data(s,0) | |
d02b48c6 | 199 | |
3a1ee3c1 | 200 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
d7e498ac RL |
201 | OSSL_DEPRECATEDIN_3_0 RSA *RSA_new(void); |
202 | OSSL_DEPRECATEDIN_3_0 RSA *RSA_new_method(ENGINE *engine); | |
203 | OSSL_DEPRECATEDIN_3_0 int RSA_bits(const RSA *rsa); | |
204 | OSSL_DEPRECATEDIN_3_0 int RSA_size(const RSA *rsa); | |
205 | OSSL_DEPRECATEDIN_3_0 int RSA_security_bits(const RSA *rsa); | |
206 | ||
207 | OSSL_DEPRECATEDIN_3_0 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d); | |
208 | OSSL_DEPRECATEDIN_3_0 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q); | |
209 | OSSL_DEPRECATEDIN_3_0 int RSA_set0_crt_params(RSA *r, | |
210 | BIGNUM *dmp1, BIGNUM *dmq1, | |
211 | BIGNUM *iqmp); | |
212 | OSSL_DEPRECATEDIN_3_0 int RSA_set0_multi_prime_params(RSA *r, | |
213 | BIGNUM *primes[], | |
214 | BIGNUM *exps[], | |
215 | BIGNUM *coeffs[], | |
216 | int pnum); | |
217 | OSSL_DEPRECATEDIN_3_0 void RSA_get0_key(const RSA *r, | |
218 | const BIGNUM **n, const BIGNUM **e, | |
219 | const BIGNUM **d); | |
220 | OSSL_DEPRECATEDIN_3_0 void RSA_get0_factors(const RSA *r, | |
221 | const BIGNUM **p, const BIGNUM **q); | |
222 | OSSL_DEPRECATEDIN_3_0 int RSA_get_multi_prime_extra_count(const RSA *r); | |
223 | OSSL_DEPRECATEDIN_3_0 int RSA_get0_multi_prime_factors(const RSA *r, | |
224 | const BIGNUM *primes[]); | |
225 | OSSL_DEPRECATEDIN_3_0 void RSA_get0_crt_params(const RSA *r, | |
226 | const BIGNUM **dmp1, | |
227 | const BIGNUM **dmq1, | |
228 | const BIGNUM **iqmp); | |
229 | OSSL_DEPRECATEDIN_3_0 | |
665d899f PY |
230 | int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[], |
231 | const BIGNUM *coeffs[]); | |
d7e498ac RL |
232 | OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_n(const RSA *d); |
233 | OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_e(const RSA *d); | |
234 | OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_d(const RSA *d); | |
235 | OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_p(const RSA *d); | |
236 | OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_q(const RSA *d); | |
237 | OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_dmp1(const RSA *r); | |
238 | OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_dmq1(const RSA *r); | |
239 | OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_iqmp(const RSA *r); | |
240 | OSSL_DEPRECATEDIN_3_0 const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r); | |
241 | OSSL_DEPRECATEDIN_3_0 void RSA_clear_flags(RSA *r, int flags); | |
242 | OSSL_DEPRECATEDIN_3_0 int RSA_test_flags(const RSA *r, int flags); | |
243 | OSSL_DEPRECATEDIN_3_0 void RSA_set_flags(RSA *r, int flags); | |
244 | OSSL_DEPRECATEDIN_3_0 int RSA_get_version(RSA *r); | |
245 | OSSL_DEPRECATEDIN_3_0 ENGINE *RSA_get0_engine(const RSA *r); | |
3a1ee3c1 | 246 | # endif /* !OPENSSL_NO_DEPRECATED_3_0 */ |
9862e9aa | 247 | |
e9224c71 | 248 | /* Deprecated version */ |
3a1ee3c1 | 249 | # ifndef OPENSSL_NO_DEPRECATED_0_9_8 |
d7e498ac RL |
250 | OSSL_DEPRECATEDIN_0_9_8 RSA *RSA_generate_key(int bits, unsigned long e, void |
251 | (*callback) (int, int, void *), | |
252 | void *cb_arg); | |
3a1ee3c1 | 253 | # endif |
e9224c71 GT |
254 | |
255 | /* New version */ | |
3a1ee3c1 | 256 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
d7e498ac RL |
257 | OSSL_DEPRECATEDIN_3_0 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, |
258 | BN_GENCB *cb); | |
665d899f | 259 | /* Multi-prime version */ |
d7e498ac RL |
260 | OSSL_DEPRECATEDIN_3_0 int RSA_generate_multi_prime_key(RSA *rsa, int bits, |
261 | int primes, BIGNUM *e, | |
262 | BN_GENCB *cb); | |
263 | ||
264 | OSSL_DEPRECATEDIN_3_0 | |
265 | int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, | |
266 | BIGNUM *q1, BIGNUM *q2, | |
267 | const BIGNUM *Xp1, const BIGNUM *Xp2, | |
268 | const BIGNUM *Xp, const BIGNUM *Xq1, | |
269 | const BIGNUM *Xq2, const BIGNUM *Xq, | |
270 | const BIGNUM *e, BN_GENCB *cb); | |
271 | OSSL_DEPRECATEDIN_3_0 int RSA_X931_generate_key_ex(RSA *rsa, int bits, | |
272 | const BIGNUM *e, | |
273 | BN_GENCB *cb); | |
274 | ||
275 | OSSL_DEPRECATEDIN_3_0 int RSA_check_key(const RSA *); | |
276 | OSSL_DEPRECATEDIN_3_0 int RSA_check_key_ex(const RSA *, BN_GENCB *cb); | |
0f113f3e | 277 | /* next 4 return -1 on error */ |
d7e498ac RL |
278 | OSSL_DEPRECATEDIN_3_0 |
279 | int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to, | |
280 | RSA *rsa, int padding); | |
281 | OSSL_DEPRECATEDIN_3_0 | |
282 | int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to, | |
283 | RSA *rsa, int padding); | |
284 | OSSL_DEPRECATEDIN_3_0 | |
285 | int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to, | |
286 | RSA *rsa, int padding); | |
287 | OSSL_DEPRECATEDIN_3_0 | |
288 | int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to, | |
289 | RSA *rsa, int padding); | |
290 | OSSL_DEPRECATEDIN_3_0 void RSA_free(RSA *r); | |
5cbc2e8b | 291 | /* "up" the RSA object's reference count */ |
d7e498ac RL |
292 | OSSL_DEPRECATEDIN_3_0 int RSA_up_ref(RSA *r); |
293 | OSSL_DEPRECATEDIN_3_0 int RSA_flags(const RSA *r); | |
58964a49 | 294 | |
d7e498ac RL |
295 | OSSL_DEPRECATEDIN_3_0 void RSA_set_default_method(const RSA_METHOD *meth); |
296 | OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_get_default_method(void); | |
297 | OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_null_method(void); | |
298 | OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_get_method(const RSA *rsa); | |
299 | OSSL_DEPRECATEDIN_3_0 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); | |
d02b48c6 | 300 | |
b0700d2c | 301 | /* these are the actual RSA functions */ |
d7e498ac | 302 | OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_PKCS1_OpenSSL(void); |
d02b48c6 | 303 | |
d7e498ac RL |
304 | DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0, |
305 | RSA, RSAPublicKey) | |
306 | DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0, | |
307 | RSA, RSAPrivateKey) | |
3a1ee3c1 | 308 | # endif /* !OPENSSL_NO_DEPRECATED_3_0 */ |
e5e04ee3 | 309 | |
d7e498ac | 310 | int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2); |
78d3b819 | 311 | |
677add38 | 312 | struct rsa_pss_params_st { |
0f113f3e MC |
313 | X509_ALGOR *hashAlgorithm; |
314 | X509_ALGOR *maskGenAlgorithm; | |
315 | ASN1_INTEGER *saltLength; | |
316 | ASN1_INTEGER *trailerField; | |
6745a1ff DSH |
317 | /* Decoded hash algorithm from maskGenAlgorithm */ |
318 | X509_ALGOR *maskHash; | |
677add38 | 319 | }; |
ff04bbe3 | 320 | |
63b825c9 | 321 | DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS) |
2145ba5e | 322 | DECLARE_ASN1_DUP_FUNCTION(RSA_PSS_PARAMS) |
ff04bbe3 | 323 | |
0f113f3e MC |
324 | typedef struct rsa_oaep_params_st { |
325 | X509_ALGOR *hashFunc; | |
326 | X509_ALGOR *maskGenFunc; | |
327 | X509_ALGOR *pSourceFunc; | |
6745a1ff DSH |
328 | /* Decoded hash algorithm from maskGenFunc */ |
329 | X509_ALGOR *maskHash; | |
0f113f3e | 330 | } RSA_OAEP_PARAMS; |
0574cadf DSH |
331 | |
332 | DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS) | |
333 | ||
3a1ee3c1 RL |
334 | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
335 | # ifndef OPENSSL_NO_STDIO | |
d7e498ac | 336 | OSSL_DEPRECATEDIN_3_0 int RSA_print_fp(FILE *fp, const RSA *r, int offset); |
3a1ee3c1 | 337 | # endif |
d02b48c6 | 338 | |
d7e498ac | 339 | OSSL_DEPRECATEDIN_3_0 int RSA_print(BIO *bp, const RSA *r, int offset); |
d02b48c6 | 340 | |
0f113f3e MC |
341 | /* |
342 | * The following 2 functions sign and verify a X509_SIG ASN1 object inside | |
343 | * PKCS#1 padded RSA encryption | |
344 | */ | |
d7e498ac RL |
345 | OSSL_DEPRECATEDIN_3_0 int RSA_sign(int type, const unsigned char *m, |
346 | unsigned int m_length, unsigned char *sigret, | |
347 | unsigned int *siglen, RSA *rsa); | |
348 | OSSL_DEPRECATEDIN_3_0 int RSA_verify(int type, const unsigned char *m, | |
349 | unsigned int m_length, | |
350 | const unsigned char *sigbuf, | |
351 | unsigned int siglen, RSA *rsa); | |
d02b48c6 | 352 | |
0f113f3e MC |
353 | /* |
354 | * The following 2 function sign and verify a ASN1_OCTET_STRING object inside | |
355 | * PKCS#1 padded RSA encryption | |
356 | */ | |
d7e498ac RL |
357 | OSSL_DEPRECATEDIN_3_0 |
358 | int RSA_sign_ASN1_OCTET_STRING(int type, | |
359 | const unsigned char *m, unsigned int m_length, | |
360 | unsigned char *sigret, unsigned int *siglen, | |
361 | RSA *rsa); | |
362 | OSSL_DEPRECATEDIN_3_0 | |
363 | int RSA_verify_ASN1_OCTET_STRING(int type, | |
364 | const unsigned char *m, unsigned int m_length, | |
365 | unsigned char *sigbuf, unsigned int siglen, | |
366 | RSA *rsa); | |
367 | ||
368 | OSSL_DEPRECATEDIN_3_0 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); | |
369 | OSSL_DEPRECATEDIN_3_0 void RSA_blinding_off(RSA *rsa); | |
370 | OSSL_DEPRECATEDIN_3_0 BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx); | |
371 | ||
372 | OSSL_DEPRECATEDIN_3_0 | |
373 | int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, | |
374 | const unsigned char *f, int fl); | |
375 | OSSL_DEPRECATEDIN_3_0 | |
376 | int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, | |
377 | const unsigned char *f, int fl, | |
378 | int rsa_len); | |
379 | OSSL_DEPRECATEDIN_3_0 | |
380 | int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, | |
381 | const unsigned char *f, int fl); | |
382 | OSSL_DEPRECATEDIN_3_0 | |
383 | int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, | |
384 | const unsigned char *f, int fl, | |
385 | int rsa_len); | |
386 | OSSL_DEPRECATEDIN_3_0 int PKCS1_MGF1(unsigned char *mask, long len, | |
387 | const unsigned char *seed, long seedlen, | |
388 | const EVP_MD *dgst); | |
389 | OSSL_DEPRECATEDIN_3_0 | |
390 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, | |
391 | const unsigned char *f, int fl, | |
392 | const unsigned char *p, int pl); | |
393 | OSSL_DEPRECATEDIN_3_0 | |
394 | int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, | |
395 | const unsigned char *f, int fl, int rsa_len, | |
396 | const unsigned char *p, int pl); | |
397 | OSSL_DEPRECATEDIN_3_0 | |
398 | int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, | |
399 | const unsigned char *from, int flen, | |
400 | const unsigned char *param, int plen, | |
401 | const EVP_MD *md, const EVP_MD *mgf1md); | |
402 | OSSL_DEPRECATEDIN_3_0 | |
403 | int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, | |
404 | const unsigned char *from, int flen, | |
405 | int num, | |
406 | const unsigned char *param, int plen, | |
407 | const EVP_MD *md, const EVP_MD *mgf1md); | |
d7e498ac RL |
408 | OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_none(unsigned char *to, int tlen, |
409 | const unsigned char *f, int fl); | |
410 | OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_none(unsigned char *to, int tlen, | |
411 | const unsigned char *f, int fl, | |
412 | int rsa_len); | |
413 | OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_X931(unsigned char *to, int tlen, | |
414 | const unsigned char *f, int fl); | |
415 | OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_X931(unsigned char *to, int tlen, | |
416 | const unsigned char *f, int fl, | |
417 | int rsa_len); | |
418 | OSSL_DEPRECATEDIN_3_0 int RSA_X931_hash_id(int nid); | |
419 | ||
420 | OSSL_DEPRECATEDIN_3_0 | |
421 | int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash, | |
422 | const EVP_MD *Hash, const unsigned char *EM, | |
423 | int sLen); | |
424 | OSSL_DEPRECATEDIN_3_0 | |
425 | int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM, | |
426 | const unsigned char *mHash, const EVP_MD *Hash, | |
427 | int sLen); | |
428 | ||
429 | OSSL_DEPRECATEDIN_3_0 | |
430 | int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, | |
431 | const EVP_MD *Hash, const EVP_MD *mgf1Hash, | |
432 | const unsigned char *EM, int sLen); | |
433 | ||
434 | OSSL_DEPRECATEDIN_3_0 | |
435 | int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, | |
436 | const unsigned char *mHash, | |
437 | const EVP_MD *Hash, const EVP_MD *mgf1Hash, | |
438 | int sLen); | |
c553721e | 439 | |
3a1ee3c1 | 440 | # define RSA_get_ex_new_index(l, p, newf, dupf, freef) \ |
e6390aca | 441 | CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef) |
d7e498ac RL |
442 | OSSL_DEPRECATEDIN_3_0 int RSA_set_ex_data(RSA *r, int idx, void *arg); |
443 | OSSL_DEPRECATEDIN_3_0 void *RSA_get_ex_data(const RSA *r, int idx); | |
58964a49 | 444 | |
d7e498ac RL |
445 | DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPublicKey) |
446 | DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPrivateKey) | |
40889b9c | 447 | |
0f113f3e MC |
448 | /* |
449 | * If this flag is set the RSA method is FIPS compliant and can be used in | |
450 | * FIPS mode. This is set in the validated module method. If an application | |
451 | * sets this flag in its own methods it is its responsibility to ensure the | |
452 | * result is compliant. | |
c553721e DSH |
453 | */ |
454 | ||
3a1ee3c1 | 455 | # define RSA_FLAG_FIPS_METHOD 0x0400 |
c553721e | 456 | |
0f113f3e MC |
457 | /* |
458 | * If this flag is set the operations normally disabled in FIPS mode are | |
c553721e DSH |
459 | * permitted it is then the applications responsibility to ensure that the |
460 | * usage is compliant. | |
461 | */ | |
462 | ||
3a1ee3c1 | 463 | # define RSA_FLAG_NON_FIPS_ALLOW 0x0400 |
0f113f3e MC |
464 | /* |
465 | * Application has decided PRNG is good enough to generate a key: don't | |
cac4fb58 DSH |
466 | * check. |
467 | */ | |
3a1ee3c1 | 468 | # define RSA_FLAG_CHECKED 0x0800 |
c5f87134 | 469 | |
d7e498ac RL |
470 | OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_new(const char *name, int flags); |
471 | OSSL_DEPRECATEDIN_3_0 void RSA_meth_free(RSA_METHOD *meth); | |
472 | OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth); | |
473 | OSSL_DEPRECATEDIN_3_0 const char *RSA_meth_get0_name(const RSA_METHOD *meth); | |
474 | OSSL_DEPRECATEDIN_3_0 int RSA_meth_set1_name(RSA_METHOD *meth, | |
475 | const char *name); | |
476 | OSSL_DEPRECATEDIN_3_0 int RSA_meth_get_flags(const RSA_METHOD *meth); | |
477 | OSSL_DEPRECATEDIN_3_0 int RSA_meth_set_flags(RSA_METHOD *meth, int flags); | |
478 | OSSL_DEPRECATEDIN_3_0 void *RSA_meth_get0_app_data(const RSA_METHOD *meth); | |
479 | OSSL_DEPRECATEDIN_3_0 int RSA_meth_set0_app_data(RSA_METHOD *meth, | |
480 | void *app_data); | |
481 | OSSL_DEPRECATEDIN_3_0 | |
482 | int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth)) (int flen, | |
483 | const unsigned char *from, | |
484 | unsigned char *to, | |
485 | RSA *rsa, int padding); | |
486 | OSSL_DEPRECATEDIN_3_0 | |
487 | int RSA_meth_set_pub_enc(RSA_METHOD *rsa, | |
b72c9121 RL |
488 | int (*pub_enc) (int flen, const unsigned char *from, |
489 | unsigned char *to, RSA *rsa, | |
d7e498ac RL |
490 | int padding)); |
491 | OSSL_DEPRECATEDIN_3_0 | |
492 | int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth)) (int flen, | |
493 | const unsigned char *from, | |
494 | unsigned char *to, | |
495 | RSA *rsa, int padding); | |
496 | OSSL_DEPRECATEDIN_3_0 | |
497 | int RSA_meth_set_pub_dec(RSA_METHOD *rsa, | |
b72c9121 RL |
498 | int (*pub_dec) (int flen, const unsigned char *from, |
499 | unsigned char *to, RSA *rsa, | |
d7e498ac RL |
500 | int padding)); |
501 | OSSL_DEPRECATEDIN_3_0 | |
502 | int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth)) (int flen, | |
503 | const unsigned char *from, | |
504 | unsigned char *to, | |
505 | RSA *rsa, int padding); | |
506 | OSSL_DEPRECATEDIN_3_0 | |
507 | int RSA_meth_set_priv_enc(RSA_METHOD *rsa, | |
b72c9121 RL |
508 | int (*priv_enc) (int flen, const unsigned char *from, |
509 | unsigned char *to, RSA *rsa, | |
d7e498ac RL |
510 | int padding)); |
511 | OSSL_DEPRECATEDIN_3_0 | |
512 | int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth)) (int flen, | |
513 | const unsigned char *from, | |
514 | unsigned char *to, | |
515 | RSA *rsa, int padding); | |
516 | OSSL_DEPRECATEDIN_3_0 | |
517 | int RSA_meth_set_priv_dec(RSA_METHOD *rsa, | |
b72c9121 RL |
518 | int (*priv_dec) (int flen, const unsigned char *from, |
519 | unsigned char *to, RSA *rsa, | |
d7e498ac RL |
520 | int padding)); |
521 | OSSL_DEPRECATEDIN_3_0 | |
522 | int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth)) (BIGNUM *r0, | |
523 | const BIGNUM *i, | |
524 | RSA *rsa, BN_CTX *ctx); | |
525 | OSSL_DEPRECATEDIN_3_0 | |
526 | int RSA_meth_set_mod_exp(RSA_METHOD *rsa, | |
972f6788 | 527 | int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa, |
d7e498ac RL |
528 | BN_CTX *ctx)); |
529 | OSSL_DEPRECATEDIN_3_0 | |
530 | int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth)) (BIGNUM *r, | |
531 | const BIGNUM *a, | |
532 | const BIGNUM *p, | |
533 | const BIGNUM *m, | |
534 | BN_CTX *ctx, | |
535 | BN_MONT_CTX *m_ctx); | |
536 | OSSL_DEPRECATEDIN_3_0 | |
537 | int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa, | |
b72c9121 RL |
538 | int (*bn_mod_exp) (BIGNUM *r, |
539 | const BIGNUM *a, | |
540 | const BIGNUM *p, | |
541 | const BIGNUM *m, | |
542 | BN_CTX *ctx, | |
d7e498ac RL |
543 | BN_MONT_CTX *m_ctx)); |
544 | OSSL_DEPRECATEDIN_3_0 | |
545 | int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa); | |
546 | OSSL_DEPRECATEDIN_3_0 | |
547 | int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa)); | |
548 | OSSL_DEPRECATEDIN_3_0 | |
549 | int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa); | |
550 | OSSL_DEPRECATEDIN_3_0 | |
551 | int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa)); | |
552 | OSSL_DEPRECATEDIN_3_0 | |
553 | int (*RSA_meth_get_sign(const RSA_METHOD *meth)) (int type, | |
554 | const unsigned char *m, | |
555 | unsigned int m_length, | |
556 | unsigned char *sigret, | |
557 | unsigned int *siglen, | |
558 | const RSA *rsa); | |
559 | OSSL_DEPRECATEDIN_3_0 | |
560 | int RSA_meth_set_sign(RSA_METHOD *rsa, | |
b72c9121 RL |
561 | int (*sign) (int type, const unsigned char *m, |
562 | unsigned int m_length, | |
563 | unsigned char *sigret, unsigned int *siglen, | |
d7e498ac RL |
564 | const RSA *rsa)); |
565 | OSSL_DEPRECATEDIN_3_0 | |
566 | int (*RSA_meth_get_verify(const RSA_METHOD *meth)) (int dtype, | |
567 | const unsigned char *m, | |
568 | unsigned int m_length, | |
569 | const unsigned char *sigbuf, | |
570 | unsigned int siglen, | |
571 | const RSA *rsa); | |
572 | OSSL_DEPRECATEDIN_3_0 | |
573 | int RSA_meth_set_verify(RSA_METHOD *rsa, | |
b72c9121 RL |
574 | int (*verify) (int dtype, const unsigned char *m, |
575 | unsigned int m_length, | |
576 | const unsigned char *sigbuf, | |
d7e498ac RL |
577 | unsigned int siglen, const RSA *rsa)); |
578 | OSSL_DEPRECATEDIN_3_0 | |
579 | int (*RSA_meth_get_keygen(const RSA_METHOD *meth)) (RSA *rsa, int bits, | |
580 | BIGNUM *e, BN_GENCB *cb); | |
581 | OSSL_DEPRECATEDIN_3_0 | |
582 | int RSA_meth_set_keygen(RSA_METHOD *rsa, | |
b72c9121 | 583 | int (*keygen) (RSA *rsa, int bits, BIGNUM *e, |
d7e498ac RL |
584 | BN_GENCB *cb)); |
585 | OSSL_DEPRECATEDIN_3_0 | |
586 | int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth)) (RSA *rsa, | |
587 | int bits, | |
588 | int primes, | |
589 | BIGNUM *e, | |
590 | BN_GENCB *cb); | |
591 | OSSL_DEPRECATEDIN_3_0 | |
592 | int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth, | |
665d899f PY |
593 | int (*keygen) (RSA *rsa, int bits, |
594 | int primes, BIGNUM *e, | |
d7e498ac RL |
595 | BN_GENCB *cb)); |
596 | #endif /* !OPENSSL_NO_DEPRECATED_3_0 */ | |
6d311938 | 597 | |
3a1ee3c1 | 598 | # ifdef __cplusplus |
d02b48c6 | 599 | } |
3c27208f | 600 | # endif |
d02b48c6 | 601 | #endif |