diff options
author | margarida <> | 2003-03-19 01:18:21 +0000 |
---|---|---|
committer | margarida <> | 2003-03-19 01:18:21 +0000 |
commit | 955149d2c1094d65e72b4aad057026602d935717 (patch) | |
tree | 14b27c938621f25f693d5eb14e3457cd8c00fcb7 | |
parent | 700eda6d2089d1107f8d3533246f55e9bc940421 (diff) | |
download | openbsd-955149d2c1094d65e72b4aad057026602d935717.tar.gz openbsd-955149d2c1094d65e72b4aad057026602d935717.tar.bz2 openbsd-955149d2c1094d65e72b4aad057026602d935717.zip |
Errata #11 (markus):
Enforce blinding on RSA operations involving private keys.
millert@ markus@ ok
-rw-r--r-- | src/lib/libssl/src/crypto/rsa/rsa_eay.c | 27 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rsa/rsa_lib.c | 8 |
2 files changed, 30 insertions, 5 deletions
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_eay.c b/src/lib/libssl/src/crypto/rsa/rsa_eay.c index 0eda816081..a3f549d8e6 100644 --- a/src/lib/libssl/src/crypto/rsa/rsa_eay.c +++ b/src/lib/libssl/src/crypto/rsa/rsa_eay.c | |||
@@ -193,6 +193,25 @@ err: | |||
193 | return(r); | 193 | return(r); |
194 | } | 194 | } |
195 | 195 | ||
196 | static int rsa_eay_blinding(RSA *rsa, BN_CTX *ctx) | ||
197 | { | ||
198 | int ret = 1; | ||
199 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
200 | /* Check again inside the lock - the macro's check is racey */ | ||
201 | if(rsa->blinding == NULL) | ||
202 | ret = RSA_blinding_on(rsa, ctx); | ||
203 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
204 | return ret; | ||
205 | } | ||
206 | |||
207 | #define BLINDING_HELPER(rsa, ctx, err_instr) \ | ||
208 | do { \ | ||
209 | if(((rsa)->flags & RSA_FLAG_BLINDING) && \ | ||
210 | ((rsa)->blinding == NULL) && \ | ||
211 | !rsa_eay_blinding(rsa, ctx)) \ | ||
212 | err_instr \ | ||
213 | } while(0) | ||
214 | |||
196 | /* signing */ | 215 | /* signing */ |
197 | static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | 216 | static int RSA_eay_private_encrypt(int flen, const unsigned char *from, |
198 | unsigned char *to, RSA *rsa, int padding) | 217 | unsigned char *to, RSA *rsa, int padding) |
@@ -237,8 +256,8 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | |||
237 | goto err; | 256 | goto err; |
238 | } | 257 | } |
239 | 258 | ||
240 | if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL)) | 259 | BLINDING_HELPER(rsa, ctx, goto err;); |
241 | RSA_blinding_on(rsa,ctx); | 260 | |
242 | if (rsa->flags & RSA_FLAG_BLINDING) | 261 | if (rsa->flags & RSA_FLAG_BLINDING) |
243 | if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err; | 262 | if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err; |
244 | 263 | ||
@@ -316,8 +335,8 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, | |||
316 | goto err; | 335 | goto err; |
317 | } | 336 | } |
318 | 337 | ||
319 | if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL)) | 338 | BLINDING_HELPER(rsa, ctx, goto err;); |
320 | RSA_blinding_on(rsa,ctx); | 339 | |
321 | if (rsa->flags & RSA_FLAG_BLINDING) | 340 | if (rsa->flags & RSA_FLAG_BLINDING) |
322 | if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err; | 341 | if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err; |
323 | 342 | ||
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_lib.c b/src/lib/libssl/src/crypto/rsa/rsa_lib.c index 93235744f7..37fff8bce3 100644 --- a/src/lib/libssl/src/crypto/rsa/rsa_lib.c +++ b/src/lib/libssl/src/crypto/rsa/rsa_lib.c | |||
@@ -70,7 +70,13 @@ static const RSA_METHOD *default_RSA_meth=NULL; | |||
70 | 70 | ||
71 | RSA *RSA_new(void) | 71 | RSA *RSA_new(void) |
72 | { | 72 | { |
73 | return(RSA_new_method(NULL)); | 73 | RSA *r=RSA_new_method(NULL); |
74 | |||
75 | #ifndef OPENSSL_NO_FORCE_RSA_BLINDING | ||
76 | r->flags|=RSA_FLAG_BLINDING; | ||
77 | #endif | ||
78 | |||
79 | return r; | ||
74 | } | 80 | } |
75 | 81 | ||
76 | void RSA_set_default_method(const RSA_METHOD *meth) | 82 | void RSA_set_default_method(const RSA_METHOD *meth) |