fix a few more style issues
[openssl.git] / crypto / rsa / rsa_locl.h
1 /*
2  * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #include <openssl/rsa.h>
11 #include "internal/refcount.h"
12
13 struct rsa_st {
14     /*
15      * The first parameter is used to pickup errors where this is passed
16      * instead of aEVP_PKEY, it is set to 0
17      */
18     int pad;
19     long version;
20     const RSA_METHOD *meth;
21     /* functional reference if 'meth' is ENGINE-provided */
22     ENGINE *engine;
23     BIGNUM *n;
24     BIGNUM *e;
25     BIGNUM *d;
26     BIGNUM *p;
27     BIGNUM *q;
28     BIGNUM *dmp1;
29     BIGNUM *dmq1;
30     BIGNUM *iqmp;
31     /* If a PSS only key this contains the parameter restrictions */
32     RSA_PSS_PARAMS *pss;
33     /* be careful using this if the RSA structure is shared */
34     CRYPTO_EX_DATA ex_data;
35     CRYPTO_REF_COUNT references;
36     int flags;
37     /* Used to cache montgomery values */
38     BN_MONT_CTX *_method_mod_n;
39     BN_MONT_CTX *_method_mod_p;
40     BN_MONT_CTX *_method_mod_q;
41     /*
42      * all BIGNUM values are actually in the following data, if it is not
43      * NULL
44      */
45     char *bignum_data;
46     BN_BLINDING *blinding;
47     BN_BLINDING *mt_blinding;
48     CRYPTO_RWLOCK *lock;
49 };
50
51 struct rsa_meth_st {
52     char *name;
53     int (*rsa_pub_enc) (int flen, const unsigned char *from,
54                         unsigned char *to, RSA *rsa, int padding);
55     int (*rsa_pub_dec) (int flen, const unsigned char *from,
56                         unsigned char *to, RSA *rsa, int padding);
57     int (*rsa_priv_enc) (int flen, const unsigned char *from,
58                          unsigned char *to, RSA *rsa, int padding);
59     int (*rsa_priv_dec) (int flen, const unsigned char *from,
60                          unsigned char *to, RSA *rsa, int padding);
61     /* Can be null */
62     int (*rsa_mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
63     /* Can be null */
64     int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
65                        const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
66     /* called at new */
67     int (*init) (RSA *rsa);
68     /* called at free */
69     int (*finish) (RSA *rsa);
70     /* RSA_METHOD_FLAG_* things */
71     int flags;
72     /* may be needed! */
73     char *app_data;
74     /*
75      * New sign and verify functions: some libraries don't allow arbitrary
76      * data to be signed/verified: this allows them to be used. Note: for
77      * this to work the RSA_public_decrypt() and RSA_private_encrypt() should
78      * *NOT* be used RSA_sign(), RSA_verify() should be used instead.
79      */
80     int (*rsa_sign) (int type,
81                      const unsigned char *m, unsigned int m_length,
82                      unsigned char *sigret, unsigned int *siglen,
83                      const RSA *rsa);
84     int (*rsa_verify) (int dtype, const unsigned char *m,
85                        unsigned int m_length, const unsigned char *sigbuf,
86                        unsigned int siglen, const RSA *rsa);
87     /*
88      * If this callback is NULL, the builtin software RSA key-gen will be
89      * used. This is for behavioural compatibility whilst the code gets
90      * rewired, but one day it would be nice to assume there are no such
91      * things as "builtin software" implementations.
92      */
93     int (*rsa_keygen) (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
94 };
95
96 extern int int_rsa_verify(int dtype, const unsigned char *m,
97                           unsigned int m_len, unsigned char *rm,
98                           size_t *prm_len, const unsigned char *sigbuf,
99                           size_t siglen, RSA *rsa);
100 /* Macros to test if a pkey or ctx is for a PSS key */
101 #define pkey_is_pss(pkey) (pkey->ameth->pkey_id == EVP_PKEY_RSA_PSS)
102 #define pkey_ctx_is_pss(ctx) (ctx->pmeth->pkey_id == EVP_PKEY_RSA_PSS)
103
104 RSA_PSS_PARAMS *rsa_pss_params_create(const EVP_MD *sigmd,
105                                       const EVP_MD *mgf1md, int saltlen);
106 int rsa_pss_get_param(const RSA_PSS_PARAMS *pss, const EVP_MD **pmd,
107                       const EVP_MD **pmgf1md, int *psaltlen);