jpayne@69: /* jpayne@69: * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. jpayne@69: * jpayne@69: * Licensed under the OpenSSL license (the "License"). You may not use jpayne@69: * this file except in compliance with the License. You can obtain a copy jpayne@69: * in the file LICENSE in the source distribution or at jpayne@69: * https://www.openssl.org/source/license.html jpayne@69: */ jpayne@69: jpayne@69: #ifndef HEADER_RSA_H jpayne@69: # define HEADER_RSA_H jpayne@69: jpayne@69: # include jpayne@69: jpayne@69: # ifndef OPENSSL_NO_RSA jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: # if OPENSSL_API_COMPAT < 0x10100000L jpayne@69: # include jpayne@69: # endif jpayne@69: # include jpayne@69: # ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: # endif jpayne@69: jpayne@69: /* The types RSA and RSA_METHOD are defined in ossl_typ.h */ jpayne@69: jpayne@69: # ifndef OPENSSL_RSA_MAX_MODULUS_BITS jpayne@69: # define OPENSSL_RSA_MAX_MODULUS_BITS 16384 jpayne@69: # endif jpayne@69: jpayne@69: # define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024 jpayne@69: jpayne@69: # ifndef OPENSSL_RSA_SMALL_MODULUS_BITS jpayne@69: # define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 jpayne@69: # endif jpayne@69: # ifndef OPENSSL_RSA_MAX_PUBEXP_BITS jpayne@69: jpayne@69: /* exponent limit enforced for "large" modulus only */ jpayne@69: # define OPENSSL_RSA_MAX_PUBEXP_BITS 64 jpayne@69: # endif jpayne@69: jpayne@69: # define RSA_3 0x3L jpayne@69: # define RSA_F4 0x10001L jpayne@69: jpayne@69: /* based on RFC 8017 appendix A.1.2 */ jpayne@69: # define RSA_ASN1_VERSION_DEFAULT 0 jpayne@69: # define RSA_ASN1_VERSION_MULTI 1 jpayne@69: jpayne@69: # define RSA_DEFAULT_PRIME_NUM 2 jpayne@69: jpayne@69: # define RSA_METHOD_FLAG_NO_CHECK 0x0001/* don't check pub/private jpayne@69: * match */ jpayne@69: jpayne@69: # define RSA_FLAG_CACHE_PUBLIC 0x0002 jpayne@69: # define RSA_FLAG_CACHE_PRIVATE 0x0004 jpayne@69: # define RSA_FLAG_BLINDING 0x0008 jpayne@69: # define RSA_FLAG_THREAD_SAFE 0x0010 jpayne@69: /* jpayne@69: * This flag means the private key operations will be handled by rsa_mod_exp jpayne@69: * and that they do not depend on the private key components being present: jpayne@69: * for example a key stored in external hardware. Without this flag jpayne@69: * bn_mod_exp gets called when private key components are absent. jpayne@69: */ jpayne@69: # define RSA_FLAG_EXT_PKEY 0x0020 jpayne@69: jpayne@69: /* jpayne@69: * new with 0.9.6j and 0.9.7b; the built-in jpayne@69: * RSA implementation now uses blinding by jpayne@69: * default (ignoring RSA_FLAG_BLINDING), jpayne@69: * but other engines might not need it jpayne@69: */ jpayne@69: # define RSA_FLAG_NO_BLINDING 0x0080 jpayne@69: # if OPENSSL_API_COMPAT < 0x10100000L jpayne@69: /* jpayne@69: * Does nothing. Previously this switched off constant time behaviour. jpayne@69: */ jpayne@69: # define RSA_FLAG_NO_CONSTTIME 0x0000 jpayne@69: # endif jpayne@69: # if OPENSSL_API_COMPAT < 0x00908000L jpayne@69: /* deprecated name for the flag*/ jpayne@69: /* jpayne@69: * new with 0.9.7h; the built-in RSA jpayne@69: * implementation now uses constant time jpayne@69: * modular exponentiation for secret exponents jpayne@69: * by default. This flag causes the jpayne@69: * faster variable sliding window method to jpayne@69: * be used for all exponents. jpayne@69: */ jpayne@69: # define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME jpayne@69: # endif jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, -1, EVP_PKEY_CTRL_RSA_PADDING, pad, NULL) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_get_rsa_padding(ctx, ppad) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, -1, EVP_PKEY_CTRL_GET_RSA_PADDING, 0, ppad) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \ jpayne@69: EVP_PKEY_CTRL_RSA_PSS_SALTLEN, len, NULL) jpayne@69: /* Salt length matches digest */ jpayne@69: # define RSA_PSS_SALTLEN_DIGEST -1 jpayne@69: /* Verify only: auto detect salt length */ jpayne@69: # define RSA_PSS_SALTLEN_AUTO -2 jpayne@69: /* Set salt length to maximum possible */ jpayne@69: # define RSA_PSS_SALTLEN_MAX -3 jpayne@69: /* Old compatible max salt length for sign only */ jpayne@69: # define RSA_PSS_SALTLEN_MAX_SIGN -2 jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(ctx, len) \ jpayne@69: EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, \ jpayne@69: EVP_PKEY_CTRL_RSA_PSS_SALTLEN, len, NULL) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, plen) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \ jpayne@69: EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, 0, plen) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \ jpayne@69: EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \ jpayne@69: EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_keygen_primes(ctx, primes) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \ jpayne@69: EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES, primes, NULL) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \ jpayne@69: EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md)) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(ctx, md) \ jpayne@69: EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, \ jpayne@69: EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md)) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md) \ jpayne@69: EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ jpayne@69: EVP_PKEY_CTRL_RSA_OAEP_MD, 0, (void *)(md)) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_get_rsa_mgf1_md(ctx, pmd) \ jpayne@69: RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \ jpayne@69: EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)(pmd)) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_get_rsa_oaep_md(ctx, pmd) \ jpayne@69: EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ jpayne@69: EVP_PKEY_CTRL_GET_RSA_OAEP_MD, 0, (void *)(pmd)) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, l, llen) \ jpayne@69: EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ jpayne@69: EVP_PKEY_CTRL_RSA_OAEP_LABEL, llen, (void *)(l)) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, l) \ jpayne@69: EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ jpayne@69: EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *)(l)) jpayne@69: jpayne@69: # define EVP_PKEY_CTX_set_rsa_pss_keygen_md(ctx, md) \ jpayne@69: EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, \ jpayne@69: EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_MD, \ jpayne@69: 0, (void *)(md)) jpayne@69: jpayne@69: # define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1) jpayne@69: # define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2) jpayne@69: jpayne@69: # define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3) jpayne@69: # define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4) jpayne@69: # define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5) jpayne@69: jpayne@69: # define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6) jpayne@69: # define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7) jpayne@69: # define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8) jpayne@69: jpayne@69: # define EVP_PKEY_CTRL_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 9) jpayne@69: # define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 10) jpayne@69: jpayne@69: # define EVP_PKEY_CTRL_GET_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 11) jpayne@69: # define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12) jpayne@69: jpayne@69: # define EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES (EVP_PKEY_ALG_CTRL + 13) jpayne@69: jpayne@69: # define RSA_PKCS1_PADDING 1 jpayne@69: # define RSA_SSLV23_PADDING 2 jpayne@69: # define RSA_NO_PADDING 3 jpayne@69: # define RSA_PKCS1_OAEP_PADDING 4 jpayne@69: # define RSA_X931_PADDING 5 jpayne@69: /* EVP_PKEY_ only */ jpayne@69: # define RSA_PKCS1_PSS_PADDING 6 jpayne@69: jpayne@69: # define RSA_PKCS1_PADDING_SIZE 11 jpayne@69: jpayne@69: # define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) jpayne@69: # define RSA_get_app_data(s) RSA_get_ex_data(s,0) jpayne@69: jpayne@69: RSA *RSA_new(void); jpayne@69: RSA *RSA_new_method(ENGINE *engine); jpayne@69: int RSA_bits(const RSA *rsa); jpayne@69: int RSA_size(const RSA *rsa); jpayne@69: int RSA_security_bits(const RSA *rsa); jpayne@69: jpayne@69: int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d); jpayne@69: int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q); jpayne@69: int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp); jpayne@69: int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[], jpayne@69: BIGNUM *coeffs[], int pnum); jpayne@69: void RSA_get0_key(const RSA *r, jpayne@69: const BIGNUM **n, const BIGNUM **e, const BIGNUM **d); jpayne@69: void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q); jpayne@69: int RSA_get_multi_prime_extra_count(const RSA *r); jpayne@69: int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]); jpayne@69: void RSA_get0_crt_params(const RSA *r, jpayne@69: const BIGNUM **dmp1, const BIGNUM **dmq1, jpayne@69: const BIGNUM **iqmp); jpayne@69: int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[], jpayne@69: const BIGNUM *coeffs[]); jpayne@69: const BIGNUM *RSA_get0_n(const RSA *d); jpayne@69: const BIGNUM *RSA_get0_e(const RSA *d); jpayne@69: const BIGNUM *RSA_get0_d(const RSA *d); jpayne@69: const BIGNUM *RSA_get0_p(const RSA *d); jpayne@69: const BIGNUM *RSA_get0_q(const RSA *d); jpayne@69: const BIGNUM *RSA_get0_dmp1(const RSA *r); jpayne@69: const BIGNUM *RSA_get0_dmq1(const RSA *r); jpayne@69: const BIGNUM *RSA_get0_iqmp(const RSA *r); jpayne@69: const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r); jpayne@69: void RSA_clear_flags(RSA *r, int flags); jpayne@69: int RSA_test_flags(const RSA *r, int flags); jpayne@69: void RSA_set_flags(RSA *r, int flags); jpayne@69: int RSA_get_version(RSA *r); jpayne@69: ENGINE *RSA_get0_engine(const RSA *r); jpayne@69: jpayne@69: /* Deprecated version */ jpayne@69: DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void jpayne@69: (*callback) (int, int, void *), jpayne@69: void *cb_arg)) jpayne@69: jpayne@69: /* New version */ jpayne@69: int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); jpayne@69: /* Multi-prime version */ jpayne@69: int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, jpayne@69: BIGNUM *e, BN_GENCB *cb); jpayne@69: jpayne@69: int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, jpayne@69: BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2, jpayne@69: const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2, jpayne@69: const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb); jpayne@69: int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, jpayne@69: BN_GENCB *cb); jpayne@69: jpayne@69: int RSA_check_key(const RSA *); jpayne@69: int RSA_check_key_ex(const RSA *, BN_GENCB *cb); jpayne@69: /* next 4 return -1 on error */ jpayne@69: int RSA_public_encrypt(int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, int padding); jpayne@69: int RSA_private_encrypt(int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, int padding); jpayne@69: int RSA_public_decrypt(int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, int padding); jpayne@69: int RSA_private_decrypt(int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, int padding); jpayne@69: void RSA_free(RSA *r); jpayne@69: /* "up" the RSA object's reference count */ jpayne@69: int RSA_up_ref(RSA *r); jpayne@69: jpayne@69: int RSA_flags(const RSA *r); jpayne@69: jpayne@69: void RSA_set_default_method(const RSA_METHOD *meth); jpayne@69: const RSA_METHOD *RSA_get_default_method(void); jpayne@69: const RSA_METHOD *RSA_null_method(void); jpayne@69: const RSA_METHOD *RSA_get_method(const RSA *rsa); jpayne@69: int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); jpayne@69: jpayne@69: /* these are the actual RSA functions */ jpayne@69: const RSA_METHOD *RSA_PKCS1_OpenSSL(void); jpayne@69: jpayne@69: int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2); jpayne@69: jpayne@69: DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey) jpayne@69: DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey) jpayne@69: jpayne@69: struct rsa_pss_params_st { jpayne@69: X509_ALGOR *hashAlgorithm; jpayne@69: X509_ALGOR *maskGenAlgorithm; jpayne@69: ASN1_INTEGER *saltLength; jpayne@69: ASN1_INTEGER *trailerField; jpayne@69: /* Decoded hash algorithm from maskGenAlgorithm */ jpayne@69: X509_ALGOR *maskHash; jpayne@69: }; jpayne@69: jpayne@69: DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS) jpayne@69: jpayne@69: typedef struct rsa_oaep_params_st { jpayne@69: X509_ALGOR *hashFunc; jpayne@69: X509_ALGOR *maskGenFunc; jpayne@69: X509_ALGOR *pSourceFunc; jpayne@69: /* Decoded hash algorithm from maskGenFunc */ jpayne@69: X509_ALGOR *maskHash; jpayne@69: } RSA_OAEP_PARAMS; jpayne@69: jpayne@69: DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS) jpayne@69: jpayne@69: # ifndef OPENSSL_NO_STDIO jpayne@69: int RSA_print_fp(FILE *fp, const RSA *r, int offset); jpayne@69: # endif jpayne@69: jpayne@69: int RSA_print(BIO *bp, const RSA *r, int offset); jpayne@69: jpayne@69: /* jpayne@69: * The following 2 functions sign and verify a X509_SIG ASN1 object inside jpayne@69: * PKCS#1 padded RSA encryption jpayne@69: */ jpayne@69: int RSA_sign(int type, const unsigned char *m, unsigned int m_length, jpayne@69: unsigned char *sigret, unsigned int *siglen, RSA *rsa); jpayne@69: int RSA_verify(int type, const unsigned char *m, unsigned int m_length, jpayne@69: const unsigned char *sigbuf, unsigned int siglen, RSA *rsa); jpayne@69: jpayne@69: /* jpayne@69: * The following 2 function sign and verify a ASN1_OCTET_STRING object inside jpayne@69: * PKCS#1 padded RSA encryption jpayne@69: */ jpayne@69: int RSA_sign_ASN1_OCTET_STRING(int type, jpayne@69: const unsigned char *m, unsigned int m_length, jpayne@69: unsigned char *sigret, unsigned int *siglen, jpayne@69: RSA *rsa); jpayne@69: int RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m, jpayne@69: unsigned int m_length, unsigned char *sigbuf, jpayne@69: unsigned int siglen, RSA *rsa); jpayne@69: jpayne@69: int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); jpayne@69: void RSA_blinding_off(RSA *rsa); jpayne@69: BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx); jpayne@69: jpayne@69: int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl); jpayne@69: int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl, jpayne@69: int rsa_len); jpayne@69: int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl); jpayne@69: int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl, jpayne@69: int rsa_len); jpayne@69: int PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed, jpayne@69: long seedlen, const EVP_MD *dgst); jpayne@69: int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl, jpayne@69: const unsigned char *p, int pl); jpayne@69: int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl, int rsa_len, jpayne@69: const unsigned char *p, int pl); jpayne@69: int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, jpayne@69: const unsigned char *from, int flen, jpayne@69: const unsigned char *param, int plen, jpayne@69: const EVP_MD *md, const EVP_MD *mgf1md); jpayne@69: int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, jpayne@69: const unsigned char *from, int flen, jpayne@69: int num, const unsigned char *param, jpayne@69: int plen, const EVP_MD *md, jpayne@69: const EVP_MD *mgf1md); jpayne@69: int RSA_padding_add_SSLv23(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl); jpayne@69: int RSA_padding_check_SSLv23(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl, int rsa_len); jpayne@69: int RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f, jpayne@69: int fl); jpayne@69: int RSA_padding_check_none(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl, int rsa_len); jpayne@69: int RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f, jpayne@69: int fl); jpayne@69: int RSA_padding_check_X931(unsigned char *to, int tlen, jpayne@69: const unsigned char *f, int fl, int rsa_len); jpayne@69: int RSA_X931_hash_id(int nid); jpayne@69: jpayne@69: int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash, jpayne@69: const EVP_MD *Hash, const unsigned char *EM, jpayne@69: int sLen); jpayne@69: int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM, jpayne@69: const unsigned char *mHash, const EVP_MD *Hash, jpayne@69: int sLen); jpayne@69: jpayne@69: int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, jpayne@69: const EVP_MD *Hash, const EVP_MD *mgf1Hash, jpayne@69: const unsigned char *EM, int sLen); jpayne@69: jpayne@69: int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, jpayne@69: const unsigned char *mHash, jpayne@69: const EVP_MD *Hash, const EVP_MD *mgf1Hash, jpayne@69: int sLen); jpayne@69: jpayne@69: #define RSA_get_ex_new_index(l, p, newf, dupf, freef) \ jpayne@69: CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef) jpayne@69: int RSA_set_ex_data(RSA *r, int idx, void *arg); jpayne@69: void *RSA_get_ex_data(const RSA *r, int idx); jpayne@69: jpayne@69: RSA *RSAPublicKey_dup(RSA *rsa); jpayne@69: RSA *RSAPrivateKey_dup(RSA *rsa); jpayne@69: jpayne@69: /* jpayne@69: * If this flag is set the RSA method is FIPS compliant and can be used in jpayne@69: * FIPS mode. This is set in the validated module method. If an application jpayne@69: * sets this flag in its own methods it is its responsibility to ensure the jpayne@69: * result is compliant. jpayne@69: */ jpayne@69: jpayne@69: # define RSA_FLAG_FIPS_METHOD 0x0400 jpayne@69: jpayne@69: /* jpayne@69: * If this flag is set the operations normally disabled in FIPS mode are jpayne@69: * permitted it is then the applications responsibility to ensure that the jpayne@69: * usage is compliant. jpayne@69: */ jpayne@69: jpayne@69: # define RSA_FLAG_NON_FIPS_ALLOW 0x0400 jpayne@69: /* jpayne@69: * Application has decided PRNG is good enough to generate a key: don't jpayne@69: * check. jpayne@69: */ jpayne@69: # define RSA_FLAG_CHECKED 0x0800 jpayne@69: jpayne@69: RSA_METHOD *RSA_meth_new(const char *name, int flags); jpayne@69: void RSA_meth_free(RSA_METHOD *meth); jpayne@69: RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth); jpayne@69: const char *RSA_meth_get0_name(const RSA_METHOD *meth); jpayne@69: int RSA_meth_set1_name(RSA_METHOD *meth, const char *name); jpayne@69: int RSA_meth_get_flags(const RSA_METHOD *meth); jpayne@69: int RSA_meth_set_flags(RSA_METHOD *meth, int flags); jpayne@69: void *RSA_meth_get0_app_data(const RSA_METHOD *meth); jpayne@69: int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data); jpayne@69: int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth)) jpayne@69: (int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, int padding); jpayne@69: int RSA_meth_set_pub_enc(RSA_METHOD *rsa, jpayne@69: int (*pub_enc) (int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, jpayne@69: int padding)); jpayne@69: int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth)) jpayne@69: (int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, int padding); jpayne@69: int RSA_meth_set_pub_dec(RSA_METHOD *rsa, jpayne@69: int (*pub_dec) (int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, jpayne@69: int padding)); jpayne@69: int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth)) jpayne@69: (int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, int padding); jpayne@69: int RSA_meth_set_priv_enc(RSA_METHOD *rsa, jpayne@69: int (*priv_enc) (int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, jpayne@69: int padding)); jpayne@69: int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth)) jpayne@69: (int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, int padding); jpayne@69: int RSA_meth_set_priv_dec(RSA_METHOD *rsa, jpayne@69: int (*priv_dec) (int flen, const unsigned char *from, jpayne@69: unsigned char *to, RSA *rsa, jpayne@69: int padding)); jpayne@69: int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth)) jpayne@69: (BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx); jpayne@69: int RSA_meth_set_mod_exp(RSA_METHOD *rsa, jpayne@69: int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa, jpayne@69: BN_CTX *ctx)); jpayne@69: int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth)) jpayne@69: (BIGNUM *r, const BIGNUM *a, const BIGNUM *p, jpayne@69: const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); jpayne@69: int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa, jpayne@69: int (*bn_mod_exp) (BIGNUM *r, jpayne@69: const BIGNUM *a, jpayne@69: const BIGNUM *p, jpayne@69: const BIGNUM *m, jpayne@69: BN_CTX *ctx, jpayne@69: BN_MONT_CTX *m_ctx)); jpayne@69: int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa); jpayne@69: int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa)); jpayne@69: int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa); jpayne@69: int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa)); jpayne@69: int (*RSA_meth_get_sign(const RSA_METHOD *meth)) jpayne@69: (int type, jpayne@69: const unsigned char *m, unsigned int m_length, jpayne@69: unsigned char *sigret, unsigned int *siglen, jpayne@69: const RSA *rsa); jpayne@69: int RSA_meth_set_sign(RSA_METHOD *rsa, jpayne@69: int (*sign) (int type, const unsigned char *m, jpayne@69: unsigned int m_length, jpayne@69: unsigned char *sigret, unsigned int *siglen, jpayne@69: const RSA *rsa)); jpayne@69: int (*RSA_meth_get_verify(const RSA_METHOD *meth)) jpayne@69: (int dtype, const unsigned char *m, jpayne@69: unsigned int m_length, const unsigned char *sigbuf, jpayne@69: unsigned int siglen, const RSA *rsa); jpayne@69: int RSA_meth_set_verify(RSA_METHOD *rsa, jpayne@69: int (*verify) (int dtype, const unsigned char *m, jpayne@69: unsigned int m_length, jpayne@69: const unsigned char *sigbuf, jpayne@69: unsigned int siglen, const RSA *rsa)); jpayne@69: int (*RSA_meth_get_keygen(const RSA_METHOD *meth)) jpayne@69: (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); jpayne@69: int RSA_meth_set_keygen(RSA_METHOD *rsa, jpayne@69: int (*keygen) (RSA *rsa, int bits, BIGNUM *e, jpayne@69: BN_GENCB *cb)); jpayne@69: int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth)) jpayne@69: (RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb); jpayne@69: int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth, jpayne@69: int (*keygen) (RSA *rsa, int bits, jpayne@69: int primes, BIGNUM *e, jpayne@69: BN_GENCB *cb)); jpayne@69: jpayne@69: # ifdef __cplusplus jpayne@69: } jpayne@69: # endif jpayne@69: # endif jpayne@69: #endif