Turn on RSA blinding by default.
authorBen Laurie <ben@openssl.org>
Tue, 18 Mar 2003 12:12:10 +0000 (12:12 +0000)
committerBen Laurie <ben@openssl.org>
Tue, 18 Mar 2003 12:12:10 +0000 (12:12 +0000)
CHANGES
crypto/rsa/rsa_eay.c
crypto/rsa/rsa_lib.c

diff --git a/CHANGES b/CHANGES
index ad3d0ae24bd3d3f308cb28ee7a1707ad0226aac6..6ab49d23a1bbd3ce0a5a0f0ee3982dd9fa104253 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,12 @@
 
  Changes between 0.9.7a and 0.9.7b  [xx XXX 2003]
 
+  *) Turn on RSA blinding by default, to avoid a timing attack. Applications
+     that don't want it can call RSA_blinding_off(). They would be ill-advised
+     to do so in most cases. The automatic enabling can also be turned off
+     by defining OPENSSL_FORCE_NO_RSA_BLINDING at compile-time.
+     [Ben Laurie, Steve Henson, Geoff Thorpe]
+
   *) Fixed a typo bug that would cause ENGINE_set_default() to set an
      ENGINE as defaults for all supported algorithms irrespective of
      the 'flags' parameter. 'flags' is now honoured, so applications
index 29ce4511bcaf8d1f7b9202c94d6c75152d334df9..e4bcf499d064a6bdc8cb37e2a7bd19fb5bce00a4 100644 (file)
@@ -195,6 +195,25 @@ err:
        return(r);
        }
 
+static int rsa_eay_blinding(RSA *rsa, BN_CTX *ctx)
+       {
+       int ret = 1;
+       CRYPTO_w_lock(CRYPTO_LOCK_RSA);
+       /* Check again inside the lock - the macro's check is racey */
+       if(rsa->blinding == NULL)
+               ret = RSA_blinding_on(rsa, ctx);
+       CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
+       return ret;
+       }
+
+#define BLINDING_HELPER(rsa, ctx, err_instr) \
+       do { \
+               if(((rsa)->flags & RSA_FLAG_BLINDING) && \
+                               ((rsa)->blinding == NULL) && \
+                               !rsa_eay_blinding(rsa, ctx)) \
+                       err_instr \
+       } while(0)
+
 /* signing */
 static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
             unsigned char *to, RSA *rsa, int padding)
@@ -239,8 +258,8 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
                goto err;
                }
 
-       if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))
-               RSA_blinding_on(rsa,ctx);
+       BLINDING_HELPER(rsa, ctx, goto err;);
+
        if (rsa->flags & RSA_FLAG_BLINDING)
                if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;
 
@@ -318,8 +337,8 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
                goto err;
                }
 
-       if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))
-               RSA_blinding_on(rsa,ctx);
+       BLINDING_HELPER(rsa, ctx, goto err;);
+
        if (rsa->flags & RSA_FLAG_BLINDING)
                if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;
 
index 889c36d3a6f4b5ddc3e3829c0b02c8192366e4ab..f234ae0748cad7acb855abcfdc1ca5a4347ddb46 100644 (file)
@@ -72,7 +72,13 @@ static const RSA_METHOD *default_RSA_meth=NULL;
 
 RSA *RSA_new(void)
        {
-       return(RSA_new_method(NULL));
+       RSA *r=RSA_new_method(NULL);
+
+#ifndef OPENSSL_NO_FORCE_RSA_BLINDING
+       r->flags|=RSA_FLAG_BLINDING;
+#endif
+
+       return r;
        }
 
 void RSA_set_default_method(const RSA_METHOD *meth)