156083Skris/* crypto/rsa/rsa.h */ 256083Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 356083Skris * All rights reserved. 456083Skris * 556083Skris * This package is an SSL implementation written 656083Skris * by Eric Young (eay@cryptsoft.com). 756083Skris * The implementation was written so as to conform with Netscapes SSL. 8296341Sdelphij * 956083Skris * This library is free for commercial and non-commercial use as long as 1056083Skris * the following conditions are aheared to. The following conditions 1156083Skris * apply to all code found in this distribution, be it the RC4, RSA, 1256083Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1356083Skris * included with this distribution is covered by the same copyright terms 1456083Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15296341Sdelphij * 1656083Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1756083Skris * the code are not to be removed. 1856083Skris * If this package is used in a product, Eric Young should be given attribution 1956083Skris * as the author of the parts of the library used. 2056083Skris * This can be in the form of a textual message at program startup or 2156083Skris * in documentation (online or textual) provided with the package. 22296341Sdelphij * 2356083Skris * Redistribution and use in source and binary forms, with or without 2456083Skris * modification, are permitted provided that the following conditions 2556083Skris * are met: 2656083Skris * 1. Redistributions of source code must retain the copyright 2756083Skris * notice, this list of conditions and the following disclaimer. 2856083Skris * 2. Redistributions in binary form must reproduce the above copyright 2956083Skris * notice, this list of conditions and the following disclaimer in the 3056083Skris * documentation and/or other materials provided with the distribution. 3156083Skris * 3. All advertising materials mentioning features or use of this software 3256083Skris * must display the following acknowledgement: 3356083Skris * "This product includes cryptographic software written by 3456083Skris * Eric Young (eay@cryptsoft.com)" 3556083Skris * The word 'cryptographic' can be left out if the rouines from the library 3656083Skris * being used are not cryptographic related :-). 37296341Sdelphij * 4. If you include any Windows specific code (or a derivative thereof) from 3856083Skris * the apps directory (application code) you must include an acknowledgement: 3956083Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40296341Sdelphij * 4156083Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4256083Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4356083Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4456083Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4556083Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4656083Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4756083Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4856083Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4956083Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5056083Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5156083Skris * SUCH DAMAGE. 52296341Sdelphij * 5356083Skris * The licence and distribution terms for any publically available version or 5456083Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5556083Skris * copied and put under another distribution licence 5656083Skris * [including the GNU Public Licence.] 5756083Skris */ 5856083Skris 5956083Skris#ifndef HEADER_RSA_H 60296341Sdelphij# define HEADER_RSA_H 6156083Skris 62296341Sdelphij# include <openssl/asn1.h> 63110007Smarkm 64296341Sdelphij# ifndef OPENSSL_NO_BIO 65296341Sdelphij# include <openssl/bio.h> 66296341Sdelphij# endif 67296341Sdelphij# include <openssl/crypto.h> 68296341Sdelphij# include <openssl/ossl_typ.h> 69296341Sdelphij# ifndef OPENSSL_NO_DEPRECATED 70296341Sdelphij# include <openssl/bn.h> 71296341Sdelphij# endif 7256083Skris 73296341Sdelphij# ifdef OPENSSL_NO_RSA 74296341Sdelphij# error RSA is disabled. 75296341Sdelphij# endif 7656083Skris 7768654Skris#ifdef __cplusplus 7868654Skrisextern "C" { 7968654Skris#endif 8068654Skris 81160817Ssimon/* Declared already in ossl_typ.h */ 82160817Ssimon/* typedef struct rsa_st RSA; */ 83160817Ssimon/* typedef struct rsa_meth_st RSA_METHOD; */ 8456083Skris 85296341Sdelphijstruct rsa_meth_st { 86296341Sdelphij const char *name; 87296341Sdelphij int (*rsa_pub_enc) (int flen, const unsigned char *from, 88296341Sdelphij unsigned char *to, RSA *rsa, int padding); 89296341Sdelphij int (*rsa_pub_dec) (int flen, const unsigned char *from, 90296341Sdelphij unsigned char *to, RSA *rsa, int padding); 91296341Sdelphij int (*rsa_priv_enc) (int flen, const unsigned char *from, 92296341Sdelphij unsigned char *to, RSA *rsa, int padding); 93296341Sdelphij int (*rsa_priv_dec) (int flen, const unsigned char *from, 94296341Sdelphij unsigned char *to, RSA *rsa, int padding); 95296341Sdelphij /* Can be null */ 96296341Sdelphij int (*rsa_mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx); 97296341Sdelphij /* Can be null */ 98296341Sdelphij int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 99296341Sdelphij const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 100296341Sdelphij /* called at new */ 101296341Sdelphij int (*init) (RSA *rsa); 102296341Sdelphij /* called at free */ 103296341Sdelphij int (*finish) (RSA *rsa); 104296341Sdelphij /* RSA_METHOD_FLAG_* things */ 105296341Sdelphij int flags; 106296341Sdelphij /* may be needed! */ 107296341Sdelphij char *app_data; 108296341Sdelphij /* 109296341Sdelphij * New sign and verify functions: some libraries don't allow arbitrary 110296341Sdelphij * data to be signed/verified: this allows them to be used. Note: for 111296341Sdelphij * this to work the RSA_public_decrypt() and RSA_private_encrypt() should 112296341Sdelphij * *NOT* be used RSA_sign(), RSA_verify() should be used instead. Note: 113296341Sdelphij * for backwards compatibility this functionality is only enabled if the 114296341Sdelphij * RSA_FLAG_SIGN_VER option is set in 'flags'. 115296341Sdelphij */ 116296341Sdelphij int (*rsa_sign) (int type, 117296341Sdelphij const unsigned char *m, unsigned int m_length, 118296341Sdelphij unsigned char *sigret, unsigned int *siglen, 119296341Sdelphij const RSA *rsa); 120296341Sdelphij int (*rsa_verify) (int dtype, const unsigned char *m, 121296341Sdelphij unsigned int m_length, const unsigned char *sigbuf, 122296341Sdelphij unsigned int siglen, const RSA *rsa); 123296341Sdelphij /* 124296341Sdelphij * If this callback is NULL, the builtin software RSA key-gen will be 125296341Sdelphij * used. This is for behavioural compatibility whilst the code gets 126296341Sdelphij * rewired, but one day it would be nice to assume there are no such 127296341Sdelphij * things as "builtin software" implementations. 128296341Sdelphij */ 129296341Sdelphij int (*rsa_keygen) (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); 130296341Sdelphij}; 131100931Snectar 132296341Sdelphijstruct rsa_st { 133296341Sdelphij /* 134296341Sdelphij * The first parameter is used to pickup errors where this is passed 135296341Sdelphij * instead of aEVP_PKEY, it is set to 0 136296341Sdelphij */ 137296341Sdelphij int pad; 138296341Sdelphij long version; 139296341Sdelphij const RSA_METHOD *meth; 140296341Sdelphij /* functional reference if 'meth' is ENGINE-provided */ 141296341Sdelphij ENGINE *engine; 142296341Sdelphij BIGNUM *n; 143296341Sdelphij BIGNUM *e; 144296341Sdelphij BIGNUM *d; 145296341Sdelphij BIGNUM *p; 146296341Sdelphij BIGNUM *q; 147296341Sdelphij BIGNUM *dmp1; 148296341Sdelphij BIGNUM *dmq1; 149296341Sdelphij BIGNUM *iqmp; 150296341Sdelphij /* be careful using this if the RSA structure is shared */ 151296341Sdelphij CRYPTO_EX_DATA ex_data; 152296341Sdelphij int references; 153296341Sdelphij int flags; 154296341Sdelphij /* Used to cache montgomery values */ 155296341Sdelphij BN_MONT_CTX *_method_mod_n; 156296341Sdelphij BN_MONT_CTX *_method_mod_p; 157296341Sdelphij BN_MONT_CTX *_method_mod_q; 158296341Sdelphij /* 159296341Sdelphij * all BIGNUM values are actually in the following data, if it is not 160296341Sdelphij * NULL 161296341Sdelphij */ 162296341Sdelphij char *bignum_data; 163296341Sdelphij BN_BLINDING *blinding; 164296341Sdelphij BN_BLINDING *mt_blinding; 165296341Sdelphij}; 16656083Skris 167296341Sdelphij# ifndef OPENSSL_RSA_MAX_MODULUS_BITS 168296341Sdelphij# define OPENSSL_RSA_MAX_MODULUS_BITS 16384 169296341Sdelphij# endif 17056083Skris 171296341Sdelphij# ifndef OPENSSL_RSA_SMALL_MODULUS_BITS 172296341Sdelphij# define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 173296341Sdelphij# endif 174296341Sdelphij# ifndef OPENSSL_RSA_MAX_PUBEXP_BITS 17556083Skris 176296341Sdelphij/* exponent limit enforced for "large" modulus only */ 177296341Sdelphij# define OPENSSL_RSA_MAX_PUBEXP_BITS 64 178296341Sdelphij# endif 179162914Ssimon 180296341Sdelphij# define RSA_3 0x3L 181296341Sdelphij# define RSA_F4 0x10001L 182162914Ssimon 183296341Sdelphij# define RSA_METHOD_FLAG_NO_CHECK 0x0001/* don't check pub/private 184296341Sdelphij * match */ 18556083Skris 186296341Sdelphij# define RSA_FLAG_CACHE_PUBLIC 0x0002 187296341Sdelphij# define RSA_FLAG_CACHE_PRIVATE 0x0004 188296341Sdelphij# define RSA_FLAG_BLINDING 0x0008 189296341Sdelphij# define RSA_FLAG_THREAD_SAFE 0x0010 190296341Sdelphij/* 191296341Sdelphij * This flag means the private key operations will be handled by rsa_mod_exp 19256083Skris * and that they do not depend on the private key components being present: 193296341Sdelphij * for example a key stored in external hardware. Without this flag 194296341Sdelphij * bn_mod_exp gets called when private key components are absent. 19556083Skris */ 196296341Sdelphij# define RSA_FLAG_EXT_PKEY 0x0020 19756083Skris 198296341Sdelphij/* 199296341Sdelphij * This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify 200296341Sdelphij * functions. 20159194Skris */ 202296341Sdelphij# define RSA_FLAG_SIGN_VER 0x0040 20359194Skris 204296341Sdelphij/* 205296341Sdelphij * new with 0.9.6j and 0.9.7b; the built-in 206296341Sdelphij * RSA implementation now uses blinding by 207296341Sdelphij * default (ignoring RSA_FLAG_BLINDING), 208296341Sdelphij * but other engines might not need it 209296341Sdelphij */ 210296341Sdelphij# define RSA_FLAG_NO_BLINDING 0x0080 211296341Sdelphij/* 212296341Sdelphij * new with 0.9.8f; the built-in RSA 213296341Sdelphij * implementation now uses constant time 214296341Sdelphij * operations by default in private key operations, 215296341Sdelphij * e.g., constant time modular exponentiation, 216296341Sdelphij * modular inverse without leaking branches, 217296341Sdelphij * division without leaking branches. This 218296341Sdelphij * flag disables these constant time 219296341Sdelphij * operations and results in faster RSA 220296341Sdelphij * private key operations. 221296341Sdelphij */ 222296341Sdelphij# define RSA_FLAG_NO_CONSTTIME 0x0100 223296341Sdelphij# ifdef OPENSSL_USE_DEPRECATED 224296341Sdelphij/* deprecated name for the flag*/ 225296341Sdelphij/* 226296341Sdelphij * new with 0.9.7h; the built-in RSA 227296341Sdelphij * implementation now uses constant time 228296341Sdelphij * modular exponentiation for secret exponents 229296341Sdelphij * by default. This flag causes the 230296341Sdelphij * faster variable sliding window method to 231296341Sdelphij * be used for all exponents. 232296341Sdelphij */ 233296341Sdelphij# define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME 234296341Sdelphij# endif 235120635Snectar 236296341Sdelphij# define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \ 237296341Sdelphij EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, EVP_PKEY_CTRL_RSA_PADDING, \ 238296341Sdelphij pad, NULL) 239194206Ssimon 240296341Sdelphij# define EVP_PKEY_CTX_get_rsa_padding(ctx, ppad) \ 241296341Sdelphij EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, \ 242296341Sdelphij EVP_PKEY_CTRL_GET_RSA_PADDING, 0, ppad) 243238405Sjkim 244296341Sdelphij# define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \ 245296341Sdelphij EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \ 246296341Sdelphij (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \ 247296341Sdelphij EVP_PKEY_CTRL_RSA_PSS_SALTLEN, \ 248296341Sdelphij len, NULL) 249238405Sjkim 250296341Sdelphij# define EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, plen) \ 251296341Sdelphij EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \ 252296341Sdelphij (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \ 253296341Sdelphij EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, \ 254296341Sdelphij 0, plen) 255238405Sjkim 256296341Sdelphij# define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \ 257296341Sdelphij EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \ 258296341Sdelphij EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL) 259238405Sjkim 260296341Sdelphij# define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \ 261296341Sdelphij EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \ 262296341Sdelphij EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp) 263238405Sjkim 264296341Sdelphij# define EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md) \ 265296341Sdelphij EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_SIG, \ 266296341Sdelphij EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)md) 267238405Sjkim 268296341Sdelphij# define EVP_PKEY_CTX_get_rsa_mgf1_md(ctx, pmd) \ 269296341Sdelphij EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_SIG, \ 270296341Sdelphij EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)pmd) 271238405Sjkim 272296341Sdelphij# define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1) 273296341Sdelphij# define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2) 274238405Sjkim 275296341Sdelphij# define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3) 276296341Sdelphij# define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4) 277296341Sdelphij# define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5) 278238405Sjkim 279296341Sdelphij# define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6) 280296341Sdelphij# define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7) 281296341Sdelphij# define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8) 282238405Sjkim 283296341Sdelphij# define RSA_PKCS1_PADDING 1 284296341Sdelphij# define RSA_SSLV23_PADDING 2 285296341Sdelphij# define RSA_NO_PADDING 3 286296341Sdelphij# define RSA_PKCS1_OAEP_PADDING 4 287296341Sdelphij# define RSA_X931_PADDING 5 288238405Sjkim/* EVP_PKEY_ only */ 289296341Sdelphij# define RSA_PKCS1_PSS_PADDING 6 29056083Skris 291296341Sdelphij# define RSA_PKCS1_PADDING_SIZE 11 292110007Smarkm 293296341Sdelphij# define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) 294296341Sdelphij# define RSA_get_app_data(s) RSA_get_ex_data(s,0) 29556083Skris 296296341SdelphijRSA *RSA_new(void); 297296341SdelphijRSA *RSA_new_method(ENGINE *engine); 298296341Sdelphijint RSA_size(const RSA *rsa); 299160817Ssimon 300160817Ssimon/* Deprecated version */ 301296341Sdelphij# ifndef OPENSSL_NO_DEPRECATED 302296341SdelphijRSA *RSA_generate_key(int bits, unsigned long e, void 303296341Sdelphij (*callback) (int, int, void *), void *cb_arg); 304296341Sdelphij# endif /* !defined(OPENSSL_NO_DEPRECATED) */ 305160817Ssimon 306160817Ssimon/* New version */ 307296341Sdelphijint RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); 308160817Ssimon 309296341Sdelphijint RSA_check_key(const RSA *); 310296341Sdelphij /* next 4 return -1 on error */ 311296341Sdelphijint RSA_public_encrypt(int flen, const unsigned char *from, 312296341Sdelphij unsigned char *to, RSA *rsa, int padding); 313296341Sdelphijint RSA_private_encrypt(int flen, const unsigned char *from, 314296341Sdelphij unsigned char *to, RSA *rsa, int padding); 315296341Sdelphijint RSA_public_decrypt(int flen, const unsigned char *from, 316296341Sdelphij unsigned char *to, RSA *rsa, int padding); 317296341Sdelphijint RSA_private_decrypt(int flen, const unsigned char *from, 318296341Sdelphij unsigned char *to, RSA *rsa, int padding); 319296341Sdelphijvoid RSA_free(RSA *r); 320110007Smarkm/* "up" the RSA object's reference count */ 321296341Sdelphijint RSA_up_ref(RSA *r); 32256083Skris 323296341Sdelphijint RSA_flags(const RSA *r); 32456083Skris 325110007Smarkmvoid RSA_set_default_method(const RSA_METHOD *meth); 326110007Smarkmconst RSA_METHOD *RSA_get_default_method(void); 327110007Smarkmconst RSA_METHOD *RSA_get_method(const RSA *rsa); 328110007Smarkmint RSA_set_method(RSA *rsa, const RSA_METHOD *meth); 32956083Skris 33056083Skris/* This function needs the memory locking malloc callbacks to be installed */ 33156083Skrisint RSA_memory_lock(RSA *r); 33256083Skris 33356083Skris/* these are the actual SSLeay RSA functions */ 334110007Smarkmconst RSA_METHOD *RSA_PKCS1_SSLeay(void); 33556083Skris 336110007Smarkmconst RSA_METHOD *RSA_null_method(void); 33759194Skris 338110007SmarkmDECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey) 339110007SmarkmDECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey) 340110007Smarkm 341296341Sdelphijtypedef struct rsa_pss_params_st { 342296341Sdelphij X509_ALGOR *hashAlgorithm; 343296341Sdelphij X509_ALGOR *maskGenAlgorithm; 344296341Sdelphij ASN1_INTEGER *saltLength; 345296341Sdelphij ASN1_INTEGER *trailerField; 346296341Sdelphij} RSA_PSS_PARAMS; 347238405Sjkim 348238405SjkimDECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS) 349238405Sjkim 350296341Sdelphij# ifndef OPENSSL_NO_FP_API 351296341Sdelphijint RSA_print_fp(FILE *fp, const RSA *r, int offset); 352296341Sdelphij# endif 35356083Skris 354296341Sdelphij# ifndef OPENSSL_NO_BIO 355296341Sdelphijint RSA_print(BIO *bp, const RSA *r, int offset); 356296341Sdelphij# endif 35756083Skris 358296341Sdelphij# ifndef OPENSSL_NO_RC4 359160817Ssimonint i2d_RSA_NET(const RSA *a, unsigned char **pp, 360296341Sdelphij int (*cb) (char *buf, int len, const char *prompt, 361296341Sdelphij int verify), int sgckey); 362160817SsimonRSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, 363296341Sdelphij int (*cb) (char *buf, int len, const char *prompt, 364296341Sdelphij int verify), int sgckey); 36568654Skris 366160817Ssimonint i2d_Netscape_RSA(const RSA *a, unsigned char **pp, 367296341Sdelphij int (*cb) (char *buf, int len, const char *prompt, 368296341Sdelphij int verify)); 369160817SsimonRSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, 370296341Sdelphij int (*cb) (char *buf, int len, const char *prompt, 371296341Sdelphij int verify)); 372296341Sdelphij# endif 37356083Skris 374296341Sdelphij/* 375296341Sdelphij * The following 2 functions sign and verify a X509_SIG ASN1 object inside 376296341Sdelphij * PKCS#1 padded RSA encryption 377296341Sdelphij */ 378110007Smarkmint RSA_sign(int type, const unsigned char *m, unsigned int m_length, 379296341Sdelphij unsigned char *sigret, unsigned int *siglen, RSA *rsa); 380110007Smarkmint RSA_verify(int type, const unsigned char *m, unsigned int m_length, 381296341Sdelphij const unsigned char *sigbuf, unsigned int siglen, RSA *rsa); 38256083Skris 383296341Sdelphij/* 384296341Sdelphij * The following 2 function sign and verify a ASN1_OCTET_STRING object inside 385296341Sdelphij * PKCS#1 padded RSA encryption 386296341Sdelphij */ 387110007Smarkmint RSA_sign_ASN1_OCTET_STRING(int type, 388296341Sdelphij const unsigned char *m, unsigned int m_length, 389296341Sdelphij unsigned char *sigret, unsigned int *siglen, 390296341Sdelphij RSA *rsa); 391296341Sdelphijint RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m, 392296341Sdelphij unsigned int m_length, unsigned char *sigbuf, 393296341Sdelphij unsigned int siglen, RSA *rsa); 39456083Skris 39556083Skrisint RSA_blinding_on(RSA *rsa, BN_CTX *ctx); 39656083Skrisvoid RSA_blinding_off(RSA *rsa); 397160817SsimonBN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx); 39856083Skris 399296341Sdelphijint RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, 400296341Sdelphij const unsigned char *f, int fl); 401296341Sdelphijint RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, 402296341Sdelphij const unsigned char *f, int fl, 403296341Sdelphij int rsa_len); 404296341Sdelphijint RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, 405296341Sdelphij const unsigned char *f, int fl); 406296341Sdelphijint RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, 407296341Sdelphij const unsigned char *f, int fl, 408296341Sdelphij int rsa_len); 409296341Sdelphijint PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed, 410296341Sdelphij long seedlen, const EVP_MD *dgst); 411296341Sdelphijint RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, 412296341Sdelphij const unsigned char *f, int fl, 413296341Sdelphij const unsigned char *p, int pl); 414296341Sdelphijint RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, 415296341Sdelphij const unsigned char *f, int fl, int rsa_len, 416296341Sdelphij const unsigned char *p, int pl); 417296341Sdelphijint RSA_padding_add_SSLv23(unsigned char *to, int tlen, 418296341Sdelphij const unsigned char *f, int fl); 419296341Sdelphijint RSA_padding_check_SSLv23(unsigned char *to, int tlen, 420296341Sdelphij const unsigned char *f, int fl, int rsa_len); 421296341Sdelphijint RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f, 422296341Sdelphij int fl); 423296341Sdelphijint RSA_padding_check_none(unsigned char *to, int tlen, 424296341Sdelphij const unsigned char *f, int fl, int rsa_len); 425296341Sdelphijint RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f, 426296341Sdelphij int fl); 427296341Sdelphijint RSA_padding_check_X931(unsigned char *to, int tlen, 428296341Sdelphij const unsigned char *f, int fl, int rsa_len); 429160817Ssimonint RSA_X931_hash_id(int nid); 43056083Skris 431160817Ssimonint RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash, 432296341Sdelphij const EVP_MD *Hash, const unsigned char *EM, 433296341Sdelphij int sLen); 434160817Ssimonint RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM, 435296341Sdelphij const unsigned char *mHash, const EVP_MD *Hash, 436296341Sdelphij int sLen); 437160817Ssimon 438238405Sjkimint RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, 439296341Sdelphij const EVP_MD *Hash, const EVP_MD *mgf1Hash, 440296341Sdelphij const unsigned char *EM, int sLen); 441238405Sjkim 442238405Sjkimint RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, 443296341Sdelphij const unsigned char *mHash, 444296341Sdelphij const EVP_MD *Hash, const EVP_MD *mgf1Hash, 445296341Sdelphij int sLen); 446238405Sjkim 44759194Skrisint RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 448296341Sdelphij CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 449296341Sdelphijint RSA_set_ex_data(RSA *r, int idx, void *arg); 450110007Smarkmvoid *RSA_get_ex_data(const RSA *r, int idx); 45157971Skris 452110007SmarkmRSA *RSAPublicKey_dup(RSA *rsa); 453110007SmarkmRSA *RSAPrivateKey_dup(RSA *rsa); 454110007Smarkm 455296341Sdelphij/* 456296341Sdelphij * If this flag is set the RSA method is FIPS compliant and can be used in 457296341Sdelphij * FIPS mode. This is set in the validated module method. If an application 458296341Sdelphij * sets this flag in its own methods it is its responsibility to ensure the 459296341Sdelphij * result is compliant. 460238405Sjkim */ 461238405Sjkim 462296341Sdelphij# define RSA_FLAG_FIPS_METHOD 0x0400 463238405Sjkim 464296341Sdelphij/* 465296341Sdelphij * If this flag is set the operations normally disabled in FIPS mode are 466238405Sjkim * permitted it is then the applications responsibility to ensure that the 467238405Sjkim * usage is compliant. 468238405Sjkim */ 469238405Sjkim 470296341Sdelphij# define RSA_FLAG_NON_FIPS_ALLOW 0x0400 471296341Sdelphij/* 472296341Sdelphij * Application has decided PRNG is good enough to generate a key: don't 473238405Sjkim * check. 474238405Sjkim */ 475296341Sdelphij# define RSA_FLAG_CHECKED 0x0800 476238405Sjkim 47756083Skris/* BEGIN ERROR CODES */ 478296341Sdelphij/* 479296341Sdelphij * The following lines are auto generated by the script mkerr.pl. Any changes 48056083Skris * made after this point may be overwritten when the script is next run. 48156083Skris */ 48289840Skrisvoid ERR_load_RSA_strings(void); 48356083Skris 48456083Skris/* Error codes for the RSA functions. */ 48556083Skris 48656083Skris/* Function codes. */ 487296341Sdelphij# define RSA_F_CHECK_PADDING_MD 140 488296341Sdelphij# define RSA_F_DO_RSA_PRINT 146 489296341Sdelphij# define RSA_F_INT_RSA_VERIFY 145 490296341Sdelphij# define RSA_F_MEMORY_LOCK 100 491296341Sdelphij# define RSA_F_OLD_RSA_PRIV_DECODE 147 492296341Sdelphij# define RSA_F_PKEY_RSA_CTRL 143 493296341Sdelphij# define RSA_F_PKEY_RSA_CTRL_STR 144 494296341Sdelphij# define RSA_F_PKEY_RSA_SIGN 142 495296341Sdelphij# define RSA_F_PKEY_RSA_VERIFY 154 496296341Sdelphij# define RSA_F_PKEY_RSA_VERIFYRECOVER 141 497296341Sdelphij# define RSA_F_RSA_BUILTIN_KEYGEN 129 498296341Sdelphij# define RSA_F_RSA_CHECK_KEY 123 499296341Sdelphij# define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101 500296341Sdelphij# define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102 501296341Sdelphij# define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103 502296341Sdelphij# define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104 503296341Sdelphij# define RSA_F_RSA_GENERATE_KEY 105 504296341Sdelphij# define RSA_F_RSA_GENERATE_KEY_EX 155 505296341Sdelphij# define RSA_F_RSA_ITEM_VERIFY 156 506296341Sdelphij# define RSA_F_RSA_MEMORY_LOCK 130 507296341Sdelphij# define RSA_F_RSA_NEW_METHOD 106 508296341Sdelphij# define RSA_F_RSA_NULL 124 509296341Sdelphij# define RSA_F_RSA_NULL_MOD_EXP 131 510296341Sdelphij# define RSA_F_RSA_NULL_PRIVATE_DECRYPT 132 511296341Sdelphij# define RSA_F_RSA_NULL_PRIVATE_ENCRYPT 133 512296341Sdelphij# define RSA_F_RSA_NULL_PUBLIC_DECRYPT 134 513296341Sdelphij# define RSA_F_RSA_NULL_PUBLIC_ENCRYPT 135 514296341Sdelphij# define RSA_F_RSA_PADDING_ADD_NONE 107 515296341Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 516296341Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125 517296341Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1 148 518296341Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 519296341Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 520296341Sdelphij# define RSA_F_RSA_PADDING_ADD_SSLV23 110 521296341Sdelphij# define RSA_F_RSA_PADDING_ADD_X931 127 522296341Sdelphij# define RSA_F_RSA_PADDING_CHECK_NONE 111 523296341Sdelphij# define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 524296341Sdelphij# define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 525296341Sdelphij# define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 526296341Sdelphij# define RSA_F_RSA_PADDING_CHECK_SSLV23 114 527296341Sdelphij# define RSA_F_RSA_PADDING_CHECK_X931 128 528296341Sdelphij# define RSA_F_RSA_PRINT 115 529296341Sdelphij# define RSA_F_RSA_PRINT_FP 116 530296341Sdelphij# define RSA_F_RSA_PRIVATE_DECRYPT 150 531296341Sdelphij# define RSA_F_RSA_PRIVATE_ENCRYPT 151 532296341Sdelphij# define RSA_F_RSA_PRIV_DECODE 137 533296341Sdelphij# define RSA_F_RSA_PRIV_ENCODE 138 534296341Sdelphij# define RSA_F_RSA_PUBLIC_DECRYPT 152 535296341Sdelphij# define RSA_F_RSA_PUBLIC_ENCRYPT 153 536296341Sdelphij# define RSA_F_RSA_PUB_DECODE 139 537296341Sdelphij# define RSA_F_RSA_SETUP_BLINDING 136 538296341Sdelphij# define RSA_F_RSA_SIGN 117 539296341Sdelphij# define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 540296341Sdelphij# define RSA_F_RSA_VERIFY 119 541296341Sdelphij# define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 542296341Sdelphij# define RSA_F_RSA_VERIFY_PKCS1_PSS 126 543296341Sdelphij# define RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1 149 54456083Skris 54556083Skris/* Reason codes. */ 546296341Sdelphij# define RSA_R_ALGORITHM_MISMATCH 100 547296341Sdelphij# define RSA_R_BAD_E_VALUE 101 548296341Sdelphij# define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 549296341Sdelphij# define RSA_R_BAD_PAD_BYTE_COUNT 103 550296341Sdelphij# define RSA_R_BAD_SIGNATURE 104 551296341Sdelphij# define RSA_R_BLOCK_TYPE_IS_NOT_01 106 552296341Sdelphij# define RSA_R_BLOCK_TYPE_IS_NOT_02 107 553296341Sdelphij# define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 554296341Sdelphij# define RSA_R_DATA_TOO_LARGE 109 555296341Sdelphij# define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 556296341Sdelphij# define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132 557296341Sdelphij# define RSA_R_DATA_TOO_SMALL 111 558296341Sdelphij# define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 559296341Sdelphij# define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 560296341Sdelphij# define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 561296341Sdelphij# define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 562296341Sdelphij# define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 563296341Sdelphij# define RSA_R_FIRST_OCTET_INVALID 133 564296341Sdelphij# define RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE 144 565296341Sdelphij# define RSA_R_INVALID_DIGEST_LENGTH 143 566296341Sdelphij# define RSA_R_INVALID_HEADER 137 567296341Sdelphij# define RSA_R_INVALID_KEYBITS 145 568296341Sdelphij# define RSA_R_INVALID_MESSAGE_LENGTH 131 569296341Sdelphij# define RSA_R_INVALID_MGF1_MD 156 570296341Sdelphij# define RSA_R_INVALID_PADDING 138 571296341Sdelphij# define RSA_R_INVALID_PADDING_MODE 141 572296341Sdelphij# define RSA_R_INVALID_PSS_PARAMETERS 149 573296341Sdelphij# define RSA_R_INVALID_PSS_SALTLEN 146 574296341Sdelphij# define RSA_R_INVALID_SALT_LENGTH 150 575296341Sdelphij# define RSA_R_INVALID_TRAILER 139 576296341Sdelphij# define RSA_R_INVALID_X931_DIGEST 142 577296341Sdelphij# define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 578296341Sdelphij# define RSA_R_KEY_SIZE_TOO_SMALL 120 579296341Sdelphij# define RSA_R_LAST_OCTET_INVALID 134 580296341Sdelphij# define RSA_R_MODULUS_TOO_LARGE 105 581296341Sdelphij# define RSA_R_NON_FIPS_RSA_METHOD 157 582296341Sdelphij# define RSA_R_NO_PUBLIC_EXPONENT 140 583296341Sdelphij# define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 584296341Sdelphij# define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 585296341Sdelphij# define RSA_R_OAEP_DECODING_ERROR 121 586296341Sdelphij# define RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE 158 587296341Sdelphij# define RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 148 588296341Sdelphij# define RSA_R_PADDING_CHECK_FAILED 114 589296341Sdelphij# define RSA_R_PKCS_DECODING_ERROR 159 590296341Sdelphij# define RSA_R_P_NOT_PRIME 128 591296341Sdelphij# define RSA_R_Q_NOT_PRIME 129 592296341Sdelphij# define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130 593296341Sdelphij# define RSA_R_SLEN_CHECK_FAILED 136 594296341Sdelphij# define RSA_R_SLEN_RECOVERY_FAILED 135 595296341Sdelphij# define RSA_R_SSLV3_ROLLBACK_ATTACK 115 596296341Sdelphij# define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 597296341Sdelphij# define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 598296341Sdelphij# define RSA_R_UNKNOWN_MASK_DIGEST 151 599296341Sdelphij# define RSA_R_UNKNOWN_PADDING_TYPE 118 600296341Sdelphij# define RSA_R_UNKNOWN_PSS_DIGEST 152 601296341Sdelphij# define RSA_R_UNSUPPORTED_MASK_ALGORITHM 153 602296341Sdelphij# define RSA_R_UNSUPPORTED_MASK_PARAMETER 154 603296341Sdelphij# define RSA_R_UNSUPPORTED_SIGNATURE_TYPE 155 604296341Sdelphij# define RSA_R_VALUE_MISSING 147 605296341Sdelphij# define RSA_R_WRONG_SIGNATURE_LENGTH 119 60656083Skris 60756083Skris#ifdef __cplusplus 60856083Skris} 60956083Skris#endif 61056083Skris#endif 611