Browse code

libgcrypt: Fix for CVE-2018-0495

Added a patch to fix CVE-2018-0495

Change-Id: Iefc1f82e5cadbbd393bd3f31616c0bd1a60feb2a
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5578
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Sharath George

Ankit Jain authored on 2018/09/04 04:04:17
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,72 @@
0
+From 9010d1576e278a4274ad3f4aa15776c28f6ba965 Mon Sep 17 00:00:00 2001
1
+From: NIIBE Yutaka <gniibe@fsij.org>
2
+Date: Wed, 13 Jun 2018 15:28:58 +0900
3
+Subject: [PATCH] ecc: Add blinding for ECDSA.
4
+
5
+* cipher/ecc-ecdsa.c (_gcry_ecc_ecdsa_sign): Blind secret D with
6
+randomized nonce B.
7
+
8
+--
9
+
10
+Reported-by: Keegan Ryan <Keegan.Ryan@nccgroup.trust>
11
+CVE-id: CVE-2018-0495
12
+Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
13
+---
14
+ cipher/ecc-ecdsa.c | 20 ++++++++++++++++++--
15
+ 1 file changed, 18 insertions(+), 2 deletions(-)
16
+
17
+diff --git a/cipher/ecc-ecdsa.c b/cipher/ecc-ecdsa.c
18
+index 1484830..140e8c0 100644
19
+--- a/cipher/ecc-ecdsa.c
20
+@@ -50,6 +50,8 @@ _gcry_ecc_ecdsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
21
+   const void *abuf;
22
+   unsigned int abits, qbits;
23
+   mpi_ec_t ctx;
24
++  gcry_mpi_t b;                /* Random number needed for blinding.  */
25
++  gcry_mpi_t bi;               /* multiplicative inverse of B.        */
26
+ 
27
+   if (DBG_CIPHER)
28
+     log_mpidump ("ecdsa sign hash  ", input );
29
+@@ -61,6 +63,15 @@ _gcry_ecc_ecdsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
30
+   if (rc)
31
+     return rc;
32
+ 
33
++  b  = mpi_snew (qbits);
34
++  bi = mpi_snew (qbits);
35
++  do
36
++    {
37
++      _gcry_mpi_randomize (b, qbits, GCRY_WEAK_RANDOM);
38
++      mpi_mod (b, b, skey->E.n);
39
++    }
40
++  while (!mpi_invm (bi, b, skey->E.n));
41
++
42
+   k = NULL;
43
+   dr = mpi_alloc (0);
44
+   sum = mpi_alloc (0);
45
+@@ -115,8 +126,11 @@ _gcry_ecc_ecdsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
46
+         }
47
+       while (!mpi_cmp_ui (r, 0));
48
+ 
49
+-      mpi_mulm (dr, skey->d, r, skey->E.n); /* dr = d*r mod n  */
50
+-      mpi_addm (sum, hash, dr, skey->E.n);  /* sum = hash + (d*r) mod n  */
51
++      mpi_mulm (dr, b, skey->d, skey->E.n);
52
++      mpi_mulm (dr, dr, r, skey->E.n);      /* dr = d*r mod n (blinded with b) */
53
++      mpi_mulm (sum, b, hash, skey->E.n);
54
++      mpi_addm (sum, sum, dr, skey->E.n);   /* sum = hash + (d*r) mod n  (blinded with b) */
55
++      mpi_mulm (sum, bi, sum, skey->E.n);   /* undo blinding by b^-1 */
56
+       mpi_invm (k_1, k, skey->E.n);         /* k_1 = k^(-1) mod n  */
57
+       mpi_mulm (s, k_1, sum, skey->E.n);    /* s = k^(-1)*(hash+(d*r)) mod n */
58
+     }
59
+@@ -129,6 +143,8 @@ _gcry_ecc_ecdsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
60
+     }
61
+ 
62
+  leave:
63
++  mpi_free (b);
64
++  mpi_free (bi);
65
+   _gcry_mpi_ec_free (ctx);
66
+   point_free (&I);
67
+   mpi_free (x);
68
+-- 
69
+2.7.4
70
+
... ...
@@ -1,11 +1,12 @@
1 1
 Summary:	Crypto Libraries
2 2
 Name:		libgcrypt
3 3
 Version:	1.8.1
4
-Release:	1%{?dist}
4
+Release:	2%{?dist}
5 5
 License:        GPLv2+ and LGPLv2+
6 6
 URL:            http://www.gnu.org/software/libgcrypt/
7 7
 Source0:        ftp://ftp.gnupg.org/gcrypt/libgcrypt/%{name}-%{version}.tar.bz2
8 8
 %define sha1 libgcrypt=dd35f00da45602afe81e01f4d60c40bbdd826fe6
9
+Patch0:         libgcrypt-CVE-2018-0495.patch
9 10
 Group:		System Environment/Libraries
10 11
 Vendor:		VMware, Inc.
11 12
 BuildRequires:	libgpg-error-devel
... ...
@@ -25,6 +26,8 @@ developing applications that use libgcrypt.
25 25
 
26 26
 %prep
27 27
 %setup -q
28
+%patch0 -p1
29
+
28 30
 %build
29 31
 ./configure \
30 32
 	--prefix=%{_prefix}
... ...
@@ -50,6 +53,8 @@ make %{?_smp_mflags} check
50 50
 %{_includedir}/*.h
51 51
 %{_libdir}/*.so
52 52
 %changelog
53
+*   Mon Sep 03 2018 Ankit Jain <ankitja@vmware.com> 1.8.1-2
54
+-   Fix for CVE-2018-0495
53 55
 *   Tue Oct 10 2017 Vinay Kulkarni <kulkarniv@vmware.com> 1.8.1-1
54 56
 -   Udpated to v1.8.1 to address CVE-2017-0379
55 57
 *   Tue Apr 04 2017 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 1.7.6-1