Blame SOURCES/gnutls-3.3.29-dummy-wait-hash-same-amount-of-blocks.patch

519d7d
diff --git a/lib/gnutls_cipher.c b/lib/gnutls_cipher.c
519d7d
index 37478a4c3..65dde6899 100644
519d7d
--- a/lib/gnutls_cipher.c
519d7d
+++ b/lib/gnutls_cipher.c
519d7d
@@ -434,40 +434,41 @@ compressed_to_ciphertext(gnutls_session_t session,
519d7d
 	return length;
519d7d
 }
519d7d
 
519d7d
-static void dummy_wait(record_parameters_st * params,
519d7d
-		       gnutls_datum_t * plaintext, unsigned pad_failed,
519d7d
-		       unsigned int pad, unsigned total)
519d7d
+static void dummy_wait(record_parameters_st *params,
519d7d
+		       gnutls_datum_t *plaintext,
519d7d
+		       unsigned int mac_data, unsigned int max_mac_data)
519d7d
 {
519d7d
 	/* this hack is only needed on CBC ciphers */
519d7d
 	if (_gnutls_cipher_is_block(params->cipher) == CIPHER_BLOCK) {
519d7d
-		unsigned len, v;
519d7d
+		unsigned v;
519d7d
+		unsigned int tag_size =
519d7d
+		    _gnutls_auth_cipher_tag_len(&params->read.cipher_state);
519d7d
+		unsigned hash_block = _gnutls_mac_block_size(params->mac);
519d7d
 
519d7d
-		/* force an additional hash compression function evaluation to prevent timing 
519d7d
+		/* force additional hash compression function evaluations to prevent timing
519d7d
 		 * attacks that distinguish between wrong-mac + correct pad, from wrong-mac + incorrect pad.
519d7d
 		 */
519d7d
-		if (pad_failed == 0 && pad > 0) {
519d7d
-			len = _gnutls_mac_block_size(params->mac);
519d7d
-			if (len > 0) {
519d7d
-				if (params->mac && params->mac->id == GNUTLS_MAC_SHA384)
519d7d
-					/* v = 1 for the hash function padding + 16 for message length */
519d7d
-					v = 17;
519d7d
-				else /* v = 1 for the hash function padding + 8 for message length */
519d7d
-					v = 9;
519d7d
-
519d7d
-				if ((pad + total) % len > len - v
519d7d
-				    && total % len <= len - v) {
519d7d
-					if (len < plaintext->size)
519d7d
-						_gnutls_auth_cipher_add_auth
519d7d
-						    (&params->read.
519d7d
-						     cipher_state,
519d7d
-						     plaintext->data, len);
519d7d
-					else
519d7d
-						_gnutls_auth_cipher_add_auth
519d7d
-						    (&params->read.
519d7d
-						     cipher_state,
519d7d
-						     plaintext->data,
519d7d
-						     plaintext->size);
519d7d
-				}
519d7d
+		if (params->mac && params->mac->id == GNUTLS_MAC_SHA384)
519d7d
+			/* v = 1 for the hash function padding + 16 for message length */
519d7d
+			v = 17;
519d7d
+		else /* v = 1 for the hash function padding + 8 for message length */
519d7d
+			v = 9;
519d7d
+
519d7d
+		if (hash_block > 0) {
519d7d
+			int max_blocks = (max_mac_data+v+hash_block-1)/hash_block;
519d7d
+			int hashed_blocks = (mac_data+v+hash_block-1)/hash_block;
519d7d
+			unsigned to_hash;
519d7d
+
519d7d
+			max_blocks -= hashed_blocks;
519d7d
+			if (max_blocks < 1)
519d7d
+				return;
519d7d
+
519d7d
+			to_hash = max_blocks * hash_block;
519d7d
+			if ((unsigned)to_hash+1+tag_size < plaintext->size) {
519d7d
+				_gnutls_auth_cipher_add_auth
519d7d
+					    (&params->read.cipher_state,
519d7d
+					     plaintext->data+plaintext->size-tag_size-to_hash-1,
519d7d
+					     to_hash);
519d7d
 			}
519d7d
 		}
519d7d
 	}
519d7d
@@ -725,8 +726,10 @@ ciphertext_to_compressed(gnutls_session_t session,
519d7d
 	if (unlikely
519d7d
 	    (memcmp(tag, tag_ptr, tag_size) != 0 || pad_failed != 0)) {
519d7d
 		/* HMAC was not the same. */
519d7d
-		dummy_wait(params, compressed, pad_failed, pad,
519d7d
-			   length + preamble_size);
519d7d
+			gnutls_datum_t data = {compressed->data, ciphertext->size};
519d7d
+
519d7d
+			dummy_wait(params, &data, length + preamble_size,
519d7d
+				   preamble_size + ciphertext->size - tag_size - 1);
519d7d
 
519d7d
 		return gnutls_assert_val(GNUTLS_E_DECRYPTION_FAILED);
519d7d
 	}
519d7d
-- 
519d7d
2.14.3
519d7d