Re: [COSE] draft-ietf-cose-hpke-00 and proposed changes for -01

Ilari Liusvaara <ilariliusvaara@welho.com> Mon, 17 January 2022 16:38 UTC

Return-Path: <ilariliusvaara@welho.com>
X-Original-To: cose@ietfa.amsl.com
Delivered-To: cose@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 2D4C33A13AB for <cose@ietfa.amsl.com>; Mon, 17 Jan 2022 08:38:10 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.897
X-Spam-Level:
X-Spam-Status: No, score=-1.897 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
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 d1hfUdv0nhEs for <cose@ietfa.amsl.com>; Mon, 17 Jan 2022 08:38:05 -0800 (PST)
Received: from welho-filter2.welho.com (welho-filter2b.welho.com [83.102.41.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id A31B83A13A5 for <cose@ietf.org>; Mon, 17 Jan 2022 08:37:33 -0800 (PST)
Received: from localhost (localhost [127.0.0.1]) by welho-filter2.welho.com (Postfix) with ESMTP id 90A74D0085; Mon, 17 Jan 2022 18:37:29 +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-filter2.welho.com [::ffff:83.102.41.24]) (amavisd-new, port 10024) with ESMTP id 1DNUEYGIVOC4; Mon, 17 Jan 2022 18:37:28 +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 20E6E2315; Mon, 17 Jan 2022 18:37:25 +0200 (EET)
Date: Mon, 17 Jan 2022 18:37:25 +0200
From: Ilari Liusvaara <ilariliusvaara@welho.com>
To: Hannes Tschofenig <Hannes.Tschofenig@arm.com>
Cc: "cose@ietf.org" <cose@ietf.org>
Message-ID: <YeWbRYe13Mk+IV+2@LK-Perkele-VII2.locald>
References: <DBBPR08MB5915C899B9EF8122898057BDFA579@DBBPR08MB5915.eurprd08.prod.outlook.com> <YeVQooQEGzfjFeE9@LK-Perkele-VII2.locald> <DBBPR08MB5915C7AFF11B55A8AA8CBBEEFA579@DBBPR08MB5915.eurprd08.prod.outlook.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
In-Reply-To: <DBBPR08MB5915C7AFF11B55A8AA8CBBEEFA579@DBBPR08MB5915.eurprd08.prod.outlook.com>
Sender: ilariliusvaara@welho.com
Archived-At: <https://mailarchive.ietf.org/arch/msg/cose/ZE0ViMuyTkcxmfx2anBgfhs_QcA>
Subject: Re: [COSE] draft-ietf-cose-hpke-00 and proposed changes for -01
X-BeenThere: cose@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: CBOR Object Signing and Encryption <cose.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cose>, <mailto:cose-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cose/>
List-Post: <mailto:cose@ietf.org>
List-Help: <mailto:cose-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cose>, <mailto:cose-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 17 Jan 2022 16:38:10 -0000

On Mon, Jan 17, 2022 at 02:51:13PM +0000, Hannes Tschofenig wrote:
> Thanks for the detailed comments, Ilari.
> 
> Let me provide comments below:
> 
> -----Original Message-----
> From: ilariliusvaara@welho.com <ilariliusvaara@welho.com>
> Sent: Monday, January 17, 2022 12:19 PM
> To: Hannes Tschofenig <Hannes.Tschofenig@arm.com>
> Cc: cose@ietf.org
> Subject: Re: [COSE] draft-ietf-cose-hpke-00 and proposed changes for -01
> 
> On Mon, Jan 17, 2022 at 09:36:34AM +0000, Hannes Tschofenig wrote:
> >
> > with draft-ietf-cose-hpke-00 I have submitted the draft version that
> > was subject to the working group call for adoption. John and Goeran
> > provided feedback already and suggested to re-use the algorithm
> > registry created by HPKE.
> >
> > In https://github.com/cose-wg/HPKE/blob/main/draft-ietf-cose-hpke.txt
> > the proposed -01 version can be found.
> >
> > Please have a look at it and let me know if the proposed changes are
> > inline with the suggestions.
> 
> In can make little sense of the way HPKE is used.
> 
> - Why are the symmetric and asymmetric parts of HPKE split into two
>   different layers? The whole point of HPKE singleshot mode is to
>   combine them.
> 
> [Hannes] We are adding another layer to allow for additional use cases.
> The use case is to encrypt a payload once for different recipients.

With HPKE, one could do that with two-layer structure (and even mix it
with other modes):

- Layer 0: Message
  - Layer 1: HPKE (CEK for recipient1)
  - Layer 1: HPKE (CEK for recipient2)
  - Layer 1: AES-KW (CEK)
    - Layer 2: ECDH-ES (KEK for recipient3)
  - Layer 1: AES-KW (CEK for recipient4)

That encrypts the message only once, for four recipients:

- recipient1 and recipient2 use HPKE (asymmetric).
- recipient3 uses ECDH-ES (asymmetric)
- recipient4 uses AES (symmetric).

> - The layer 1 algorithm is specified as COSE encryption algorithm,
>   but for actually performing the encryption/decryption, one needs
>   HPKE AEAD ID.
> 
> [Hannes] Layer 2 uses the KEM algorithms from Section 7.1 of the HPKE spec:
> https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hpke-12#section-7.1
> 
> Layer 1 uses the COSE algorithms instead of the algorithms in Section 7.3 of the HPKE spec
> https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hpke-12#section-7.3
> 
> 
>   * How is the mapping between the two done?
>   * If new AEAD is added to HPKE, does one also have to register COSE
>     algorithm for it?
> 
>   Embedding the registry would mean 5 byte algorithm identifiers, as
>   there is just not enough space with smaller ones (need continuous
>   block of 65534 (sic) algorithm ids).
> 
> 
> [Hannes] It is possible to re-use the AEAD ID values from the HPKE
> spec instead of the corresponding COSE algorithms. However, there is
> not much of variation between the AEAD algorithms in COSE vs. the HPKE
> spec.
 
However, using COSE algorithms requires implemntation to translate those
into HPKE algorithms. This is because key derivation depends on HPKE
algorithm ID.

> - Recipients at layer 1 are specified as one-or-more. AFAICT, more than
>   one recipient here makes absolutely no sense.
> 
> [Hannes] It makes sense if you consider the use of firmware encryption.
> There, you want to have one CEK to encrypt the firmware image but multiple
> recipients.

It seems that Layer1 is ciphertext and Layer2 is encapsulated key.

So using multiple recipients at this layer would seem to correspond with
trying to use multiple encapsulated keys with the same ciphertext. At
best this produces decryption errors. At worst, it produces corrupt
plaintext.

(HPKE does have multishot mode where the same encapsulated key is used
with multiple ciphertexts.)
 
> - The algorithm ID at layer 2 needs new registrations to take advantage
>   of new HPKE algorithms. This especially inclures KEMs, which are one
>   of the most important extension points (post-quantum!).
> 
> [Hannes] By re-using the HPKE registry the idea was to re-use new KEMs
> as they come along.

Oh, the algorithm ID is HPKE KEM id. However, there is KDF id too.

For the present KEM algorithms, one could just match the KDF
(16 => 1, 17 => 2, 18 => 3, 32 => 1, 33 => 3), but this might not work
with future KEMs.

E.g., suppose Kyber v3.02 (one of the NISTPQC finalists) was added. 
What KDF does it use? None of the KDFs HPKE has (HKDF with SHA-2) are
in any way related to KDF Kyber internally uses (SHAKE256, which is
related to SHA-3).

> - Decomposing the keys at layer 2 needs code changes to support new
>   KEMs. Which likely can not be nontrivially decomposed anyway.
> 
>   However, currently HPKE does not have compact NIST curves, which
>   allows space saving via decomposition.
> 
>   Compromise might be to embed the registries (both may be jointly
>   embededed into 5 byte algorithm identifier) and have special values
>   for decomposed stuff (and shorthands for X25519/X448).[1]
> 
>   If both KEM and KDF can be sepcified, the KDFs SHOULD be matched.
> 
> [Hannes] There is obviously a downside to the re-use of the HPKE
> registry, as you point out. Splitting the registry into two appears
> quite complex to me. Adding new KEMs will, of course, require code
> changes. We should indeed think carefully whether this registry re-use
> offers enough benefits to do it.

Well, yes, there are tradeoffs:

- Special processing like compressing keys requires special-casing
  codepoints.
- Reusing the registry means COSE does not have to deal with
  registration requests. :-)

(Add compact NIST curves to HPKE, and then one does not have to deal
with key compression anymore.)

And then HPKE support might be shipped as library, which can change
indepedently of main application, in order to add new algorithms.

> - HPKE is different enough that I think both new kty and a new
>   operational mode are justified (I can make very little sense of
>   existing operational modes).
> 
> [Hannes] We are currently only using the base mode from the HPKE
> spec and utilize the COSE capabilities for authentication. The
> kty is used to describe the encapsulated key and there is no
> difference in the keys.

Actually, I got an idea that one could use OKP for raw HPKE
encapsulated keys, and other types for compressed encapsulated
keys (one probably only ever wants to compress P-256/P-384/P-521
encapsulated keys). And this would be independent of HPKE KEM
used.

One problem with that is the OKP crv parameter makes absolutely no
sense in such context. And it would not be quite as compact as
C509-style compression with special-case algorithm identifiers.

> - Doing HPKE with two layers with cose_encrypt, easily extends to
>   doing HPKE in cose_encrypt0: The only difference is directly operating
>   on the plaintext instead operating on the CEK. The limitation is
>   only having one recipient.
> 
> [Hannes] If the group wants a variant of COSE-HPKE that supports
> hybrid public key encryption for a single recipient only then I will,
> of course, do it. However, it is not clear to me whether this few
> additional bytes justify the extra variant. More variants = more
> complexity.

Well, OTOH it seems to be pretty trivial to do. And yes, it is
very few bytes saved, rough guess would be a dozen or so.


-Ilari