Re: [TLS] Length of a variable-length vector: Could it be an odd multiple?

Ilari Liusvaara <ilariliusvaara@welho.com> Fri, 22 January 2016 16:22 UTC

Return-Path: <ilariliusvaara@welho.com>
X-Original-To: tls@ietfa.amsl.com
Delivered-To: tls@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id DE9201AD36B for <tls@ietfa.amsl.com>; Fri, 22 Jan 2016 08:22:51 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.901
X-Spam-Level:
X-Spam-Status: No, score=-1.901 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RP_MATCHES_RCVD=-0.001] autolearn=ham
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0QT4wZZq1WFH for <tls@ietfa.amsl.com>; Fri, 22 Jan 2016 08:22:49 -0800 (PST)
Received: from welho-filter4.welho.com (welho-filter4.welho.com [83.102.41.26]) by ietfa.amsl.com (Postfix) with ESMTP id 6A7861AD369 for <tls@ietf.org>; Fri, 22 Jan 2016 08:22:49 -0800 (PST)
Received: from localhost (localhost [127.0.0.1]) by welho-filter4.welho.com (Postfix) with ESMTP id 7D5B327EE; Fri, 22 Jan 2016 18:22:47 +0200 (EET)
X-Virus-Scanned: Debian amavisd-new at pp.htv.fi
Received: from welho-smtp2.welho.com ([IPv6:::ffff:83.102.41.85]) by localhost (welho-filter4.welho.com [::ffff:83.102.41.26]) (amavisd-new, port 10024) with ESMTP id Pl1VyjbsBPMS; Fri, 22 Jan 2016 18:22:47 +0200 (EET)
Received: from LK-Perkele-V2 (87-92-35-116.bb.dnainternet.fi [87.92.35.116]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by welho-smtp2.welho.com (Postfix) with ESMTPSA id 11AD1231; Fri, 22 Jan 2016 18:22:47 +0200 (EET)
Date: Fri, 22 Jan 2016 18:22:42 +0200
From: Ilari Liusvaara <ilariliusvaara@welho.com>
To: "Hodges, Jeff" <jeff.hodges@paypal.com>
Message-ID: <20160122162242.GA22338@LK-Perkele-V2.elisa-laajakaista.fi>
References: <CA+_zv04F0EiLdcbkhyNo9P8dR3BW3JAsDys_WKFXXUW92x=LcQ@mail.gmail.com> <5696B946.3050405@akamai.com> <D2C5128F.5D7C9%jehodges@paypalcorp.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <D2C5128F.5D7C9%jehodges@paypalcorp.com>
User-Agent: Mutt/1.5.24 (2015-08-30)
Sender: ilariliusvaara@welho.com
Archived-At: <http://mailarchive.ietf.org/arch/msg/tls/0WNt3_MFoaBkUEWcVQgqdUQfOqw>
Cc: Jong-Shian Wu <js@crypto.tw>, "tls@ietf.org" <tls@ietf.org>
Subject: Re: [TLS] Length of a variable-length vector: Could it be an odd multiple?
X-BeenThere: tls@ietf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: "This is the mailing list for the Transport Layer Security working group of the IETF." <tls.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/tls>, <mailto:tls-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/tls/>
List-Post: <mailto:tls@ietf.org>
List-Help: <mailto:tls-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/tls>, <mailto:tls-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 22 Jan 2016 16:22:52 -0000

On Wed, Jan 20, 2016 at 06:47:12PM +0000, Hodges, Jeff wrote:
> On 1/13/16, 12:53 PM, "Benjamin Kaduk" <bkaduk@akamai.com>; wrote:
> >On 01/13/2016 02:44 PM, Jong-Shian Wu wrote:
> >> I have a question about the even-vs-odd restrictions on the length of
> >> a valid variable-length vector defined in TLS specification after
> >> reading the section 4.3 of RFC 5246 [1] which states that:
> 
> >>"The length of an encoded vector must be an even multiple of the length
> >>of a single element (for example, a 17-byte vector of uint16 would be
> >> illegal)."
> >>
> >
> >It means "whole-number" as opposed to fractional, i.e., there should not
> >be unused "junk bytes" at the end.
> 
> In case it's helpful, here's a suggested re-write of that quoted sentence
> above..
> 
>   The length of an encoded variable-length vector must be an
>   exact multiple of the length of a single element. For example,
>   an encoded 17-byte vector of uint16 would be illegal, and an
>   encoded variable-length vector of four 32 byte elements,
>   having a ceiling of 2^16-1, will be 130 bytes long overall
>   (2 byte length field followed by 128 bytes of data).
> 
> ..assuming I'm correctly understanding variable-length vectors :)

The length of length is inferred from the upper limit:
- 1-255 bytes => 1 Byte
- 256-65535 bytes => 2 Bytes
- 65536-16777215 bytes => 3 bytes
- 16777216-2^32-1 bytes => 4 bytes (not used anywhere)
... And so on.

So yes, 4x32 byte elements in vector with upper limit of 2^16-1 (or
2^16-32 rounded) is 130 bytes total: 2 byte length and 4*32=128 byte
value.

But I think that all lengths above 255 are either specified to be one
byte shy of power of 255 or rounding thereof to integral multiple of
elements (the only exception I offhand remember is session IDs in
TLS 1.0-1.2, which have maximum length of 32).

Then there are vectors with variable length elements. Those can be
created by putting in a vector or discriminant/case in the element
type (the latter can easily lead to interop problems later).


-Ilari