rfc-7366

Encrypt-then-MAC for Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)

P. Gutmann
date2014-09 streamIETF areasec wgtls statusPROPOSED STANDARD pages7 canonicalhttps://www.rfc-editor.org/rfc/rfc7366 doi10.17487/RFC7366 errataview
This document describes a means of negotiating the use of the encrypt-then-MAC security mechanism in place of the existing MAC-then-encrypt mechanism in Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS). The MAC-then-encrypt mechanism has been the subject of a number of security vulnerabilities over a period of many years.

Extracted elements (20)

design-rationale §2.1

Introducing encrypt-then-MAC via the extension mechanism rather than waiting for TLS 1.3 is justified because TLS 1.3 would require full implementation and deployment of TLS 1.2 merely to support a trivial ordering change, whereas the extension mechanism allows incremental deployment.

tls, security

design-rationale §2.1

The use of TLS extensions precludes use with SSL 3.0, which is intentional: SSL 3.0 is nearly two decades old and likely vulnerable to many other attacks, making backward compatibility with it not worth the effort.

tls, security

design-rationale §2.1

Using a TLS/DTLS extension to negotiate encrypt-then-MAC is preferred over defining new ciphersuites because new ciphersuites would cause a Cartesian explosion requiring duplication of every existing suite. The extension approach requires a single new extension type and changed less than a dozen lines of code in one implementation.

tls, security

interoperability-note §3

Encrypt-then-MAC applies exclusively to GenericBlockCipher ciphersuites. GenericStreamCiphers and GenericAEADCiphers already include integrity protection within the cipher and are therefore unaffected by this extension.

tls, security

normative-requirement §3 MUST NOT

Encrypt-then-MAC applies only to block ciphers (GenericBlockCipher). If a server receives an encrypt-then-MAC request extension but then selects a stream or AEAD ciphersuite, it MUST NOT send an encrypt-then-MAC response extension back to the client.

tls, security

normative-requirement §3 MUST

For TLS, a MAC verification failure MUST generate a fatal bad_record_mac alert. For DTLS, the record MUST be discarded and a fatal bad_record_mac MAY be generated.

tls, security

normative-requirement §3 MAY

Implementations MAY negotiate a truncated MAC through the TLS truncated_hmac extension (RFC 6066) when using encrypt-then-MAC.

tls, crypto

normative-requirement §3.1 MUST NOT

Implementations MUST NOT renegotiate a downgrade from encrypt-then-MAC to MAC-then-encrypt, directly or indirectly (e.g., via an intermediate AEAD ciphersuite selection followed by a MAC-then-encrypt selection).

tls, security

normative-requirement §3.1 SHOULD

Implementations SHOULD retain the current session's MAC ordering (encrypt-then-MAC or MAC-then-encrypt) across all rehandshakes for that session, and SHOULD NOT change state during a rehandshake.

tls, security

normative-requirement §2 MUST NOT

The client and server MUST NOT use encrypt-then-MAC unless both sides have successfully exchanged encrypt_then_mac extensions.

tls, security

normative-requirement §3 SHALL

The MAC SHALL be evaluated before any further processing such as decryption is performed. If MAC verification fails, processing SHALL terminate immediately.

tls, security, crypto

protocol-element §3

For TLS 1.0 (without explicit IV), the MAC is computed as MAC(MAC_write_key, seq_num + TLSCipherText.type + TLSCipherText.version + TLSCipherText.length + ENC(content+padding+padding_length)). For TLS 1.1 and greater with explicit IV, the IV field is included between the length and the encrypted payload in the MAC input.

tls, crypto, security

protocol-element §2

The encrypt_then_mac TLS extension is identified by extension_type value 22 (0x16) and carries an empty extension_data field. The client includes it in ClientHello to request encrypt-then-MAC; the server echoes it in ServerHello to confirm.

tls, security

protocol-element §3.1

When an upgrade from MAC-then-encrypt to encrypt-then-MAC is negotiated during rehandshake, the change takes effect in the first message following the Change Cipher Spec (CCS) message. All messages up to and including the CCS use MAC-then-encrypt.

tls, security

registry §5

IANA has added extension code point 22 (0x16) for the encrypt_then_mac extension to the TLS 'ExtensionType Values' registry as specified in TLS (RFC 5246).

tls, registry

security-consideration §4

An active attacker who can emulate a client or server with extension intolerance may cause implementations to fall back to older protocol versions that do not support extensions, forcing non-encrypt-then-MAC behaviour. The recommended mitigation is to avoid fallback to older, less secure protocol versions.

tls, security

security-consideration §4

Immediate MAC verification before decryption eliminates timing side-channels that could otherwise be exploited through manipulated packet data, which were a key vulnerability of the original MAC-then-encrypt construction.

tls, security, crypto

state-machine §3.1

Rehandshake rules for encrypt-then-MAC: MAC-then-encrypt -> MAC-then-encrypt is no change; MAC-then-encrypt -> encrypt-then-MAC is an upgrade; encrypt-then-MAC -> MAC-then-encrypt is an error (downgrade forbidden); encrypt-then-MAC -> encrypt-then-MAC is no change. These rules apply across all rehandshakes, including indirect downgrades via AEAD ciphersuites.

tls, security

wire-format §3

The encrypt-then-MAC TLS packet structure is: {ContentType type; ProtocolVersion version; uint16 length; GenericBlockCipher fragment; opaque MAC;}. The DTLS equivalent adds uint16 epoch and uint48 sequence_number fields between version and length.

tls, security

wire-format §3

Under encrypt-then-MAC, TLS processing switches from encrypt(data||MAC||pad) to encrypt(data||pad)||MAC, with the MAC covering the entire packet up to the start of the MAC value. The TLSCiphertext struct gains a trailing opaque MAC field outside the GenericBlockCipher fragment.

tls, security, crypto