]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/rsa/rsa_locl.h
Fix VMS use of util/mkdef.pl in top build.info
[thirdparty/openssl.git] / crypto / rsa / rsa_locl.h
CommitLineData
9862e9aa 1/*
665d899f 2 * Copyright 2006-2017 The OpenSSL Project Authors. All Rights Reserved.
9862e9aa 3 *
2039c421
RS
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
9862e9aa 7 * https://www.openssl.org/source/license.html
9862e9aa
RL
8 */
9
10#include <openssl/rsa.h>
2f545ae4 11#include "internal/refcount.h"
9862e9aa 12
665d899f
PY
13#define RSA_MAX_PRIME_NUM 16
14#define RSA_MIN_PRIME_SIZE 64
cac19d19 15#define RSA_MIN_MODULUS_BITS 512
665d899f
PY
16
17typedef struct rsa_prime_info_st {
18 BIGNUM *r;
19 BIGNUM *d;
20 BIGNUM *t;
21 /* save product of primes prior to this one */
22 BIGNUM *pp;
23 BN_MONT_CTX *m;
24} RSA_PRIME_INFO;
25
26DECLARE_ASN1_ITEM(RSA_PRIME_INFO)
27DEFINE_STACK_OF(RSA_PRIME_INFO)
28
9862e9aa
RL
29struct rsa_st {
30 /*
31 * The first parameter is used to pickup errors where this is passed
0759f934 32 * instead of an EVP_PKEY, it is set to 0
9862e9aa
RL
33 */
34 int pad;
6a32a3c0 35 int32_t version;
9862e9aa
RL
36 const RSA_METHOD *meth;
37 /* functional reference if 'meth' is ENGINE-provided */
38 ENGINE *engine;
39 BIGNUM *n;
40 BIGNUM *e;
41 BIGNUM *d;
42 BIGNUM *p;
43 BIGNUM *q;
44 BIGNUM *dmp1;
45 BIGNUM *dmq1;
46 BIGNUM *iqmp;
665d899f
PY
47 /* for multi-prime RSA, defined in RFC 8017 */
48 STACK_OF(RSA_PRIME_INFO) *prime_infos;
d771441d
DSH
49 /* If a PSS only key this contains the parameter restrictions */
50 RSA_PSS_PARAMS *pss;
9862e9aa
RL
51 /* be careful using this if the RSA structure is shared */
52 CRYPTO_EX_DATA ex_data;
2f545ae4 53 CRYPTO_REF_COUNT references;
9862e9aa
RL
54 int flags;
55 /* Used to cache montgomery values */
56 BN_MONT_CTX *_method_mod_n;
57 BN_MONT_CTX *_method_mod_p;
58 BN_MONT_CTX *_method_mod_q;
59 /*
60 * all BIGNUM values are actually in the following data, if it is not
61 * NULL
62 */
63 char *bignum_data;
64 BN_BLINDING *blinding;
65 BN_BLINDING *mt_blinding;
66 CRYPTO_RWLOCK *lock;
67};
68
b72c9121
RL
69struct rsa_meth_st {
70 char *name;
71 int (*rsa_pub_enc) (int flen, const unsigned char *from,
72 unsigned char *to, RSA *rsa, int padding);
73 int (*rsa_pub_dec) (int flen, const unsigned char *from,
74 unsigned char *to, RSA *rsa, int padding);
75 int (*rsa_priv_enc) (int flen, const unsigned char *from,
76 unsigned char *to, RSA *rsa, int padding);
77 int (*rsa_priv_dec) (int flen, const unsigned char *from,
78 unsigned char *to, RSA *rsa, int padding);
79 /* Can be null */
80 int (*rsa_mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
81 /* Can be null */
82 int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
83 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
84 /* called at new */
85 int (*init) (RSA *rsa);
86 /* called at free */
87 int (*finish) (RSA *rsa);
88 /* RSA_METHOD_FLAG_* things */
89 int flags;
90 /* may be needed! */
91 char *app_data;
92 /*
93 * New sign and verify functions: some libraries don't allow arbitrary
94 * data to be signed/verified: this allows them to be used. Note: for
95 * this to work the RSA_public_decrypt() and RSA_private_encrypt() should
96 * *NOT* be used RSA_sign(), RSA_verify() should be used instead.
97 */
98 int (*rsa_sign) (int type,
99 const unsigned char *m, unsigned int m_length,
100 unsigned char *sigret, unsigned int *siglen,
101 const RSA *rsa);
102 int (*rsa_verify) (int dtype, const unsigned char *m,
103 unsigned int m_length, const unsigned char *sigbuf,
104 unsigned int siglen, const RSA *rsa);
105 /*
106 * If this callback is NULL, the builtin software RSA key-gen will be
107 * used. This is for behavioural compatibility whilst the code gets
108 * rewired, but one day it would be nice to assume there are no such
109 * things as "builtin software" implementations.
110 */
111 int (*rsa_keygen) (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
665d899f
PY
112 int (*rsa_multi_prime_keygen) (RSA *rsa, int bits, int primes,
113 BIGNUM *e, BN_GENCB *cb);
b72c9121
RL
114};
115
0f113f3e
MC
116extern int int_rsa_verify(int dtype, const unsigned char *m,
117 unsigned int m_len, unsigned char *rm,
118 size_t *prm_len, const unsigned char *sigbuf,
119 size_t siglen, RSA *rsa);
87ee7b22
DSH
120/* Macros to test if a pkey or ctx is for a PSS key */
121#define pkey_is_pss(pkey) (pkey->ameth->pkey_id == EVP_PKEY_RSA_PSS)
122#define pkey_ctx_is_pss(ctx) (ctx->pmeth->pkey_id == EVP_PKEY_RSA_PSS)
47e42b3c
DSH
123
124RSA_PSS_PARAMS *rsa_pss_params_create(const EVP_MD *sigmd,
125 const EVP_MD *mgf1md, int saltlen);
cfd81c6d
DSH
126int rsa_pss_get_param(const RSA_PSS_PARAMS *pss, const EVP_MD **pmd,
127 const EVP_MD **pmgf1md, int *psaltlen);
665d899f
PY
128/* internal function to clear and free multi-prime parameters */
129void rsa_multip_info_free_ex(RSA_PRIME_INFO *pinfo);
130void rsa_multip_info_free(RSA_PRIME_INFO *pinfo);
131RSA_PRIME_INFO *rsa_multip_info_new(void);
132int rsa_multip_calc_product(RSA *rsa);
0122add6 133int rsa_multip_cap(int bits);