Fix the ECDSA timing attack mentioned in the paper at:
authorDr. Stephen Henson <steve@openssl.org>
Wed, 25 May 2011 14:41:56 +0000 (14:41 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 25 May 2011 14:41:56 +0000 (14:41 +0000)
http://eprint.iacr.org/2011/232.pdf

Thanks to the original authors Billy Bob Brumley and Nicola Tuveri for
bringing this to our attention.

CHANGES
crypto/ecdsa/ecs_ossl.c

diff --git a/CHANGES b/CHANGES
index 22749650b701d91cc43af24a226369116c2a46f8..1633d27975c91f122c4e9266b2c3cf4e56e8ffbf 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,13 @@
 
  Changes between 1.0.1 and 1.1.0  [xx XXX xxxx]
 
+  *) Add protection against ECDSA timing attacks as mentioned in the paper
+     by Billy Bob Brumley and Nicola Tuveri, see:
+
+       http://eprint.iacr.org/2011/232.pdf
+
+     [Billy Bob Brumley and Nicola Tuveri]
+
   *) Add TLS v1.2 server support for client authentication. 
      [Steve Henson]
 
index 3518bb02e12350cace57f6c6e7ad05f2f56ebaf3..50d02ed0691c8b9d85e8e5072ef3222de25389fd 100644 (file)
@@ -151,6 +151,16 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
                        }
                while (BN_is_zero(k));
 
+#ifdef ECDSA_POINT_MUL_NO_CONSTTIME
+               /* We do not want timing information to leak the length of k,
+                * so we compute G*k using an equivalent scalar of fixed
+                * bit-length. */
+
+               if (!BN_add(k, k, order)) goto err;
+               if (BN_num_bits(k) <= BN_num_bits(order))
+                       if (!BN_add(k, k, order)) goto err;
+#endif /* def(ECDSA_POINT_MUL_NO_CONSTTIME) */
+
                /* compute r the x-coordinate of generator * k */
                if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx))
                {