Re: [jose] [COSE] COSE and JOSE Keys for Kyber

Orie Steele <orie@transmute.industries> Mon, 14 November 2022 15:21 UTC

Return-Path: <orie@transmute.industries>
X-Original-To: jose@ietfa.amsl.com
Delivered-To: jose@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 7C2A2C1526FF for <jose@ietfa.amsl.com>; Mon, 14 Nov 2022 07:21:49 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7.095
X-Spam-Level:
X-Spam-Status: No, score=-7.095 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, 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=unavailable autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=transmute.industries
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 bu_0esVaXlvA for <jose@ietfa.amsl.com>; Mon, 14 Nov 2022 07:21:45 -0800 (PST)
Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 90BDEC1526FC for <jose@ietf.org>; Mon, 14 Nov 2022 07:21:43 -0800 (PST)
Received: by mail-ed1-x52d.google.com with SMTP id a5so17781489edb.11 for <jose@ietf.org>; Mon, 14 Nov 2022 07:21:43 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=transmute.industries; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=zZhBT/0gIF1ZYDmQXGm35QwZ6H79Bf23jO5pRt7rzpU=; b=ctv05th/a7KvHu7jsuJx5CVGL4pOfEsUpSJe+8B2kFdV/N/r44AR3LYTVGRU99D1zm LFXBRHjGLUXn3l5pTEdpxeyWauA1VjU+tynkpglpSjqi+na69LcJeEdR/vK0sWpTiBvn IYt/gtOtFUDdZ/hcbGht8ot0X0yUySTbu+kTgFA0xZjk+/jXnukSG9o2c1MMDM4X05LY OAQmKyTGysKGwkAvKqNQAjeyP9kod/sO14x6at2ygzYF5nB6vcWdsDosY3kjxGA47KfG opun1T+YdzBcVsNCm1sEszqAv/0kuXdeTzyLY8HEmTfedtVgj8jXGV6sQzEai0LHgPej EbJw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zZhBT/0gIF1ZYDmQXGm35QwZ6H79Bf23jO5pRt7rzpU=; b=Z0OWMESe4vmSVa3ftkZngQydm7LjMtt6xQWsxOE/jLHmvSEyY7OfBxQhHSannG2p5V rZZNxgfBATdXaOJO2sXxUIPZ0Rq4JT2sBuYCRU3caEqJlx5SCv4mxh0/8mry+PakKIIW Mv02QsfPWTZW0Dr/o1N85YrYiYY6k9zzTcGQU7Kjtaj3BvZAK7cXlIJOPjWM6UrLApiA x76I+bygKS+/odzTqeD/dxXRdN/9b5+5hJ6PViIZ3xf6wi+DMQCTrOwlmbsqivIzuhlc SBqNWvU2QMZO7Ln+ZJShJMFjfKBHm6VvWs7sT1XadeISJSIILv2BqZKbeAnvkf7p9liy G9dA==
X-Gm-Message-State: ANoB5pmAmwrY+z2kEOJPeWVHN9Z3B2ob/LA4gVegXAk119KhBXPhC19Z sLkyikVfvnouKzxMvZ6CQTA0lgl8+45FGTSihnuueB/svE1CIg==
X-Google-Smtp-Source: AA0mqf5uMQzP/d08gRKC61k4E8Z/XUEPuOXEtkvLMTzmRS2P6BhCUc4LCfPlCjyclXGuTTwActQ75KZfjhkPUpQX3Jw=
X-Received: by 2002:a50:fd15:0:b0:458:fc30:f1ff with SMTP id i21-20020a50fd15000000b00458fc30f1ffmr11389205eds.132.1668439299808; Mon, 14 Nov 2022 07:21:39 -0800 (PST)
MIME-Version: 1.0
References: <CAN8C-_LVgq0j5YtFrrO-fWNNXvGSWohQ0874DV5qgfYT4FXT0Q@mail.gmail.com> <Y3IquzJcwMXpwqF0@LK-Perkele-VII2.locald>
In-Reply-To: <Y3IquzJcwMXpwqF0@LK-Perkele-VII2.locald>
From: Orie Steele <orie@transmute.industries>
Date: Mon, 14 Nov 2022 09:21:28 -0600
Message-ID: <CAN8C-_JdGMVMTt16DpDXCqMbmVmqSRAMaHb57X2j092=PAn1Jg@mail.gmail.com>
To: Ilari Liusvaara <ilariliusvaara@welho.com>, Cose Chairs Wg <cose-chairs@ietf.org>
Cc: cose <cose@ietf.org>, JOSE WG <jose@ietf.org>
Content-Type: multipart/related; boundary="000000000000cc503605ed6fcb35"
Archived-At: <https://mailarchive.ietf.org/arch/msg/jose/qui6HuPFYSJe_obwMH7UjPtKauA>
Subject: Re: [jose] [COSE] COSE and JOSE Keys for Kyber
X-BeenThere: jose@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: Javascript Object Signing and Encryption <jose.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/jose>, <mailto:jose-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/jose/>
List-Post: <mailto:jose@ietf.org>
List-Help: <mailto:jose-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/jose>, <mailto:jose-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 14 Nov 2022 15:21:49 -0000

Thanks! Responses inline:

On Mon, Nov 14, 2022 at 5:47 AM Ilari Liusvaara <ilariliusvaara@welho.com>
wrote:

> On Sun, Nov 13, 2022 at 03:00:06PM -0600, Orie Steele wrote:
> >
> > Mike O. and I have been discussing the need to represent Kyber keys in
> > JOSE and COSE, especially as we prepare to consider their use with
> > HPKE.
>
> You do not need this for HPKE. Use the generic HPKE key representation
> instead.
>
>
Consider: https://github.com/dajiaji/hpke-js#base-mode

Especially this part:

const recipient = await suite.createRecipientContext({
  recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also
acceptable.... here we might expect a COSE Key or JWK for Kyber.
  enc: sender.enc, // this is opaque.
});



> And being CFRG product, I doubt initial version will have pure Kyber
> (instead being hybridized). And after Kyber is standardized, there might
> be Kyber1024 (being part of CNSA 2.0) but no others.
>
> > Mike P. and I have previously shared a draft for presenting Dilithium,
> > Falcon and Sphincs -
> >
> https://datatracker.ietf.org/doc/draft-ietf-cose-post-quantum-signatures/
>
> The kty assignments in that draft actually are problematic here, as both
> Dilithium and Kyber are based on (M)LWE, but the keys are very much
> incompatible.
>
>
P-256 and P-384 are both kty:EC and not compatible...
Ed25519 and Bls12381 are both kty: OKP and not compatible... What is your
point?


> > I reviewed the original registries established in:
> > https://www.rfc-editor.org/rfc/rfc7518.html#section-7
> >
> > I also reviewed the latest "kty" and "alg" registered in
> > https://datatracker.ietf.org/doc/html/rfc8778
> >
> > I'm going to stick to JOSE(ish) notation here, my goal is to get a
> > clear answer on
> > *"which values for `kty` and `alg` are relevant to kyber".*
> > See the latest editor's draft for additional details:
> > https://github.com/OR13/draft-steele-cose-kyber.
>
> Like with ECDH (but unlike with modern signatures), there can be
> multiple applicable alg's, so one can not subtype keys by using
> alg.
>
> There already is kty with the correct properties (OKP).
>

[image: Screen Shot 2022-11-14 at 8.24.25 AM.png]
https://www.rfc-editor.org/rfc/rfc8037#section-2

It seems like some people are interpreting the crv related MUST as being
bound to Ed25519 and others are interpreting it as being bound to kty: OKP

@Cose Chairs Wg <cose-chairs@ietf.org> Can you help establish consensus
regarding intention here? Which reading is intended by the working group?


The relevant algs are modeled after ECDH(-ES) ones. However, one can
> not use ECDH-ES ones, because ECDH-ES uses JWK/COSE_Key for the
> ephemeral value, which does not work with Kyber.
>
> And since Kyber internally uses SHA-3, one presumably wants the KDF
> to be based on SHA-3 too. However, neither concat-KDF (JOSE) nor HKDF
> (COSE) work with SHA-3 all too well.
>
> NIST SP 800-56Cr2 almost has a decent KDF based on SHA-3. Almost,
> because of two issues:
>
> - The space reserved for key block headers in default salt is one
>   byte too short. It reserves 4 bytes, but block headers are 5
>   bytes.
> - It does not outright say to set H_outputbits = L. Not only this
>   would make it faster, it would also make it easier to implement.
>
>
> Here is description of a bit tweaked NIST SP 800-56Cr2 KDF (from
> what I can tell, this is actually compliant with 800-56):
>
>
> - Assert desired output length L is positive.
>   (the upper limit it too big to care about.)
> - If not specified otherwise, salt is empty string.
> - Compute KMAC128 or KMAC256 (depending on security level), with:
>   + S being ASCII string "KDF".
>   + K being the salt
>   + X being concatenation of:
>     * 32-bit big-endian 1 (i.e., 0x00 0x00 0x00 0x01)
>     * The input key.
>     * Information structure.
>   + L being the desired output length in bits.
> - The KDF output is the KMAC output.
>
>
> KMAC128 is slightly more performant than KMAC256. However, the
> difference is so slight that it is probably good idea to always use
> KMAC256.
>
> The checks in steps 2 and 4 of 800-56 can never fail.
>
>
>
This is almost a suggestion for an `alg` value that would work with kyber.

Something like:

Kem-Kyber-1024+A256KW

This is the main question I am hoping to answer for Kyber, since kty, as
better grounding in existing registry entries,


>
> > First, let's start with what we have today:
> >
> > - https://www.iana.org/assignments/cose/cose.xhtml
> > - https://www.iana.org/assignments/jose/jose.xhtml
> >
> > { kty: RSA, alg: PS384 / RSAES-OAEP w/ SHA-256}
> > { kty: RSA, alg: RS384 / RSAES-OAEP w/ SHA-256}
> > { kty: EC2, crv: P-256, alg: ES256 / ECDH-ES+A256KW }
> > { kty: OKP, crv: Ed25519, alg: EdDSA } -
> > https://www.rfc-editor.org/rfc/rfc8037#section-2
> > { kty: OKP, crv: Bls12381G1, alg: ??? } ...
> >
> https://datatracker.ietf.org/doc/html/draft-ietf-cose-bls-key-representations-01#section-2.1.3
> > { kty: HSS-LMS, alg: HSS-LMS }
> > { kty: WalnutDSA, alg: WalnutDSA }
> >
> > Observations:
> >
> > 1. Although `alg` is optional... It looks especially needed in some
> > cases (RSA), and especially not needed in others (HSS-LMS, WalnutDSA)
>
> Sometimes there is only one sensible algorithm for given key (e.g.,
> Ed25519 keys) sometimes there are multiple (e.g., RSA).
>
>
This observation is correct, but still at the time of key generation, the
party generating the key should declare its purpose,
otherwise I might use a key for a million signatures and then suddenly
start using it for encryption...
that's the kind of security issue we are welcoming when we make `alg`
optional in a key representation...
It is also a reflection of the uneasy feeling we get when we see a new key
defined with no supported algs.


>
> > 2. We appear to have slowly started to encode "Purpose" in the key
> > type (HSS-LMS / WalnutDSA) , which suggests that we are commiting to
> > keeping `alg` optional forever, and also acknowledging that it is best
> > to use a key for a single purpose.
>
> These are kinds of keys where only signing makes sense, and the
> keyshapes are different from anything else (first is stateful,
> the second has decomposed parameters).
>
>
I agree about the stateful part, perhaps that allows us to ignore the
precedent set by putting the word "stateful signature" in a `kty` value?

Should the word "kem" be in all kem enabled kty?


>
> > 3. It is possible to define a key and NOT define any algorithms for it...
> > (see bls-key draft above).
>
> Seems to limit the usefulness, however...
>
>
I agree, but since the signature candidates are still in CFRG, it seems
nice they can move the key formats along independently...
... alg is optional after all ...


>
> > 4. OKP is reserved for Elliptic Curves only.
>
> This is incorrect. Both RFC 8037 (JOSE) and RFC 9053 (COSE) explicitly
> say otherwise.
>
>
[image: Screen Shot 2022-11-14 at 8.24.25 AM.png]

https://www.rfc-editor.org/rfc/rfc8037#section-2
<https://www.rfc-editor.org/rfc/rfc8037#section-2>

[image: Screen Shot 2022-11-14 at 8.36.02 AM.png]

https://www.rfc-editor.org/rfc/rfc9053.html#section-2.2

How is a reader supposed to interpret these sections together?

Where does it say you can use kty:OKP for lattices, hashes, curves and
whatever comes next ?

I agree that OKP should not be bound to curves, I disagree (strongly) that
there is consensus or clarity on this matter.

If the working group / list is saying that it is valid to represent non
elliptic curves with OKP, that is a revelation I would like to see
formalized.

@Cose Chairs Wg <cose-chairs@ietf.org> Is there a way to resolve this
ambiguity for future readers?


> > 5. IANA Registries exist for Elliptic Curves but no other "families"
> > such as lattices, stateful hash based schemes, or stateless hash based
> > schemes... based on HSS-LMS not attempting to fix this, it seems we
> > are ok not establishing new IANA registries for lattice or hash types.
>
> Lattices and hashes are very complicated things, far exceeding what IANA
> registry is useful for.
>
>
I take this as a request NOT to establish an IANA registry for lattices or
hash based systems, that would mirror the registries for curves.

Is there consensus on the lists that we should not ask IANA to maintain
registries for lattices?


> > 6. Walnut encodes parameters as separate values in the key type, but not
> > the algorithm name... similar to RSA... which seems like a step backwards
> > to me.
>
> What if the two do not agree?
>
>
Exactly.

It would be better to keep your parameters embedded in the `alg`, similar
to how "ECDH-ES+A256KW" implies "Concat KDF".

Imagine seeing something like this:

kty: EC
crv: P-256
alg: ES256 // alg for signing
kdf: "Concat-KDF" // parameter for key agreement

I'm not sure if this kind of parameter issue will exist for 1 or more PQC
algorithms, and I would like to avoid accidentally creating unsafe
registries.


>
> > Here is a proposal for Kyber keys that aligns with the previous proposals
> > and drafts for post quantum signatures:
> >
> > { kty: LWE, alg: CRYDI5 }
> > { kty: LWE, alg: CRYDI3 }
> > { kty: LWE, alg: CRYDI2 }
> >
> > { kty: NTRU, alg: FALCON1024 }
> > { kty: NTRU, alg: FALCON512 }
> >
> > { kty: HASH, alg: SPHINCS+-SHAKE-256s-robust }
> >
> > { kty: LWE, alg: Kyber-1024 }
> > { kty: LWE, alg: Kyber-768 }
> > { kty: LWE, alg: Kyber-512 }
> >
> > Please focus your comments on establishing consensus for relevant values
> > for `kty` and `alg`.
>
> This will not work.
>
> Kyber can not be subtyped on alg, because it also requires KDF (like
> ECDH). And this impiles it can not have the same kty as Dilitihium,
> which subtypes on alg.
>
>
Why do you say this? ECDH-ES+A256KW implies "Concat KDF"... You can't
do "ECDH-ES+A256KW"
from P-256 to P-384 either.... but both have the same kty: EC.

We are talking about "key formats here...." we are not talking about JWS /
JWE Header parameters.

Are you suggesting that when a kyber key is created it's allowed to be used
with any `alg` forever, based only on the header parameters of a ciphertext?

Is it a good idea for kyber keys to distribute 1 billion decryptions
uniformly across all registered kdf in HPKE, based only on the header
parameters of a ciphertext?

Is it better to announce the kdf that is supported by kyber at the time the
key is generated, similar to what is done for ECDH-ES+A256KW over P-256
today?


> Seriously, "LWE", "NTRU" and "HASH" are not "families of algorithms",
> those are underlying problems. The families in this care are Dilithium,
> Falcon, Sphincs+ and Kyber themselves.
>
>
I am going to infer this counter-proposal from what you have said:

{ kty: Dilithium, alg: CRYDI5 }
{ kty: Dilithium, alg: CRYDI3 }
{ kty: Dilithium, alg: CRYDI2 }

{ kty: Falcon, alg: FALCON1024 }
{ kty: Falcon, alg: FALCON512 }

{ kty: SPHINCS, alg: SPHINCS+-SHAKE-256s-robust }

{ kty: Kyber, alg: Kem-Kyber-1024+A256KW }
{ kty: Kyber, alg: Kem-Kyber-768+A256KW }
{ kty: Kyber, alg: Kem-Kyber-512+A256KW }

Does this counter proposal capture the `alg` and `kty` values that you
believe are relevant to Kyber key representations?

@Ilari Liusvaara <ilariliusvaara@welho.com> Thank you for your comments!


>
> -Ilari
>
> _______________________________________________
> COSE mailing list
> COSE@ietf.org
> https://www.ietf.org/mailman/listinfo/cose
>


-- 
*ORIE STEELE*
Chief Technical Officer
www.transmute.industries

<https://www.transmute.industries>