annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/openssl/rsa.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 /*
jpayne@69 2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
jpayne@69 3 *
jpayne@69 4 * Licensed under the OpenSSL license (the "License"). You may not use
jpayne@69 5 * this file except in compliance with the License. You can obtain a copy
jpayne@69 6 * in the file LICENSE in the source distribution or at
jpayne@69 7 * https://www.openssl.org/source/license.html
jpayne@69 8 */
jpayne@69 9
jpayne@69 10 #ifndef HEADER_RSA_H
jpayne@69 11 # define HEADER_RSA_H
jpayne@69 12
jpayne@69 13 # include <openssl/opensslconf.h>
jpayne@69 14
jpayne@69 15 # ifndef OPENSSL_NO_RSA
jpayne@69 16 # include <openssl/asn1.h>
jpayne@69 17 # include <openssl/bio.h>
jpayne@69 18 # include <openssl/crypto.h>
jpayne@69 19 # include <openssl/ossl_typ.h>
jpayne@69 20 # if OPENSSL_API_COMPAT < 0x10100000L
jpayne@69 21 # include <openssl/bn.h>
jpayne@69 22 # endif
jpayne@69 23 # include <openssl/rsaerr.h>
jpayne@69 24 # ifdef __cplusplus
jpayne@69 25 extern "C" {
jpayne@69 26 # endif
jpayne@69 27
jpayne@69 28 /* The types RSA and RSA_METHOD are defined in ossl_typ.h */
jpayne@69 29
jpayne@69 30 # ifndef OPENSSL_RSA_MAX_MODULUS_BITS
jpayne@69 31 # define OPENSSL_RSA_MAX_MODULUS_BITS 16384
jpayne@69 32 # endif
jpayne@69 33
jpayne@69 34 # define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024
jpayne@69 35
jpayne@69 36 # ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
jpayne@69 37 # define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
jpayne@69 38 # endif
jpayne@69 39 # ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
jpayne@69 40
jpayne@69 41 /* exponent limit enforced for "large" modulus only */
jpayne@69 42 # define OPENSSL_RSA_MAX_PUBEXP_BITS 64
jpayne@69 43 # endif
jpayne@69 44
jpayne@69 45 # define RSA_3 0x3L
jpayne@69 46 # define RSA_F4 0x10001L
jpayne@69 47
jpayne@69 48 /* based on RFC 8017 appendix A.1.2 */
jpayne@69 49 # define RSA_ASN1_VERSION_DEFAULT 0
jpayne@69 50 # define RSA_ASN1_VERSION_MULTI 1
jpayne@69 51
jpayne@69 52 # define RSA_DEFAULT_PRIME_NUM 2
jpayne@69 53
jpayne@69 54 # define RSA_METHOD_FLAG_NO_CHECK 0x0001/* don't check pub/private
jpayne@69 55 * match */
jpayne@69 56
jpayne@69 57 # define RSA_FLAG_CACHE_PUBLIC 0x0002
jpayne@69 58 # define RSA_FLAG_CACHE_PRIVATE 0x0004
jpayne@69 59 # define RSA_FLAG_BLINDING 0x0008
jpayne@69 60 # define RSA_FLAG_THREAD_SAFE 0x0010
jpayne@69 61 /*
jpayne@69 62 * This flag means the private key operations will be handled by rsa_mod_exp
jpayne@69 63 * and that they do not depend on the private key components being present:
jpayne@69 64 * for example a key stored in external hardware. Without this flag
jpayne@69 65 * bn_mod_exp gets called when private key components are absent.
jpayne@69 66 */
jpayne@69 67 # define RSA_FLAG_EXT_PKEY 0x0020
jpayne@69 68
jpayne@69 69 /*
jpayne@69 70 * new with 0.9.6j and 0.9.7b; the built-in
jpayne@69 71 * RSA implementation now uses blinding by
jpayne@69 72 * default (ignoring RSA_FLAG_BLINDING),
jpayne@69 73 * but other engines might not need it
jpayne@69 74 */
jpayne@69 75 # define RSA_FLAG_NO_BLINDING 0x0080
jpayne@69 76 # if OPENSSL_API_COMPAT < 0x10100000L
jpayne@69 77 /*
jpayne@69 78 * Does nothing. Previously this switched off constant time behaviour.
jpayne@69 79 */
jpayne@69 80 # define RSA_FLAG_NO_CONSTTIME 0x0000
jpayne@69 81 # endif
jpayne@69 82 # if OPENSSL_API_COMPAT < 0x00908000L
jpayne@69 83 /* deprecated name for the flag*/
jpayne@69 84 /*
jpayne@69 85 * new with 0.9.7h; the built-in RSA
jpayne@69 86 * implementation now uses constant time
jpayne@69 87 * modular exponentiation for secret exponents
jpayne@69 88 * by default. This flag causes the
jpayne@69 89 * faster variable sliding window method to
jpayne@69 90 * be used for all exponents.
jpayne@69 91 */
jpayne@69 92 # define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
jpayne@69 93 # endif
jpayne@69 94
jpayne@69 95 # define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \
jpayne@69 96 RSA_pkey_ctx_ctrl(ctx, -1, EVP_PKEY_CTRL_RSA_PADDING, pad, NULL)
jpayne@69 97
jpayne@69 98 # define EVP_PKEY_CTX_get_rsa_padding(ctx, ppad) \
jpayne@69 99 RSA_pkey_ctx_ctrl(ctx, -1, EVP_PKEY_CTRL_GET_RSA_PADDING, 0, ppad)
jpayne@69 100
jpayne@69 101 # define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \
jpayne@69 102 RSA_pkey_ctx_ctrl(ctx, (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
jpayne@69 103 EVP_PKEY_CTRL_RSA_PSS_SALTLEN, len, NULL)
jpayne@69 104 /* Salt length matches digest */
jpayne@69 105 # define RSA_PSS_SALTLEN_DIGEST -1
jpayne@69 106 /* Verify only: auto detect salt length */
jpayne@69 107 # define RSA_PSS_SALTLEN_AUTO -2
jpayne@69 108 /* Set salt length to maximum possible */
jpayne@69 109 # define RSA_PSS_SALTLEN_MAX -3
jpayne@69 110 /* Old compatible max salt length for sign only */
jpayne@69 111 # define RSA_PSS_SALTLEN_MAX_SIGN -2
jpayne@69 112
jpayne@69 113 # define EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(ctx, len) \
jpayne@69 114 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, \
jpayne@69 115 EVP_PKEY_CTRL_RSA_PSS_SALTLEN, len, NULL)
jpayne@69 116
jpayne@69 117 # define EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, plen) \
jpayne@69 118 RSA_pkey_ctx_ctrl(ctx, (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
jpayne@69 119 EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, 0, plen)
jpayne@69 120
jpayne@69 121 # define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \
jpayne@69 122 RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \
jpayne@69 123 EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL)
jpayne@69 124
jpayne@69 125 # define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \
jpayne@69 126 RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \
jpayne@69 127 EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp)
jpayne@69 128
jpayne@69 129 # define EVP_PKEY_CTX_set_rsa_keygen_primes(ctx, primes) \
jpayne@69 130 RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \
jpayne@69 131 EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES, primes, NULL)
jpayne@69 132
jpayne@69 133 # define EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md) \
jpayne@69 134 RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \
jpayne@69 135 EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md))
jpayne@69 136
jpayne@69 137 # define EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(ctx, md) \
jpayne@69 138 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, \
jpayne@69 139 EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md))
jpayne@69 140
jpayne@69 141 # define EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md) \
jpayne@69 142 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
jpayne@69 143 EVP_PKEY_CTRL_RSA_OAEP_MD, 0, (void *)(md))
jpayne@69 144
jpayne@69 145 # define EVP_PKEY_CTX_get_rsa_mgf1_md(ctx, pmd) \
jpayne@69 146 RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \
jpayne@69 147 EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)(pmd))
jpayne@69 148
jpayne@69 149 # define EVP_PKEY_CTX_get_rsa_oaep_md(ctx, pmd) \
jpayne@69 150 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
jpayne@69 151 EVP_PKEY_CTRL_GET_RSA_OAEP_MD, 0, (void *)(pmd))
jpayne@69 152
jpayne@69 153 # define EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, l, llen) \
jpayne@69 154 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
jpayne@69 155 EVP_PKEY_CTRL_RSA_OAEP_LABEL, llen, (void *)(l))
jpayne@69 156
jpayne@69 157 # define EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, l) \
jpayne@69 158 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
jpayne@69 159 EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *)(l))
jpayne@69 160
jpayne@69 161 # define EVP_PKEY_CTX_set_rsa_pss_keygen_md(ctx, md) \
jpayne@69 162 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, \
jpayne@69 163 EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_MD, \
jpayne@69 164 0, (void *)(md))
jpayne@69 165
jpayne@69 166 # define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1)
jpayne@69 167 # define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2)
jpayne@69 168
jpayne@69 169 # define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3)
jpayne@69 170 # define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4)
jpayne@69 171 # define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5)
jpayne@69 172
jpayne@69 173 # define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6)
jpayne@69 174 # define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7)
jpayne@69 175 # define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8)
jpayne@69 176
jpayne@69 177 # define EVP_PKEY_CTRL_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 9)
jpayne@69 178 # define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 10)
jpayne@69 179
jpayne@69 180 # define EVP_PKEY_CTRL_GET_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 11)
jpayne@69 181 # define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
jpayne@69 182
jpayne@69 183 # define EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES (EVP_PKEY_ALG_CTRL + 13)
jpayne@69 184
jpayne@69 185 # define RSA_PKCS1_PADDING 1
jpayne@69 186 # define RSA_SSLV23_PADDING 2
jpayne@69 187 # define RSA_NO_PADDING 3
jpayne@69 188 # define RSA_PKCS1_OAEP_PADDING 4
jpayne@69 189 # define RSA_X931_PADDING 5
jpayne@69 190 /* EVP_PKEY_ only */
jpayne@69 191 # define RSA_PKCS1_PSS_PADDING 6
jpayne@69 192
jpayne@69 193 # define RSA_PKCS1_PADDING_SIZE 11
jpayne@69 194
jpayne@69 195 # define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg)
jpayne@69 196 # define RSA_get_app_data(s) RSA_get_ex_data(s,0)
jpayne@69 197
jpayne@69 198 RSA *RSA_new(void);
jpayne@69 199 RSA *RSA_new_method(ENGINE *engine);
jpayne@69 200 int RSA_bits(const RSA *rsa);
jpayne@69 201 int RSA_size(const RSA *rsa);
jpayne@69 202 int RSA_security_bits(const RSA *rsa);
jpayne@69 203
jpayne@69 204 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
jpayne@69 205 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
jpayne@69 206 int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
jpayne@69 207 int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[],
jpayne@69 208 BIGNUM *coeffs[], int pnum);
jpayne@69 209 void RSA_get0_key(const RSA *r,
jpayne@69 210 const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
jpayne@69 211 void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
jpayne@69 212 int RSA_get_multi_prime_extra_count(const RSA *r);
jpayne@69 213 int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]);
jpayne@69 214 void RSA_get0_crt_params(const RSA *r,
jpayne@69 215 const BIGNUM **dmp1, const BIGNUM **dmq1,
jpayne@69 216 const BIGNUM **iqmp);
jpayne@69 217 int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[],
jpayne@69 218 const BIGNUM *coeffs[]);
jpayne@69 219 const BIGNUM *RSA_get0_n(const RSA *d);
jpayne@69 220 const BIGNUM *RSA_get0_e(const RSA *d);
jpayne@69 221 const BIGNUM *RSA_get0_d(const RSA *d);
jpayne@69 222 const BIGNUM *RSA_get0_p(const RSA *d);
jpayne@69 223 const BIGNUM *RSA_get0_q(const RSA *d);
jpayne@69 224 const BIGNUM *RSA_get0_dmp1(const RSA *r);
jpayne@69 225 const BIGNUM *RSA_get0_dmq1(const RSA *r);
jpayne@69 226 const BIGNUM *RSA_get0_iqmp(const RSA *r);
jpayne@69 227 const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r);
jpayne@69 228 void RSA_clear_flags(RSA *r, int flags);
jpayne@69 229 int RSA_test_flags(const RSA *r, int flags);
jpayne@69 230 void RSA_set_flags(RSA *r, int flags);
jpayne@69 231 int RSA_get_version(RSA *r);
jpayne@69 232 ENGINE *RSA_get0_engine(const RSA *r);
jpayne@69 233
jpayne@69 234 /* Deprecated version */
jpayne@69 235 DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void
jpayne@69 236 (*callback) (int, int, void *),
jpayne@69 237 void *cb_arg))
jpayne@69 238
jpayne@69 239 /* New version */
jpayne@69 240 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
jpayne@69 241 /* Multi-prime version */
jpayne@69 242 int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes,
jpayne@69 243 BIGNUM *e, BN_GENCB *cb);
jpayne@69 244
jpayne@69 245 int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
jpayne@69 246 BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2,
jpayne@69 247 const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2,
jpayne@69 248 const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb);
jpayne@69 249 int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
jpayne@69 250 BN_GENCB *cb);
jpayne@69 251
jpayne@69 252 int RSA_check_key(const RSA *);
jpayne@69 253 int RSA_check_key_ex(const RSA *, BN_GENCB *cb);
jpayne@69 254 /* next 4 return -1 on error */
jpayne@69 255 int RSA_public_encrypt(int flen, const unsigned char *from,
jpayne@69 256 unsigned char *to, RSA *rsa, int padding);
jpayne@69 257 int RSA_private_encrypt(int flen, const unsigned char *from,
jpayne@69 258 unsigned char *to, RSA *rsa, int padding);
jpayne@69 259 int RSA_public_decrypt(int flen, const unsigned char *from,
jpayne@69 260 unsigned char *to, RSA *rsa, int padding);
jpayne@69 261 int RSA_private_decrypt(int flen, const unsigned char *from,
jpayne@69 262 unsigned char *to, RSA *rsa, int padding);
jpayne@69 263 void RSA_free(RSA *r);
jpayne@69 264 /* "up" the RSA object's reference count */
jpayne@69 265 int RSA_up_ref(RSA *r);
jpayne@69 266
jpayne@69 267 int RSA_flags(const RSA *r);
jpayne@69 268
jpayne@69 269 void RSA_set_default_method(const RSA_METHOD *meth);
jpayne@69 270 const RSA_METHOD *RSA_get_default_method(void);
jpayne@69 271 const RSA_METHOD *RSA_null_method(void);
jpayne@69 272 const RSA_METHOD *RSA_get_method(const RSA *rsa);
jpayne@69 273 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
jpayne@69 274
jpayne@69 275 /* these are the actual RSA functions */
jpayne@69 276 const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
jpayne@69 277
jpayne@69 278 int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2);
jpayne@69 279
jpayne@69 280 DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
jpayne@69 281 DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
jpayne@69 282
jpayne@69 283 struct rsa_pss_params_st {
jpayne@69 284 X509_ALGOR *hashAlgorithm;
jpayne@69 285 X509_ALGOR *maskGenAlgorithm;
jpayne@69 286 ASN1_INTEGER *saltLength;
jpayne@69 287 ASN1_INTEGER *trailerField;
jpayne@69 288 /* Decoded hash algorithm from maskGenAlgorithm */
jpayne@69 289 X509_ALGOR *maskHash;
jpayne@69 290 };
jpayne@69 291
jpayne@69 292 DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
jpayne@69 293
jpayne@69 294 typedef struct rsa_oaep_params_st {
jpayne@69 295 X509_ALGOR *hashFunc;
jpayne@69 296 X509_ALGOR *maskGenFunc;
jpayne@69 297 X509_ALGOR *pSourceFunc;
jpayne@69 298 /* Decoded hash algorithm from maskGenFunc */
jpayne@69 299 X509_ALGOR *maskHash;
jpayne@69 300 } RSA_OAEP_PARAMS;
jpayne@69 301
jpayne@69 302 DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
jpayne@69 303
jpayne@69 304 # ifndef OPENSSL_NO_STDIO
jpayne@69 305 int RSA_print_fp(FILE *fp, const RSA *r, int offset);
jpayne@69 306 # endif
jpayne@69 307
jpayne@69 308 int RSA_print(BIO *bp, const RSA *r, int offset);
jpayne@69 309
jpayne@69 310 /*
jpayne@69 311 * The following 2 functions sign and verify a X509_SIG ASN1 object inside
jpayne@69 312 * PKCS#1 padded RSA encryption
jpayne@69 313 */
jpayne@69 314 int RSA_sign(int type, const unsigned char *m, unsigned int m_length,
jpayne@69 315 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
jpayne@69 316 int RSA_verify(int type, const unsigned char *m, unsigned int m_length,
jpayne@69 317 const unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
jpayne@69 318
jpayne@69 319 /*
jpayne@69 320 * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
jpayne@69 321 * PKCS#1 padded RSA encryption
jpayne@69 322 */
jpayne@69 323 int RSA_sign_ASN1_OCTET_STRING(int type,
jpayne@69 324 const unsigned char *m, unsigned int m_length,
jpayne@69 325 unsigned char *sigret, unsigned int *siglen,
jpayne@69 326 RSA *rsa);
jpayne@69 327 int RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m,
jpayne@69 328 unsigned int m_length, unsigned char *sigbuf,
jpayne@69 329 unsigned int siglen, RSA *rsa);
jpayne@69 330
jpayne@69 331 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
jpayne@69 332 void RSA_blinding_off(RSA *rsa);
jpayne@69 333 BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
jpayne@69 334
jpayne@69 335 int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
jpayne@69 336 const unsigned char *f, int fl);
jpayne@69 337 int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
jpayne@69 338 const unsigned char *f, int fl,
jpayne@69 339 int rsa_len);
jpayne@69 340 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
jpayne@69 341 const unsigned char *f, int fl);
jpayne@69 342 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
jpayne@69 343 const unsigned char *f, int fl,
jpayne@69 344 int rsa_len);
jpayne@69 345 int PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed,
jpayne@69 346 long seedlen, const EVP_MD *dgst);
jpayne@69 347 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
jpayne@69 348 const unsigned char *f, int fl,
jpayne@69 349 const unsigned char *p, int pl);
jpayne@69 350 int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
jpayne@69 351 const unsigned char *f, int fl, int rsa_len,
jpayne@69 352 const unsigned char *p, int pl);
jpayne@69 353 int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
jpayne@69 354 const unsigned char *from, int flen,
jpayne@69 355 const unsigned char *param, int plen,
jpayne@69 356 const EVP_MD *md, const EVP_MD *mgf1md);
jpayne@69 357 int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
jpayne@69 358 const unsigned char *from, int flen,
jpayne@69 359 int num, const unsigned char *param,
jpayne@69 360 int plen, const EVP_MD *md,
jpayne@69 361 const EVP_MD *mgf1md);
jpayne@69 362 int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
jpayne@69 363 const unsigned char *f, int fl);
jpayne@69 364 int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
jpayne@69 365 const unsigned char *f, int fl, int rsa_len);
jpayne@69 366 int RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f,
jpayne@69 367 int fl);
jpayne@69 368 int RSA_padding_check_none(unsigned char *to, int tlen,
jpayne@69 369 const unsigned char *f, int fl, int rsa_len);
jpayne@69 370 int RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f,
jpayne@69 371 int fl);
jpayne@69 372 int RSA_padding_check_X931(unsigned char *to, int tlen,
jpayne@69 373 const unsigned char *f, int fl, int rsa_len);
jpayne@69 374 int RSA_X931_hash_id(int nid);
jpayne@69 375
jpayne@69 376 int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
jpayne@69 377 const EVP_MD *Hash, const unsigned char *EM,
jpayne@69 378 int sLen);
jpayne@69 379 int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
jpayne@69 380 const unsigned char *mHash, const EVP_MD *Hash,
jpayne@69 381 int sLen);
jpayne@69 382
jpayne@69 383 int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
jpayne@69 384 const EVP_MD *Hash, const EVP_MD *mgf1Hash,
jpayne@69 385 const unsigned char *EM, int sLen);
jpayne@69 386
jpayne@69 387 int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
jpayne@69 388 const unsigned char *mHash,
jpayne@69 389 const EVP_MD *Hash, const EVP_MD *mgf1Hash,
jpayne@69 390 int sLen);
jpayne@69 391
jpayne@69 392 #define RSA_get_ex_new_index(l, p, newf, dupf, freef) \
jpayne@69 393 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef)
jpayne@69 394 int RSA_set_ex_data(RSA *r, int idx, void *arg);
jpayne@69 395 void *RSA_get_ex_data(const RSA *r, int idx);
jpayne@69 396
jpayne@69 397 RSA *RSAPublicKey_dup(RSA *rsa);
jpayne@69 398 RSA *RSAPrivateKey_dup(RSA *rsa);
jpayne@69 399
jpayne@69 400 /*
jpayne@69 401 * If this flag is set the RSA method is FIPS compliant and can be used in
jpayne@69 402 * FIPS mode. This is set in the validated module method. If an application
jpayne@69 403 * sets this flag in its own methods it is its responsibility to ensure the
jpayne@69 404 * result is compliant.
jpayne@69 405 */
jpayne@69 406
jpayne@69 407 # define RSA_FLAG_FIPS_METHOD 0x0400
jpayne@69 408
jpayne@69 409 /*
jpayne@69 410 * If this flag is set the operations normally disabled in FIPS mode are
jpayne@69 411 * permitted it is then the applications responsibility to ensure that the
jpayne@69 412 * usage is compliant.
jpayne@69 413 */
jpayne@69 414
jpayne@69 415 # define RSA_FLAG_NON_FIPS_ALLOW 0x0400
jpayne@69 416 /*
jpayne@69 417 * Application has decided PRNG is good enough to generate a key: don't
jpayne@69 418 * check.
jpayne@69 419 */
jpayne@69 420 # define RSA_FLAG_CHECKED 0x0800
jpayne@69 421
jpayne@69 422 RSA_METHOD *RSA_meth_new(const char *name, int flags);
jpayne@69 423 void RSA_meth_free(RSA_METHOD *meth);
jpayne@69 424 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
jpayne@69 425 const char *RSA_meth_get0_name(const RSA_METHOD *meth);
jpayne@69 426 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
jpayne@69 427 int RSA_meth_get_flags(const RSA_METHOD *meth);
jpayne@69 428 int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
jpayne@69 429 void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
jpayne@69 430 int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data);
jpayne@69 431 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
jpayne@69 432 (int flen, const unsigned char *from,
jpayne@69 433 unsigned char *to, RSA *rsa, int padding);
jpayne@69 434 int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
jpayne@69 435 int (*pub_enc) (int flen, const unsigned char *from,
jpayne@69 436 unsigned char *to, RSA *rsa,
jpayne@69 437 int padding));
jpayne@69 438 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
jpayne@69 439 (int flen, const unsigned char *from,
jpayne@69 440 unsigned char *to, RSA *rsa, int padding);
jpayne@69 441 int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
jpayne@69 442 int (*pub_dec) (int flen, const unsigned char *from,
jpayne@69 443 unsigned char *to, RSA *rsa,
jpayne@69 444 int padding));
jpayne@69 445 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
jpayne@69 446 (int flen, const unsigned char *from,
jpayne@69 447 unsigned char *to, RSA *rsa, int padding);
jpayne@69 448 int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
jpayne@69 449 int (*priv_enc) (int flen, const unsigned char *from,
jpayne@69 450 unsigned char *to, RSA *rsa,
jpayne@69 451 int padding));
jpayne@69 452 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
jpayne@69 453 (int flen, const unsigned char *from,
jpayne@69 454 unsigned char *to, RSA *rsa, int padding);
jpayne@69 455 int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
jpayne@69 456 int (*priv_dec) (int flen, const unsigned char *from,
jpayne@69 457 unsigned char *to, RSA *rsa,
jpayne@69 458 int padding));
jpayne@69 459 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
jpayne@69 460 (BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx);
jpayne@69 461 int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
jpayne@69 462 int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa,
jpayne@69 463 BN_CTX *ctx));
jpayne@69 464 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
jpayne@69 465 (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
jpayne@69 466 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
jpayne@69 467 int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
jpayne@69 468 int (*bn_mod_exp) (BIGNUM *r,
jpayne@69 469 const BIGNUM *a,
jpayne@69 470 const BIGNUM *p,
jpayne@69 471 const BIGNUM *m,
jpayne@69 472 BN_CTX *ctx,
jpayne@69 473 BN_MONT_CTX *m_ctx));
jpayne@69 474 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa);
jpayne@69 475 int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa));
jpayne@69 476 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa);
jpayne@69 477 int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa));
jpayne@69 478 int (*RSA_meth_get_sign(const RSA_METHOD *meth))
jpayne@69 479 (int type,
jpayne@69 480 const unsigned char *m, unsigned int m_length,
jpayne@69 481 unsigned char *sigret, unsigned int *siglen,
jpayne@69 482 const RSA *rsa);
jpayne@69 483 int RSA_meth_set_sign(RSA_METHOD *rsa,
jpayne@69 484 int (*sign) (int type, const unsigned char *m,
jpayne@69 485 unsigned int m_length,
jpayne@69 486 unsigned char *sigret, unsigned int *siglen,
jpayne@69 487 const RSA *rsa));
jpayne@69 488 int (*RSA_meth_get_verify(const RSA_METHOD *meth))
jpayne@69 489 (int dtype, const unsigned char *m,
jpayne@69 490 unsigned int m_length, const unsigned char *sigbuf,
jpayne@69 491 unsigned int siglen, const RSA *rsa);
jpayne@69 492 int RSA_meth_set_verify(RSA_METHOD *rsa,
jpayne@69 493 int (*verify) (int dtype, const unsigned char *m,
jpayne@69 494 unsigned int m_length,
jpayne@69 495 const unsigned char *sigbuf,
jpayne@69 496 unsigned int siglen, const RSA *rsa));
jpayne@69 497 int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
jpayne@69 498 (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
jpayne@69 499 int RSA_meth_set_keygen(RSA_METHOD *rsa,
jpayne@69 500 int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
jpayne@69 501 BN_GENCB *cb));
jpayne@69 502 int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth))
jpayne@69 503 (RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb);
jpayne@69 504 int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
jpayne@69 505 int (*keygen) (RSA *rsa, int bits,
jpayne@69 506 int primes, BIGNUM *e,
jpayne@69 507 BN_GENCB *cb));
jpayne@69 508
jpayne@69 509 # ifdef __cplusplus
jpayne@69 510 }
jpayne@69 511 # endif
jpayne@69 512 # endif
jpayne@69 513 #endif