[openpgp] Re: pure vs. pre-hash in FIPS 204 and 205

Daniel Huigens <d.huigens@protonmail.com> Fri, 30 August 2024 07:19 UTC

Return-Path: <d.huigens@protonmail.com>
X-Original-To: openpgp@ietfa.amsl.com
Delivered-To: openpgp@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id B0583C14F682 for <openpgp@ietfa.amsl.com>; Fri, 30 Aug 2024 00:19:06 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.105
X-Spam-Level:
X-Spam-Status: No, score=-2.105 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, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=protonmail.com
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 fRD6t90Bh6w8 for <openpgp@ietfa.amsl.com>; Fri, 30 Aug 2024 00:19:02 -0700 (PDT)
Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 75577C14F600 for <openpgp@ietf.org>; Fri, 30 Aug 2024 00:19:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1725002339; x=1725261539; bh=CPovdJV2fzdZWgz+UWhHnPy8JRz9f36eFGmU6pq+KqM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=iAbVRKPtZ+xJd+ne2j3zF8+CXSjRRTk2bhKQzb3m/v6GCFp5TYZ0TnJVHOvnUFpRz igv2kB+PEFbnp7gXwGmr68d8HH9oW2BUj1+UZ9qtp9nxIWLoyYQCparS8BxlMvjnCE L687iO525IbZCgQUNwEfO7ZGNIo2+DJ99ENRRcnfBYRSeyKavA8HDaq8UEpLNntKzC GlWcMs1mBhfcViG7VtHPlshDJtxtm2PNr98zzW94GtNYx8651n3pY5tbhcsgl+0kfN qs4k99azODkd8cBj/g6ZrpGv3OdfUrIvOFJgKblABP2tUc0rXjJRlLNzr21GydM2vh bkw6asA/RE5Gg==
Date: Fri, 30 Aug 2024 07:18:54 +0000
To: Simo Sorce <simo@redhat.com>
From: Daniel Huigens <d.huigens@protonmail.com>
Message-ID: <4e9oBXl8Mu7-Fcj3fn0UssCr_qyeZFhmgvf9CzVEw4-ueyG5h678x4P3x04DrTznZQs88Mcqp5mzPIoumsdAQb7gqJc6SdsZuCWLU__ugdI=@protonmail.com>
In-Reply-To: <b329a33a05f8dca61571ea049357c421c48f6927.camel@redhat.com>
References: <gp_qhnxiYq_pgzpw26Gw5lC53i2aOD1tik9Lrprf0yhURin012f3YvwxS-8mGXOX7ObRAiMqjBkyyxiC8vkwuMMg0Kng4dSOI4Edwww0v4I=@proton.me> <C248DA16-5642-4141-8561-108F157A0D97@andrewg.com> <nLeggcwwubArYMbVyxeaaGb3-QcrtILJob0uhfTjhbXRnCUQWJv0sjwhDuXvc705DhqW2XNEJHqagEFow2v0i5L1cRAv2ixFvqDIDp3lFiQ=@protonmail.com> <55c42efdaea1bd661f5d3607706a6d4d388cea61.camel@redhat.com> <fU3_9MgtQjRnA48uQszLXegERJDcKOLGHUssln9CZfamMwBNpbD6Wj5zVpCl_DrfaTqkuJpDGsI4-13uRDyBDZuHNMtcsD5wP376GsxSWSU=@protonmail.com> <b329a33a05f8dca61571ea049357c421c48f6927.camel@redhat.com>
Feedback-ID: 2934448:user:proton
X-Pm-Message-ID: 4d9abf48a0e25da356fbb9f3ea901d137157b439
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Message-ID-Hash: B3MYFHKTLOH2XLX2XYUI6SI2IPETLYFN
X-Message-ID-Hash: B3MYFHKTLOH2XLX2XYUI6SI2IPETLYFN
X-MailFrom: d.huigens@protonmail.com
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-openpgp.ietf.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
CC: Andrew Gallagher <andrewg@andrewg.com>, Akhil CM <akhilacm@proton.me>, "openpgp@ietf.org" <openpgp@ietf.org>
X-Mailman-Version: 3.3.9rc4
Precedence: list
Subject: [openpgp] Re: pure vs. pre-hash in FIPS 204 and 205
List-Id: "Ongoing discussion of OpenPGP issues." <openpgp.ietf.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/openpgp/INtKItJBQPnzQPucELi-k96hQf0>
List-Archive: <https://mailarchive.ietf.org/arch/browse/openpgp>
List-Help: <mailto:openpgp-request@ietf.org?subject=help>
List-Owner: <mailto:openpgp-owner@ietf.org>
List-Post: <mailto:openpgp@ietf.org>
List-Subscribe: <mailto:openpgp-join@ietf.org>
List-Unsubscribe: <mailto:openpgp-leave@ietf.org>

Hi Simo,

You're making an argument that goes roughly as follows:

- I don't understand the purpose of HashML-DSA as described in FIPS 204
- Therefore I assume the purpose must be something else, and interpret
  the text of FIPS 204 differently to fit that assumption
- The purpose I assume is the one that would be relevant for OpenPGP
- Therefore we should use HashML-DSA for OpenPGP

IMHO, this is faulty reasoning. If you don't understand the purpose
of HashML-DSA, that's fine. I don't see it as my job to justify the
existence of HashML-DSA for something other than being used in OpenPGP.
For all I care it might be completely useless and nobody implements it,
like what happened with the pre-hash variants of EdDSA.

In any case I prefer to take the text in FIPS 204 at face value, and
the straightforward reading of the text says that we shouldn't use it.


> The explanation in 5.4, the whole point of providing a pre-hash ML-DSA
> version is to allow application to doh!) "pre" Hash the message.

That's not what it says. It says: "Like ML-DSA, the signing algorithm of
HashML-DSA takes the content to be signed, the private key, and a
context as input, as well as a hash function or XOF that is to be used
to pre-hash the content to be signed."
So it's the HashML-DSA function itself that pre-hashes the content.

> What would be the point of doing that, and then re-hashing the whole
> thing a second time ? (and then a third time internally).

Indeed you wouldn't. That's why it says "If the content is *not* hashed
at the application level, the pre-hash version of ML-DSA signing may be
used." (emphasis mine)

> If you are still unconvinced look at the text at the bottom of Page 20
> which says explicitly: "As with the pre-hash signature generation, 𝑀 ′
> may be constructed outside of the cryptographic module that performs
> ML-DSA.Verify_internal."

The text after your quote continues "However, in the case of HashML-DSA,
the hash or XOF of the content must be computed within a FIPS 140-
validated cryptographic module, which may be a different cryptographic
module than the one that performs ML-DSA.Verify_internal."

Like I said, you might have a "core cryptographic module" that's on an
HSM, and a different cryptographic module that computes the hash.

> for the non-FIPS language versed "Outside the cryptographic module" ==
> "The application"

So no, in this case they mean "in a different cryptographic module".

> I know that OpenPGP does not do that, but NIST puts down general rules
> to follow that cover all cases. That is the spirit of the
> specification, and yes if you "hold it right" you can be safe using
> Pure ML-DSA, but why go against the spirit and the recommendation of
> the spec when it is rather easy to actually follow the spec and use the
> correct function which is HashML-DSA ?

You still haven't actually quoted a recommendation of the spec.
The only relevant recommendation I see is: "In general, the “pure”
ML-DSA version is preferred."

> They would not have made available HashML-DSA if there weren't
> legitimate cases for it.

Like the text I quoted above says, "If the content is not hashed at the
application level, the pre-hash version of ML-DSA signing may be used."
So the exact opposite case of OpenPGP.


Btw, if your position is that you _disagree_ with NIST and/or FIPS 204,
like some parts of your email seem to suggest, that's perfectly fine,
but that's something entirely different than claiming that the spec
recommends something different than what it actually recommends.

Best,
Daniel