Re: [CFRG] RFC9180/HPKE erratum on recommended sizes

Ilari Liusvaara <ilariliusvaara@welho.com> Thu, 17 November 2022 20:36 UTC

Return-Path: <ilariliusvaara@welho.com>
X-Original-To: cfrg@ietfa.amsl.com
Delivered-To: cfrg@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 89038C14CEE2 for <cfrg@ietfa.amsl.com>; Thu, 17 Nov 2022 12:36:34 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -6.896
X-Spam-Level:
X-Spam-Status: No, score=-6.896 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wQDutHAj1XmX for <cfrg@ietfa.amsl.com>; Thu, 17 Nov 2022 12:36:30 -0800 (PST)
Received: from welho-filter4.welho.com (welho-filter4b.welho.com [83.102.41.30]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 7F711C14CEE9 for <Cfrg@irtf.org>; Thu, 17 Nov 2022 12:36:29 -0800 (PST)
Received: from localhost (localhost [127.0.0.1]) by welho-filter4.welho.com (Postfix) with ESMTP id B1CEF67B47 for <Cfrg@irtf.org>; Thu, 17 Nov 2022 22:36:26 +0200 (EET)
X-Virus-Scanned: Debian amavisd-new at pp.htv.fi
Received: from welho-smtp3.welho.com ([IPv6:::ffff:83.102.41.86]) by localhost (welho-filter4.welho.com [::ffff:83.102.41.26]) (amavisd-new, port 10024) with ESMTP id sMbEFmonKLrY for <Cfrg@irtf.org>; Thu, 17 Nov 2022 22:36:25 +0200 (EET)
Received: from LK-Perkele-VII2 (87-92-216-160.rev.dnainternet.fi [87.92.216.160]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by welho-smtp3.welho.com (Postfix) with ESMTPSA id 92C9A2315 for <Cfrg@irtf.org>; Thu, 17 Nov 2022 22:36:24 +0200 (EET)
Date: Thu, 17 Nov 2022 22:36:24 +0200
From: Ilari Liusvaara <ilariliusvaara@welho.com>
To: "cfrg@irtf.org" <Cfrg@irtf.org>
Message-ID: <Y3abSGvTHV7aRvul@LK-Perkele-VII2.locald>
References: <2268807e-e934-2061-608a-afd422934acb@cs.tcd.ie> <CAF8qwaCsHeTA6fmrZzLGnfk-NjXZ9qgYdw9KLHQ7OKfrfC5PdQ@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
In-Reply-To: <CAF8qwaCsHeTA6fmrZzLGnfk-NjXZ9qgYdw9KLHQ7OKfrfC5PdQ@mail.gmail.com>
Sender: ilariliusvaara@welho.com
Archived-At: <https://mailarchive.ietf.org/arch/msg/cfrg/unTkBWo3_mGYl04MR6L_rdq2nWg>
Subject: Re: [CFRG] RFC9180/HPKE erratum on recommended sizes
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: Crypto Forum Research Group <cfrg.irtf.org>
List-Unsubscribe: <https://www.irtf.org/mailman/options/cfrg>, <mailto:cfrg-request@irtf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cfrg/>
List-Post: <mailto:cfrg@irtf.org>
List-Help: <mailto:cfrg-request@irtf.org?subject=help>
List-Subscribe: <https://www.irtf.org/mailman/listinfo/cfrg>, <mailto:cfrg-request@irtf.org?subject=subscribe>
X-List-Received-Date: Thu, 17 Nov 2022 20:36:34 -0000

On Thu, Nov 17, 2022 at 10:04:33AM -0500, David Benjamin wrote:
> Our implementation doesn't impose any particular limits on info. But this
> maybe points to a larger issue here. The resolution of
> https://github.com/cfrg/draft-irtf-cfrg-hpke/issues/226 to recommend using
> info like an AEAD's aad parameter, which typically does not have tight
> limits. And, even independent of that advice, non-single-shot uses (like
> ECH) may well have non-trivial per-context additional authenticated data.
> For ECH in particular, should we ever stick PQ KEMs into ECH, the info
> field will become a lot larger.
> https://www.rfc-editor.org/rfc/rfc9180.html#section-8.1

For the implementation I have written, the only limit on info is
fitting into the memory space.


> Looks like the size issue comes from info being used as the IKM to
> LabeledExtract, which constructs a labeled_ikm by prepending a prefix.
> This means that, if your HKDF API requires contiguous IKMs, you need
> to make a copy of the info string.
> https://www.rfc-editor.org/rfc/rfc9180.html#section-5.1-9
> https://www.rfc-editor.org/rfc/rfc9180.html#section-4-9
> 
> I would not expect most HKDF-Extract APIs to support discontiguous
> IKMs, as that's kinda weird for keying material. Then again, if we
> break the abstraction, it's just the body of an HMAC, which typically
> can be streamed, much less discontiguous. So we do't *actually* need
> to make a copy here. But breaking the abstraction here is not ideal
> because HPKE aims to abstract over KDFs. So if we want to rely on
> that, we might need to make a note to tweak the definition for future
> KDFs so they don't need to rely on the HMAC internals.

The implementation I have written has internal abstraction for KDF that
can take suitable discontiguous IKM. It does not need to copy the IKM.
Currently the only implemented KDF is HKDF<H>.


And on new KDFs, one would probably want a KDF based on SHA-3, as most
PQC stuff (especially Kyber) internally uses SHA-3 (I first took a look
at NIST SP 800-56C rev 2 if it defines something suitable, but alas, it
does not).


One proposal:


Extract(ikm, salt):

- If no salt specified, default to empty octet string.
- Run KMAC256 with:
  + K = <salt>  
  + X = <ikm>
  + L = 512
  + S = "KDF-extract"
- Return the 64 octet result from KMAC256.


Expand(prk, info, L):

- Run KMAC256 with:
  + K = <prk>
  + X = <info>
  + L = 8*<L>
  + S = "KDF-expand"
- Return the octet string result from KMAC256.


Both steps behave very similarly to the corresponding steps of HKDF
The multiply by 8 in expand is due to expand taking length in octets,
but KMAC wanting length in bits.




-Ilari