[IPsec] [Cryptography] Why RSA-PSS is much less secure than PKCS #1 v1.5 (fwd)
Paul Wouters <paul@nohats.ca> Wed, 13 November 2019 19:59 UTC
Return-Path: <paul@nohats.ca>
X-Original-To: ipsec@ietfa.amsl.com
Delivered-To: ipsec@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 2E7AF120942 for <ipsec@ietfa.amsl.com>; Wed, 13 Nov 2019 11:59:10 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.997
X-Spam-Level:
X-Spam-Status: No, score=-1.997 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=nohats.ca
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 UZro4fmCI7bH for <ipsec@ietfa.amsl.com>; Wed, 13 Nov 2019 11:59:08 -0800 (PST)
Received: from mx.nohats.ca (mx.nohats.ca [193.110.157.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 47FA8120885 for <ipsec@ietf.org>; Wed, 13 Nov 2019 11:59:05 -0800 (PST)
Received: from localhost (localhost [IPv6:::1]) by mx.nohats.ca (Postfix) with ESMTP id 47CwRW1rl9zFkj; Wed, 13 Nov 2019 20:59:03 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nohats.ca; s=default; t=1573675143; bh=NjPijLi6OHfBXEmPmE04j5j/tvLUxA2VPUzah1vpzag=; h=Date:From:To:Subject; b=nGak8WXffs04da1u3RrzGFStdZ65S1twQ8hc4y8Imo3eLOIUIM6hpnC1NVZQsD939 esdGwvgP6iejHYhURb1SArWuLg2iSTwS84Ha/tzuwVi7ItQ+zso4RBDF0U3QfOAlUv 5c0PzmHrOpEOn7B8bouXJbK7QFhA21rEvesPZS5g=
X-Virus-Scanned: amavisd-new at mx.nohats.ca
Received: from mx.nohats.ca ([IPv6:::1]) by localhost (mx.nohats.ca [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id KNXi8CAUZrqD; Wed, 13 Nov 2019 20:59:01 +0100 (CET)
Received: from bofh.nohats.ca (bofh.nohats.ca [76.10.157.69]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx.nohats.ca (Postfix) with ESMTPS; Wed, 13 Nov 2019 20:59:00 +0100 (CET)
Received: by bofh.nohats.ca (Postfix, from userid 1000) id C7A31602980B; Wed, 13 Nov 2019 14:58:59 -0500 (EST)
Received: from localhost (localhost [127.0.0.1]) by bofh.nohats.ca (Postfix) with ESMTP id C6723CB854; Wed, 13 Nov 2019 14:58:59 -0500 (EST)
Date: Wed, 13 Nov 2019 14:58:59 -0500
From: Paul Wouters <paul@nohats.ca>
To: "ipsec@ietf.org WG" <ipsec@ietf.org>
Message-ID: <alpine.LRH.2.21.1911131458190.22669@bofh.nohats.ca>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"; format="flowed"
Archived-At: <https://mailarchive.ietf.org/arch/msg/ipsec/dwetlvDmrEWU1aKq9z7z-bYd-Q8>
Subject: [IPsec] [Cryptography] Why RSA-PSS is much less secure than PKCS #1 v1.5 (fwd)
X-BeenThere: ipsec@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Discussion of IPsec protocols <ipsec.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/ipsec>, <mailto:ipsec-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/ipsec/>
List-Post: <mailto:ipsec@ietf.org>
List-Help: <mailto:ipsec-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/ipsec>, <mailto:ipsec-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 13 Nov 2019 19:59:10 -0000
Interesting, since we basically said to do only PSS for RFC 7427 .... Paul ---------- Forwarded message ---------- Date: Sun, 10 Nov 2019 23:34:28 From: Peter Gutmann <pgut001@cs.auckland.ac.nz> To: Cryptography Mailing List <cryptography@metzdowd.com> Subject: [Cryptography] Why RSA-PSS is much less secure than PKCS #1 v1.5 There is a view that RSA-PSS (henceforth referred to as PSS) is more secure than PKCS #1 v1.5 (henceforth PKCS #1), presumably because PSS has the words "provable" and "secure" in its description (the abbreviation PSS stands for Probabilistic Signature Scheme, it's the scheme itself which has "provable" in it). In practice however PSS is much less secure and vastly more brittle than PKCS #1, despite its "provable security". Here's why. To understand the problem, you need to look at PKCS #1 vs. PSS. PKCS #1 has the following external, unauthenticated parameters: The PKCS #1 verification operation, following the RSA operation that both PSS and PKCS #1 require, is as follows. Given a hash of the data being signed, perform the following: fixed_sig_data[ hash_offset ] = hash; result = memcmp fixed_sig_data, recovered_sig_data; In other words, copy the hash onto the end of the fixed-format PKCS #1 signature data and compare it with the recovered signature data. The fixed- format PKCS #1 signature data encodes the hash algorithm, parameters, signature type, and anything else that's required to verify the signature. PSS in contrast has the following external, unauthenticated parameters: RSASSA-PSS-params ::= SEQUENCE { hashAlgorithm [0] { SEQUENCE { algorithm OBJECT IDENTIFER, parameters ANY DEFINED BY algorithm OPTIONAL }, maskGenAlgorithm [1] { SEQUENCE { algorithm OBJECT IDENTIFER DEFAULT mgf1SHA1, parameters SEQUENCE { algorithm OBJECT IDENTIFIER, parameters ANY DEFINED BY algorithm OPTIONAL }, } saltLength [2] { length INTEGER DEFAULT 20 }, trailerField [3] { trailer INTEGER DEFAULT trailerFieldBC } } The PSS verification operation, again following the common RSA operation, is as follows... Actually I won't post it here. No matter how much I try and condense it, I can't get it down to less than four solid pages of pseudocode. In addition, I have no idea whether it's actually correct or not, meaning whether it captures all of the boundless corner cases and conditions that it's required to handle. Just to help with the explanation that follows, here's a diagram of what's going on. mHash is the hash of the message as for PKCS #1 (this diagram requires a fixed-width font to see): +-----------------------------------+------+---+ EM = |# maskedDB | mHash|xDB| +-----------------------------------+------+---+ | | v | xor <------- MGF() ------+---+ | | v | +---------------------------+-------+ | DB = | 00 ... 00 01 | salt | | +---------------------------+-------+ | | | | | v | +-------------------+-------+-------+ | M' = | 00 x 8 | hash | salt |---+ | +-------------------+-------+-------+ | | v | Hash() | | | v v Compare Now let's look at what an attacker can do with the above. The immediately obvious, trivial attack is a hash-substitution attack. Unlike PKCS #1, PSS doesn't encode the hash algorithm used anywhere in the signature. This encoding, known as a hash function firewall ("On Hash Function Firewalls in Signature Schemes", CT-RSA 2002) was ironically not added to PSS because it would have caused problems with the security proof. By changing hashAlgorithm to whatever you like, for example an algorithm of the same size that you know how to break, you can forge the signature. Change the hash from SHA-2/256 to Streebog, Blake2, Keccak, CRC-256, XOR256, whatever you like, PSS won't detect the change, making it only as strong as the weakest hash algorithm of the same bit width that the victim will accept. There's a lot more fun you can have with this. Remember that you've got a huge pile of external parameters, all controllable by the attacker. For example look at the way MGF() is applied, it's a simple stream cipher, meaning that you can flip any bit in DB by flipping the corresponding bit in EM. Note that there's just a single bit in DB that tells you where the salt starts, so if you can flip a bit in EM it'll set the corresponding bit in DB to 1. In theory you then run into a problem with the salt, but since the salt length is another attacker-controlled parameter you just extend it to cover the extra data that's been added by the bit flip. Then there's M', which is assembled by the victim under the attacker's control since they can set the salt length and hash algorithm to anything they want, which PSS again won't detect. There's quite a large pile of problems present here: * There's no internal structure to the data so you can't see what's what, and in particular where one field ends and another begins. Specifically, it violates Abadi and Needham's Principle #1, "Every message should say what it means" ("Prudent Engineering Practice for Cryptographic Protocols", Security and Privacy 1994). * There's a ton of external, attacker-controlled parameters that allow an attacker excessive control over every step of the verification process (see also the previous point). * The algorithm is ridiculously over-parameterised (why would you want to use a different hash algorithm for the message hash and mask generation hash, or a salt of a different length than the hash, or ...), all of which helps the attacker. * It uses a stream cipher (XOR-mask) that allows you to make easily predictable changes to the data. * The victim has to assemble the data block M' using attacker-controlled parameters rather than recovering it from the signature. * The high level of complexity and special-case checks and operations make it pretty much impossible to implement in a side-channel-free manner. It's almost a textbook example of what not to do when designing a signature, or more generally crypto, mechanism. (In its defence, PSS was very much a product of the times, with building blocks like the hash function and MGF and parameters values subject to change, so that parameter-combinatorial-explosion ended up being a frequent design pattern, with the expectation being that usage profiles would address some of the issues that arose. Unfortunately none were ever really created beyond de facto usage patterns, there's a suggested one at the end of this writeup. For a great introduction to the early history of RSA signature mechanism design, see Burt Kaliski's talk from ZKProof 2019, https://www.youtube.com/watch?v=sqsDKjPaJVg). At the moment there isn't an obvious attack that takes advantage of this beyond the obvious hash-substitution, but it gives the attacker an awful lot of control over the internals of the PSS verification operation. Contrast this with PKCS #1, where there's only one fixed-format string possible for each hash algorithm, and no ambiguity or manipulation by the attacker is possible. In terms of the unauthenticated parameters, in theory there is sort-of protection against these in both X.509 and S/MIME / CMS, but in practice there isn't. X.509 includes the signature algorithm parameters in the certificate in the form of the badly-named 'signature' field, which doesn't contain the signature at all but the algorithm parameters. Support for this is hit-and- miss, with some implementations skipping it (which is perfectly justifiable, since there's never been a need for it if you're not using PSS), some implementations checking basic parameters but not the mass of optional and situation-specific values used in PSS, and some meticulously checking every parameter. CMS in theory has a means of protecting the parameters by signing them into the SignedAttributes as an RFC 6211 Algorithm Identifier Protection Attribute, but I know of only one implementation that supports that, and in any case if you've got a hash function that you can create collisions with you can rewrite the CMS signature to remove the SignedAttributes. Note that this problem is specific to PSS, it doesn't affect PKCS #1 which encodes the algorithm information into the signature. So for the vanishingly small number of users of PSS, I'd recommend switching to something more secure like PKCS #1, and disabling the PSS code before someone attacks you through it. If you must use PSS then hardcode in one, and only one, signature scheme, say { hashAlgorithm = SHA-256, maskGenAlgorithm = mgf1 with SHA-256, saltLength = 32, trailerField = trailerFieldBC } and don't allow any substitutions. "Beware of bugs in the above signature scheme; I have only proved it secure, not implemented it" - Apologies to Donald Knuth. Thanks to various members of the cryptography community who commented on early drafts of this writeup. My opinions, not theirs. Peter. _______________________________________________ The cryptography mailing list cryptography@metzdowd.com https://www.metzdowd.com/mailman/listinfo/cryptography
- [IPsec] [Cryptography] Why RSA-PSS is much less s… Paul Wouters