summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libssl/src/ssl/t1_enc.c41
-rw-r--r--src/lib/libssl/t1_enc.c41
2 files changed, 48 insertions, 34 deletions
diff --git a/src/lib/libssl/src/ssl/t1_enc.c b/src/lib/libssl/src/ssl/t1_enc.c
index 9a2d979fd7..e3acf59ab0 100644
--- a/src/lib/libssl/src/ssl/t1_enc.c
+++ b/src/lib/libssl/src/ssl/t1_enc.c
@@ -537,12 +537,12 @@ err2:
537int 537int
538tls1_setup_key_block(SSL *s) 538tls1_setup_key_block(SSL *s)
539{ 539{
540 unsigned char *p1, *p2 = NULL; 540 unsigned char *key_block, *tmp_block = NULL;
541 const EVP_CIPHER *c; 541 int mac_type = NID_undef, mac_secret_size = 0;
542 int key_block_len, key_len, iv_len;
543 const EVP_CIPHER *cipher;
542 const EVP_MD *hash; 544 const EVP_MD *hash;
543 int num;
544 SSL_COMP *comp; 545 SSL_COMP *comp;
545 int mac_type = NID_undef, mac_secret_size = 0;
546 int ret = 0; 546 int ret = 0;
547 547
548 if (s->s3->tmp.key_block_length != 0) 548 if (s->s3->tmp.key_block_length != 0)
@@ -554,41 +554,48 @@ tls1_setup_key_block(SSL *s)
554 return (0); 554 return (0);
555 } 555 }
556 556
557 if (!ssl_cipher_get_evp(s->session, &c, &hash, &mac_type, 557 if (!ssl_cipher_get_evp(s->session, &cipher, &hash, &mac_type,
558 &mac_secret_size)) { 558 &mac_secret_size)) {
559 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, 559 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,
560 SSL_R_CIPHER_OR_HASH_UNAVAILABLE); 560 SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
561 return (0); 561 return (0);
562 } 562 }
563 563
564 s->s3->tmp.new_sym_enc = c; 564 key_len = EVP_CIPHER_key_length(cipher);
565
566 if (EVP_CIPHER_mode(cipher) == EVP_CIPH_GCM_MODE)
567 iv_len = EVP_GCM_TLS_FIXED_IV_LEN;
568 else
569 iv_len = EVP_CIPHER_iv_length(cipher);
570
571 s->s3->tmp.new_sym_enc = cipher;
565 s->s3->tmp.new_hash = hash; 572 s->s3->tmp.new_hash = hash;
566 s->s3->tmp.new_mac_pkey_type = mac_type; 573 s->s3->tmp.new_mac_pkey_type = mac_type;
567 s->s3->tmp.new_mac_secret_size = mac_secret_size; 574 s->s3->tmp.new_mac_secret_size = mac_secret_size;
568 num = EVP_CIPHER_key_length(c) + mac_secret_size + EVP_CIPHER_iv_length(c); 575 key_block_len = (mac_secret_size + key_len + iv_len) * 2;
569 num *= 2;
570 576
571 ssl3_cleanup_key_block(s); 577 ssl3_cleanup_key_block(s);
572 578
573 if ((p1 = malloc(num)) == NULL) { 579 if ((key_block = malloc(key_block_len)) == NULL) {
574 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE); 580 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
575 goto err; 581 goto err;
576 } 582 }
577 583
578 s->s3->tmp.key_block_length = num; 584 s->s3->tmp.key_block_length = key_block_len;
579 s->s3->tmp.key_block = p1; 585 s->s3->tmp.key_block = key_block;
580 586
581 if ((p2 = malloc(num)) == NULL) { 587 if ((tmp_block = malloc(key_block_len)) == NULL) {
582 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE); 588 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
583 goto err; 589 goto err;
584 } 590 }
585 591
586 if (!tls1_generate_key_block(s, p1, p2, num)) 592 if (!tls1_generate_key_block(s, key_block, tmp_block, key_block_len))
587 goto err; 593 goto err;
588 594
589 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) && 595 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) &&
590 s->method->version <= TLS1_VERSION) { 596 s->method->version <= TLS1_VERSION) {
591 /* enable vulnerability countermeasure for CBC ciphers with 597 /*
598 * Enable vulnerability countermeasure for CBC ciphers with
592 * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt) 599 * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt)
593 */ 600 */
594 s->s3->need_empty_fragments = 1; 601 s->s3->need_empty_fragments = 1;
@@ -606,9 +613,9 @@ tls1_setup_key_block(SSL *s)
606 613
607 ret = 1; 614 ret = 1;
608err: 615err:
609 if (p2) { 616 if (tmp_block) {
610 OPENSSL_cleanse(p2, num); 617 OPENSSL_cleanse(tmp_block, key_block_len);
611 free(p2); 618 free(tmp_block);
612 } 619 }
613 return (ret); 620 return (ret);
614} 621}
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c
index 9a2d979fd7..e3acf59ab0 100644
--- a/src/lib/libssl/t1_enc.c
+++ b/src/lib/libssl/t1_enc.c
@@ -537,12 +537,12 @@ err2:
537int 537int
538tls1_setup_key_block(SSL *s) 538tls1_setup_key_block(SSL *s)
539{ 539{
540 unsigned char *p1, *p2 = NULL; 540 unsigned char *key_block, *tmp_block = NULL;
541 const EVP_CIPHER *c; 541 int mac_type = NID_undef, mac_secret_size = 0;
542 int key_block_len, key_len, iv_len;
543 const EVP_CIPHER *cipher;
542 const EVP_MD *hash; 544 const EVP_MD *hash;
543 int num;
544 SSL_COMP *comp; 545 SSL_COMP *comp;
545 int mac_type = NID_undef, mac_secret_size = 0;
546 int ret = 0; 546 int ret = 0;
547 547
548 if (s->s3->tmp.key_block_length != 0) 548 if (s->s3->tmp.key_block_length != 0)
@@ -554,41 +554,48 @@ tls1_setup_key_block(SSL *s)
554 return (0); 554 return (0);
555 } 555 }
556 556
557 if (!ssl_cipher_get_evp(s->session, &c, &hash, &mac_type, 557 if (!ssl_cipher_get_evp(s->session, &cipher, &hash, &mac_type,
558 &mac_secret_size)) { 558 &mac_secret_size)) {
559 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, 559 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,
560 SSL_R_CIPHER_OR_HASH_UNAVAILABLE); 560 SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
561 return (0); 561 return (0);
562 } 562 }
563 563
564 s->s3->tmp.new_sym_enc = c; 564 key_len = EVP_CIPHER_key_length(cipher);
565
566 if (EVP_CIPHER_mode(cipher) == EVP_CIPH_GCM_MODE)
567 iv_len = EVP_GCM_TLS_FIXED_IV_LEN;
568 else
569 iv_len = EVP_CIPHER_iv_length(cipher);
570
571 s->s3->tmp.new_sym_enc = cipher;
565 s->s3->tmp.new_hash = hash; 572 s->s3->tmp.new_hash = hash;
566 s->s3->tmp.new_mac_pkey_type = mac_type; 573 s->s3->tmp.new_mac_pkey_type = mac_type;
567 s->s3->tmp.new_mac_secret_size = mac_secret_size; 574 s->s3->tmp.new_mac_secret_size = mac_secret_size;
568 num = EVP_CIPHER_key_length(c) + mac_secret_size + EVP_CIPHER_iv_length(c); 575 key_block_len = (mac_secret_size + key_len + iv_len) * 2;
569 num *= 2;
570 576
571 ssl3_cleanup_key_block(s); 577 ssl3_cleanup_key_block(s);
572 578
573 if ((p1 = malloc(num)) == NULL) { 579 if ((key_block = malloc(key_block_len)) == NULL) {
574 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE); 580 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
575 goto err; 581 goto err;
576 } 582 }
577 583
578 s->s3->tmp.key_block_length = num; 584 s->s3->tmp.key_block_length = key_block_len;
579 s->s3->tmp.key_block = p1; 585 s->s3->tmp.key_block = key_block;
580 586
581 if ((p2 = malloc(num)) == NULL) { 587 if ((tmp_block = malloc(key_block_len)) == NULL) {
582 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE); 588 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
583 goto err; 589 goto err;
584 } 590 }
585 591
586 if (!tls1_generate_key_block(s, p1, p2, num)) 592 if (!tls1_generate_key_block(s, key_block, tmp_block, key_block_len))
587 goto err; 593 goto err;
588 594
589 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) && 595 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) &&
590 s->method->version <= TLS1_VERSION) { 596 s->method->version <= TLS1_VERSION) {
591 /* enable vulnerability countermeasure for CBC ciphers with 597 /*
598 * Enable vulnerability countermeasure for CBC ciphers with
592 * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt) 599 * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt)
593 */ 600 */
594 s->s3->need_empty_fragments = 1; 601 s->s3->need_empty_fragments = 1;
@@ -606,9 +613,9 @@ tls1_setup_key_block(SSL *s)
606 613
607 ret = 1; 614 ret = 1;
608err: 615err:
609 if (p2) { 616 if (tmp_block) {
610 OPENSSL_cleanse(p2, num); 617 OPENSSL_cleanse(tmp_block, key_block_len);
611 free(p2); 618 free(tmp_block);
612 } 619 }
613 return (ret); 620 return (ret);
614} 621}