[lamps] Re: [EXT] Re: [EXTERNAL] Re: Seed as private key for ML-DSA and ML-KEM

David Benjamin <davidben@chromium.org> Thu, 22 August 2024 23:30 UTC

Return-Path: <davidben@google.com>
X-Original-To: spasm@ietfa.amsl.com
Delivered-To: spasm@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 026CEC1519AA for <spasm@ietfa.amsl.com>; Thu, 22 Aug 2024 16:30:25 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -9.402
X-Spam-Level:
X-Spam-Status: No, score=-9.402 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HTML_FONT_LOW_CONTRAST=0.001, HTML_MESSAGE=0.001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001, USER_IN_DEF_SPF_WL=-7.5] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=chromium.org
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 470RkCUexbed for <spasm@ietfa.amsl.com>; Thu, 22 Aug 2024 16:30:21 -0700 (PDT)
Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id CB452C15155A for <spasm@ietf.org>; Thu, 22 Aug 2024 16:30:20 -0700 (PDT)
Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5bec4e00978so1566052a12.0 for <spasm@ietf.org>; Thu, 22 Aug 2024 16:30:20 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724369419; x=1724974219; darn=ietf.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=CsMB11hz7v2fvvJ2uzEe2p9xBxhgSGao7oCsqTVQ8Wk=; b=c806BIJaWAmUYXoBo+op1qpmKX73a4mDgEEzQkSFClK/O8QJkQRiLDjA78NW7ArNgD mJU2m/rNzMs9yiIuPPmFO57iAKzxSWNtrUVAC+XagsgmHfChyaNIbubDi4xEv5BpQ+Q3 /iWpnBJ4FdmsizxmenkXoNjLcrL7XtwWmeXsw=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724369419; x=1724974219; 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=CsMB11hz7v2fvvJ2uzEe2p9xBxhgSGao7oCsqTVQ8Wk=; b=pEq3CYhB2UnmEv50GeSyogki7VEwSDpu7QRzM47J47nnDxvTsilaYd/8RrgfqQiMOh fu1Olif669/ymkJFZ6+PGUctR7/BkYFMzw4cK9twu7MQGzD/TIOQ0GPH3pFFo5JOOXL5 ZOylR/6WOYofJ+uqTq/XvFl9c4pWZUZylqwiOO3asJhUUuWIUDQxBSIzQXSjP3UXPgcP T0kdxB3FIeSKG730/rcrToI8PhQCXjiFbizs0fPMWkDtyj9XQ+B6u45ePX4e+Wqn90R0 ROO7/Rj2HYV4ZFUwQ2kfjsvYn2WTewxa7QSILDul8RA9/e+gtmCyW/hUzaiBmbm0vBl0 e5aQ==
X-Forwarded-Encrypted: i=1; AJvYcCX+k+VBAT76/mAQYAPe3mXjnzVyBd/Om5jhuTnYwvPAm5qUBByeBbXgvfqXueZ7vrCwWKKHCw==@ietf.org
X-Gm-Message-State: AOJu0Yw75mjPFFdHRLVN2jan2kJvrzWBmqK4lRhLzS42jdah9CLRcJ+D yCudAZoElAw7kChI2bWgf2u7prNyeYO5sfHzTpHDm9m2CpOvSgFJJCKVSj9T6br35WVK4if2gIo cfq6Z8OUkS5Y+/ZfF4fYNeW6SCNdLMTStCkw=
X-Google-Smtp-Source: AGHT+IFsJySOAqo2gXDOUi4VjijyJilj5Y5kBH3fIQ3ukvEt8LncKtRt6tHz7kTiKUnflDWi81zSrLhiKk6JFPRQwgI=
X-Received: by 2002:a05:6402:1d49:b0:5bf:25c3:7cb9 with SMTP id 4fb4d7f45d1cf-5c089165f72mr120502a12.15.1724369418504; Thu, 22 Aug 2024 16:30:18 -0700 (PDT)
MIME-Version: 1.0
References: <CAMjbhoUOLfcRHT12ubSsPMEnDGT=UJUCvy34VX+qJYmyoFbscg@mail.gmail.com> <CAF8qwaCb8BJLqZQ__9+QsQ1+dWw426BwS4J+vQkUwfjWhdevnA@mail.gmail.com> <CH0PR11MB573952F98971721CF82D30B59F8F2@CH0PR11MB5739.namprd11.prod.outlook.com> <BN0P110MB1419EA3B96228DFA9727037D908FA@BN0P110MB1419.NAMP110.PROD.OUTLOOK.COM> <CH0PR11MB573976A9DD719F6EA6C94B3F9F8F2@CH0PR11MB5739.namprd11.prod.outlook.com>
In-Reply-To: <CH0PR11MB573976A9DD719F6EA6C94B3F9F8F2@CH0PR11MB5739.namprd11.prod.outlook.com>
From: David Benjamin <davidben@chromium.org>
Date: Thu, 22 Aug 2024 19:29:59 -0400
Message-ID: <CAF8qwaBqDkn2_OE1bKWF21hjyaG-T5yUxJqscqBtqNOh4jGLJQ@mail.gmail.com>
To: Mike Ounsworth <Mike.Ounsworth@entrust.com>
Content-Type: multipart/alternative; boundary="000000000000a7847a06204e0a9a"
Message-ID-Hash: AN2QCAAM56SSEOGS7ZMO7SRQYNPZAGK5
X-Message-ID-Hash: AN2QCAAM56SSEOGS7ZMO7SRQYNPZAGK5
X-MailFrom: davidben@google.com
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-spasm.ietf.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
CC: "Blumenthal, Uri - 0553 - MITLL" <uri@ll.mit.edu>, Bas Westerbaan <bas@cloudflare.com>, LAMPS <spasm@ietf.org>
X-Mailman-Version: 3.3.9rc4
Precedence: list
Subject: [lamps] Re: [EXT] Re: [EXTERNAL] Re: Seed as private key for ML-DSA and ML-KEM
List-Id: This is the mail list for the LAMPS Working Group <spasm.ietf.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/spasm/kCfhiMB1U9ncCKSqr4oMmod1HxU>
List-Archive: <https://mailarchive.ietf.org/arch/browse/spasm>
List-Help: <mailto:spasm-request@ietf.org?subject=help>
List-Owner: <mailto:spasm-owner@ietf.org>
List-Post: <mailto:spasm@ietf.org>
List-Subscribe: <mailto:spasm-join@ietf.org>
List-Unsubscribe: <mailto:spasm-leave@ietf.org>

ASN.1 structures are for defining interchange formats, not in-memory
representations. Indeed, I expect in-memory representation of one of these
keys will often include the expanded matrix, so that repeat operations
don't need to compute it twice. These are very different use cases and we
shouldn't conflate them.

In an in-memory representation, redundant information may be a useful time
vs space trade-off to avoid computing some intermediate value multiple
times.
In an interchange format, redundant information adds complexity because now
one needs to answer silly questions like "what happens if the seed and
(partially) expanded private key are inconsistent" and check them for
consistency.

Case in point, the ECPrivateKey ASN.1 structure includes the public key,
but is optional. This has been a mess. When the public key is missing, we
need to compute it because our APIs want to have both. When the public key
is present... we *still* need to compute it to avoid getting into a
self-inconsistent state, and then need to check it. It just adds complexity.

On Thu, Aug 22, 2024 at 4:35 PM Mike Ounsworth <Mike.Ounsworth@entrust.com>
wrote:

> The reason for storing both seed and private key is because that’s how you
> get yourself into the trouble where you import a key (seed), expand it,
> drop the seed, and can’t export it again. The reason for a SeedAndFull is
> to give a data structure that encourages implementers to hang on to the
> seed even if they are only using the full version. Transmitting both is
> only wasteful by ~ 32 bytes.
>
>
>
> ---
>
> *Mike* Ounsworth
>
>
>
> *From:* Blumenthal, Uri - 0553 - MITLL <uri@ll.mit.edu>
> *Sent:* Thursday, August 22, 2024 3:27 PM
> *To:* Mike Ounsworth <Mike.Ounsworth@entrust.com>; David Benjamin <
> davidben@chromium.org>; Bas Westerbaan <bas@cloudflare.com>
> *Cc:* LAMPS <spasm@ietf.org>
> *Subject:* Re: [EXT] [lamps] Re: [EXTERNAL] Re: Seed as private key for
> ML-DSA and ML-KEM
>
>
>
> IMHO, it does *not* make sense to send both seed *and* private key. I’m
> fully for sending/storing seed only, but don’t want to preclude “weird”
> (from y point of view) apps that insist on storing (or sending???) the
> private key itself.
>
>
>
> Thus, in your ASN.1 below, I’d kill option [2].
>
>
>
> TNX
>
> --
>
> V/R,
>
> Uri
>
>
>
>
>
> *From: *Mike Ounsworth <Mike.Ounsworth=40entrust.com@dmarc.ietf.org>
> *Date: *Thursday, August 22, 2024 at 16:24
> *To: *David Benjamin <davidben@chromium.org>, Bas Westerbaan <
> bas=40cloudflare.com@dmarc.ietf.org>
> *Cc: *LAMPS <spasm@ietf.org>
> *Subject: *[EXT] [lamps] Re: [EXTERNAL] Re: Seed as private key for
> ML-DSA and ML-KEM
>
> Observation: you can trivially go from seed -> full key, but not full key
> --> seed.  – at least I’m not seeing anything in FIPS 203 Algorithm 13 that
> the seed `d` is included in the decryption key `dk_pke`.
>
>
>
> As the guy whose company gets called in when people have broken their
> on-prem PKIs, if we only allow seeds in P12’s, then I foresee problems
> where an HSM company goes out of business and we need to get keys out of
> that hardware, and they chose to only store the expanded private key and so
> can’t give us the seed even if we ask nicely: now we can’t use standard
> private key transports and will have to kludge something. The point of a
> standard is to be standard – to say that you’re allowed to store the key
> expanded internally, but then you’ll be up a creek without a paddle if you
> want to export it, feels wrong.
>
>
>
>
>
> “2. Allow both seed and the expanded private key” ends up looking
> something like this:
>
> This would certainly not be the most complicated thing in RFC 5912.
>
>
>
> ML-*-PrivateKey ::= CHOICE {
>
>    seed               [0] SIZE 32 OCTET STRING,
>
>    full                  [1] OCTET STRING,
>
>    seedAndFull   [2] SeedAndFull
>
> }
>
>
>
> SeedAndFull ::= SEQUENCE {
>
>    seed   SIZE 32 OCTET STRING,
>
>    full      OCTET STRING
>
> }
>
>
>
> ---
>
> *Mike* Ounsworth
>
>
>
> *From:* David Benjamin <davidben@chromium.org>
> *Sent:* Wednesday, August 21, 2024 1:04 PM
> *To:* Bas Westerbaan <bas=40cloudflare.com@dmarc.ietf.org>
> *Cc:* LAMPS <spasm@ietf.org>
> *Subject:* [EXTERNAL] [lamps] Re: Seed as private key for ML-DSA and
> ML-KEM
>
>
>
> I'm also sold on option 4. On Wed, Aug 21, 2024, 11: 50 Bas Westerbaan
> <bas=40cloudflare. com@ dmarc. ietf. org> wrote: Hi all, NIST allows two
> formats in which private keys are stored ML-DSA and ML-KEM. 1. Seed. 32
> bytes for ML-DSA; 64
>
> I'm also sold on option 4.
>
> On Wed, Aug 21, 2024, 11:50 Bas Westerbaan <bas=
> 40cloudflare.com@dmarc.ietf.org> wrote:
>
> Hi all,
>
>
>
> NIST allows two formats in which private keys are stored ML-DSA and ML-KEM.
>
>
>
> 1. Seed. 32 bytes for ML-DSA; 64 bytes for ML-KEM.
>
> 2. Expanded private key. Multiple kilobytes depending on instance.
>
>
>
> An expanded private key is obtained from the seed by calling the
> KeyGen_internal function.
>
>
>
> In contrast to RSA, key generation for these algorithms is very fast. In
> fact, if you use spinning disks, then using a seed is probably faster than
> the expanded private key.
>
>
>
> Another advantage is that we do not need to worry about private key
> validation. NIST specified a few checks to perform, but there are more we
> could do (eg. whether the decoded coefficients of \hat{s} are bounded.)
>
>
>
> Of course a big advantage is storage space: the seeds are much smaller.
>
>
>
> Now, how do we want to proceed? I see a few options.
>
>
>
> 1. Ignore the seed as private key.
>
>
>
> 2. Allow both seed and the expanded private key.
>
>
>
> 3. Assign separate algorithm for seed-as-private-key.
>
>
>
> 4. Switch to seed as private key only.
>
>
>
> I prefer 4, and would otherwise go for 1.
>
>
>
> The downside of 2 is that it adds complexity without the gain of
> simplifying verification. If one only cares about size savings, then one
> can use seed-as-private-key without needing a portable format for it.
>
>
>
> So I'd prefer 4 and 1 second.
>
>
>
> Best,
>
>
>
>  Bas
>
> _______________________________________________
> Spasm mailing list -- spasm@ietf.org
> To unsubscribe send an email to spasm-leave@ietf.org
>
>