diff options
Diffstat (limited to 'meta/recipes-support/libgcrypt/files/CVE-2021-33560.patch')
-rw-r--r-- | meta/recipes-support/libgcrypt/files/CVE-2021-33560.patch | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/meta/recipes-support/libgcrypt/files/CVE-2021-33560.patch b/meta/recipes-support/libgcrypt/files/CVE-2021-33560.patch new file mode 100644 index 0000000000..bf26486d8b --- /dev/null +++ b/meta/recipes-support/libgcrypt/files/CVE-2021-33560.patch | |||
@@ -0,0 +1,77 @@ | |||
1 | From e8b7f10be275bcedb5fc05ed4837a89bfd605c61 Mon Sep 17 00:00:00 2001 | ||
2 | From: NIIBE Yutaka <gniibe@fsij.org> | ||
3 | Date: Tue, 13 Apr 2021 10:00:00 +0900 | ||
4 | Subject: [PATCH] cipher: Hardening ElGamal by introducing exponent blinding | ||
5 | too. | ||
6 | |||
7 | * cipher/elgamal.c (do_encrypt): Also do exponent blinding. | ||
8 | |||
9 | -- | ||
10 | |||
11 | Base blinding had been introduced with USE_BLINDING. This patch add | ||
12 | exponent blinding as well to mitigate side-channel attack on mpi_powm. | ||
13 | |||
14 | GnuPG-bug-id: 5328 | ||
15 | Signed-off-by: NIIBE Yutaka <gniibe@fsij.org> | ||
16 | |||
17 | Upstream-Status: Backport | ||
18 | CVE: CVE-2021-33560 | ||
19 | Signed-off-by: Marta Rybczynska <marta.rybczynska@huawei.com> | ||
20 | --- | ||
21 | cipher/elgamal.c | 20 +++++++++++++++++--- | ||
22 | 1 file changed, 17 insertions(+), 3 deletions(-) | ||
23 | |||
24 | diff --git a/cipher/elgamal.c b/cipher/elgamal.c | ||
25 | index 4eb52d62..9835122f 100644 | ||
26 | --- a/cipher/elgamal.c | ||
27 | +++ b/cipher/elgamal.c | ||
28 | @@ -522,8 +522,9 @@ do_encrypt(gcry_mpi_t a, gcry_mpi_t b, gcry_mpi_t input, ELG_public_key *pkey ) | ||
29 | static void | ||
30 | decrypt (gcry_mpi_t output, gcry_mpi_t a, gcry_mpi_t b, ELG_secret_key *skey ) | ||
31 | { | ||
32 | - gcry_mpi_t t1, t2, r; | ||
33 | + gcry_mpi_t t1, t2, r, r1, h; | ||
34 | unsigned int nbits = mpi_get_nbits (skey->p); | ||
35 | + gcry_mpi_t x_blind; | ||
36 | |||
37 | mpi_normalize (a); | ||
38 | mpi_normalize (b); | ||
39 | @@ -534,20 +535,33 @@ decrypt (gcry_mpi_t output, gcry_mpi_t a, gcry_mpi_t b, ELG_secret_key *skey ) | ||
40 | |||
41 | t2 = mpi_snew (nbits); | ||
42 | r = mpi_new (nbits); | ||
43 | + r1 = mpi_new (nbits); | ||
44 | + h = mpi_new (nbits); | ||
45 | + x_blind = mpi_snew (nbits); | ||
46 | |||
47 | /* We need a random number of about the prime size. The random | ||
48 | number merely needs to be unpredictable; thus we use level 0. */ | ||
49 | _gcry_mpi_randomize (r, nbits, GCRY_WEAK_RANDOM); | ||
50 | |||
51 | + /* Also, exponent blinding: x_blind = x + (p-1)*r1 */ | ||
52 | + _gcry_mpi_randomize (r1, nbits, GCRY_WEAK_RANDOM); | ||
53 | + mpi_set_highbit (r1, nbits - 1); | ||
54 | + mpi_sub_ui (h, skey->p, 1); | ||
55 | + mpi_mul (x_blind, h, r1); | ||
56 | + mpi_add (x_blind, skey->x, x_blind); | ||
57 | + | ||
58 | /* t1 = r^x mod p */ | ||
59 | - mpi_powm (t1, r, skey->x, skey->p); | ||
60 | + mpi_powm (t1, r, x_blind, skey->p); | ||
61 | /* t2 = (a * r)^-x mod p */ | ||
62 | mpi_mulm (t2, a, r, skey->p); | ||
63 | - mpi_powm (t2, t2, skey->x, skey->p); | ||
64 | + mpi_powm (t2, t2, x_blind, skey->p); | ||
65 | mpi_invm (t2, t2, skey->p); | ||
66 | /* t1 = (t1 * t2) mod p*/ | ||
67 | mpi_mulm (t1, t1, t2, skey->p); | ||
68 | |||
69 | + mpi_free (x_blind); | ||
70 | + mpi_free (h); | ||
71 | + mpi_free (r1); | ||
72 | mpi_free (r); | ||
73 | mpi_free (t2); | ||
74 | |||
75 | -- | ||
76 | 2.11.0 | ||
77 | |||