diff options
| author | beck <> | 2002-05-15 02:29:21 +0000 |
|---|---|---|
| committer | beck <> | 2002-05-15 02:29:21 +0000 |
| commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
| tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libssl/t1_enc.c | |
| parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
| download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip | |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libssl/t1_enc.c | 221 |
1 files changed, 188 insertions, 33 deletions
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c index a0758e9261..b80525f3ba 100644 --- a/src/lib/libssl/t1_enc.c +++ b/src/lib/libssl/t1_enc.c | |||
| @@ -55,14 +55,66 @@ | |||
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | /* ==================================================================== | ||
| 59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
| 60 | * | ||
| 61 | * Redistribution and use in source and binary forms, with or without | ||
| 62 | * modification, are permitted provided that the following conditions | ||
| 63 | * are met: | ||
| 64 | * | ||
| 65 | * 1. Redistributions of source code must retain the above copyright | ||
| 66 | * notice, this list of conditions and the following disclaimer. | ||
| 67 | * | ||
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 69 | * notice, this list of conditions and the following disclaimer in | ||
| 70 | * the documentation and/or other materials provided with the | ||
| 71 | * distribution. | ||
| 72 | * | ||
| 73 | * 3. All advertising materials mentioning features or use of this | ||
| 74 | * software must display the following acknowledgment: | ||
| 75 | * "This product includes software developed by the OpenSSL Project | ||
| 76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 77 | * | ||
| 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 79 | * endorse or promote products derived from this software without | ||
| 80 | * prior written permission. For written permission, please contact | ||
| 81 | * openssl-core@openssl.org. | ||
| 82 | * | ||
| 83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 84 | * nor may "OpenSSL" appear in their names without prior written | ||
| 85 | * permission of the OpenSSL Project. | ||
| 86 | * | ||
| 87 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 88 | * acknowledgment: | ||
| 89 | * "This product includes software developed by the OpenSSL Project | ||
| 90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 91 | * | ||
| 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 104 | * ==================================================================== | ||
| 105 | * | ||
| 106 | * This product includes cryptographic software written by Eric Young | ||
| 107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 108 | * Hudson (tjh@cryptsoft.com). | ||
| 109 | * | ||
| 110 | */ | ||
| 58 | 111 | ||
| 59 | #include <stdio.h> | 112 | #include <stdio.h> |
| 60 | #include <openssl/comp.h> | 113 | #include <openssl/comp.h> |
| 61 | #include <openssl/md5.h> | ||
| 62 | #include <openssl/sha.h> | ||
| 63 | #include <openssl/evp.h> | 114 | #include <openssl/evp.h> |
| 64 | #include <openssl/hmac.h> | 115 | #include <openssl/hmac.h> |
| 65 | #include "ssl_locl.h" | 116 | #include "ssl_locl.h" |
| 117 | #include <openssl/md5.h> | ||
| 66 | 118 | ||
| 67 | static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | 119 | static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, |
| 68 | int sec_len, unsigned char *seed, int seed_len, | 120 | int sec_len, unsigned char *seed, int seed_len, |
| @@ -77,16 +129,20 @@ static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | |||
| 77 | 129 | ||
| 78 | chunk=EVP_MD_size(md); | 130 | chunk=EVP_MD_size(md); |
| 79 | 131 | ||
| 80 | HMAC_Init(&ctx,sec,sec_len,md); | 132 | HMAC_CTX_init(&ctx); |
| 133 | HMAC_CTX_init(&ctx_tmp); | ||
| 134 | HMAC_Init_ex(&ctx,sec,sec_len,md, NULL); | ||
| 135 | HMAC_Init_ex(&ctx_tmp,sec,sec_len,md, NULL); | ||
| 81 | HMAC_Update(&ctx,seed,seed_len); | 136 | HMAC_Update(&ctx,seed,seed_len); |
| 82 | HMAC_Final(&ctx,A1,&A1_len); | 137 | HMAC_Final(&ctx,A1,&A1_len); |
| 83 | 138 | ||
| 84 | n=0; | 139 | n=0; |
| 85 | for (;;) | 140 | for (;;) |
| 86 | { | 141 | { |
| 87 | HMAC_Init(&ctx,NULL,0,NULL); /* re-init */ | 142 | HMAC_Init_ex(&ctx,NULL,0,NULL,NULL); /* re-init */ |
| 143 | HMAC_Init_ex(&ctx_tmp,NULL,0,NULL,NULL); /* re-init */ | ||
| 88 | HMAC_Update(&ctx,A1,A1_len); | 144 | HMAC_Update(&ctx,A1,A1_len); |
| 89 | memcpy(&ctx_tmp,&ctx,sizeof(ctx)); /* Copy for A2 */ /* not needed for last one */ | 145 | HMAC_Update(&ctx_tmp,A1,A1_len); |
| 90 | HMAC_Update(&ctx,seed,seed_len); | 146 | HMAC_Update(&ctx,seed,seed_len); |
| 91 | 147 | ||
| 92 | if (olen > chunk) | 148 | if (olen > chunk) |
| @@ -103,8 +159,8 @@ static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | |||
| 103 | break; | 159 | break; |
| 104 | } | 160 | } |
| 105 | } | 161 | } |
| 106 | HMAC_cleanup(&ctx); | 162 | HMAC_CTX_cleanup(&ctx); |
| 107 | HMAC_cleanup(&ctx_tmp); | 163 | HMAC_CTX_cleanup(&ctx_tmp); |
| 108 | memset(A1,0,sizeof(A1)); | 164 | memset(A1,0,sizeof(A1)); |
| 109 | } | 165 | } |
| 110 | 166 | ||
| @@ -148,6 +204,17 @@ static void tls1_generate_key_block(SSL *s, unsigned char *km, | |||
| 148 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf), | 204 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf), |
| 149 | s->session->master_key,s->session->master_key_length, | 205 | s->session->master_key,s->session->master_key_length, |
| 150 | km,tmp,num); | 206 | km,tmp,num); |
| 207 | #ifdef KSSL_DEBUG | ||
| 208 | printf("tls1_generate_key_block() ==> %d byte master_key =\n\t", | ||
| 209 | s->session->master_key_length); | ||
| 210 | { | ||
| 211 | int i; | ||
| 212 | for (i=0; i < s->session->master_key_length; i++) | ||
| 213 | { | ||
| 214 | printf("%02X", s->session->master_key[i]); | ||
| 215 | } | ||
| 216 | printf("\n"); } | ||
| 217 | #endif /* KSSL_DEBUG */ | ||
| 151 | } | 218 | } |
| 152 | 219 | ||
| 153 | int tls1_change_cipher_state(SSL *s, int which) | 220 | int tls1_change_cipher_state(SSL *s, int which) |
| @@ -166,19 +233,35 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 166 | const EVP_CIPHER *c; | 233 | const EVP_CIPHER *c; |
| 167 | const SSL_COMP *comp; | 234 | const SSL_COMP *comp; |
| 168 | const EVP_MD *m; | 235 | const EVP_MD *m; |
| 169 | int _exp,n,i,j,k,exp_label_len,cl; | 236 | int is_export,n,i,j,k,exp_label_len,cl; |
| 237 | int reuse_dd = 0; | ||
| 170 | 238 | ||
| 171 | _exp=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | 239 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); |
| 172 | c=s->s3->tmp.new_sym_enc; | 240 | c=s->s3->tmp.new_sym_enc; |
| 173 | m=s->s3->tmp.new_hash; | 241 | m=s->s3->tmp.new_hash; |
| 174 | comp=s->s3->tmp.new_compression; | 242 | comp=s->s3->tmp.new_compression; |
| 175 | key_block=s->s3->tmp.key_block; | 243 | key_block=s->s3->tmp.key_block; |
| 176 | 244 | ||
| 245 | #ifdef KSSL_DEBUG | ||
| 246 | printf("tls1_change_cipher_state(which= %d) w/\n", which); | ||
| 247 | printf("\talg= %ld, comp= %p\n", s->s3->tmp.new_cipher->algorithms, | ||
| 248 | comp); | ||
| 249 | printf("\tevp_cipher == %p ==? &d_cbc_ede_cipher3\n", c); | ||
| 250 | printf("\tevp_cipher: nid, blksz= %d, %d, keylen=%d, ivlen=%d\n", | ||
| 251 | c->nid,c->block_size,c->key_len,c->iv_len); | ||
| 252 | printf("\tkey_block: len= %d, data= ", s->s3->tmp.key_block_length); | ||
| 253 | { | ||
| 254 | int i; | ||
| 255 | for (i=0; i<s->s3->tmp.key_block_length; i++) | ||
| 256 | printf("%02x", key_block[i]); printf("\n"); | ||
| 257 | } | ||
| 258 | #endif /* KSSL_DEBUG */ | ||
| 259 | |||
| 177 | if (which & SSL3_CC_READ) | 260 | if (which & SSL3_CC_READ) |
| 178 | { | 261 | { |
| 179 | if ((s->enc_read_ctx == NULL) && | 262 | if (s->enc_read_ctx != NULL) |
| 180 | ((s->enc_read_ctx=(EVP_CIPHER_CTX *) | 263 | reuse_dd = 1; |
| 181 | OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) | 264 | else if ((s->enc_read_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) |
| 182 | goto err; | 265 | goto err; |
| 183 | dd= s->enc_read_ctx; | 266 | dd= s->enc_read_ctx; |
| 184 | s->read_hash=m; | 267 | s->read_hash=m; |
| @@ -206,6 +289,10 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 206 | } | 289 | } |
| 207 | else | 290 | else |
| 208 | { | 291 | { |
| 292 | if (s->enc_write_ctx != NULL) | ||
| 293 | reuse_dd = 1; | ||
| 294 | else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) | ||
| 295 | goto err; | ||
| 209 | if ((s->enc_write_ctx == NULL) && | 296 | if ((s->enc_write_ctx == NULL) && |
| 210 | ((s->enc_write_ctx=(EVP_CIPHER_CTX *) | 297 | ((s->enc_write_ctx=(EVP_CIPHER_CTX *) |
| 211 | OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) | 298 | OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) |
| @@ -230,13 +317,15 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 230 | mac_secret= &(s->s3->write_mac_secret[0]); | 317 | mac_secret= &(s->s3->write_mac_secret[0]); |
| 231 | } | 318 | } |
| 232 | 319 | ||
| 320 | if (reuse_dd) | ||
| 321 | EVP_CIPHER_CTX_cleanup(dd); | ||
| 233 | EVP_CIPHER_CTX_init(dd); | 322 | EVP_CIPHER_CTX_init(dd); |
| 234 | 323 | ||
| 235 | p=s->s3->tmp.key_block; | 324 | p=s->s3->tmp.key_block; |
| 236 | i=EVP_MD_size(m); | 325 | i=EVP_MD_size(m); |
| 237 | cl=EVP_CIPHER_key_length(c); | 326 | cl=EVP_CIPHER_key_length(c); |
| 238 | j=_exp ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ? | 327 | j=is_export ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ? |
| 239 | cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl; | 328 | cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl; |
| 240 | /* Was j=(exp)?5:EVP_CIPHER_key_length(c); */ | 329 | /* Was j=(exp)?5:EVP_CIPHER_key_length(c); */ |
| 241 | k=EVP_CIPHER_iv_length(c); | 330 | k=EVP_CIPHER_iv_length(c); |
| 242 | er1= &(s->s3->client_random[0]); | 331 | er1= &(s->s3->client_random[0]); |
| @@ -264,7 +353,7 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 264 | 353 | ||
| 265 | if (n > s->s3->tmp.key_block_length) | 354 | if (n > s->s3->tmp.key_block_length) |
| 266 | { | 355 | { |
| 267 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_INTERNAL_ERROR); | 356 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_INTERNAL_ERROR); |
| 268 | goto err2; | 357 | goto err2; |
| 269 | } | 358 | } |
| 270 | 359 | ||
| @@ -273,7 +362,7 @@ int tls1_change_cipher_state(SSL *s, int which) | |||
| 273 | printf("which = %04X\nmac key=",which); | 362 | printf("which = %04X\nmac key=",which); |
| 274 | { int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); } | 363 | { int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); } |
| 275 | #endif | 364 | #endif |
| 276 | if (_exp) | 365 | if (is_export) |
| 277 | { | 366 | { |
| 278 | /* In here I set both the read and write key/iv to the | 367 | /* In here I set both the read and write key/iv to the |
| 279 | * same value since only the correct one will be used :-). | 368 | * same value since only the correct one will be used :-). |
| @@ -309,8 +398,18 @@ printf("which = %04X\nmac key=",which); | |||
| 309 | } | 398 | } |
| 310 | 399 | ||
| 311 | s->session->key_arg_length=0; | 400 | s->session->key_arg_length=0; |
| 401 | #ifdef KSSL_DEBUG | ||
| 402 | { | ||
| 403 | int i; | ||
| 404 | printf("EVP_CipherInit_ex(dd,c,key=,iv=,which)\n"); | ||
| 405 | printf("\tkey= "); for (i=0; i<c->key_len; i++) printf("%02x", key[i]); | ||
| 406 | printf("\n"); | ||
| 407 | printf("\t iv= "); for (i=0; i<c->iv_len; i++) printf("%02x", iv[i]); | ||
| 408 | printf("\n"); | ||
| 409 | } | ||
| 410 | #endif /* KSSL_DEBUG */ | ||
| 312 | 411 | ||
| 313 | EVP_CipherInit(dd,c,key,iv,(which & SSL3_CC_WRITE)); | 412 | EVP_CipherInit_ex(dd,c,NULL,key,iv,(which & SSL3_CC_WRITE)); |
| 314 | #ifdef TLS_DEBUG | 413 | #ifdef TLS_DEBUG |
| 315 | printf("which = %04X\nkey=",which); | 414 | printf("which = %04X\nkey=",which); |
| 316 | { int z; for (z=0; z<EVP_CIPHER_key_length(c); z++) printf("%02X%c",key[z],((z+1)%16)?' ':'\n'); } | 415 | { int z; for (z=0; z<EVP_CIPHER_key_length(c); z++) printf("%02X%c",key[z],((z+1)%16)?' ':'\n'); } |
| @@ -338,6 +437,10 @@ int tls1_setup_key_block(SSL *s) | |||
| 338 | int num; | 437 | int num; |
| 339 | SSL_COMP *comp; | 438 | SSL_COMP *comp; |
| 340 | 439 | ||
| 440 | #ifdef KSSL_DEBUG | ||
| 441 | printf ("tls1_setup_key_block()\n"); | ||
| 442 | #endif /* KSSL_DEBUG */ | ||
| 443 | |||
| 341 | if (s->s3->tmp.key_block_length != 0) | 444 | if (s->s3->tmp.key_block_length != 0) |
| 342 | return(1); | 445 | return(1); |
| 343 | 446 | ||
| @@ -380,6 +483,14 @@ printf("\nkey block\n"); | |||
| 380 | { int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); } | 483 | { int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); } |
| 381 | #endif | 484 | #endif |
| 382 | 485 | ||
| 486 | /* enable vulnerability countermeasure for CBC ciphers with | ||
| 487 | * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt) */ | ||
| 488 | s->s3->need_empty_fragments = 1; | ||
| 489 | #ifndef NO_RC4 | ||
| 490 | if ((s->session->cipher != NULL) && ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_RC4)) | ||
| 491 | s->s3->need_empty_fragments = 0; | ||
| 492 | #endif | ||
| 493 | |||
| 383 | return(1); | 494 | return(1); |
| 384 | err: | 495 | err: |
| 385 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE); | 496 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE); |
| @@ -417,6 +528,10 @@ int tls1_enc(SSL *s, int send) | |||
| 417 | enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx); | 528 | enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx); |
| 418 | } | 529 | } |
| 419 | 530 | ||
| 531 | #ifdef KSSL_DEBUG | ||
| 532 | printf("tls1_enc(%d)\n", send); | ||
| 533 | #endif /* KSSL_DEBUG */ | ||
| 534 | |||
| 420 | if ((s->session == NULL) || (ds == NULL) || | 535 | if ((s->session == NULL) || (ds == NULL) || |
| 421 | (enc == NULL)) | 536 | (enc == NULL)) |
| 422 | { | 537 | { |
| @@ -447,18 +562,45 @@ int tls1_enc(SSL *s, int send) | |||
| 447 | rec->length+=i; | 562 | rec->length+=i; |
| 448 | } | 563 | } |
| 449 | 564 | ||
| 565 | #ifdef KSSL_DEBUG | ||
| 566 | { | ||
| 567 | unsigned long ui; | ||
| 568 | printf("EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n", | ||
| 569 | ds,rec->data,rec->input,l); | ||
| 570 | printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n", | ||
| 571 | ds->buf_len, ds->cipher->key_len, | ||
| 572 | DES_KEY_SZ, DES_SCHEDULE_SZ, | ||
| 573 | ds->cipher->iv_len); | ||
| 574 | printf("\t\tIV: "); | ||
| 575 | for (i=0; i<ds->cipher->iv_len; i++) printf("%02X", ds->iv[i]); | ||
| 576 | printf("\n"); | ||
| 577 | printf("\trec->input="); | ||
| 578 | for (ui=0; ui<l; ui++) printf(" %02x", rec->input[ui]); | ||
| 579 | printf("\n"); | ||
| 580 | } | ||
| 581 | #endif /* KSSL_DEBUG */ | ||
| 582 | |||
| 450 | if (!send) | 583 | if (!send) |
| 451 | { | 584 | { |
| 452 | if (l == 0 || l%bs != 0) | 585 | if (l == 0 || l%bs != 0) |
| 453 | { | 586 | { |
| 454 | SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG); | 587 | SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG); |
| 455 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPT_ERROR); | 588 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); |
| 456 | return(0); | 589 | return 0; |
| 457 | } | 590 | } |
| 458 | } | 591 | } |
| 459 | 592 | ||
| 460 | EVP_Cipher(ds,rec->data,rec->input,l); | 593 | EVP_Cipher(ds,rec->data,rec->input,l); |
| 461 | 594 | ||
| 595 | #ifdef KSSL_DEBUG | ||
| 596 | { | ||
| 597 | unsigned long i; | ||
| 598 | printf("\trec->data="); | ||
| 599 | for (i=0; i<l; i++) | ||
| 600 | printf(" %02x", rec->data[i]); printf("\n"); | ||
| 601 | } | ||
| 602 | #endif /* KSSL_DEBUG */ | ||
| 603 | |||
| 462 | if ((bs != 1) && !send) | 604 | if ((bs != 1) && !send) |
| 463 | { | 605 | { |
| 464 | ii=i=rec->data[l-1]; /* padding_length */ | 606 | ii=i=rec->data[l-1]; /* padding_length */ |
| @@ -476,17 +618,18 @@ int tls1_enc(SSL *s, int send) | |||
| 476 | * All of them must have value 'padding_length'. */ | 618 | * All of them must have value 'padding_length'. */ |
| 477 | if (i > (int)rec->length) | 619 | if (i > (int)rec->length) |
| 478 | { | 620 | { |
| 479 | SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG); | 621 | /* Incorrect padding. SSLerr() and ssl3_alert are done |
| 480 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); | 622 | * by caller: we don't want to reveal whether this is |
| 481 | return(0); | 623 | * a decryption error or a MAC verification failure |
| 624 | * (see http://www.openssl.org/~bodo/tls-cbc.txt) */ | ||
| 625 | return -1; | ||
| 482 | } | 626 | } |
| 483 | for (j=(int)(l-i); j<(int)l; j++) | 627 | for (j=(int)(l-i); j<(int)l; j++) |
| 484 | { | 628 | { |
| 485 | if (rec->data[j] != ii) | 629 | if (rec->data[j] != ii) |
| 486 | { | 630 | { |
| 487 | SSLerr(SSL_F_TLS1_ENC,SSL_R_DECRYPTION_FAILED); | 631 | /* Incorrect padding */ |
| 488 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); | 632 | return -1; |
| 489 | return(0); | ||
| 490 | } | 633 | } |
| 491 | } | 634 | } |
| 492 | rec->length-=i; | 635 | rec->length-=i; |
| @@ -500,8 +643,10 @@ int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in_ctx, unsigned char *out) | |||
| 500 | unsigned int ret; | 643 | unsigned int ret; |
| 501 | EVP_MD_CTX ctx; | 644 | EVP_MD_CTX ctx; |
| 502 | 645 | ||
| 503 | EVP_MD_CTX_copy(&ctx,in_ctx); | 646 | EVP_MD_CTX_init(&ctx); |
| 504 | EVP_DigestFinal(&ctx,out,&ret); | 647 | EVP_MD_CTX_copy_ex(&ctx,in_ctx); |
| 648 | EVP_DigestFinal_ex(&ctx,out,&ret); | ||
| 649 | EVP_MD_CTX_cleanup(&ctx); | ||
| 505 | return((int)ret); | 650 | return((int)ret); |
| 506 | } | 651 | } |
| 507 | 652 | ||
| @@ -517,17 +662,18 @@ int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx, | |||
| 517 | memcpy(q,str,slen); | 662 | memcpy(q,str,slen); |
| 518 | q+=slen; | 663 | q+=slen; |
| 519 | 664 | ||
| 520 | EVP_MD_CTX_copy(&ctx,in1_ctx); | 665 | EVP_MD_CTX_init(&ctx); |
| 521 | EVP_DigestFinal(&ctx,q,&i); | 666 | EVP_MD_CTX_copy_ex(&ctx,in1_ctx); |
| 667 | EVP_DigestFinal_ex(&ctx,q,&i); | ||
| 522 | q+=i; | 668 | q+=i; |
| 523 | EVP_MD_CTX_copy(&ctx,in2_ctx); | 669 | EVP_MD_CTX_copy_ex(&ctx,in2_ctx); |
| 524 | EVP_DigestFinal(&ctx,q,&i); | 670 | EVP_DigestFinal_ex(&ctx,q,&i); |
| 525 | q+=i; | 671 | q+=i; |
| 526 | 672 | ||
| 527 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf), | 673 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf), |
| 528 | s->session->master_key,s->session->master_key_length, | 674 | s->session->master_key,s->session->master_key_length, |
| 529 | out,buf2,12); | 675 | out,buf2,12); |
| 530 | memset(&ctx,0,sizeof(EVP_MD_CTX)); | 676 | EVP_MD_CTX_cleanup(&ctx); |
| 531 | 677 | ||
| 532 | return((int)12); | 678 | return((int)12); |
| 533 | } | 679 | } |
| @@ -566,11 +712,13 @@ int tls1_mac(SSL *ssl, unsigned char *md, int send) | |||
| 566 | buf[4]=rec->length&0xff; | 712 | buf[4]=rec->length&0xff; |
| 567 | 713 | ||
| 568 | /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ | 714 | /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ |
| 569 | HMAC_Init(&hmac,mac_sec,EVP_MD_size(hash),hash); | 715 | HMAC_CTX_init(&hmac); |
| 716 | HMAC_Init_ex(&hmac,mac_sec,EVP_MD_size(hash),hash,NULL); | ||
| 570 | HMAC_Update(&hmac,seq,8); | 717 | HMAC_Update(&hmac,seq,8); |
| 571 | HMAC_Update(&hmac,buf,5); | 718 | HMAC_Update(&hmac,buf,5); |
| 572 | HMAC_Update(&hmac,rec->input,rec->length); | 719 | HMAC_Update(&hmac,rec->input,rec->length); |
| 573 | HMAC_Final(&hmac,md,&md_size); | 720 | HMAC_Final(&hmac,md,&md_size); |
| 721 | HMAC_CTX_cleanup(&hmac); | ||
| 574 | 722 | ||
| 575 | #ifdef TLS_DEBUG | 723 | #ifdef TLS_DEBUG |
| 576 | printf("sec="); | 724 | printf("sec="); |
| @@ -601,6 +749,10 @@ int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, | |||
| 601 | unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE]; | 749 | unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE]; |
| 602 | unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH]; | 750 | unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH]; |
| 603 | 751 | ||
| 752 | #ifdef KSSL_DEBUG | ||
| 753 | printf ("tls1_generate_master_secret(%p,%p, %p, %d)\n", s,out, p,len); | ||
| 754 | #endif /* KSSL_DEBUG */ | ||
| 755 | |||
| 604 | /* Setup the stuff to munge */ | 756 | /* Setup the stuff to munge */ |
| 605 | memcpy(buf,TLS_MD_MASTER_SECRET_CONST, | 757 | memcpy(buf,TLS_MD_MASTER_SECRET_CONST, |
| 606 | TLS_MD_MASTER_SECRET_CONST_SIZE); | 758 | TLS_MD_MASTER_SECRET_CONST_SIZE); |
| @@ -611,6 +763,9 @@ int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, | |||
| 611 | tls1_PRF(s->ctx->md5,s->ctx->sha1, | 763 | tls1_PRF(s->ctx->md5,s->ctx->sha1, |
| 612 | buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len, | 764 | buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len, |
| 613 | s->session->master_key,buff,SSL3_MASTER_SECRET_SIZE); | 765 | s->session->master_key,buff,SSL3_MASTER_SECRET_SIZE); |
| 766 | #ifdef KSSL_DEBUG | ||
| 767 | printf ("tls1_generate_master_secret() complete\n"); | ||
| 768 | #endif /* KSSL_DEBUG */ | ||
| 614 | return(SSL3_MASTER_SECRET_SIZE); | 769 | return(SSL3_MASTER_SECRET_SIZE); |
| 615 | } | 770 | } |
| 616 | 771 | ||
