diff options
| author | cvs2svn <admin@example.com> | 1999-10-10 21:32:04 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 1999-10-10 21:32:04 +0000 |
| commit | 9b77a555b5e85a4473f23ac7342ddfb4d9ff309d (patch) | |
| tree | dae5e50679bccd1ed8d7d4041fbb9f3d96bbc98c /src/lib/libcrypto/rsa | |
| parent | 3ef9529fbf0c1f8f1c9da1172e92ad3370d5fcfe (diff) | |
| download | openbsd-OPENBSD_2_6.tar.gz openbsd-OPENBSD_2_6.tar.bz2 openbsd-OPENBSD_2_6.zip | |
This commit was manufactured by cvs2git to create branch 'OPENBSD_2_6'.OPENBSD_2_6
Diffstat (limited to 'src/lib/libcrypto/rsa')
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa.h | 317 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_chk.c | 184 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_eay.c | 288 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_err.c | 144 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_gen.c | 99 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_lib.c | 329 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_none.c | 98 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_oaep.c | 162 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_pk1.c | 212 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_saos.c | 144 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_sign.c | 188 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_ssl.c | 147 |
12 files changed, 0 insertions, 2312 deletions
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h deleted file mode 100644 index 9230b2fcc9..0000000000 --- a/src/lib/libcrypto/rsa/rsa.h +++ /dev/null | |||
| @@ -1,317 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_RSA_H | ||
| 60 | #define HEADER_RSA_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include <openssl/bn.h> | ||
| 67 | #include <openssl/crypto.h> | ||
| 68 | |||
| 69 | #ifdef NO_RSA | ||
| 70 | #error RSA is disabled. | ||
| 71 | #endif | ||
| 72 | |||
| 73 | typedef struct rsa_st RSA; | ||
| 74 | |||
| 75 | typedef struct rsa_meth_st | ||
| 76 | { | ||
| 77 | const char *name; | ||
| 78 | int (*rsa_pub_enc)(int flen,unsigned char *from,unsigned char *to, | ||
| 79 | RSA *rsa,int padding); | ||
| 80 | int (*rsa_pub_dec)(int flen,unsigned char *from,unsigned char *to, | ||
| 81 | RSA *rsa,int padding); | ||
| 82 | int (*rsa_priv_enc)(int flen,unsigned char *from,unsigned char *to, | ||
| 83 | RSA *rsa,int padding); | ||
| 84 | int (*rsa_priv_dec)(int flen,unsigned char *from,unsigned char *to, | ||
| 85 | RSA *rsa,int padding); | ||
| 86 | int (*rsa_mod_exp)(BIGNUM *r0,BIGNUM *I,RSA *rsa); /* Can be null */ | ||
| 87 | int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 88 | const BIGNUM *m, BN_CTX *ctx, | ||
| 89 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
| 90 | int (*init)(RSA *rsa); /* called at new */ | ||
| 91 | int (*finish)(RSA *rsa); /* called at free */ | ||
| 92 | int flags; /* RSA_METHOD_FLAG_* things */ | ||
| 93 | char *app_data; /* may be needed! */ | ||
| 94 | } RSA_METHOD; | ||
| 95 | |||
| 96 | struct rsa_st | ||
| 97 | { | ||
| 98 | /* The first parameter is used to pickup errors where | ||
| 99 | * this is passed instead of aEVP_PKEY, it is set to 0 */ | ||
| 100 | int pad; | ||
| 101 | int version; | ||
| 102 | RSA_METHOD *meth; | ||
| 103 | BIGNUM *n; | ||
| 104 | BIGNUM *e; | ||
| 105 | BIGNUM *d; | ||
| 106 | BIGNUM *p; | ||
| 107 | BIGNUM *q; | ||
| 108 | BIGNUM *dmp1; | ||
| 109 | BIGNUM *dmq1; | ||
| 110 | BIGNUM *iqmp; | ||
| 111 | /* be careful using this if the RSA structure is shared */ | ||
| 112 | CRYPTO_EX_DATA ex_data; | ||
| 113 | int references; | ||
| 114 | int flags; | ||
| 115 | |||
| 116 | /* Used to cache montgomery values */ | ||
| 117 | BN_MONT_CTX *_method_mod_n; | ||
| 118 | BN_MONT_CTX *_method_mod_p; | ||
| 119 | BN_MONT_CTX *_method_mod_q; | ||
| 120 | |||
| 121 | /* all BIGNUM values are actually in the following data, if it is not | ||
| 122 | * NULL */ | ||
| 123 | char *bignum_data; | ||
| 124 | BN_BLINDING *blinding; | ||
| 125 | }; | ||
| 126 | |||
| 127 | #define RSA_3 0x3L | ||
| 128 | #define RSA_F4 0x10001L | ||
| 129 | |||
| 130 | #define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */ | ||
| 131 | |||
| 132 | #define RSA_FLAG_CACHE_PUBLIC 0x02 | ||
| 133 | #define RSA_FLAG_CACHE_PRIVATE 0x04 | ||
| 134 | #define RSA_FLAG_BLINDING 0x08 | ||
| 135 | #define RSA_FLAG_THREAD_SAFE 0x10 | ||
| 136 | /* This flag means the private key operations will be handled by rsa_mod_exp | ||
| 137 | * and that they do not depend on the private key components being present: | ||
| 138 | * for example a key stored in external hardware. Without this flag bn_mod_exp | ||
| 139 | * gets called when private key components are absent. | ||
| 140 | */ | ||
| 141 | #define RSA_FLAG_EXT_PKEY 0x20 | ||
| 142 | |||
| 143 | #define RSA_PKCS1_PADDING 1 | ||
| 144 | #define RSA_SSLV23_PADDING 2 | ||
| 145 | #define RSA_NO_PADDING 3 | ||
| 146 | #define RSA_PKCS1_OAEP_PADDING 4 | ||
| 147 | |||
| 148 | #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg) | ||
| 149 | #define RSA_get_app_data(s) RSA_get_ex_data(s,0) | ||
| 150 | |||
| 151 | RSA * RSA_new(void); | ||
| 152 | RSA * RSA_new_method(RSA_METHOD *method); | ||
| 153 | int RSA_size(RSA *); | ||
| 154 | RSA * RSA_generate_key(int bits, unsigned long e,void | ||
| 155 | (*callback)(int,int,void *),void *cb_arg); | ||
| 156 | int RSA_check_key(RSA *); | ||
| 157 | /* next 4 return -1 on error */ | ||
| 158 | int RSA_public_encrypt(int flen, unsigned char *from, | ||
| 159 | unsigned char *to, RSA *rsa,int padding); | ||
| 160 | int RSA_private_encrypt(int flen, unsigned char *from, | ||
| 161 | unsigned char *to, RSA *rsa,int padding); | ||
| 162 | int RSA_public_decrypt(int flen, unsigned char *from, | ||
| 163 | unsigned char *to, RSA *rsa,int padding); | ||
| 164 | int RSA_private_decrypt(int flen, unsigned char *from, | ||
| 165 | unsigned char *to, RSA *rsa,int padding); | ||
| 166 | void RSA_free (RSA *r); | ||
| 167 | |||
| 168 | int RSA_flags(RSA *r); | ||
| 169 | |||
| 170 | void RSA_set_default_method(RSA_METHOD *meth); | ||
| 171 | RSA_METHOD *RSA_get_default_method(void); | ||
| 172 | RSA_METHOD *RSA_get_method(RSA *rsa); | ||
| 173 | RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth); | ||
| 174 | |||
| 175 | /* This function needs the memory locking malloc callbacks to be installed */ | ||
| 176 | int RSA_memory_lock(RSA *r); | ||
| 177 | |||
| 178 | /* If you have RSAref compiled in. */ | ||
| 179 | RSA_METHOD *RSA_PKCS1_RSAref(void); | ||
| 180 | |||
| 181 | /* these are the actual SSLeay RSA functions */ | ||
| 182 | RSA_METHOD *RSA_PKCS1_SSLeay(void); | ||
| 183 | |||
| 184 | void ERR_load_RSA_strings(void ); | ||
| 185 | |||
| 186 | RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length); | ||
| 187 | int i2d_RSAPublicKey(RSA *a, unsigned char **pp); | ||
| 188 | RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length); | ||
| 189 | int i2d_RSAPrivateKey(RSA *a, unsigned char **pp); | ||
| 190 | #ifndef NO_FP_API | ||
| 191 | int RSA_print_fp(FILE *fp, RSA *r,int offset); | ||
| 192 | #endif | ||
| 193 | |||
| 194 | #ifdef HEADER_BIO_H | ||
| 195 | int RSA_print(BIO *bp, RSA *r,int offset); | ||
| 196 | #endif | ||
| 197 | |||
| 198 | int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)()); | ||
| 199 | RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)()); | ||
| 200 | /* Naughty internal function required elsewhere, to handle a MS structure | ||
| 201 | * that is the same as the netscape one :-) */ | ||
| 202 | RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length, int (*cb)()); | ||
| 203 | |||
| 204 | /* The following 2 functions sign and verify a X509_SIG ASN1 object | ||
| 205 | * inside PKCS#1 padded RSA encryption */ | ||
| 206 | int RSA_sign(int type, unsigned char *m, unsigned int m_len, | ||
| 207 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | ||
| 208 | int RSA_verify(int type, unsigned char *m, unsigned int m_len, | ||
| 209 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | ||
| 210 | |||
| 211 | /* The following 2 function sign and verify a ASN1_OCTET_STRING | ||
| 212 | * object inside PKCS#1 padded RSA encryption */ | ||
| 213 | int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, | ||
| 214 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | ||
| 215 | int RSA_verify_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, | ||
| 216 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | ||
| 217 | |||
| 218 | int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); | ||
| 219 | void RSA_blinding_off(RSA *rsa); | ||
| 220 | |||
| 221 | int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, | ||
| 222 | unsigned char *f,int fl); | ||
| 223 | int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen, | ||
| 224 | unsigned char *f,int fl,int rsa_len); | ||
| 225 | int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, | ||
| 226 | unsigned char *f,int fl); | ||
| 227 | int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, | ||
| 228 | unsigned char *f,int fl,int rsa_len); | ||
| 229 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen, | ||
| 230 | unsigned char *f,int fl,unsigned char *p, | ||
| 231 | int pl); | ||
| 232 | int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen, | ||
| 233 | unsigned char *f,int fl,int rsa_len, | ||
| 234 | unsigned char *p,int pl); | ||
| 235 | int RSA_padding_add_SSLv23(unsigned char *to,int tlen, | ||
| 236 | unsigned char *f,int fl); | ||
| 237 | int RSA_padding_check_SSLv23(unsigned char *to,int tlen, | ||
| 238 | unsigned char *f,int fl,int rsa_len); | ||
| 239 | int RSA_padding_add_none(unsigned char *to,int tlen, | ||
| 240 | unsigned char *f,int fl); | ||
| 241 | int RSA_padding_check_none(unsigned char *to,int tlen, | ||
| 242 | unsigned char *f,int fl,int rsa_len); | ||
| 243 | |||
| 244 | int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
| 245 | int (*dup_func)(), void (*free_func)()); | ||
| 246 | int RSA_set_ex_data(RSA *r,int idx,char *arg); | ||
| 247 | char *RSA_get_ex_data(RSA *r, int idx); | ||
| 248 | |||
| 249 | /* BEGIN ERROR CODES */ | ||
| 250 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 251 | * made after this point may be overwritten when the script is next run. | ||
| 252 | */ | ||
| 253 | |||
| 254 | /* Error codes for the RSA functions. */ | ||
| 255 | |||
| 256 | /* Function codes. */ | ||
| 257 | #define RSA_F_MEMORY_LOCK 100 | ||
| 258 | #define RSA_F_RSA_CHECK_KEY 123 | ||
| 259 | #define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101 | ||
| 260 | #define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102 | ||
| 261 | #define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103 | ||
| 262 | #define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104 | ||
| 263 | #define RSA_F_RSA_GENERATE_KEY 105 | ||
| 264 | #define RSA_F_RSA_NEW_METHOD 106 | ||
| 265 | #define RSA_F_RSA_PADDING_ADD_NONE 107 | ||
| 266 | #define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 | ||
| 267 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 | ||
| 268 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 | ||
| 269 | #define RSA_F_RSA_PADDING_ADD_SSLV23 110 | ||
| 270 | #define RSA_F_RSA_PADDING_CHECK_NONE 111 | ||
| 271 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 | ||
| 272 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 | ||
| 273 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 | ||
| 274 | #define RSA_F_RSA_PADDING_CHECK_SSLV23 114 | ||
| 275 | #define RSA_F_RSA_PRINT 115 | ||
| 276 | #define RSA_F_RSA_PRINT_FP 116 | ||
| 277 | #define RSA_F_RSA_SIGN 117 | ||
| 278 | #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 | ||
| 279 | #define RSA_F_RSA_VERIFY 119 | ||
| 280 | #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 | ||
| 281 | |||
| 282 | /* Reason codes. */ | ||
| 283 | #define RSA_R_ALGORITHM_MISMATCH 100 | ||
| 284 | #define RSA_R_BAD_E_VALUE 101 | ||
| 285 | #define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 | ||
| 286 | #define RSA_R_BAD_PAD_BYTE_COUNT 103 | ||
| 287 | #define RSA_R_BAD_SIGNATURE 104 | ||
| 288 | #define RSA_R_BLOCK_TYPE_IS_NOT_01 106 | ||
| 289 | #define RSA_R_BLOCK_TYPE_IS_NOT_02 107 | ||
| 290 | #define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 | ||
| 291 | #define RSA_R_DATA_TOO_LARGE 109 | ||
| 292 | #define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 | ||
| 293 | #define RSA_R_DATA_TOO_SMALL 111 | ||
| 294 | #define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 | ||
| 295 | #define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 | ||
| 296 | #define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 | ||
| 297 | #define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 | ||
| 298 | #define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 | ||
| 299 | #define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 | ||
| 300 | #define RSA_R_KEY_SIZE_TOO_SMALL 120 | ||
| 301 | #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 | ||
| 302 | #define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 | ||
| 303 | #define RSA_R_OAEP_DECODING_ERROR 121 | ||
| 304 | #define RSA_R_PADDING_CHECK_FAILED 114 | ||
| 305 | #define RSA_R_P_NOT_PRIME 128 | ||
| 306 | #define RSA_R_Q_NOT_PRIME 129 | ||
| 307 | #define RSA_R_SSLV3_ROLLBACK_ATTACK 115 | ||
| 308 | #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 | ||
| 309 | #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 | ||
| 310 | #define RSA_R_UNKNOWN_PADDING_TYPE 118 | ||
| 311 | #define RSA_R_WRONG_SIGNATURE_LENGTH 119 | ||
| 312 | |||
| 313 | #ifdef __cplusplus | ||
| 314 | } | ||
| 315 | #endif | ||
| 316 | #endif | ||
| 317 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c deleted file mode 100644 index 91b9115798..0000000000 --- a/src/lib/libcrypto/rsa/rsa_chk.c +++ /dev/null | |||
| @@ -1,184 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_chk.c -*- Mode: C; c-file-style: "eay" -*- */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | */ | ||
| 50 | |||
| 51 | #include <openssl/bn.h> | ||
| 52 | #include <openssl/err.h> | ||
| 53 | #include <openssl/rsa.h> | ||
| 54 | |||
| 55 | |||
| 56 | int RSA_check_key(RSA *key) | ||
| 57 | { | ||
| 58 | BIGNUM *i, *j, *k, *l, *m; | ||
| 59 | BN_CTX *ctx; | ||
| 60 | int r; | ||
| 61 | int ret=1; | ||
| 62 | |||
| 63 | i = BN_new(); | ||
| 64 | j = BN_new(); | ||
| 65 | k = BN_new(); | ||
| 66 | l = BN_new(); | ||
| 67 | m = BN_new(); | ||
| 68 | ctx = BN_CTX_new(); | ||
| 69 | if (i == NULL || j == NULL || k == NULL || l == NULL || | ||
| 70 | m == NULL || ctx == NULL) | ||
| 71 | { | ||
| 72 | ret = -1; | ||
| 73 | RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE); | ||
| 74 | goto err; | ||
| 75 | } | ||
| 76 | |||
| 77 | /* p prime? */ | ||
| 78 | r = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL); | ||
| 79 | if (r != 1) | ||
| 80 | { | ||
| 81 | ret = r; | ||
| 82 | if (r != 0) | ||
| 83 | goto err; | ||
| 84 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME); | ||
| 85 | } | ||
| 86 | |||
| 87 | /* q prime? */ | ||
| 88 | r = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL); | ||
| 89 | if (r != 1) | ||
| 90 | { | ||
| 91 | ret = r; | ||
| 92 | if (r != 0) | ||
| 93 | goto err; | ||
| 94 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME); | ||
| 95 | } | ||
| 96 | |||
| 97 | /* n = p*q? */ | ||
| 98 | r = BN_mul(i, key->p, key->q, ctx); | ||
| 99 | if (!r) { ret = -1; goto err; } | ||
| 100 | |||
| 101 | if (BN_cmp(i, key->n) != 0) | ||
| 102 | { | ||
| 103 | ret = 0; | ||
| 104 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q); | ||
| 105 | } | ||
| 106 | |||
| 107 | /* d*e = 1 mod lcm(p-1,q-1)? */ | ||
| 108 | |||
| 109 | r = BN_sub(i, key->p, BN_value_one()); | ||
| 110 | if (!r) { ret = -1; goto err; } | ||
| 111 | r = BN_sub(j, key->q, BN_value_one()); | ||
| 112 | if (!r) { ret = -1; goto err; } | ||
| 113 | |||
| 114 | /* now compute k = lcm(i,j) */ | ||
| 115 | r = BN_mul(l, i, j, ctx); | ||
| 116 | if (!r) { ret = -1; goto err; } | ||
| 117 | r = BN_gcd(m, i, j, ctx); | ||
| 118 | if (!r) { ret = -1; goto err; } | ||
| 119 | r = BN_div(k, NULL, l, m, ctx); /* remainder is 0 */ | ||
| 120 | if (!r) { ret = -1; goto err; } | ||
| 121 | |||
| 122 | r = BN_mod_mul(i, key->d, key->e, k, ctx); | ||
| 123 | if (!r) { ret = -1; goto err; } | ||
| 124 | |||
| 125 | if (!BN_is_one(i)) | ||
| 126 | { | ||
| 127 | ret = 0; | ||
| 128 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1); | ||
| 129 | } | ||
| 130 | |||
| 131 | if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) | ||
| 132 | { | ||
| 133 | /* dmp1 = d mod (p-1)? */ | ||
| 134 | r = BN_sub(i, key->p, BN_value_one()); | ||
| 135 | if (!r) { ret = -1; goto err; } | ||
| 136 | |||
| 137 | r = BN_mod(j, key->d, i, ctx); | ||
| 138 | if (!r) { ret = -1; goto err; } | ||
| 139 | |||
| 140 | if (BN_cmp(j, key->dmp1) != 0) | ||
| 141 | { | ||
| 142 | ret = 0; | ||
| 143 | RSAerr(RSA_F_RSA_CHECK_KEY, | ||
| 144 | RSA_R_DMP1_NOT_CONGRUENT_TO_D); | ||
| 145 | } | ||
| 146 | |||
| 147 | /* dmq1 = d mod (q-1)? */ | ||
| 148 | r = BN_sub(i, key->q, BN_value_one()); | ||
| 149 | if (!r) { ret = -1; goto err; } | ||
| 150 | |||
| 151 | r = BN_mod(j, key->d, i, ctx); | ||
| 152 | if (!r) { ret = -1; goto err; } | ||
| 153 | |||
| 154 | if (BN_cmp(j, key->dmq1) != 0) | ||
| 155 | { | ||
| 156 | ret = 0; | ||
| 157 | RSAerr(RSA_F_RSA_CHECK_KEY, | ||
| 158 | RSA_R_DMQ1_NOT_CONGRUENT_TO_D); | ||
| 159 | } | ||
| 160 | |||
| 161 | /* iqmp = q^-1 mod p? */ | ||
| 162 | if(!BN_mod_inverse(i, key->q, key->p, ctx)) | ||
| 163 | { | ||
| 164 | ret = -1; | ||
| 165 | goto err; | ||
| 166 | } | ||
| 167 | |||
| 168 | if (BN_cmp(i, key->iqmp) != 0) | ||
| 169 | { | ||
| 170 | ret = 0; | ||
| 171 | RSAerr(RSA_F_RSA_CHECK_KEY, | ||
| 172 | RSA_R_IQMP_NOT_INVERSE_OF_Q); | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | err: | ||
| 177 | if (i != NULL) BN_free(i); | ||
| 178 | if (j != NULL) BN_free(j); | ||
| 179 | if (k != NULL) BN_free(k); | ||
| 180 | if (l != NULL) BN_free(l); | ||
| 181 | if (m != NULL) BN_free(m); | ||
| 182 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 183 | return (ret); | ||
| 184 | } | ||
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c deleted file mode 100644 index 776324860c..0000000000 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ /dev/null | |||
| @@ -1,288 +0,0 @@ | |||
| 1 | |||
| 2 | /* This file has been explicitly broken by ryker for OpenBSD, July | ||
| 3 | * 1, 1998. In spite of the title, there is no implementation of the | ||
| 4 | * RSA algorithm left in this file. All these routines will return an | ||
| 5 | * error and fail when called. They exist as stubs and can be | ||
| 6 | * ressurected from the bit bucket by someone in the free world once | ||
| 7 | * the RSA algorithm is no longer subject to patent problems. Eric | ||
| 8 | * Young's original copyright is below. | ||
| 9 | */ | ||
| 10 | |||
| 11 | /* crypto/rsa/rsa_eay.c */ | ||
| 12 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 13 | * All rights reserved. | ||
| 14 | * | ||
| 15 | * This package is an SSL implementation written | ||
| 16 | * by Eric Young (eay@cryptsoft.com). | ||
| 17 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 18 | * | ||
| 19 | * This library is free for commercial and non-commercial use as long as | ||
| 20 | * the following conditions are aheared to. The following conditions | ||
| 21 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 22 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 23 | * included with this distribution is covered by the same copyright terms | ||
| 24 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 25 | * | ||
| 26 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 27 | * the code are not to be removed. | ||
| 28 | * If this package is used in a product, Eric Young should be given attribution | ||
| 29 | * as the author of the parts of the library used. | ||
| 30 | * This can be in the form of a textual message at program startup or | ||
| 31 | * in documentation (online or textual) provided with the package. | ||
| 32 | * | ||
| 33 | * Redistribution and use in source and binary forms, with or without | ||
| 34 | * modification, are permitted provided that the following conditions | ||
| 35 | * are met: | ||
| 36 | * 1. Redistributions of source code must retain the copyright | ||
| 37 | * notice, this list of conditions and the following disclaimer. | ||
| 38 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 39 | * notice, this list of conditions and the following disclaimer in the | ||
| 40 | * documentation and/or other materials provided with the distribution. | ||
| 41 | * 3. All advertising materials mentioning features or use of this software | ||
| 42 | * must display the following acknowledgement: | ||
| 43 | * "This product includes cryptographic software written by | ||
| 44 | * Eric Young (eay@cryptsoft.com)" | ||
| 45 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 46 | * being used are not cryptographic related :-). | ||
| 47 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 48 | * the apps directory (application code) you must include an acknowledgement: | ||
| 49 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 50 | * | ||
| 51 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 52 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 61 | * SUCH DAMAGE. | ||
| 62 | * | ||
| 63 | * The licence and distribution terms for any publically available version or | ||
| 64 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 65 | * copied and put under another distribution licence | ||
| 66 | * [including the GNU Public Licence.] | ||
| 67 | */ | ||
| 68 | |||
| 69 | #include <stdio.h> | ||
| 70 | #include "cryptlib.h" | ||
| 71 | #include <openssl/bn.h> | ||
| 72 | #include <openssl/rsa.h> | ||
| 73 | #include <openssl/rand.h> | ||
| 74 | |||
| 75 | static int RSA_eay_public_encrypt(int flen, unsigned char *from, | ||
| 76 | unsigned char *to, RSA *rsa,int padding); | ||
| 77 | static int RSA_eay_private_encrypt(int flen, unsigned char *from, | ||
| 78 | unsigned char *to, RSA *rsa,int padding); | ||
| 79 | static int RSA_eay_public_decrypt(int flen, unsigned char *from, | ||
| 80 | unsigned char *to, RSA *rsa,int padding); | ||
| 81 | static int RSA_eay_private_decrypt(int flen, unsigned char *from, | ||
| 82 | unsigned char *to, RSA *rsa,int padding); | ||
| 83 | static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa); | ||
| 84 | static int RSA_eay_init(RSA *rsa); | ||
| 85 | static int RSA_eay_finish(RSA *rsa); | ||
| 86 | static RSA_METHOD rsa_pkcs1_eay_meth={ | ||
| 87 | "Eric Young's PKCS#1 RSA", | ||
| 88 | RSA_eay_public_encrypt, | ||
| 89 | RSA_eay_public_decrypt, | ||
| 90 | RSA_eay_private_encrypt, | ||
| 91 | RSA_eay_private_decrypt, | ||
| 92 | RSA_eay_mod_exp, | ||
| 93 | BN_mod_exp_mont, | ||
| 94 | RSA_eay_init, | ||
| 95 | RSA_eay_finish, | ||
| 96 | 0, | ||
| 97 | NULL, | ||
| 98 | }; | ||
| 99 | |||
| 100 | RSA_METHOD *RSA_PKCS1_SSLeay(void) | ||
| 101 | { | ||
| 102 | return(&rsa_pkcs1_eay_meth); | ||
| 103 | } | ||
| 104 | |||
| 105 | static int RSA_eay_public_encrypt(int flen, unsigned char *from, | ||
| 106 | unsigned char *to, RSA *rsa, int padding) | ||
| 107 | { | ||
| 108 | BIGNUM f,ret; | ||
| 109 | int i,j,k,num=0,r= -1; | ||
| 110 | unsigned char *buf=NULL; | ||
| 111 | BN_CTX *ctx=NULL; | ||
| 112 | |||
| 113 | BN_init(&f); | ||
| 114 | BN_init(&ret); | ||
| 115 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 116 | num=BN_num_bytes(rsa->n); | ||
| 117 | if ((buf=(unsigned char *)Malloc(num)) == NULL) | ||
| 118 | { | ||
| 119 | RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE); | ||
| 120 | goto err; | ||
| 121 | } | ||
| 122 | |||
| 123 | switch (padding) | ||
| 124 | { | ||
| 125 | case RSA_PKCS1_PADDING: | ||
| 126 | i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen); | ||
| 127 | break; | ||
| 128 | #ifndef NO_SHA | ||
| 129 | case RSA_PKCS1_OAEP_PADDING: | ||
| 130 | i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0); | ||
| 131 | break; | ||
| 132 | #endif | ||
| 133 | case RSA_SSLV23_PADDING: | ||
| 134 | i=RSA_padding_add_SSLv23(buf,num,from,flen); | ||
| 135 | break; | ||
| 136 | case RSA_NO_PADDING: | ||
| 137 | i=RSA_padding_add_none(buf,num,from,flen); | ||
| 138 | break; | ||
| 139 | default: | ||
| 140 | RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE); | ||
| 141 | goto err; | ||
| 142 | } | ||
| 143 | if (i <= 0) goto err; | ||
| 144 | |||
| 145 | if (BN_bin2bn(buf,num,&f) == NULL) goto err; | ||
| 146 | |||
| 147 | if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) | ||
| 148 | { | ||
| 149 | if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL) | ||
| 150 | if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx)) | ||
| 151 | goto err; | ||
| 152 | } | ||
| 153 | |||
| 154 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, | ||
| 155 | rsa->_method_mod_n)) goto err; | ||
| 156 | |||
| 157 | /* put in leading 0 bytes if the number is less than the | ||
| 158 | * length of the modulus */ | ||
| 159 | j=BN_num_bytes(&ret); | ||
| 160 | i=BN_bn2bin(&ret,&(to[num-j])); | ||
| 161 | for (k=0; k<(num-i); k++) | ||
| 162 | to[k]=0; | ||
| 163 | |||
| 164 | r=num; | ||
| 165 | err: | ||
| 166 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 167 | BN_clear_free(&f); | ||
| 168 | BN_clear_free(&ret); | ||
| 169 | if (buf != NULL) | ||
| 170 | { | ||
| 171 | memset(buf,0,num); | ||
| 172 | Free(buf); | ||
| 173 | } | ||
| 174 | return(r); | ||
| 175 | } | ||
| 176 | |||
| 177 | static int RSA_eay_private_encrypt(int flen, unsigned char *from, | ||
| 178 | unsigned char *to, RSA *rsa, int padding) | ||
| 179 | { | ||
| 180 | BIGNUM f,ret; | ||
| 181 | int i,j,k,num=0,r= -1; | ||
| 182 | unsigned char *buf=NULL; | ||
| 183 | BN_CTX *ctx=NULL; | ||
| 184 | |||
| 185 | /* Body of this routine removed for OpenBSD - will return | ||
| 186 | * when the RSA patent expires | ||
| 187 | */ | ||
| 188 | |||
| 189 | err: | ||
| 190 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 191 | BN_clear_free(&ret); | ||
| 192 | BN_clear_free(&f); | ||
| 193 | if (buf != NULL) | ||
| 194 | { | ||
| 195 | memset(buf,0,num); | ||
| 196 | Free(buf); | ||
| 197 | } | ||
| 198 | return(r); | ||
| 199 | } | ||
| 200 | |||
| 201 | static int RSA_eay_private_decrypt(int flen, unsigned char *from, | ||
| 202 | unsigned char *to, RSA *rsa, int padding) | ||
| 203 | { | ||
| 204 | BIGNUM f,ret; | ||
| 205 | int j,num=0,r= -1; | ||
| 206 | unsigned char *p; | ||
| 207 | unsigned char *buf=NULL; | ||
| 208 | BN_CTX *ctx=NULL; | ||
| 209 | |||
| 210 | /* Body of this routine removed for OpenBSD - will return | ||
| 211 | * when the RSA patent expires | ||
| 212 | */ | ||
| 213 | |||
| 214 | err: | ||
| 215 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 216 | BN_clear_free(&f); | ||
| 217 | BN_clear_free(&ret); | ||
| 218 | if (buf != NULL) | ||
| 219 | { | ||
| 220 | memset(buf,0,num); | ||
| 221 | Free(buf); | ||
| 222 | } | ||
| 223 | return(r); | ||
| 224 | } | ||
| 225 | |||
| 226 | static int RSA_eay_public_decrypt(int flen, unsigned char *from, | ||
| 227 | unsigned char *to, RSA *rsa, int padding) | ||
| 228 | { | ||
| 229 | BIGNUM f,ret; | ||
| 230 | int i,num=0,r= -1; | ||
| 231 | unsigned char *p; | ||
| 232 | unsigned char *buf=NULL; | ||
| 233 | BN_CTX *ctx=NULL; | ||
| 234 | |||
| 235 | /* Body of this routine removed for OpenBSD - will return | ||
| 236 | * when the RSA patent expires | ||
| 237 | */ | ||
| 238 | |||
| 239 | err: | ||
| 240 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 241 | BN_clear_free(&f); | ||
| 242 | BN_clear_free(&ret); | ||
| 243 | if (buf != NULL) | ||
| 244 | { | ||
| 245 | memset(buf,0,num); | ||
| 246 | Free(buf); | ||
| 247 | } | ||
| 248 | return(r); | ||
| 249 | } | ||
| 250 | |||
| 251 | static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa) | ||
| 252 | { | ||
| 253 | BIGNUM r1,m1; | ||
| 254 | int ret=0; | ||
| 255 | BN_CTX *ctx; | ||
| 256 | |||
| 257 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 258 | BN_init(&m1); | ||
| 259 | BN_init(&r1); | ||
| 260 | |||
| 261 | /* Body of this routine removed for OpenBSD - will return | ||
| 262 | * when the RSA patent expires | ||
| 263 | */ | ||
| 264 | err: | ||
| 265 | BN_clear_free(&m1); | ||
| 266 | BN_clear_free(&r1); | ||
| 267 | BN_CTX_free(ctx); | ||
| 268 | return(ret); | ||
| 269 | } | ||
| 270 | |||
| 271 | static int RSA_eay_init(RSA *rsa) | ||
| 272 | { | ||
| 273 | rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE; | ||
| 274 | return(1); | ||
| 275 | } | ||
| 276 | |||
| 277 | static int RSA_eay_finish(RSA *rsa) | ||
| 278 | { | ||
| 279 | if (rsa->_method_mod_n != NULL) | ||
| 280 | BN_MONT_CTX_free(rsa->_method_mod_n); | ||
| 281 | if (rsa->_method_mod_p != NULL) | ||
| 282 | BN_MONT_CTX_free(rsa->_method_mod_p); | ||
| 283 | if (rsa->_method_mod_q != NULL) | ||
| 284 | BN_MONT_CTX_free(rsa->_method_mod_q); | ||
| 285 | return(1); | ||
| 286 | } | ||
| 287 | |||
| 288 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c deleted file mode 100644 index 9fb15e398d..0000000000 --- a/src/lib/libcrypto/rsa/rsa_err.c +++ /dev/null | |||
| @@ -1,144 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file. | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include <stdio.h> | ||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/rsa.h> | ||
| 63 | |||
| 64 | /* BEGIN ERROR CODES */ | ||
| 65 | #ifndef NO_ERR | ||
| 66 | static ERR_STRING_DATA RSA_str_functs[]= | ||
| 67 | { | ||
| 68 | {ERR_PACK(0,RSA_F_MEMORY_LOCK,0), "MEMORY_LOCK"}, | ||
| 69 | {ERR_PACK(0,RSA_F_RSA_CHECK_KEY,0), "RSA_check_key"}, | ||
| 70 | {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"}, | ||
| 71 | {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"}, | ||
| 72 | {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"}, | ||
| 73 | {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"}, | ||
| 74 | {ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"}, | ||
| 75 | {ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"}, | ||
| 76 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"}, | ||
| 77 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"}, | ||
| 78 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"}, | ||
| 79 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"}, | ||
| 80 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"}, | ||
| 81 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"}, | ||
| 82 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,0), "RSA_padding_check_PKCS1_OAEP"}, | ||
| 83 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"}, | ||
| 84 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"}, | ||
| 85 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"}, | ||
| 86 | {ERR_PACK(0,RSA_F_RSA_PRINT,0), "RSA_print"}, | ||
| 87 | {ERR_PACK(0,RSA_F_RSA_PRINT_FP,0), "RSA_print_fp"}, | ||
| 88 | {ERR_PACK(0,RSA_F_RSA_SIGN,0), "RSA_sign"}, | ||
| 89 | {ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"}, | ||
| 90 | {ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"}, | ||
| 91 | {ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"}, | ||
| 92 | {0,NULL} | ||
| 93 | }; | ||
| 94 | |||
| 95 | static ERR_STRING_DATA RSA_str_reasons[]= | ||
| 96 | { | ||
| 97 | {RSA_R_ALGORITHM_MISMATCH ,"algorithm mismatch"}, | ||
| 98 | {RSA_R_BAD_E_VALUE ,"bad e value"}, | ||
| 99 | {RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"}, | ||
| 100 | {RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"}, | ||
| 101 | {RSA_R_BAD_SIGNATURE ,"bad signature"}, | ||
| 102 | {RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"}, | ||
| 103 | {RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"}, | ||
| 104 | {RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"}, | ||
| 105 | {RSA_R_DATA_TOO_LARGE ,"data too large"}, | ||
| 106 | {RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, | ||
| 107 | {RSA_R_DATA_TOO_SMALL ,"data too small"}, | ||
| 108 | {RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"}, | ||
| 109 | {RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"}, | ||
| 110 | {RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"}, | ||
| 111 | {RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"}, | ||
| 112 | {RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"}, | ||
| 113 | {RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"}, | ||
| 114 | {RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"}, | ||
| 115 | {RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"}, | ||
| 116 | {RSA_R_N_DOES_NOT_EQUAL_P_Q ,"n does not equal p q"}, | ||
| 117 | {RSA_R_OAEP_DECODING_ERROR ,"oaep decoding error"}, | ||
| 118 | {RSA_R_PADDING_CHECK_FAILED ,"padding check failed"}, | ||
| 119 | {RSA_R_P_NOT_PRIME ,"p not prime"}, | ||
| 120 | {RSA_R_Q_NOT_PRIME ,"q not prime"}, | ||
| 121 | {RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"}, | ||
| 122 | {RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, | ||
| 123 | {RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, | ||
| 124 | {RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"}, | ||
| 125 | {RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"}, | ||
| 126 | {0,NULL} | ||
| 127 | }; | ||
| 128 | |||
| 129 | #endif | ||
| 130 | |||
| 131 | void ERR_load_RSA_strings(void) | ||
| 132 | { | ||
| 133 | static int init=1; | ||
| 134 | |||
| 135 | if (init) | ||
| 136 | { | ||
| 137 | init=0; | ||
| 138 | #ifndef NO_ERR | ||
| 139 | ERR_load_strings(ERR_LIB_RSA,RSA_str_functs); | ||
| 140 | ERR_load_strings(ERR_LIB_RSA,RSA_str_reasons); | ||
| 141 | #endif | ||
| 142 | |||
| 143 | } | ||
| 144 | } | ||
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c deleted file mode 100644 index 3227dba794..0000000000 --- a/src/lib/libcrypto/rsa/rsa_gen.c +++ /dev/null | |||
| @@ -1,99 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_gen.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | #include <openssl/rsa.h> | ||
| 64 | |||
| 65 | RSA *RSA_generate_key(int bits, unsigned long e_value, | ||
| 66 | void (*callback)(int,int,void *), void *cb_arg) | ||
| 67 | { | ||
| 68 | RSA *rsa=NULL; | ||
| 69 | BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp; | ||
| 70 | int bitsp,bitsq,ok= -1,n=0,i; | ||
| 71 | BN_CTX *ctx=NULL,*ctx2=NULL; | ||
| 72 | |||
| 73 | ctx=BN_CTX_new(); | ||
| 74 | if (ctx == NULL) goto err; | ||
| 75 | ctx2=BN_CTX_new(); | ||
| 76 | if (ctx2 == NULL) goto err; | ||
| 77 | |||
| 78 | /* Body of this routine removed for OpenBSD - will return | ||
| 79 | * when the RSA patent expires | ||
| 80 | */ | ||
| 81 | |||
| 82 | err: | ||
| 83 | if (ok == -1) | ||
| 84 | { | ||
| 85 | RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN); | ||
| 86 | ok=0; | ||
| 87 | } | ||
| 88 | BN_CTX_free(ctx); | ||
| 89 | BN_CTX_free(ctx2); | ||
| 90 | |||
| 91 | if (!ok) | ||
| 92 | { | ||
| 93 | if (rsa != NULL) RSA_free(rsa); | ||
| 94 | return(NULL); | ||
| 95 | } | ||
| 96 | else | ||
| 97 | return(rsa); | ||
| 98 | } | ||
| 99 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c deleted file mode 100644 index c0ca2923a6..0000000000 --- a/src/lib/libcrypto/rsa/rsa_lib.c +++ /dev/null | |||
| @@ -1,329 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_lib.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <openssl/crypto.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/lhash.h> | ||
| 63 | #include <openssl/bn.h> | ||
| 64 | #include <openssl/rsa.h> | ||
| 65 | |||
| 66 | const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT; | ||
| 67 | |||
| 68 | static RSA_METHOD *default_RSA_meth=NULL; | ||
| 69 | static int rsa_meth_num=0; | ||
| 70 | static STACK *rsa_meth=NULL; | ||
| 71 | |||
| 72 | RSA *RSA_new(void) | ||
| 73 | { | ||
| 74 | return(RSA_new_method(NULL)); | ||
| 75 | } | ||
| 76 | |||
| 77 | void RSA_set_default_method(RSA_METHOD *meth) | ||
| 78 | { | ||
| 79 | default_RSA_meth=meth; | ||
| 80 | } | ||
| 81 | |||
| 82 | RSA_METHOD *RSA_get_default_method(void) | ||
| 83 | { | ||
| 84 | return default_RSA_meth; | ||
| 85 | } | ||
| 86 | |||
| 87 | RSA_METHOD *RSA_get_method(RSA *rsa) | ||
| 88 | { | ||
| 89 | return rsa->meth; | ||
| 90 | } | ||
| 91 | |||
| 92 | RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth) | ||
| 93 | { | ||
| 94 | RSA_METHOD *mtmp; | ||
| 95 | mtmp = rsa->meth; | ||
| 96 | if (mtmp->finish) mtmp->finish(rsa); | ||
| 97 | rsa->meth = meth; | ||
| 98 | if (meth->init) meth->init(rsa); | ||
| 99 | return mtmp; | ||
| 100 | } | ||
| 101 | |||
| 102 | RSA *RSA_new_method(RSA_METHOD *meth) | ||
| 103 | { | ||
| 104 | RSA *ret; | ||
| 105 | |||
| 106 | if (default_RSA_meth == NULL) | ||
| 107 | { | ||
| 108 | #ifdef RSAref | ||
| 109 | default_RSA_meth=RSA_PKCS1_RSAref(); | ||
| 110 | #else | ||
| 111 | default_RSA_meth=RSA_PKCS1_SSLeay(); | ||
| 112 | #endif | ||
| 113 | } | ||
| 114 | ret=(RSA *)Malloc(sizeof(RSA)); | ||
| 115 | if (ret == NULL) | ||
| 116 | { | ||
| 117 | RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE); | ||
| 118 | return(NULL); | ||
| 119 | } | ||
| 120 | |||
| 121 | if (meth == NULL) | ||
| 122 | ret->meth=default_RSA_meth; | ||
| 123 | else | ||
| 124 | ret->meth=meth; | ||
| 125 | |||
| 126 | ret->pad=0; | ||
| 127 | ret->version=0; | ||
| 128 | ret->n=NULL; | ||
| 129 | ret->e=NULL; | ||
| 130 | ret->d=NULL; | ||
| 131 | ret->p=NULL; | ||
| 132 | ret->q=NULL; | ||
| 133 | ret->dmp1=NULL; | ||
| 134 | ret->dmq1=NULL; | ||
| 135 | ret->iqmp=NULL; | ||
| 136 | ret->references=1; | ||
| 137 | ret->_method_mod_n=NULL; | ||
| 138 | ret->_method_mod_p=NULL; | ||
| 139 | ret->_method_mod_q=NULL; | ||
| 140 | ret->blinding=NULL; | ||
| 141 | ret->bignum_data=NULL; | ||
| 142 | ret->flags=ret->meth->flags; | ||
| 143 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) | ||
| 144 | { | ||
| 145 | Free(ret); | ||
| 146 | ret=NULL; | ||
| 147 | } | ||
| 148 | else | ||
| 149 | CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data); | ||
| 150 | return(ret); | ||
| 151 | } | ||
| 152 | |||
| 153 | void RSA_free(RSA *r) | ||
| 154 | { | ||
| 155 | int i; | ||
| 156 | |||
| 157 | if (r == NULL) return; | ||
| 158 | |||
| 159 | i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA); | ||
| 160 | #ifdef REF_PRINT | ||
| 161 | REF_PRINT("RSA",r); | ||
| 162 | #endif | ||
| 163 | if (i > 0) return; | ||
| 164 | #ifdef REF_CHECK | ||
| 165 | if (i < 0) | ||
| 166 | { | ||
| 167 | fprintf(stderr,"RSA_free, bad reference count\n"); | ||
| 168 | abort(); | ||
| 169 | } | ||
| 170 | #endif | ||
| 171 | |||
| 172 | CRYPTO_free_ex_data(rsa_meth,(char *)r,&r->ex_data); | ||
| 173 | |||
| 174 | if (r->meth->finish != NULL) | ||
| 175 | r->meth->finish(r); | ||
| 176 | |||
| 177 | if (r->n != NULL) BN_clear_free(r->n); | ||
| 178 | if (r->e != NULL) BN_clear_free(r->e); | ||
| 179 | if (r->d != NULL) BN_clear_free(r->d); | ||
| 180 | if (r->p != NULL) BN_clear_free(r->p); | ||
| 181 | if (r->q != NULL) BN_clear_free(r->q); | ||
| 182 | if (r->dmp1 != NULL) BN_clear_free(r->dmp1); | ||
| 183 | if (r->dmq1 != NULL) BN_clear_free(r->dmq1); | ||
| 184 | if (r->iqmp != NULL) BN_clear_free(r->iqmp); | ||
| 185 | if (r->blinding != NULL) BN_BLINDING_free(r->blinding); | ||
| 186 | if (r->bignum_data != NULL) Free_locked(r->bignum_data); | ||
| 187 | Free(r); | ||
| 188 | } | ||
| 189 | |||
| 190 | int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
| 191 | int (*dup_func)(), void (*free_func)()) | ||
| 192 | { | ||
| 193 | rsa_meth_num++; | ||
| 194 | return(CRYPTO_get_ex_new_index(rsa_meth_num-1, | ||
| 195 | &rsa_meth,argl,argp,new_func,dup_func,free_func)); | ||
| 196 | } | ||
| 197 | |||
| 198 | int RSA_set_ex_data(RSA *r, int idx, char *arg) | ||
| 199 | { | ||
| 200 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | ||
| 201 | } | ||
| 202 | |||
| 203 | char *RSA_get_ex_data(RSA *r, int idx) | ||
| 204 | { | ||
| 205 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | ||
| 206 | } | ||
| 207 | |||
| 208 | int RSA_size(RSA *r) | ||
| 209 | { | ||
| 210 | return(BN_num_bytes(r->n)); | ||
| 211 | } | ||
| 212 | |||
| 213 | int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to, | ||
| 214 | RSA *rsa, int padding) | ||
| 215 | { | ||
| 216 | return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding)); | ||
| 217 | } | ||
| 218 | |||
| 219 | int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to, | ||
| 220 | RSA *rsa, int padding) | ||
| 221 | { | ||
| 222 | return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding)); | ||
| 223 | } | ||
| 224 | |||
| 225 | int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to, | ||
| 226 | RSA *rsa, int padding) | ||
| 227 | { | ||
| 228 | return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding)); | ||
| 229 | } | ||
| 230 | |||
| 231 | int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to, | ||
| 232 | RSA *rsa, int padding) | ||
| 233 | { | ||
| 234 | return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding)); | ||
| 235 | } | ||
| 236 | |||
| 237 | int RSA_flags(RSA *r) | ||
| 238 | { | ||
| 239 | return((r == NULL)?0:r->meth->flags); | ||
| 240 | } | ||
| 241 | |||
| 242 | void RSA_blinding_off(RSA *rsa) | ||
| 243 | { | ||
| 244 | if (rsa->blinding != NULL) | ||
| 245 | { | ||
| 246 | BN_BLINDING_free(rsa->blinding); | ||
| 247 | rsa->blinding=NULL; | ||
| 248 | } | ||
| 249 | rsa->flags&= ~RSA_FLAG_BLINDING; | ||
| 250 | } | ||
| 251 | |||
| 252 | int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) | ||
| 253 | { | ||
| 254 | BIGNUM *A,*Ai; | ||
| 255 | BN_CTX *ctx; | ||
| 256 | int ret=0; | ||
| 257 | |||
| 258 | if (p_ctx == NULL) | ||
| 259 | { | ||
| 260 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 261 | } | ||
| 262 | else | ||
| 263 | ctx=p_ctx; | ||
| 264 | |||
| 265 | if (rsa->blinding != NULL) | ||
| 266 | BN_BLINDING_free(rsa->blinding); | ||
| 267 | |||
| 268 | A= &(ctx->bn[0]); | ||
| 269 | ctx->tos++; | ||
| 270 | if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err; | ||
| 271 | if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; | ||
| 272 | |||
| 273 | if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) | ||
| 274 | goto err; | ||
| 275 | rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); | ||
| 276 | ctx->tos--; | ||
| 277 | rsa->flags|=RSA_FLAG_BLINDING; | ||
| 278 | BN_free(Ai); | ||
| 279 | ret=1; | ||
| 280 | err: | ||
| 281 | if (ctx != p_ctx) BN_CTX_free(ctx); | ||
| 282 | return(ret); | ||
| 283 | } | ||
| 284 | |||
| 285 | int RSA_memory_lock(RSA *r) | ||
| 286 | { | ||
| 287 | int i,j,k,off; | ||
| 288 | char *p; | ||
| 289 | BIGNUM *bn,**t[6],*b; | ||
| 290 | BN_ULONG *ul; | ||
| 291 | |||
| 292 | if (r->d == NULL) return(1); | ||
| 293 | t[0]= &r->d; | ||
| 294 | t[1]= &r->p; | ||
| 295 | t[2]= &r->q; | ||
| 296 | t[3]= &r->dmp1; | ||
| 297 | t[4]= &r->dmq1; | ||
| 298 | t[5]= &r->iqmp; | ||
| 299 | k=sizeof(BIGNUM)*6; | ||
| 300 | off=k/sizeof(BN_ULONG)+1; | ||
| 301 | j=1; | ||
| 302 | for (i=0; i<6; i++) | ||
| 303 | j+= (*t[i])->top; | ||
| 304 | if ((p=Malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL) | ||
| 305 | { | ||
| 306 | RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE); | ||
| 307 | return(0); | ||
| 308 | } | ||
| 309 | bn=(BIGNUM *)p; | ||
| 310 | ul=(BN_ULONG *)&(p[off]); | ||
| 311 | for (i=0; i<6; i++) | ||
| 312 | { | ||
| 313 | b= *(t[i]); | ||
| 314 | *(t[i])= &(bn[i]); | ||
| 315 | memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM)); | ||
| 316 | bn[i].flags=BN_FLG_STATIC_DATA; | ||
| 317 | bn[i].d=ul; | ||
| 318 | memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top); | ||
| 319 | ul+=b->top; | ||
| 320 | BN_clear_free(b); | ||
| 321 | } | ||
| 322 | |||
| 323 | /* I should fix this so it can still be done */ | ||
| 324 | r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC); | ||
| 325 | |||
| 326 | r->bignum_data=p; | ||
| 327 | return(1); | ||
| 328 | } | ||
| 329 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c deleted file mode 100644 index f22fce5016..0000000000 --- a/src/lib/libcrypto/rsa/rsa_none.c +++ /dev/null | |||
| @@ -1,98 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_none.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/rsa.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | int RSA_padding_add_none(unsigned char *to, int tlen, unsigned char *from, | ||
| 66 | int flen) | ||
| 67 | { | ||
| 68 | if (flen > tlen) | ||
| 69 | { | ||
| 70 | RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 71 | return(0); | ||
| 72 | } | ||
| 73 | |||
| 74 | if (flen < tlen) | ||
| 75 | { | ||
| 76 | RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE); | ||
| 77 | return(0); | ||
| 78 | } | ||
| 79 | |||
| 80 | memcpy(to,from,(unsigned int)flen); | ||
| 81 | return(1); | ||
| 82 | } | ||
| 83 | |||
| 84 | int RSA_padding_check_none(unsigned char *to, int tlen, unsigned char *from, | ||
| 85 | int flen, int num) | ||
| 86 | { | ||
| 87 | |||
| 88 | if (flen > tlen) | ||
| 89 | { | ||
| 90 | RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE); | ||
| 91 | return(-1); | ||
| 92 | } | ||
| 93 | |||
| 94 | memset(to,0,tlen-flen); | ||
| 95 | memcpy(to+tlen-flen,from,flen); | ||
| 96 | return(tlen); | ||
| 97 | } | ||
| 98 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c deleted file mode 100644 index 843c40c864..0000000000 --- a/src/lib/libcrypto/rsa/rsa_oaep.c +++ /dev/null | |||
| @@ -1,162 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_oaep.c */ | ||
| 2 | /* Written by Ulf Moeller. This software is distributed on an "AS IS" | ||
| 3 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ | ||
| 4 | |||
| 5 | /* EME_OAEP as defined in RFC 2437 (PKCS #1 v2.0) */ | ||
| 6 | |||
| 7 | #if !defined(NO_SHA) && !defined(NO_SHA1) | ||
| 8 | #include <stdio.h> | ||
| 9 | #include "cryptlib.h" | ||
| 10 | #include <openssl/bn.h> | ||
| 11 | #include <openssl/rsa.h> | ||
| 12 | #include <openssl/sha.h> | ||
| 13 | #include <openssl/rand.h> | ||
| 14 | |||
| 15 | int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen); | ||
| 16 | |||
| 17 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, | ||
| 18 | unsigned char *from, int flen, unsigned char *param, int plen) | ||
| 19 | { | ||
| 20 | int i, emlen = tlen - 1; | ||
| 21 | unsigned char *db, *seed; | ||
| 22 | unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH]; | ||
| 23 | |||
| 24 | if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1) | ||
| 25 | { | ||
| 26 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, | ||
| 27 | RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 28 | return (0); | ||
| 29 | } | ||
| 30 | |||
| 31 | if (emlen < 2 * SHA_DIGEST_LENGTH + 1) | ||
| 32 | { | ||
| 33 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL); | ||
| 34 | return (0); | ||
| 35 | } | ||
| 36 | |||
| 37 | dbmask = Malloc(emlen - SHA_DIGEST_LENGTH); | ||
| 38 | if (dbmask == NULL) | ||
| 39 | { | ||
| 40 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); | ||
| 41 | return (0); | ||
| 42 | } | ||
| 43 | |||
| 44 | to[0] = 0; | ||
| 45 | seed = to + 1; | ||
| 46 | db = to + SHA_DIGEST_LENGTH + 1; | ||
| 47 | |||
| 48 | SHA1(param, plen, db); | ||
| 49 | memset(db + SHA_DIGEST_LENGTH, 0, | ||
| 50 | emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); | ||
| 51 | db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; | ||
| 52 | memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen); | ||
| 53 | RAND_bytes(seed, SHA_DIGEST_LENGTH); | ||
| 54 | #ifdef PKCS_TESTVECT | ||
| 55 | memcpy(seed, | ||
| 56 | "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f", | ||
| 57 | 20); | ||
| 58 | #endif | ||
| 59 | |||
| 60 | MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH); | ||
| 61 | for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) | ||
| 62 | db[i] ^= dbmask[i]; | ||
| 63 | |||
| 64 | MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH); | ||
| 65 | for (i = 0; i < SHA_DIGEST_LENGTH; i++) | ||
| 66 | seed[i] ^= seedmask[i]; | ||
| 67 | |||
| 68 | Free(dbmask); | ||
| 69 | return (1); | ||
| 70 | } | ||
| 71 | |||
| 72 | int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, | ||
| 73 | unsigned char *from, int flen, int num, unsigned char *param, | ||
| 74 | int plen) | ||
| 75 | { | ||
| 76 | int i, dblen, mlen = -1; | ||
| 77 | unsigned char *maskeddb; | ||
| 78 | int lzero; | ||
| 79 | unsigned char *db, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH]; | ||
| 80 | |||
| 81 | if (--num < 2 * SHA_DIGEST_LENGTH + 1) | ||
| 82 | { | ||
| 83 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR); | ||
| 84 | return (-1); | ||
| 85 | } | ||
| 86 | |||
| 87 | dblen = num - SHA_DIGEST_LENGTH; | ||
| 88 | db = Malloc(dblen); | ||
| 89 | if (db == NULL) | ||
| 90 | { | ||
| 91 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); | ||
| 92 | return (-1); | ||
| 93 | } | ||
| 94 | |||
| 95 | lzero = num - flen; | ||
| 96 | maskeddb = from - lzero + SHA_DIGEST_LENGTH; | ||
| 97 | |||
| 98 | MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen); | ||
| 99 | for (i = lzero; i < SHA_DIGEST_LENGTH; i++) | ||
| 100 | seed[i] ^= from[i - lzero]; | ||
| 101 | |||
| 102 | MGF1(db, dblen, seed, SHA_DIGEST_LENGTH); | ||
| 103 | for (i = 0; i < dblen; i++) | ||
| 104 | db[i] ^= maskeddb[i]; | ||
| 105 | |||
| 106 | SHA1(param, plen, phash); | ||
| 107 | |||
| 108 | if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0) | ||
| 109 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR); | ||
| 110 | else | ||
| 111 | { | ||
| 112 | for (i = SHA_DIGEST_LENGTH; i < dblen; i++) | ||
| 113 | if (db[i] != 0x00) | ||
| 114 | break; | ||
| 115 | if (db[i] != 0x01 || i++ >= dblen) | ||
| 116 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, | ||
| 117 | RSA_R_OAEP_DECODING_ERROR); | ||
| 118 | else | ||
| 119 | { | ||
| 120 | mlen = dblen - i; | ||
| 121 | if (tlen < mlen) | ||
| 122 | { | ||
| 123 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE); | ||
| 124 | mlen = -1; | ||
| 125 | } | ||
| 126 | else | ||
| 127 | memcpy(to, db + i, mlen); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | Free(db); | ||
| 131 | return (mlen); | ||
| 132 | } | ||
| 133 | |||
| 134 | int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen) | ||
| 135 | { | ||
| 136 | long i, outlen = 0; | ||
| 137 | unsigned char cnt[4]; | ||
| 138 | SHA_CTX c; | ||
| 139 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 140 | |||
| 141 | for (i = 0; outlen < len; i++) | ||
| 142 | { | ||
| 143 | cnt[0] = (i >> 24) & 255, cnt[1] = (i >> 16) & 255, | ||
| 144 | cnt[2] = (i >> 8) & 255, cnt[3] = i & 255; | ||
| 145 | SHA1_Init(&c); | ||
| 146 | SHA1_Update(&c, seed, seedlen); | ||
| 147 | SHA1_Update(&c, cnt, 4); | ||
| 148 | if (outlen + SHA_DIGEST_LENGTH <= len) | ||
| 149 | { | ||
| 150 | SHA1_Final(mask + outlen, &c); | ||
| 151 | outlen += SHA_DIGEST_LENGTH; | ||
| 152 | } | ||
| 153 | else | ||
| 154 | { | ||
| 155 | SHA1_Final(md, &c); | ||
| 156 | memcpy(mask + outlen, md, len - outlen); | ||
| 157 | outlen = len; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | return (0); | ||
| 161 | } | ||
| 162 | #endif | ||
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c deleted file mode 100644 index f0ae51f234..0000000000 --- a/src/lib/libcrypto/rsa/rsa_pk1.c +++ /dev/null | |||
| @@ -1,212 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_pk1.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/rsa.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, | ||
| 66 | unsigned char *from, int flen) | ||
| 67 | { | ||
| 68 | int j; | ||
| 69 | unsigned char *p; | ||
| 70 | |||
| 71 | if (flen > (tlen-11)) | ||
| 72 | { | ||
| 73 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 74 | return(0); | ||
| 75 | } | ||
| 76 | |||
| 77 | p=(unsigned char *)to; | ||
| 78 | |||
| 79 | *(p++)=0; | ||
| 80 | *(p++)=1; /* Private Key BT (Block Type) */ | ||
| 81 | |||
| 82 | /* padd out with 0xff data */ | ||
| 83 | j=tlen-3-flen; | ||
| 84 | memset(p,0xff,j); | ||
| 85 | p+=j; | ||
| 86 | *(p++)='\0'; | ||
| 87 | memcpy(p,from,(unsigned int)flen); | ||
| 88 | return(1); | ||
| 89 | } | ||
| 90 | |||
| 91 | int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, | ||
| 92 | unsigned char *from, int flen, int num) | ||
| 93 | { | ||
| 94 | int i,j; | ||
| 95 | unsigned char *p; | ||
| 96 | |||
| 97 | p=from; | ||
| 98 | if ((num != (flen+1)) || (*(p++) != 01)) | ||
| 99 | { | ||
| 100 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01); | ||
| 101 | return(-1); | ||
| 102 | } | ||
| 103 | |||
| 104 | /* scan over padding data */ | ||
| 105 | j=flen-1; /* one for type. */ | ||
| 106 | for (i=0; i<j; i++) | ||
| 107 | { | ||
| 108 | if (*p != 0xff) /* should decrypt to 0xff */ | ||
| 109 | { | ||
| 110 | if (*p == 0) | ||
| 111 | { p++; break; } | ||
| 112 | else { | ||
| 113 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_FIXED_HEADER_DECRYPT); | ||
| 114 | return(-1); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | p++; | ||
| 118 | } | ||
| 119 | |||
| 120 | if (i == j) | ||
| 121 | { | ||
| 122 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
| 123 | return(-1); | ||
| 124 | } | ||
| 125 | |||
| 126 | if (i < 8) | ||
| 127 | { | ||
| 128 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_PAD_BYTE_COUNT); | ||
| 129 | return(-1); | ||
| 130 | } | ||
| 131 | i++; /* Skip over the '\0' */ | ||
| 132 | j-=i; | ||
| 133 | memcpy(to,p,(unsigned int)j); | ||
| 134 | |||
| 135 | return(j); | ||
| 136 | } | ||
| 137 | |||
| 138 | int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, | ||
| 139 | unsigned char *from, int flen) | ||
| 140 | { | ||
| 141 | int i,j; | ||
| 142 | unsigned char *p; | ||
| 143 | |||
| 144 | if (flen > (tlen-11)) | ||
| 145 | { | ||
| 146 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 147 | return(0); | ||
| 148 | } | ||
| 149 | |||
| 150 | p=(unsigned char *)to; | ||
| 151 | |||
| 152 | *(p++)=0; | ||
| 153 | *(p++)=2; /* Public Key BT (Block Type) */ | ||
| 154 | |||
| 155 | /* pad out with non-zero random data */ | ||
| 156 | j=tlen-3-flen; | ||
| 157 | |||
| 158 | RAND_bytes(p,j); | ||
| 159 | for (i=0; i<j; i++) | ||
| 160 | { | ||
| 161 | if (*p == '\0') | ||
| 162 | do { | ||
| 163 | RAND_bytes(p,1); | ||
| 164 | } while (*p == '\0'); | ||
| 165 | p++; | ||
| 166 | } | ||
| 167 | |||
| 168 | *(p++)='\0'; | ||
| 169 | |||
| 170 | memcpy(p,from,(unsigned int)flen); | ||
| 171 | return(1); | ||
| 172 | } | ||
| 173 | |||
| 174 | int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, | ||
| 175 | unsigned char *from, int flen, int num) | ||
| 176 | { | ||
| 177 | int i,j; | ||
| 178 | unsigned char *p; | ||
| 179 | |||
| 180 | p=from; | ||
| 181 | if ((num != (flen+1)) || (*(p++) != 02)) | ||
| 182 | { | ||
| 183 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02); | ||
| 184 | return(-1); | ||
| 185 | } | ||
| 186 | #ifdef PKCS1_CHECK | ||
| 187 | return(num-11); | ||
| 188 | #endif | ||
| 189 | |||
| 190 | /* scan over padding data */ | ||
| 191 | j=flen-1; /* one for type. */ | ||
| 192 | for (i=0; i<j; i++) | ||
| 193 | if (*(p++) == 0) break; | ||
| 194 | |||
| 195 | if (i == j) | ||
| 196 | { | ||
| 197 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
| 198 | return(-1); | ||
| 199 | } | ||
| 200 | |||
| 201 | if (i < 8) | ||
| 202 | { | ||
| 203 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BAD_PAD_BYTE_COUNT); | ||
| 204 | return(-1); | ||
| 205 | } | ||
| 206 | i++; /* Skip over the '\0' */ | ||
| 207 | j-=i; | ||
| 208 | memcpy(to,p,(unsigned int)j); | ||
| 209 | |||
| 210 | return(j); | ||
| 211 | } | ||
| 212 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c deleted file mode 100644 index 73b8b0c7ad..0000000000 --- a/src/lib/libcrypto/rsa/rsa_saos.c +++ /dev/null | |||
| @@ -1,144 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_saos.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/rsa.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | |||
| 66 | int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, | ||
| 67 | unsigned char *sigret, unsigned int *siglen, RSA *rsa) | ||
| 68 | { | ||
| 69 | ASN1_OCTET_STRING sig; | ||
| 70 | int i,j,ret=1; | ||
| 71 | unsigned char *p,*s; | ||
| 72 | |||
| 73 | sig.type=V_ASN1_OCTET_STRING; | ||
| 74 | sig.length=m_len; | ||
| 75 | sig.data=m; | ||
| 76 | |||
| 77 | i=i2d_ASN1_OCTET_STRING(&sig,NULL); | ||
| 78 | j=RSA_size(rsa); | ||
| 79 | if ((i-RSA_PKCS1_PADDING) > j) | ||
| 80 | { | ||
| 81 | RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | ||
| 82 | return(0); | ||
| 83 | } | ||
| 84 | s=(unsigned char *)Malloc((unsigned int)j+1); | ||
| 85 | if (s == NULL) | ||
| 86 | { | ||
| 87 | RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); | ||
| 88 | return(0); | ||
| 89 | } | ||
| 90 | p=s; | ||
| 91 | i2d_ASN1_OCTET_STRING(&sig,&p); | ||
| 92 | i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); | ||
| 93 | if (i <= 0) | ||
| 94 | ret=0; | ||
| 95 | else | ||
| 96 | *siglen=i; | ||
| 97 | |||
| 98 | memset(s,0,(unsigned int)j+1); | ||
| 99 | Free(s); | ||
| 100 | return(ret); | ||
| 101 | } | ||
| 102 | |||
| 103 | int RSA_verify_ASN1_OCTET_STRING(int dtype, unsigned char *m, | ||
| 104 | unsigned int m_len, unsigned char *sigbuf, unsigned int siglen, | ||
| 105 | RSA *rsa) | ||
| 106 | { | ||
| 107 | int i,ret=0; | ||
| 108 | unsigned char *p,*s; | ||
| 109 | ASN1_OCTET_STRING *sig=NULL; | ||
| 110 | |||
| 111 | if (siglen != (unsigned int)RSA_size(rsa)) | ||
| 112 | { | ||
| 113 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_WRONG_SIGNATURE_LENGTH); | ||
| 114 | return(0); | ||
| 115 | } | ||
| 116 | |||
| 117 | s=(unsigned char *)Malloc((unsigned int)siglen); | ||
| 118 | if (s == NULL) | ||
| 119 | { | ||
| 120 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); | ||
| 121 | goto err; | ||
| 122 | } | ||
| 123 | i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING); | ||
| 124 | |||
| 125 | if (i <= 0) goto err; | ||
| 126 | |||
| 127 | p=s; | ||
| 128 | sig=d2i_ASN1_OCTET_STRING(NULL,&p,(long)i); | ||
| 129 | if (sig == NULL) goto err; | ||
| 130 | |||
| 131 | if ( ((unsigned int)sig->length != m_len) || | ||
| 132 | (memcmp(m,sig->data,m_len) != 0)) | ||
| 133 | { | ||
| 134 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_BAD_SIGNATURE); | ||
| 135 | } | ||
| 136 | else | ||
| 137 | ret=1; | ||
| 138 | err: | ||
| 139 | if (sig != NULL) ASN1_OCTET_STRING_free(sig); | ||
| 140 | memset(s,0,(unsigned int)siglen); | ||
| 141 | Free(s); | ||
| 142 | return(ret); | ||
| 143 | } | ||
| 144 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c deleted file mode 100644 index 1740494a4c..0000000000 --- a/src/lib/libcrypto/rsa/rsa_sign.c +++ /dev/null | |||
| @@ -1,188 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_sign.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/rsa.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | |||
| 66 | int RSA_sign(int type, unsigned char *m, unsigned int m_len, | ||
| 67 | unsigned char *sigret, unsigned int *siglen, RSA *rsa) | ||
| 68 | { | ||
| 69 | X509_SIG sig; | ||
| 70 | ASN1_TYPE parameter; | ||
| 71 | int i,j,ret=1; | ||
| 72 | unsigned char *p,*s; | ||
| 73 | X509_ALGOR algor; | ||
| 74 | ASN1_OCTET_STRING digest; | ||
| 75 | |||
| 76 | sig.algor= &algor; | ||
| 77 | sig.algor->algorithm=OBJ_nid2obj(type); | ||
| 78 | if (sig.algor->algorithm == NULL) | ||
| 79 | { | ||
| 80 | RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE); | ||
| 81 | return(0); | ||
| 82 | } | ||
| 83 | if (sig.algor->algorithm->length == 0) | ||
| 84 | { | ||
| 85 | RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); | ||
| 86 | return(0); | ||
| 87 | } | ||
| 88 | parameter.type=V_ASN1_NULL; | ||
| 89 | parameter.value.ptr=NULL; | ||
| 90 | sig.algor->parameter= ¶meter; | ||
| 91 | |||
| 92 | sig.digest= &digest; | ||
| 93 | sig.digest->data=m; | ||
| 94 | sig.digest->length=m_len; | ||
| 95 | |||
| 96 | i=i2d_X509_SIG(&sig,NULL); | ||
| 97 | j=RSA_size(rsa); | ||
| 98 | if ((i-RSA_PKCS1_PADDING) > j) | ||
| 99 | { | ||
| 100 | RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | ||
| 101 | return(0); | ||
| 102 | } | ||
| 103 | s=(unsigned char *)Malloc((unsigned int)j+1); | ||
| 104 | if (s == NULL) | ||
| 105 | { | ||
| 106 | RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE); | ||
| 107 | return(0); | ||
| 108 | } | ||
| 109 | p=s; | ||
| 110 | i2d_X509_SIG(&sig,&p); | ||
| 111 | i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); | ||
| 112 | if (i <= 0) | ||
| 113 | ret=0; | ||
| 114 | else | ||
| 115 | *siglen=i; | ||
| 116 | |||
| 117 | memset(s,0,(unsigned int)j+1); | ||
| 118 | Free(s); | ||
| 119 | return(ret); | ||
| 120 | } | ||
| 121 | |||
| 122 | int RSA_verify(int dtype, unsigned char *m, unsigned int m_len, | ||
| 123 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa) | ||
| 124 | { | ||
| 125 | int i,ret=0,sigtype; | ||
| 126 | unsigned char *p,*s; | ||
| 127 | X509_SIG *sig=NULL; | ||
| 128 | |||
| 129 | if (siglen != (unsigned int)RSA_size(rsa)) | ||
| 130 | { | ||
| 131 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH); | ||
| 132 | return(0); | ||
| 133 | } | ||
| 134 | |||
| 135 | s=(unsigned char *)Malloc((unsigned int)siglen); | ||
| 136 | if (s == NULL) | ||
| 137 | { | ||
| 138 | RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE); | ||
| 139 | goto err; | ||
| 140 | } | ||
| 141 | i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING); | ||
| 142 | |||
| 143 | if (i <= 0) goto err; | ||
| 144 | |||
| 145 | p=s; | ||
| 146 | sig=d2i_X509_SIG(NULL,&p,(long)i); | ||
| 147 | |||
| 148 | if (sig == NULL) goto err; | ||
| 149 | sigtype=OBJ_obj2nid(sig->algor->algorithm); | ||
| 150 | |||
| 151 | |||
| 152 | #ifdef RSA_DEBUG | ||
| 153 | /* put a backward compatability flag in EAY */ | ||
| 154 | fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype), | ||
| 155 | OBJ_nid2ln(dtype)); | ||
| 156 | #endif | ||
| 157 | if (sigtype != dtype) | ||
| 158 | { | ||
| 159 | if (((dtype == NID_md5) && | ||
| 160 | (sigtype == NID_md5WithRSAEncryption)) || | ||
| 161 | ((dtype == NID_md2) && | ||
| 162 | (sigtype == NID_md2WithRSAEncryption))) | ||
| 163 | { | ||
| 164 | /* ok, we will let it through */ | ||
| 165 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 166 | fprintf(stderr,"signature has problems, re-make with post SSLeay045\n"); | ||
| 167 | #endif | ||
| 168 | } | ||
| 169 | else | ||
| 170 | { | ||
| 171 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_ALGORITHM_MISMATCH); | ||
| 172 | goto err; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | if ( ((unsigned int)sig->digest->length != m_len) || | ||
| 176 | (memcmp(m,sig->digest->data,m_len) != 0)) | ||
| 177 | { | ||
| 178 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE); | ||
| 179 | } | ||
| 180 | else | ||
| 181 | ret=1; | ||
| 182 | err: | ||
| 183 | if (sig != NULL) X509_SIG_free(sig); | ||
| 184 | memset(s,0,(unsigned int)siglen); | ||
| 185 | Free(s); | ||
| 186 | return(ret); | ||
| 187 | } | ||
| 188 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c deleted file mode 100644 index 1050844f8d..0000000000 --- a/src/lib/libcrypto/rsa/rsa_ssl.c +++ /dev/null | |||
| @@ -1,147 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_ssl.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/rsa.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | int RSA_padding_add_SSLv23(unsigned char *to, int tlen, unsigned char *from, | ||
| 66 | int flen) | ||
| 67 | { | ||
| 68 | int i,j; | ||
| 69 | unsigned char *p; | ||
| 70 | |||
| 71 | if (flen > (tlen-11)) | ||
| 72 | { | ||
| 73 | RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 74 | return(0); | ||
| 75 | } | ||
| 76 | |||
| 77 | p=(unsigned char *)to; | ||
| 78 | |||
| 79 | *(p++)=0; | ||
| 80 | *(p++)=2; /* Public Key BT (Block Type) */ | ||
| 81 | |||
| 82 | /* pad out with non-zero random data */ | ||
| 83 | j=tlen-3-8-flen; | ||
| 84 | |||
| 85 | RAND_bytes(p,j); | ||
| 86 | for (i=0; i<j; i++) | ||
| 87 | { | ||
| 88 | if (*p == '\0') | ||
| 89 | do { | ||
| 90 | RAND_bytes(p,1); | ||
| 91 | } while (*p == '\0'); | ||
| 92 | p++; | ||
| 93 | } | ||
| 94 | |||
| 95 | memset(p,3,8); | ||
| 96 | p+=8; | ||
| 97 | *(p++)='\0'; | ||
| 98 | |||
| 99 | memcpy(p,from,(unsigned int)flen); | ||
| 100 | return(1); | ||
| 101 | } | ||
| 102 | |||
| 103 | int RSA_padding_check_SSLv23(unsigned char *to, int tlen, unsigned char *from, | ||
| 104 | int flen, int num) | ||
| 105 | { | ||
| 106 | int i,j,k; | ||
| 107 | unsigned char *p; | ||
| 108 | |||
| 109 | p=from; | ||
| 110 | if (flen < 10) | ||
| 111 | { | ||
| 112 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL); | ||
| 113 | return(-1); | ||
| 114 | } | ||
| 115 | if ((num != (flen+1)) || (*(p++) != 02)) | ||
| 116 | { | ||
| 117 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02); | ||
| 118 | return(-1); | ||
| 119 | } | ||
| 120 | |||
| 121 | /* scan over padding data */ | ||
| 122 | j=flen-1; /* one for type */ | ||
| 123 | for (i=0; i<j; i++) | ||
| 124 | if (*(p++) == 0) break; | ||
| 125 | |||
| 126 | if ((i == j) || (i < 8)) | ||
| 127 | { | ||
| 128 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
| 129 | return(-1); | ||
| 130 | } | ||
| 131 | for (k= -8; k<0; k++) | ||
| 132 | { | ||
| 133 | if (p[k] != 0x03) break; | ||
| 134 | } | ||
| 135 | if (k == 0) | ||
| 136 | { | ||
| 137 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK); | ||
| 138 | return(-1); | ||
| 139 | } | ||
| 140 | |||
| 141 | i++; /* Skip over the '\0' */ | ||
| 142 | j-=i; | ||
| 143 | memcpy(to,p,(unsigned int)j); | ||
| 144 | |||
| 145 | return(j); | ||
| 146 | } | ||
| 147 | |||
