00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #ifndef HEADER_RSA_H
00063 #define HEADER_RSA_H
00064
00065 #if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
00066 #define SYMBIAN
00067 #endif
00068
00069 #ifdef SYMBIAN
00070 #include <e32def.h>
00071 #endif
00072 #include <openssl/asn1.h>
00073
00074 #ifndef OPENSSL_NO_BIO
00075 #include <openssl/bio.h>
00076 #endif
00077 #include <openssl/crypto.h>
00078 #include <openssl/ossl_typ.h>
00079 #ifndef OPENSSL_NO_DEPRECATED
00080 #include <openssl/bn.h>
00081 #endif
00082
00083 #ifdef OPENSSL_NO_RSA
00084 #error RSA is disabled.
00085 #endif
00086
00087 #ifdef __cplusplus
00088 extern "C" {
00089 #endif
00090
00091
00092
00093
00094
00095 struct rsa_meth_st
00096 {
00097 const char *name;
00098 int (*rsa_pub_enc)(int flen,const unsigned char *from,
00099 unsigned char *to,
00100 RSA *rsa,int padding);
00101 int (*rsa_pub_dec)(int flen,const unsigned char *from,
00102 unsigned char *to,
00103 RSA *rsa,int padding);
00104 int (*rsa_priv_enc)(int flen,const unsigned char *from,
00105 unsigned char *to,
00106 RSA *rsa,int padding);
00107 int (*rsa_priv_dec)(int flen,const unsigned char *from,
00108 unsigned char *to,
00109 RSA *rsa,int padding);
00110 int (*rsa_mod_exp)(BIGNUM *r0,const BIGNUM *I,RSA *rsa,BN_CTX *ctx);
00111 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
00112 const BIGNUM *m, BN_CTX *ctx,
00113 BN_MONT_CTX *m_ctx);
00114 int (*init)(RSA *rsa);
00115 int (*finish)(RSA *rsa);
00116 int flags;
00117 char *app_data;
00118
00119
00120
00121
00122
00123
00124
00125 int (*rsa_sign)(int type,
00126 const unsigned char *m, unsigned int m_length,
00127 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
00128 int (*rsa_verify)(int dtype,
00129 const unsigned char *m, unsigned int m_length,
00130 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
00131
00132
00133
00134
00135 int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
00136 };
00137
00138 struct rsa_st
00139 {
00140
00141
00142 int pad;
00143 long version;
00144 const RSA_METHOD *meth;
00145
00146 ENGINE *engine;
00147 BIGNUM *n;
00148 BIGNUM *e;
00149 BIGNUM *d;
00150 BIGNUM *p;
00151 BIGNUM *q;
00152 BIGNUM *dmp1;
00153 BIGNUM *dmq1;
00154 BIGNUM *iqmp;
00155
00156 CRYPTO_EX_DATA ex_data;
00157 int references;
00158 int flags;
00159
00160
00161 BN_MONT_CTX *_method_mod_n;
00162 BN_MONT_CTX *_method_mod_p;
00163 BN_MONT_CTX *_method_mod_q;
00164
00165
00166
00167 char *bignum_data;
00168 BN_BLINDING *blinding;
00169 BN_BLINDING *mt_blinding;
00170 };
00171 #ifndef OPENSSL_RSA_MAX_MODULUS_BITS
00172 # define OPENSSL_RSA_MAX_MODULUS_BITS 16384
00173 #endif
00174
00175 #ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
00176 # define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
00177 #endif
00178 #ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
00179 # define OPENSSL_RSA_MAX_PUBEXP_BITS 64
00180 #endif
00181
00182
00183 #define RSA_3 0x3L
00184 #define RSA_F4 0x10001L
00185
00186 #define RSA_METHOD_FLAG_NO_CHECK 0x0001
00187
00188 #define RSA_FLAG_CACHE_PUBLIC 0x0002
00189 #define RSA_FLAG_CACHE_PRIVATE 0x0004
00190 #define RSA_FLAG_BLINDING 0x0008
00191 #define RSA_FLAG_THREAD_SAFE 0x0010
00192
00193
00194
00195
00196
00197 #define RSA_FLAG_EXT_PKEY 0x0020
00198
00199
00200
00201 #define RSA_FLAG_SIGN_VER 0x0040
00202
00203 #define RSA_FLAG_NO_BLINDING 0x0080
00204
00205
00206
00207
00208 #define RSA_FLAG_NO_EXP_CONSTTIME 0x0100
00209
00210
00211
00212
00213
00214
00215
00216 #define RSA_PKCS1_PADDING 1
00217 #define RSA_SSLV23_PADDING 2
00218 #define RSA_NO_PADDING 3
00219 #define RSA_PKCS1_OAEP_PADDING 4
00220 #define RSA_X931_PADDING 5
00221
00222 #define RSA_PKCS1_PADDING_SIZE 11
00223
00224 #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg)
00225 #define RSA_get_app_data(s) RSA_get_ex_data(s,0)
00226
00227 RSA * RSA_new(void);
00228 RSA * RSA_new_method(ENGINE *engine);
00229 int RSA_size(const RSA *);
00230
00231
00232
00233 IMPORT_C int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
00234
00235 IMPORT_C int RSA_check_key(const RSA *);
00236
00237 IMPORT_C int RSA_public_encrypt(int flen, const unsigned char *from,
00238 unsigned char *to, RSA *rsa,int padding);
00239 IMPORT_C int RSA_private_encrypt(int flen, const unsigned char *from,
00240 unsigned char *to, RSA *rsa,int padding);
00241 IMPORT_C int RSA_public_decrypt(int flen, const unsigned char *from,
00242 unsigned char *to, RSA *rsa,int padding);
00243 IMPORT_C int RSA_private_decrypt(int flen, const unsigned char *from,
00244 unsigned char *to, RSA *rsa,int padding);
00245 IMPORT_C void RSA_free (RSA *r);
00246
00247 IMPORT_C int RSA_up_ref(RSA *r);
00248
00249 IMPORT_C int RSA_flags(const RSA *r);
00250
00251 IMPORT_C void RSA_set_default_method(const RSA_METHOD *meth);
00252 IMPORT_C const RSA_METHOD *RSA_get_default_method(void);
00253 IMPORT_C const RSA_METHOD *RSA_get_method(const RSA *rsa);
00254 IMPORT_C int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
00255
00256
00257 IMPORT_C int RSA_memory_lock(RSA *r);
00258
00259
00260 IMPORT_C const RSA_METHOD *RSA_PKCS1_SSLeay(void);
00261
00262 IMPORT_C const RSA_METHOD *RSA_null_method(void);
00263
00264 DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
00265 DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
00266
00267 #ifndef OPENSSL_NO_FP_API
00268 IMPORT_C int RSA_print_fp(FILE *fp, const RSA *r,int offset);
00269 #endif
00270
00271 #ifndef OPENSSL_NO_BIO
00272 IMPORT_C int RSA_print(BIO *bp, const RSA *r,int offset);
00273 #endif
00274
00275 IMPORT_C int i2d_RSA_NET(const RSA *a, unsigned char **pp,
00276 int (*cb)(char *buf, int len, const char *prompt, int verify),
00277 int sgckey);
00278 IMPORT_C RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
00279 int (*cb)(char *buf, int len, const char *prompt, int verify),
00280 int sgckey);
00281
00282 IMPORT_C int i2d_Netscape_RSA(const RSA *a, unsigned char **pp,
00283 int (*cb)(char *buf, int len, const char *prompt,
00284 int verify));
00285 IMPORT_C RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length,
00286 int (*cb)(char *buf, int len, const char *prompt,
00287 int verify));
00288
00289
00290
00291 IMPORT_C int RSA_sign(int type, const unsigned char *m, unsigned int m_length,
00292 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
00293 IMPORT_C int RSA_verify(int type, const unsigned char *m, unsigned int m_length,
00294 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
00295
00296
00297
00298 IMPORT_C int RSA_sign_ASN1_OCTET_STRING(int type,
00299 const unsigned char *m, unsigned int m_length,
00300 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
00301 IMPORT_C int RSA_verify_ASN1_OCTET_STRING(int type,
00302 const unsigned char *m, unsigned int m_length,
00303 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
00304
00305 IMPORT_C int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
00306 IMPORT_C void RSA_blinding_off(RSA *rsa);
00307 IMPORT_C BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
00308
00309 IMPORT_C int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,
00310 const unsigned char *f,int fl);
00311 IMPORT_C int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen,
00312 const unsigned char *f,int fl,int rsa_len);
00313 IMPORT_C int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen,
00314 const unsigned char *f,int fl);
00315 IMPORT_C int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen,
00316 const unsigned char *f,int fl,int rsa_len);
00317 IMPORT_C int PKCS1_MGF1(unsigned char *mask, long len,
00318 const unsigned char *seed, long seedlen, const EVP_MD *dgst);
00319 IMPORT_C int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen,
00320 const unsigned char *f,int fl,
00321 const unsigned char *p,int pl);
00322 IMPORT_C int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen,
00323 const unsigned char *f,int fl,int rsa_len,
00324 const unsigned char *p,int pl);
00325 IMPORT_C int RSA_padding_add_SSLv23(unsigned char *to,int tlen,
00326 const unsigned char *f,int fl);
00327 IMPORT_C int RSA_padding_check_SSLv23(unsigned char *to,int tlen,
00328 const unsigned char *f,int fl,int rsa_len);
00329 IMPORT_C int RSA_padding_add_none(unsigned char *to,int tlen,
00330 const unsigned char *f,int fl);
00331 IMPORT_C int RSA_padding_check_none(unsigned char *to,int tlen,
00332 const unsigned char *f,int fl,int rsa_len);
00333 IMPORT_C int RSA_padding_add_X931(unsigned char *to,int tlen,
00334 const unsigned char *f,int fl);
00335 IMPORT_C int RSA_padding_check_X931(unsigned char *to,int tlen,
00336 const unsigned char *f,int fl,int rsa_len);
00337 IMPORT_C int RSA_X931_hash_id(int nid);
00338
00339 IMPORT_C int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
00340 const EVP_MD *Hash, const unsigned char *EM, int sLen);
00341 IMPORT_C int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
00342 const unsigned char *mHash,
00343 const EVP_MD *Hash, int sLen);
00344
00345 IMPORT_C int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
00346 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
00347 IMPORT_C int RSA_set_ex_data(RSA *r,int idx,void *arg);
00348 IMPORT_C void *RSA_get_ex_data(const RSA *r, int idx);
00349
00350 IMPORT_C RSA *RSAPublicKey_dup(RSA *rsa);
00351 IMPORT_C RSA *RSAPrivateKey_dup(RSA *rsa);
00352
00353
00354
00355
00356
00357 IMPORT_C void ERR_load_RSA_strings(void);
00358
00359
00360
00361
00362 #define RSA_F_MEMORY_LOCK 100
00363 #define RSA_F_RSA_BUILTIN_KEYGEN 129
00364 #define RSA_F_RSA_CHECK_KEY 123
00365 #define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101
00366 #define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102
00367 #define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103
00368 #define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104
00369 #define RSA_F_RSA_GENERATE_KEY 105
00370 #define RSA_F_RSA_MEMORY_LOCK 130
00371 #define RSA_F_RSA_NEW_METHOD 106
00372 #define RSA_F_RSA_NULL 124
00373 #define RSA_F_RSA_NULL_MOD_EXP 131
00374 #define RSA_F_RSA_NULL_PRIVATE_DECRYPT 132
00375 #define RSA_F_RSA_NULL_PRIVATE_ENCRYPT 133
00376 #define RSA_F_RSA_NULL_PUBLIC_DECRYPT 134
00377 #define RSA_F_RSA_NULL_PUBLIC_ENCRYPT 135
00378 #define RSA_F_RSA_PADDING_ADD_NONE 107
00379 #define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
00380 #define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125
00381 #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
00382 #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109
00383 #define RSA_F_RSA_PADDING_ADD_SSLV23 110
00384 #define RSA_F_RSA_PADDING_ADD_X931 127
00385 #define RSA_F_RSA_PADDING_CHECK_NONE 111
00386 #define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122
00387 #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112
00388 #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113
00389 #define RSA_F_RSA_PADDING_CHECK_SSLV23 114
00390 #define RSA_F_RSA_PADDING_CHECK_X931 128
00391 #define RSA_F_RSA_PRINT 115
00392 #define RSA_F_RSA_PRINT_FP 116
00393 #define RSA_F_RSA_SETUP_BLINDING 136
00394 #define RSA_F_RSA_SIGN 117
00395 #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
00396 #define RSA_F_RSA_VERIFY 119
00397 #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120
00398 #define RSA_F_RSA_VERIFY_PKCS1_PSS 126
00399
00400
00401 #define RSA_R_ALGORITHM_MISMATCH 100
00402 #define RSA_R_BAD_E_VALUE 101
00403 #define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
00404 #define RSA_R_BAD_PAD_BYTE_COUNT 103
00405 #define RSA_R_BAD_SIGNATURE 104
00406 #define RSA_R_BLOCK_TYPE_IS_NOT_01 106
00407 #define RSA_R_BLOCK_TYPE_IS_NOT_02 107
00408 #define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
00409 #define RSA_R_DATA_TOO_LARGE 109
00410 #define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
00411 #define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132
00412 #define RSA_R_DATA_TOO_SMALL 111
00413 #define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
00414 #define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
00415 #define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
00416 #define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
00417 #define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
00418 #define RSA_R_FIRST_OCTET_INVALID 133
00419 #define RSA_R_INVALID_HEADER 137
00420 #define RSA_R_INVALID_MESSAGE_LENGTH 131
00421 #define RSA_R_INVALID_PADDING 138
00422 #define RSA_R_INVALID_TRAILER 139
00423 #define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
00424 #define RSA_R_KEY_SIZE_TOO_SMALL 120
00425 #define RSA_R_LAST_OCTET_INVALID 134
00426 #define RSA_R_MODULUS_TOO_LARGE 105
00427 #define RSA_R_NO_PUBLIC_EXPONENT 140
00428 #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
00429 #define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
00430 #define RSA_R_OAEP_DECODING_ERROR 121
00431 #define RSA_R_SLEN_RECOVERY_FAILED 135
00432 #define RSA_R_PADDING_CHECK_FAILED 114
00433 #define RSA_R_P_NOT_PRIME 128
00434 #define RSA_R_Q_NOT_PRIME 129
00435 #define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130
00436 #define RSA_R_SSLV3_ROLLBACK_ATTACK 115
00437 #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
00438 #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
00439 #define RSA_R_UNKNOWN_PADDING_TYPE 118
00440 #define RSA_R_WRONG_SIGNATURE_LENGTH 119
00441 #define RSA_R_SLEN_CHECK_FAILED 136
00442
00443 #ifdef __cplusplus
00444 }
00445 #endif
00446 #endif