Re: [CFRG] Psychic Signatures

Neil Madden <neil.e.madden@gmail.com> Thu, 21 April 2022 10:55 UTC

Return-Path: <neil.e.madden@gmail.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 33A823A0ED1 for <cfrg@ietfa.amsl.com>; Thu, 21 Apr 2022 03:55:30 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.104
X-Spam-Level:
X-Spam-Status: No, score=-2.104 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, 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] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
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 AdlsaoSQhRo7 for <cfrg@ietfa.amsl.com>; Thu, 21 Apr 2022 03:55:25 -0700 (PDT)
Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2D2A93A0CF1 for <cfrg@irtf.org>; Thu, 21 Apr 2022 03:55:25 -0700 (PDT)
Received: by mail-wr1-x42c.google.com with SMTP id s25so1238207wrb.8 for <cfrg@irtf.org>; Thu, 21 Apr 2022 03:55:25 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=TpGmqZNl/pwnzswtsBc3g9OusIk/6emocaBGjwhhl1c=; b=oJdkxdmcXn6aUCG8dCcYIgQBfjqgIYWZNV23KZuSLD7WJrsouaSGEMUgpiFpKxWS7Q wHRBnP6wGm3sjSspdo/o6KkD+X5VRqG3+IAmMn+xiR4bVPslX4b3nIi6ZhH7sE7NtGF3 cKO3LLgsiZJBSYF84h9LY02IlLFYFmz6fmQppbjNTlLD3LAFTowCgAPl+V5t1cLmr7Br BRan6GHMXBOKvJYT83Sw/m2wH8I8oiWSwGFtGynI5Pi3v96XSbcbHNalm0FTjwTrknGp YbiGiOW2gTbex9CcXaDadft6jbB9bzhDy7X4tBiz0r+sOO2v9HhjSyw3tORGqsKMoNhP aXHg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=TpGmqZNl/pwnzswtsBc3g9OusIk/6emocaBGjwhhl1c=; b=BJWWS2kfp5tm7zcjb0FaPNZaTrlFLFo10d6J0rqwyKxtgV5wF9wMU5PsubU0FTDn6T 1kLBLXdxLduENAY4aunT3r3g80f9jukSVdW5mfhQNx6EKoPCUHbd4AK+TvevdTvMAQjb /Xy7xwmEcl22vKttkAtwhhRBFJoEC5wuOjcT+K+KnRGGt6kRwBwkxOAeqaAfhWubfY4Q vCy1ZeVtJqP4jzQ6fTd5xEyE/nw+XeZnLaAc+TziYLjSeOw3YKrkspgF+e61rFynKkNE q44xl5dYeCkFoLRiqpfntHV+bTGU0HedrTER5AlvfXP8d0NqnRhrj1RDjGJKIzCJfCDp opjw==
X-Gm-Message-State: AOAM532fPZC5QbYJKVwQOLHdYBAv8/0tiI9YPy+vZlBWTuszCNjy/lDt 044fcUtTBiiwIAJzHrIpF23uKnW6tkI=
X-Google-Smtp-Source: ABdhPJxfLjBKXdmwCCm3ozHnyhFiDCQzhFe3qzH+qIVUTwOQeM/tdJ06ilkwEMEzIQNifD70Gtcj6w==
X-Received: by 2002:a05:6000:c4:b0:20a:bfeb:68dc with SMTP id q4-20020a05600000c400b0020abfeb68dcmr1675355wrx.488.1650538522554; Thu, 21 Apr 2022 03:55:22 -0700 (PDT)
Received: from smtpclient.apple ([195.224.190.250]) by smtp.gmail.com with ESMTPSA id m2-20020a056000008200b00207a6f32833sm2310753wrx.117.2022.04.21.03.55.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Apr 2022 03:55:22 -0700 (PDT)
From: Neil Madden <neil.e.madden@gmail.com>
Message-Id: <2D35E3A0-0335-4430-AF7B-A91939EF21C1@gmail.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_99443F91-49E1-4F6D-95A3-828875B3585A"
Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\))
Date: Thu, 21 Apr 2022 11:55:20 +0100
In-Reply-To: <2CBA5AE5-DF84-4E9C-85DA-4DC38464710A@ericlagergren.com>
Cc: Peter Gutmann <pgut001@cs.auckland.ac.nz>, IRTF CFRG <cfrg@irtf.org>
To: Eric Lagergren <eric@ericlagergren.com>
References: <SY4PR01MB62519FEA53D39AABAF0BD0F4EEF49@SY4PR01MB6251.ausprd01.prod.outlook.com> <2CBA5AE5-DF84-4E9C-85DA-4DC38464710A@ericlagergren.com>
X-Mailer: Apple Mail (2.3654.120.0.1.13)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cfrg/2LpnI-MorJmuWb_EBaZ6lCnGZeA>
Subject: Re: [CFRG] Psychic Signatures
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.29
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, 21 Apr 2022 10:55:30 -0000

> On 21 Apr 2022, at 07:56, Eric Lagergren <eric@ericlagergren.com> wrote:
> 
> Project Wycheproof has a very good set of test vectors like this. They should be table stakes at this point. Alas, (most) test vectors can only demonstrate that the code isn’t _obviously_ broken, which is a low bar. 
> 

After I found this bug I ran the Wycheproof test suite against the JVM - it has a mode specifically to test Java cryptography implementations. Unfortunately, it appears to have been broken by changes made in Java 9 that introduced modules to the Java language. After I hacked around that in a local copy it found the bug immediately. So, a low bar, but one that Java failed to reach anyway.

Ironically, the work that introduced this bug into Java [1] appears to have been partially motivated by a desire to remove older curves [2]:

“Removal of obsolete elliptic curves support, including underlying library libsunec.
[…]
Weaknesses in the implementation of the native library EC code make it necessary to remove support for future releases. The most common EC curves have already been re-implemented in Java in the SunEC JCE provider.”

I’m not sure what “weaknesses” were in the C++ implementation, but it did at least check for this all-zero condition, and with a very clear comment referencing the spec to justify it [3]. So how did this get missed in the rewrite?

Well, lack of tests is one cause - and I note that no unit test was included in the fix (that took 5 months for them to release) [4].

The ECDSA rewrite in Java uses a new constant-time (branch-free) modular big integer framework in the JDK that was developed specifically “for crypto algorithms like Poly1305 and X25519” according to the commit message [5]. The previous C++ implementation uses a generic big integer library instead, so perhaps timing side-channels are the weakness that the above quoted message refers to. 

It’s tempting to conclude that a rush to protect against the "new shiny" side-channel vulns has led to a neglect of much more basic and devastating security checks, but I’ll note that Java’s EdDSA implementation does make the similar (much simpler) check on the range of the s value [6]. As I understand it, forgetting this check in EdDSA would anyway “merely” lead to malleable signatures [7], and not to a total loss of security as in ECDSA. 

The sooner ECDSA goes away the better, but as I learnt when writing up this bug, ECDSA over NIST P-256 is basically the only game in town for current WebAuthn/FIDO authenticator devices, with only a tiny handful supporting Ed25519 (*in addition to* ECDSA) and the one outsider of Windows Hello still using RSA PKCS#1 v1.5 signatures. Sigh.

[1]: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8237218 <https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8237218> 
[2]: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8251547 <https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8251547> 
[3]: https://github.com/openjdk/jdk/blob/jdk-15-ga/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c#L956 <https://github.com/openjdk/jdk/blob/jdk-15-ga/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c#L956> 
[4]: https://github.com/openjdk/jdk/commit/e2f8ce9c3ff4518e070960bafa70ba780746aa5c <https://github.com/openjdk/jdk/commit/e2f8ce9c3ff4518e070960bafa70ba780746aa5c> 
[5]: https://github.com/openjdk/jdk/commit/f15ab37909c2621bef10332c9b031668bb489de9 <https://github.com/openjdk/jdk/commit/f15ab37909c2621bef10332c9b031668bb489de9> 
[6]: https://github.com/openjdk/jdk/blob/master/src/jdk.crypto.ec/share/classes/sun/security/ec/ed/EdDSAOperations.java#L144 <https://github.com/openjdk/jdk/blob/master/src/jdk.crypto.ec/share/classes/sun/security/ec/ed/EdDSAOperations.java#L144> 
[7]: https://www.rfc-editor.org/rfc/rfc8032.html#section-8.4 <https://www.rfc-editor.org/rfc/rfc8032.html#section-8.4> 

— Neil