Re: aes128gcm: why verify padding?

Martin Thomson <> Mon, 23 January 2017 23:40 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id C3E91129422 for <>; Mon, 23 Jan 2017 15:40:25 -0800 (PST)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -9.72
X-Spam-Status: No, score=-9.72 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, RP_MATCHES_RCVD=-3.199, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: (amavisd-new); dkim=pass (2048-bit key)
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id mQkJbCzDZzS5 for <>; Mon, 23 Jan 2017 15:40:24 -0800 (PST)
Received: from ( []) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by (Postfix) with ESMTPS id B3EF1129420 for <>; Mon, 23 Jan 2017 15:40:24 -0800 (PST)
Received: from lists by with local (Exim 4.80) (envelope-from <>) id 1cVoBv-0005Cu-HO for; Mon, 23 Jan 2017 23:38:27 +0000
Resent-Date: Mon, 23 Jan 2017 23:38:27 +0000
Resent-Message-Id: <>
Received: from ([]) by with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from <>) id 1cVoBs-0005C9-Iq for; Mon, 23 Jan 2017 23:38:24 +0000
Received: from ([]) by with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <>) id 1cVoBm-0004bk-JL for; Mon, 23 Jan 2017 23:38:19 +0000
Received: by with SMTP id v23so152601899qtb.0 for <>; Mon, 23 Jan 2017 15:37:58 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=x/MiRN+KlHN1CkKK68v9o6mORgezGejCleYfPwH2hwA=; b=FBn2K6hHR+i7ijK/nucd1Zcbaz5lKAvdFWZXdJvhCy1/frE70Vpw4kkYC3AE0TRVH3 AzLYuXMOarMT7ToWyEZCMLCLrHXUzMaS0WddNjb+B/+FaFD6ipJNq1oJcWldwBrksZSP NQYmxRGGq7OLMt6HKg9Utd/MAwETlXzSh+2TXYyUPIK5wEHoYX3eeca1AY1h9DAeaWM0 MY2MIY+lUA4v+fWKfC65s+qhJzNuq0wEZvT0K+X+pebj3ro/rhszJ0RAcWq8eHDEZT1d ZexH6u0lUgxSQxsF9Z/V+2s1JD4oiPD6Y3skyW2zm/lAB20aSqROWhf4QzEMAbMe8DXp MV4A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=x/MiRN+KlHN1CkKK68v9o6mORgezGejCleYfPwH2hwA=; b=R44+tOpKM8aCbYtrc5Ahs45LDENKzpi65bs5BFPvEUo9O/T8S49VG+2AUb1jTrzrSo BRXAJzgKohOZ6kjZ1vzYmBkVhw8qABr3bfgcuj3khOC4ZHpyoY7NGBawE4e5RET9wbSP UILry29baRgAD4bKmo+DYupwYFrasnjW9kUSc+VgiEj5skhwX/FIjlO+NO/k0d/HTLvC AmyOxG/zD01CkpZMR1DNHqC7gBCWH75gn6Zw/xVbnm390g3G1KHSmERTomi5dFzeFaXe bTbqgQi0HF4ecN04rKc7osPbvPv+VD3Sys2mL6VhrTOqQK5GnwQSw24SElQZyqJE2m1G PKhg==
X-Gm-Message-State: AIkVDXJJsWswNmocj7BLW1o5pfv+suZrn/DIDTPGNxB3PrSh5Jma3R1IYbgLS+V/svmQwUA6PmkS6Z4+6JwlfQ==
X-Received: by with SMTP id x82mr26231512qkb.147.1485214672684; Mon, 23 Jan 2017 15:37:52 -0800 (PST)
MIME-Version: 1.0
Received: by with HTTP; Mon, 23 Jan 2017 15:37:51 -0800 (PST)
In-Reply-To: <>
References: <> <> <> <> <> <> <>
From: Martin Thomson <>
Date: Tue, 24 Jan 2017 08:37:51 +0900
Message-ID: <>
To: "Manger, James" <>
Cc: "" <>, "" <>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass client-ip=;;
X-W3C-Hub-Spam-Status: No, score=-5.8
X-W3C-Hub-Spam-Report: AWL=-0.230, BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001, W3C_AA=-1, W3C_DB=-1, W3C_IRA=-1, W3C_WL=-1
X-W3C-Scan-Sig: 1cVoBm-0004bk-JL fc352fd7c81bbc7605120040eb106698
Subject: Re: aes128gcm: why verify padding?
Archived-At: <>
X-Mailing-List: <> archive/latest/33360
Precedence: list
List-Id: <>
List-Help: <>
List-Post: <>
List-Unsubscribe: <>

On 23 January 2017 at 21:47, Manger, James
<> wrote:
> A padding byte to distinguish intermediate and final records could indeed work.

I like it.  You can pad an arbitrary amount and you only pay one octet
per record overhead if you don't like padding, and the trailing record
requirement goes away.

> It doesn't consume any extra bytes in this scheme as it piggy-backs on an end-of-padding byte. But in a different multiple-AEAD-record scheme that didn't offer padding (a nice, but not strictly necessary feature) it wouldn't be so ideal. I've seen ideas to put the first-vs-intermediate-vs-last indicator in the nonce, in the KDF, in the AAD, in the record length, and now in the plaintext. I'm not sure how to pick.

I believe that it doesn't matter.

> What do you do if last non-zero byte isn't 0x01 or 0x02?

Explode and discard the data - it's corrupted.  If we don't require
that, then an attacker gains a decryption oracle.  (Same reason for
requiring that the padding be fixed in size.)