]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/rsa/rsa_local.h
Remove RSA bignum_data that is not used anywhere
[thirdparty/openssl.git] / crypto / rsa / rsa_local.h
CommitLineData
9862e9aa 1/*
8020d79b 2 * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
9862e9aa 3 *
2a7b6f39 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
2039c421
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
9862e9aa 7 * https://www.openssl.org/source/license.html
9862e9aa
RL
8 */
9
ae4186b0
DMSP
10#ifndef OSSL_CRYPTO_RSA_LOCAL_H
11#define OSSL_CRYPTO_RSA_LOCAL_H
8240d5fa 12
2f545ae4 13#include "internal/refcount.h"
15671090 14#include "crypto/rsa.h"
9862e9aa 15
f9085209
BE
16#define RSA_MAX_PRIME_NUM 5
17#define RSA_MIN_MODULUS_BITS 512
665d899f
PY
18
19typedef struct rsa_prime_info_st {
20 BIGNUM *r;
21 BIGNUM *d;
22 BIGNUM *t;
23 /* save product of primes prior to this one */
24 BIGNUM *pp;
25 BN_MONT_CTX *m;
26} RSA_PRIME_INFO;
27
28DECLARE_ASN1_ITEM(RSA_PRIME_INFO)
29DEFINE_STACK_OF(RSA_PRIME_INFO)
30
4f2271d5
SL
31#if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
32struct rsa_acvp_test_st {
33 /* optional inputs */
34 BIGNUM *Xp1;
35 BIGNUM *Xp2;
36 BIGNUM *Xq1;
37 BIGNUM *Xq2;
38 BIGNUM *Xp;
39 BIGNUM *Xq;
40
41 /* optional outputs */
42 BIGNUM *p1;
43 BIGNUM *p2;
44 BIGNUM *q1;
45 BIGNUM *q2;
46};
47#endif
48
9862e9aa
RL
49struct rsa_st {
50 /*
ca7f7b95
RL
51 * #legacy
52 * The first field is used to pickup errors where this is passed
53 * instead of an EVP_PKEY. It is always zero.
54 * THIS MUST REMAIN THE FIRST FIELD.
9862e9aa 55 */
ca7f7b95
RL
56 int dummy_zero;
57
b4250010 58 OSSL_LIB_CTX *libctx;
6a32a3c0 59 int32_t version;
9862e9aa
RL
60 const RSA_METHOD *meth;
61 /* functional reference if 'meth' is ENGINE-provided */
62 ENGINE *engine;
63 BIGNUM *n;
64 BIGNUM *e;
65 BIGNUM *d;
66 BIGNUM *p;
67 BIGNUM *q;
68 BIGNUM *dmp1;
69 BIGNUM *dmq1;
70 BIGNUM *iqmp;
15671090
RL
71
72 /*
73 * If a PSS only key this contains the parameter restrictions.
74 * There are two structures for the same thing, used in different cases.
75 */
76 /* This is used uniquely by OpenSSL provider implementations. */
77 RSA_PSS_PARAMS_30 pss_params;
4f2271d5
SL
78
79#if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
80 RSA_ACVP_TEST *acvp_test;
15671090
RL
81#endif
82
f844f9eb 83#ifndef FIPS_MODULE
4f2271d5
SL
84 /* This is used uniquely by rsa_ameth.c and rsa_pmeth.c. */
85 RSA_PSS_PARAMS *pss;
665d899f
PY
86 /* for multi-prime RSA, defined in RFC 8017 */
87 STACK_OF(RSA_PRIME_INFO) *prime_infos;
d16d0b71 88 /* Be careful using this if the RSA structure is shared */
9862e9aa 89 CRYPTO_EX_DATA ex_data;
a3327784 90#endif
2f545ae4 91 CRYPTO_REF_COUNT references;
9862e9aa
RL
92 int flags;
93 /* Used to cache montgomery values */
94 BN_MONT_CTX *_method_mod_n;
95 BN_MONT_CTX *_method_mod_p;
96 BN_MONT_CTX *_method_mod_q;
9862e9aa
RL
97 BN_BLINDING *blinding;
98 BN_BLINDING *mt_blinding;
99 CRYPTO_RWLOCK *lock;
29be6023
RL
100
101 int dirty_cnt;
9862e9aa
RL
102};
103
b72c9121
RL
104struct rsa_meth_st {
105 char *name;
106 int (*rsa_pub_enc) (int flen, const unsigned char *from,
107 unsigned char *to, RSA *rsa, int padding);
108 int (*rsa_pub_dec) (int flen, const unsigned char *from,
109 unsigned char *to, RSA *rsa, int padding);
110 int (*rsa_priv_enc) (int flen, const unsigned char *from,
111 unsigned char *to, RSA *rsa, int padding);
112 int (*rsa_priv_dec) (int flen, const unsigned char *from,
113 unsigned char *to, RSA *rsa, int padding);
114 /* Can be null */
115 int (*rsa_mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
116 /* Can be null */
117 int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
118 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
119 /* called at new */
120 int (*init) (RSA *rsa);
121 /* called at free */
122 int (*finish) (RSA *rsa);
123 /* RSA_METHOD_FLAG_* things */
124 int flags;
125 /* may be needed! */
126 char *app_data;
127 /*
128 * New sign and verify functions: some libraries don't allow arbitrary
129 * data to be signed/verified: this allows them to be used. Note: for
130 * this to work the RSA_public_decrypt() and RSA_private_encrypt() should
8287a4c3 131 * *NOT* be used. RSA_sign(), RSA_verify() should be used instead.
b72c9121
RL
132 */
133 int (*rsa_sign) (int type,
134 const unsigned char *m, unsigned int m_length,
135 unsigned char *sigret, unsigned int *siglen,
136 const RSA *rsa);
137 int (*rsa_verify) (int dtype, const unsigned char *m,
138 unsigned int m_length, const unsigned char *sigbuf,
139 unsigned int siglen, const RSA *rsa);
140 /*
141 * If this callback is NULL, the builtin software RSA key-gen will be
142 * used. This is for behavioural compatibility whilst the code gets
143 * rewired, but one day it would be nice to assume there are no such
144 * things as "builtin software" implementations.
145 */
146 int (*rsa_keygen) (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
665d899f
PY
147 int (*rsa_multi_prime_keygen) (RSA *rsa, int bits, int primes,
148 BIGNUM *e, BN_GENCB *cb);
b72c9121
RL
149};
150
87ee7b22
DSH
151/* Macros to test if a pkey or ctx is for a PSS key */
152#define pkey_is_pss(pkey) (pkey->ameth->pkey_id == EVP_PKEY_RSA_PSS)
153#define pkey_ctx_is_pss(ctx) (ctx->pmeth->pkey_id == EVP_PKEY_RSA_PSS)
47e42b3c 154
4158b0dc
SL
155RSA_PSS_PARAMS *ossl_rsa_pss_params_create(const EVP_MD *sigmd,
156 const EVP_MD *mgf1md, int saltlen);
157int ossl_rsa_pss_get_param(const RSA_PSS_PARAMS *pss, const EVP_MD **pmd,
158 const EVP_MD **pmgf1md, int *psaltlen);
665d899f 159/* internal function to clear and free multi-prime parameters */
4158b0dc
SL
160void ossl_rsa_multip_info_free_ex(RSA_PRIME_INFO *pinfo);
161void ossl_rsa_multip_info_free(RSA_PRIME_INFO *pinfo);
162RSA_PRIME_INFO *ossl_rsa_multip_info_new(void);
163int ossl_rsa_multip_calc_product(RSA *rsa);
164int ossl_rsa_multip_cap(int bits);
8240d5fa 165
23b2fc0b
P
166int ossl_rsa_sp800_56b_validate_strength(int nbits, int strength);
167int ossl_rsa_check_pminusq_diff(BIGNUM *diff, const BIGNUM *p, const BIGNUM *q,
168 int nbits);
169int ossl_rsa_get_lcm(BN_CTX *ctx, const BIGNUM *p, const BIGNUM *q,
170 BIGNUM *lcm, BIGNUM *gcd, BIGNUM *p1, BIGNUM *q1,
171 BIGNUM *p1q1);
172
173int ossl_rsa_check_public_exponent(const BIGNUM *e);
174int ossl_rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx);
175int ossl_rsa_check_prime_factor(BIGNUM *p, BIGNUM *e, int nbits, BN_CTX *ctx);
176int ossl_rsa_check_prime_factor_range(const BIGNUM *p, int nbits, BN_CTX *ctx);
177int ossl_rsa_check_crt_components(const RSA *rsa, BN_CTX *ctx);
178
179int ossl_rsa_sp800_56b_pairwise_test(RSA *rsa, BN_CTX *ctx);
180int ossl_rsa_sp800_56b_check_public(const RSA *rsa);
181int ossl_rsa_sp800_56b_check_private(const RSA *rsa);
182int ossl_rsa_sp800_56b_check_keypair(const RSA *rsa, const BIGNUM *efixed,
183 int strength, int nbits);
184int ossl_rsa_sp800_56b_generate_key(RSA *rsa, int nbits, const BIGNUM *efixed,
185 BN_GENCB *cb);
186
187int ossl_rsa_sp800_56b_derive_params_from_pq(RSA *rsa, int nbits,
188 const BIGNUM *e, BN_CTX *ctx);
189int ossl_rsa_fips186_4_gen_prob_primes(RSA *rsa, RSA_ACVP_TEST *test,
190 int nbits, const BIGNUM *e, BN_CTX *ctx,
191 BN_GENCB *cb);
192
b4250010 193int ossl_rsa_padding_add_PKCS1_type_2_ex(OSSL_LIB_CTX *libctx, unsigned char *to,
23b2fc0b
P
194 int tlen, const unsigned char *from,
195 int flen);
0f2deef5 196
ae4186b0 197#endif /* OSSL_CRYPTO_RSA_LOCAL_H */