diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2017-02-03 02:44:15 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2017-02-08 02:16:27 +0000 |
commit | ec07b1d872300f347c436ff5e549b94f79c0fa63 (patch) | |
tree | 891a0305c6b29e792200fc73e6646c1bf964358d /ssl/tls13_enc.c | |
parent | aa24c47c834015dd34d00bcf9373113f0c57e1f0 (diff) |
Add CCM mode support for TLS 1.3
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2550)
Diffstat (limited to 'ssl/tls13_enc.c')
-rw-r--r-- | ssl/tls13_enc.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/ssl/tls13_enc.c b/ssl/tls13_enc.c index 0d29dae042..ebfeecdfb2 100644 --- a/ssl/tls13_enc.c +++ b/ssl/tls13_enc.c @@ -264,7 +264,7 @@ int tls13_change_cipher_state(SSL *s, int which) const char *log_label = NULL; EVP_CIPHER_CTX *ciph_ctx; const EVP_CIPHER *ciph = s->s3->tmp.new_sym_enc; - size_t ivlen, keylen, finsecretlen = 0; + size_t ivlen, keylen, taglen, finsecretlen = 0; const unsigned char *label; size_t labellen, hashlen = 0; int ret = 0; @@ -373,7 +373,17 @@ int tls13_change_cipher_state(SSL *s, int which) /* TODO(size_t): convert me */ keylen = EVP_CIPHER_key_length(ciph); - ivlen = EVP_CIPHER_iv_length(ciph); + if (EVP_CIPHER_mode(ciph) == EVP_CIPH_CCM_MODE) { + ivlen = EVP_CCM_TLS_IV_LEN; + if (s->s3->tmp.new_cipher->algorithm_enc + & (SSL_AES128CCM8 | SSL_AES256CCM8)) + taglen = EVP_CCM8_TLS_TAG_LEN; + else + taglen = EVP_CCM_TLS_TAG_LEN; + } else { + ivlen = EVP_CIPHER_iv_length(ciph); + taglen = 0; + } if (!ssl_log_secret(s, log_label, secret, hashlen)) { SSLerr(SSL_F_TLS13_CHANGE_CIPHER_STATE, ERR_R_INTERNAL_ERROR); @@ -391,8 +401,12 @@ int tls13_change_cipher_state(SSL *s, int which) goto err; } - if (EVP_CipherInit_ex(ciph_ctx, ciph, NULL, key, NULL, - (which & SSL3_CC_WRITE)) <= 0) { + if (EVP_CipherInit_ex(ciph_ctx, ciph, NULL, NULL, NULL, + (which & SSL3_CC_WRITE)) <= 0 + || !EVP_CIPHER_CTX_ctrl(ciph_ctx, EVP_CTRL_AEAD_SET_IVLEN, ivlen, NULL) + || (taglen != 0 && !EVP_CIPHER_CTX_ctrl(ciph_ctx, EVP_CTRL_AEAD_SET_TAG, + taglen, NULL)) + || EVP_CipherInit_ex(ciph_ctx, NULL, NULL, key, NULL, -1) <= 0) { SSLerr(SSL_F_TLS13_CHANGE_CIPHER_STATE, ERR_R_EVP_LIB); goto err; } |