]> git.ipfire.org Git - thirdparty/openssl.git/commit
rsa: add implicit rejection in PKCS#1 v1.5
authorHubert Kario <hkario@redhat.com>
Tue, 15 Mar 2022 12:58:08 +0000 (13:58 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 12 Dec 2022 10:30:52 +0000 (11:30 +0100)
commit7fc67e0a33102aa47bbaa56533eeecb98c0450f7
treeacf95cf7b89eb0f2d24150969e94998f4b44b0da
parent1ca61aa56090356bbdbb16cf48916fbd9886c78d
rsa: add implicit rejection in PKCS#1 v1.5

The RSA decryption as implemented before required very careful handling
of both the exit code returned by OpenSSL and the potentially returned
ciphertext. Looking at the recent security vulnerabilities
(CVE-2020-25659 and CVE-2020-25657) it is unlikely that most users of
OpenSSL do it correctly.

Given that correct code requires side channel secure programming in
application code, we can classify the existing RSA decryption methods
as CWE-676, which in turn likely causes CWE-208 and CWE-385 in
application code.

To prevent that, we can use a technique called "implicit rejection".
For that we generate a random message to be returned in case the
padding check fails. We generate the message based on static secret
data (the private exponent) and the provided ciphertext (so that the
attacker cannot determine that the returned value is randomly generated
instead of result of decryption and de-padding). We return it in case
any part of padding check fails.

The upshot of this approach is that then not only is the length of the
returned message useless as the Bleichenbacher oracle, so are the
actual bytes of the returned message. So application code doesn't have
to perform any operations on the returned message in side-channel free
way to remain secure against Bleichenbacher attacks.

Note: this patch implements a specific algorithm, shared with Mozilla
NSS, so that the attacker cannot use one library as an oracle against the
other in heterogeneous environments.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13817)
crypto/rsa/rsa_ossl.c
crypto/rsa/rsa_pk1.c
doc/man1/openssl-pkeyutl.pod.in
doc/man1/openssl-rsautl.pod.in
doc/man3/EVP_PKEY_CTX_ctrl.pod
doc/man3/EVP_PKEY_decrypt.pod
doc/man3/RSA_padding_add_PKCS1_type_1.pod
doc/man3/RSA_public_encrypt.pod
include/crypto/rsa.h
test/recipes/30-test_evp_data/evppkey_rsa_common.txt