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