diff options
author | djm <> | 2009-01-09 12:14:11 +0000 |
---|---|---|
committer | djm <> | 2009-01-09 12:14:11 +0000 |
commit | a0fdc9ec41594852f67ec77dfad9cb06bacc4186 (patch) | |
tree | c43f6b3a4d93ad2cb3dcf93275295679d895a033 /src/lib/libcrypto/rsa/rsa_eay.c | |
parent | 5a3c0a05c7f2c5d3c584b7c8d6aec836dd724c80 (diff) | |
download | openbsd-a0fdc9ec41594852f67ec77dfad9cb06bacc4186.tar.gz openbsd-a0fdc9ec41594852f67ec77dfad9cb06bacc4186.tar.bz2 openbsd-a0fdc9ec41594852f67ec77dfad9cb06bacc4186.zip |
import openssl-0.9.8j
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_eay.c')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_eay.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c index ffadaab9a4..0ac6418449 100644 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ b/src/lib/libcrypto/rsa/rsa_eay.c | |||
@@ -115,7 +115,7 @@ | |||
115 | #include <openssl/rsa.h> | 115 | #include <openssl/rsa.h> |
116 | #include <openssl/rand.h> | 116 | #include <openssl/rand.h> |
117 | 117 | ||
118 | #ifndef RSA_NULL | 118 | #if !defined(RSA_NULL) && !defined(OPENSSL_FIPS) |
119 | 119 | ||
120 | static int RSA_eay_public_encrypt(int flen, const unsigned char *from, | 120 | static int RSA_eay_public_encrypt(int flen, const unsigned char *from, |
121 | unsigned char *to, RSA *rsa,int padding); | 121 | unsigned char *to, RSA *rsa,int padding); |
@@ -150,16 +150,6 @@ const RSA_METHOD *RSA_PKCS1_SSLeay(void) | |||
150 | return(&rsa_pkcs1_eay_meth); | 150 | return(&rsa_pkcs1_eay_meth); |
151 | } | 151 | } |
152 | 152 | ||
153 | /* Usage example; | ||
154 | * MONT_HELPER(rsa->_method_mod_p, bn_ctx, rsa->p, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err); | ||
155 | */ | ||
156 | #define MONT_HELPER(method_mod, ctx, m, pre_cond, err_instr) \ | ||
157 | if ((pre_cond) && ((method_mod) == NULL) && \ | ||
158 | !BN_MONT_CTX_set_locked(&(method_mod), \ | ||
159 | CRYPTO_LOCK_RSA, \ | ||
160 | (m), (ctx))) \ | ||
161 | err_instr | ||
162 | |||
163 | static int RSA_eay_public_encrypt(int flen, const unsigned char *from, | 153 | static int RSA_eay_public_encrypt(int flen, const unsigned char *from, |
164 | unsigned char *to, RSA *rsa, int padding) | 154 | unsigned char *to, RSA *rsa, int padding) |
165 | { | 155 | { |
@@ -233,7 +223,9 @@ static int RSA_eay_public_encrypt(int flen, const unsigned char *from, | |||
233 | goto err; | 223 | goto err; |
234 | } | 224 | } |
235 | 225 | ||
236 | MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err); | 226 | if (rsa->flags & RSA_FLAG_CACHE_PUBLIC) |
227 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) | ||
228 | goto err; | ||
237 | 229 | ||
238 | if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx, | 230 | if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx, |
239 | rsa->_method_mod_n)) goto err; | 231 | rsa->_method_mod_n)) goto err; |
@@ -438,7 +430,9 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | |||
438 | else | 430 | else |
439 | d= rsa->d; | 431 | d= rsa->d; |
440 | 432 | ||
441 | MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err); | 433 | if (rsa->flags & RSA_FLAG_CACHE_PUBLIC) |
434 | if(!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) | ||
435 | goto err; | ||
442 | 436 | ||
443 | if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx, | 437 | if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx, |
444 | rsa->_method_mod_n)) goto err; | 438 | rsa->_method_mod_n)) goto err; |
@@ -559,7 +553,9 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, | |||
559 | else | 553 | else |
560 | d = rsa->d; | 554 | d = rsa->d; |
561 | 555 | ||
562 | MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err); | 556 | if (rsa->flags & RSA_FLAG_CACHE_PUBLIC) |
557 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) | ||
558 | goto err; | ||
563 | if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx, | 559 | if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx, |
564 | rsa->_method_mod_n)) | 560 | rsa->_method_mod_n)) |
565 | goto err; | 561 | goto err; |
@@ -669,7 +665,9 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from, | |||
669 | goto err; | 665 | goto err; |
670 | } | 666 | } |
671 | 667 | ||
672 | MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err); | 668 | if (rsa->flags & RSA_FLAG_CACHE_PUBLIC) |
669 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) | ||
670 | goto err; | ||
673 | 671 | ||
674 | if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx, | 672 | if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx, |
675 | rsa->_method_mod_n)) goto err; | 673 | rsa->_method_mod_n)) goto err; |
@@ -747,11 +745,18 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | |||
747 | q = rsa->q; | 745 | q = rsa->q; |
748 | } | 746 | } |
749 | 747 | ||
750 | MONT_HELPER(rsa->_method_mod_p, ctx, p, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err); | 748 | if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) |
751 | MONT_HELPER(rsa->_method_mod_q, ctx, q, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err); | 749 | { |
750 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_p, CRYPTO_LOCK_RSA, p, ctx)) | ||
751 | goto err; | ||
752 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_q, CRYPTO_LOCK_RSA, q, ctx)) | ||
753 | goto err; | ||
754 | } | ||
752 | } | 755 | } |
753 | 756 | ||
754 | MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err); | 757 | if (rsa->flags & RSA_FLAG_CACHE_PUBLIC) |
758 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) | ||
759 | goto err; | ||
755 | 760 | ||
756 | /* compute I mod q */ | 761 | /* compute I mod q */ |
757 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | 762 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) |