]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
EtM fixes: it only applies to block ciphers
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 4 Nov 2014 18:27:24 +0000 (19:27 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 4 Nov 2014 18:27:24 +0000 (19:27 +0100)
lib/ext/etm.c
lib/gnutls_cipher.c
lib/gnutls_cipher_int.c

index 2ae9eba7fda69e7ea6c9be7540307ca1732e013c..755690119415a485cada3260c62eb70cb915d4cc 100644 (file)
@@ -79,7 +79,7 @@ _gnutls_ext_etm_recv_params(gnutls_session_t session,
                const cipher_entry_st *c;
 
                c = _gnutls_cipher_suite_get_cipher_algo(session->security_parameters.cipher_suite);
-               if (c == NULL || c->type == CIPHER_AEAD)
+               if (c == NULL || (c->type == CIPHER_AEAD || c->type == CIPHER_STREAM))
                        return 0;
 
                session->security_parameters.etm = 1;
@@ -106,7 +106,7 @@ _gnutls_ext_etm_send_params(gnutls_session_t session,
                extension_priv_data_t epriv;
 
                c = _gnutls_cipher_suite_get_cipher_algo(session->security_parameters.cipher_suite);
-               if (c == NULL || c->type == CIPHER_AEAD)
+               if (c == NULL || (c->type == CIPHER_AEAD || c->type == CIPHER_STREAM))
                        return 0;
 
                ret = _gnutls_ext_get_session_data(session,
index 82abe270e3e85afab2a28f77870495ce3b53e1f0..ba8796bad787b03912d32a87a112c09512829a94 100644 (file)
@@ -303,7 +303,7 @@ compressed_to_ciphertext(gnutls_session_t session,
        int auth_cipher =
            _gnutls_auth_cipher_is_aead(&params->write.cipher_state);
        uint8_t nonce[MAX_CIPHER_BLOCK_SIZE];
-       unsigned imp_iv_size, exp_iv_size;
+       unsigned imp_iv_size = 0, exp_iv_size = 0;
 
        if (unlikely(ver == NULL))
                return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
@@ -396,7 +396,7 @@ compressed_to_ciphertext(gnutls_session_t session,
                cipher_data += exp_iv_size;
        }
 
-       if (params->etm && algo_type != CIPHER_AEAD)
+       if (params->etm && algo_type == CIPHER_BLOCK)
                ret = length-tag_size;
        else
                ret = compressed->size;
@@ -506,7 +506,7 @@ ciphertext_to_compressed(gnutls_session_t session,
        blocksize = _gnutls_cipher_get_block_size(params->cipher);
 
        /* if EtM mode and not AEAD */
-       if (params->etm !=0 && cipher_type != CIPHER_AEAD) {
+       if (params->etm !=0 && cipher_type == CIPHER_BLOCK) {
                if (unlikely(ciphertext->size < tag_size))
                        return gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET_LENGTH);
 
@@ -626,18 +626,16 @@ ciphertext_to_compressed(gnutls_session_t session,
                /* Pass the type, version, length and compressed through
                 * MAC.
                 */
-               if (params->etm == 0) {
-                       preamble_size =
-                           make_preamble(UINT64DATA(*sequence), type,
-                                         length, ver, preamble);
+               preamble_size =
+                   make_preamble(UINT64DATA(*sequence), type,
+                                 length, ver, preamble);
 
-                       ret =
-                           _gnutls_auth_cipher_add_auth(&params->read.
-                                                        cipher_state, preamble,
-                                                        preamble_size);
-                       if (unlikely(ret < 0))
-                               return gnutls_assert_val(ret);
-               }
+               ret =
+                   _gnutls_auth_cipher_add_auth(&params->read.
+                                                cipher_state, preamble,
+                                                preamble_size);
+               if (unlikely(ret < 0))
+                       return gnutls_assert_val(ret);
 
                if (unlikely
                    ((unsigned) length_to_decrypt > compressed->size)) {
@@ -780,7 +778,7 @@ ciphertext_to_compressed(gnutls_session_t session,
                return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
        }
 
-       if (params->etm ==0 && cipher_type != CIPHER_AEAD) {
+       if (params->etm == 0 || cipher_type != CIPHER_BLOCK) {
                ret =
                    _gnutls_auth_cipher_tag(&params->read.cipher_state, tag,
                                            tag_size);
index 8a7c6ff5524c6b6da1bc2b21523bc69640cfbe8e..e3a40d1aec9dc0d9ca14d5998dd599bbb5d62b0a 100644 (file)
@@ -253,7 +253,7 @@ int _gnutls_auth_cipher_encrypt2_tag(auth_cipher_hd_st * handle,
                } else {
                        uint8_t *orig_ciphertext = ciphertext;
 
-                       if (handle->etm == 0) {
+                       if (handle->etm == 0 || handle->cipher.e->type != CIPHER_BLOCK) {
                                MAC(handle, text, textlen);
                        }
 
@@ -277,7 +277,7 @@ int _gnutls_auth_cipher_encrypt2_tag(auth_cipher_hd_st * handle,
                        if (ciphertext != text && textlen > 0)
                                memcpy(ciphertext, text, textlen);
 
-                       if (handle->etm == 0) {
+                       if (handle->etm == 0 || handle->cipher.e->type != CIPHER_BLOCK) {
                                ret =
                                    _gnutls_auth_cipher_tag(handle,
                                                            ciphertext + textlen,
@@ -302,7 +302,7 @@ int _gnutls_auth_cipher_encrypt2_tag(auth_cipher_hd_st * handle,
                        if (ret < 0)
                                return gnutls_assert_val(ret);
 
-                       if (handle->etm != 0) {
+                       if (handle->etm != 0 && handle->cipher.e->type == CIPHER_BLOCK) {
                                MAC(handle, orig_ciphertext, l);
                                MAC(handle, ciphertext, textlen);
 
@@ -341,7 +341,7 @@ int _gnutls_auth_cipher_decrypt2(auth_cipher_hd_st * handle,
        if (unlikely(ciphertextlen > textlen))
                return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
 
-       if (handle->is_mac && handle->etm != 0) {
+       if (handle->is_mac && (handle->etm != 0 && handle->cipher.e->type == CIPHER_BLOCK)) {
                /* The MAC is not to be hashed */
                ciphertextlen -= handle->tag_size;
 
@@ -357,7 +357,7 @@ int _gnutls_auth_cipher_decrypt2(auth_cipher_hd_st * handle,
        } else if (handle->non_null == 0 && text != ciphertext)
                memcpy(text, ciphertext, ciphertextlen);
 
-       if (handle->is_mac && handle->etm == 0) {
+       if (handle->is_mac && (handle->etm == 0 || handle->cipher.e->type != CIPHER_BLOCK)) {
                /* The MAC is not to be hashed */
                ciphertextlen -= handle->tag_size;