Skip to content

Commit d2ca0f4

Browse files
mattcaswellt8m
authored andcommitted
Fix Timing Oracle in RSA decryption
A timing based side channel exists in the OpenSSL RSA Decryption implementation which could be sufficient to recover a plaintext across a network in a Bleichenbacher style attack. To achieve a successful decryption an attacker would have to be able to send a very large number of trial messages for decryption. The vulnerability affects all RSA padding modes: PKCS#1 v1.5, RSA-OEAP and RSASVE. Patch written by Dmitry Belyavsky and Hubert Kario Backport to 1.0.2 by Matt Caswell. CVE-2022-4304 Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org>
1 parent 0c55850 commit d2ca0f4

File tree

10 files changed

+731
-28
lines changed

10 files changed

+731
-28
lines changed

crypto/bn/Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \
2626
bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
2727
bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \
2828
bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c \
29-
bn_depr.c bn_const.c bn_x931p.c
29+
bn_depr.c bn_const.c bn_x931p.c rsa_sup_mul.c
3030

3131
LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \
3232
bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \
3333
bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \
3434
bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o bn_gf2m.o bn_nist.o \
35-
bn_depr.o bn_const.o bn_x931p.o
35+
bn_depr.o bn_const.o bn_x931p.o rsa_sup_mul.o
3636

3737
SRC= $(LIBSRC)
3838

@@ -408,3 +408,13 @@ bn_x931p.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
408408
bn_x931p.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
409409
bn_x931p.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
410410
bn_x931p.o: ../../include/openssl/symhacks.h bn_x931p.c
411+
rsa_sup_mul.o: ../../e_os.h ../../include/openssl/asn1.h
412+
rsa_sup_mul.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
413+
rsa_sup_mul.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
414+
rsa_sup_mul.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
415+
rsa_sup_mul.o: ../../include/openssl/opensslconf.h
416+
rsa_sup_mul.o: ../../include/openssl/opensslv.h
417+
rsa_sup_mul.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
418+
rsa_sup_mul.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
419+
rsa_sup_mul.o: ../../include/openssl/symhacks.h ../bn_int.h bn_lcl.h
420+
rsa_sup_mul.o: rsa_sup_mul.c

crypto/bn/bn.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom);
940940
* The following lines are auto generated by the script mkerr.pl. Any changes
941941
* made after this point may be overwritten when the script is next run.
942942
*/
943+
943944
void ERR_load_BN_strings(void);
944945

945946
/* Error codes for the BN functions. */
@@ -959,6 +960,7 @@ void ERR_load_BN_strings(void);
959960
# define BN_F_BN_DIV 107
960961
# define BN_F_BN_DIV_NO_BRANCH 138
961962
# define BN_F_BN_DIV_RECP 130
963+
# define BN_F_BN_DO_UNBLIND 140
962964
# define BN_F_BN_EXP 123
963965
# define BN_F_BN_EXPAND2 108
964966
# define BN_F_BN_EXPAND_INTERNAL 120
@@ -1005,11 +1007,12 @@ void ERR_load_BN_strings(void);
10051007
# define BN_R_NOT_INITIALIZED 107
10061008
# define BN_R_NO_INVERSE 108
10071009
# define BN_R_NO_SOLUTION 116
1010+
# define BN_R_PASSED_INVALID_ARGUMENT 117
10081011
# define BN_R_P_IS_NOT_PRIME 112
10091012
# define BN_R_TOO_MANY_ITERATIONS 113
10101013
# define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109
10111014

1012-
#ifdef __cplusplus
1015+
# ifdef __cplusplus
10131016
}
1014-
#endif
1017+
# endif
10151018
#endif

crypto/bn/bn_blind.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,6 @@
115115

116116
#define BN_BLINDING_COUNTER 32
117117

118-
struct bn_blinding_st {
119-
BIGNUM *A;
120-
BIGNUM *Ai;
121-
BIGNUM *e;
122-
BIGNUM *mod; /* just a reference */
123-
#ifndef OPENSSL_NO_DEPRECATED
124-
unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b; used
125-
* only by crypto/rsa/rsa_eay.c, rsa_lib.c */
126-
#endif
127-
CRYPTO_THREADID tid;
128-
int counter;
129-
unsigned long flags;
130-
BN_MONT_CTX *m_ctx;
131-
int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
132-
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
133-
};
134-
135118
BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
136119
{
137120
BN_BLINDING *ret = NULL;

crypto/bn/bn_err.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* crypto/bn/bn_err.c */
22
/* ====================================================================
3-
* Copyright (c) 1999-2015 The OpenSSL Project. All rights reserved.
3+
* Copyright (c) 1999-2023 The OpenSSL Project. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -84,6 +84,7 @@ static ERR_STRING_DATA BN_str_functs[] = {
8484
{ERR_FUNC(BN_F_BN_DIV), "BN_div"},
8585
{ERR_FUNC(BN_F_BN_DIV_NO_BRANCH), "BN_div_no_branch"},
8686
{ERR_FUNC(BN_F_BN_DIV_RECP), "BN_div_recp"},
87+
{ERR_FUNC(BN_F_BN_DO_UNBLIND), "bn_do_unblind"},
8788
{ERR_FUNC(BN_F_BN_EXP), "BN_exp"},
8889
{ERR_FUNC(BN_F_BN_EXPAND2), "bn_expand2"},
8990
{ERR_FUNC(BN_F_BN_EXPAND_INTERNAL), "BN_EXPAND_INTERNAL"},
@@ -133,6 +134,7 @@ static ERR_STRING_DATA BN_str_reasons[] = {
133134
{ERR_REASON(BN_R_NOT_INITIALIZED), "not initialized"},
134135
{ERR_REASON(BN_R_NO_INVERSE), "no inverse"},
135136
{ERR_REASON(BN_R_NO_SOLUTION), "no solution"},
137+
{ERR_REASON(BN_R_PASSED_INVALID_ARGUMENT), "passed invalid argument"},
136138
{ERR_REASON(BN_R_P_IS_NOT_PRIME), "p is not prime"},
137139
{ERR_REASON(BN_R_TOO_MANY_ITERATIONS), "too many iterations"},
138140
{ERR_REASON(BN_R_TOO_MANY_TEMPORARY_VARIABLES),

crypto/bn/bn_lcl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,23 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
531531
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
532532
const BN_ULONG *np, const BN_ULONG *n0, int num);
533533

534+
struct bn_blinding_st {
535+
BIGNUM *A;
536+
BIGNUM *Ai;
537+
BIGNUM *e;
538+
BIGNUM *mod; /* just a reference */
539+
#ifndef OPENSSL_NO_DEPRECATED
540+
unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b; used
541+
* only by crypto/rsa/rsa_eay.c, rsa_lib.c */
542+
#endif
543+
CRYPTO_THREADID tid;
544+
int counter;
545+
unsigned long flags;
546+
BN_MONT_CTX *m_ctx;
547+
int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
548+
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
549+
};
550+
534551
#ifdef __cplusplus
535552
}
536553
#endif

0 commit comments

Comments
 (0)