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

source code of include/openssl/rsa.h