summaryrefslogtreecommitdiff
path: root/lib/libcrypto/rsa
diff options
context:
space:
mode:
authorHakan Olsson <ho@cvs.openbsd.org>2003-03-15 16:35:54 +0000
committerHakan Olsson <ho@cvs.openbsd.org>2003-03-15 16:35:54 +0000
commitb39414e39b731f07eb5a3af8bc94d066713e9001 (patch)
tree05fbedb81b0b7ce0d3595c0bf0e7464a286b1303 /lib/libcrypto/rsa
parent50aa1c4de6d85ff5f290ccef90a8607ec5f56aa8 (diff)
Enforce blinding on RSA operations involving private keys.
From http://www.openssl.org/~geoff, modified to be enabled at all times.
Diffstat (limited to 'lib/libcrypto/rsa')
-rw-r--r--lib/libcrypto/rsa/rsa_eay.c27
-rw-r--r--lib/libcrypto/rsa/rsa_lib.c4
2 files changed, 27 insertions, 4 deletions
diff --git a/lib/libcrypto/rsa/rsa_eay.c b/lib/libcrypto/rsa/rsa_eay.c
index 0eda816081d..3fe1cd6540e 100644
--- a/lib/libcrypto/rsa/rsa_eay.c
+++ b/lib/libcrypto/rsa/rsa_eay.c
@@ -97,6 +97,21 @@ const RSA_METHOD *RSA_PKCS1_SSLeay(void)
return(&rsa_pkcs1_eay_meth);
}
+static void rsa_eay_blinding(RSA *rsa, BN_CTX *ctx)
+ {
+ CRYPTO_w_lock(CRYPTO_LOCK_RSA);
+ /* Check again inside the lock - the macro's check is racey */
+ if(rsa->blinding == NULL)
+ RSA_blinding_on(rsa, ctx);
+ CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
+ }
+#define BLINDING_HELPER(rsa, ctx) \
+ do { \
+ if(((rsa)->flags & RSA_FLAG_BLINDING) && \
+ ((rsa)->blinding == NULL)) \
+ rsa_eay_blinding(rsa, ctx); \
+ } while(0)
+
static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
@@ -237,8 +252,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);
+
if (rsa->flags & RSA_FLAG_BLINDING)
if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;
@@ -316,8 +331,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);
+
if (rsa->flags & RSA_FLAG_BLINDING)
if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;
@@ -592,6 +607,10 @@ err:
static int RSA_eay_init(RSA *rsa)
{
rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
+
+ /* Enforce blinding. */
+ rsa->flags|=RSA_FLAG_BLINDING;
+
return(1);
}
diff --git a/lib/libcrypto/rsa/rsa_lib.c b/lib/libcrypto/rsa/rsa_lib.c
index 93235744f7a..f71870a3387 100644
--- a/lib/libcrypto/rsa/rsa_lib.c
+++ b/lib/libcrypto/rsa/rsa_lib.c
@@ -181,6 +181,10 @@ RSA *RSA_new_method(ENGINE *engine)
OPENSSL_free(ret);
ret=NULL;
}
+
+ /* Enforce blinding. */
+ ret->flags |= RSA_FLAG_BLINDING;
+
return(ret);
}