2 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
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
10 #include <openssl/rsa.h>
11 #include "internal/refcount.h"
15 * The first parameter is used to pickup errors where this is passed
16 * instead of aEVP_PKEY, it is set to 0
20 const RSA_METHOD
*meth
;
21 /* functional reference if 'meth' is ENGINE-provided */
31 /* If a PSS only key this contains the parameter restrictions */
33 /* be careful using this if the RSA structure is shared */
34 CRYPTO_EX_DATA ex_data
;
35 CRYPTO_REF_COUNT references
;
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
;
42 * all BIGNUM values are actually in the following data, if it is not
46 BN_BLINDING
*blinding
;
47 BN_BLINDING
*mt_blinding
;
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
);
62 int (*rsa_mod_exp
) (BIGNUM
*r0
, const BIGNUM
*I
, RSA
*rsa
, BN_CTX
*ctx
);
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
);
67 int (*init
) (RSA
*rsa
);
69 int (*finish
) (RSA
*rsa
);
70 /* RSA_METHOD_FLAG_* things */
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.
80 int (*rsa_sign
) (int type
,
81 const unsigned char *m
, unsigned int m_length
,
82 unsigned char *sigret
, unsigned int *siglen
,
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
);
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.
93 int (*rsa_keygen
) (RSA
*rsa
, int bits
, BIGNUM
*e
, BN_GENCB
*cb
);
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)
104 RSA_PSS_PARAMS
*rsa_pss_params_create(const EVP_MD
*sigmd
,
105 const EVP_MD
*mgf1md
, int saltlen
);