diff options
| author | markus <> | 2003-05-12 02:18:40 +0000 |
|---|---|---|
| committer | markus <> | 2003-05-12 02:18:40 +0000 |
| commit | d4fcd82bb7f6d603bd61e19a81ba97337b89dfca (patch) | |
| tree | d52e3a0f1f08f65ad283027e560e17ed0d720462 /src/lib/libcrypto/rsa/rsa_lib.c | |
| parent | 582bbd139cd2afd58d10dc051c5b0b989b441074 (diff) | |
| download | openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.gz openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.bz2 openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.zip | |
merge 0.9.7b with local changes; crank majors for libssl/libcrypto
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_lib.c')
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_lib.c | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c index 37fff8bce3..53c5092014 100644 --- a/src/lib/libcrypto/rsa/rsa_lib.c +++ b/src/lib/libcrypto/rsa/rsa_lib.c | |||
| @@ -62,7 +62,10 @@ | |||
| 62 | #include <openssl/lhash.h> | 62 | #include <openssl/lhash.h> |
| 63 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
| 64 | #include <openssl/rsa.h> | 64 | #include <openssl/rsa.h> |
| 65 | #include <openssl/rand.h> | ||
| 66 | #ifndef OPENSSL_NO_ENGINE | ||
| 65 | #include <openssl/engine.h> | 67 | #include <openssl/engine.h> |
| 68 | #endif | ||
| 66 | 69 | ||
| 67 | const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT; | 70 | const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT; |
| 68 | 71 | ||
| @@ -72,10 +75,6 @@ RSA *RSA_new(void) | |||
| 72 | { | 75 | { |
| 73 | RSA *r=RSA_new_method(NULL); | 76 | RSA *r=RSA_new_method(NULL); |
| 74 | 77 | ||
| 75 | #ifndef OPENSSL_NO_FORCE_RSA_BLINDING | ||
| 76 | r->flags|=RSA_FLAG_BLINDING; | ||
| 77 | #endif | ||
| 78 | |||
| 79 | return r; | 78 | return r; |
| 80 | } | 79 | } |
| 81 | 80 | ||
| @@ -114,11 +113,13 @@ int RSA_set_method(RSA *rsa, const RSA_METHOD *meth) | |||
| 114 | const RSA_METHOD *mtmp; | 113 | const RSA_METHOD *mtmp; |
| 115 | mtmp = rsa->meth; | 114 | mtmp = rsa->meth; |
| 116 | if (mtmp->finish) mtmp->finish(rsa); | 115 | if (mtmp->finish) mtmp->finish(rsa); |
| 116 | #ifndef OPENSSL_NO_ENGINE | ||
| 117 | if (rsa->engine) | 117 | if (rsa->engine) |
| 118 | { | 118 | { |
| 119 | ENGINE_finish(rsa->engine); | 119 | ENGINE_finish(rsa->engine); |
| 120 | rsa->engine = NULL; | 120 | rsa->engine = NULL; |
| 121 | } | 121 | } |
| 122 | #endif | ||
| 122 | rsa->meth = meth; | 123 | rsa->meth = meth; |
| 123 | if (meth->init) meth->init(rsa); | 124 | if (meth->init) meth->init(rsa); |
| 124 | return 1; | 125 | return 1; |
| @@ -136,6 +137,7 @@ RSA *RSA_new_method(ENGINE *engine) | |||
| 136 | } | 137 | } |
| 137 | 138 | ||
| 138 | ret->meth = RSA_get_default_method(); | 139 | ret->meth = RSA_get_default_method(); |
| 140 | #ifndef OPENSSL_NO_ENGINE | ||
| 139 | if (engine) | 141 | if (engine) |
| 140 | { | 142 | { |
| 141 | if (!ENGINE_init(engine)) | 143 | if (!ENGINE_init(engine)) |
| @@ -160,6 +162,7 @@ RSA *RSA_new_method(ENGINE *engine) | |||
| 160 | return NULL; | 162 | return NULL; |
| 161 | } | 163 | } |
| 162 | } | 164 | } |
| 165 | #endif | ||
| 163 | 166 | ||
| 164 | ret->pad=0; | 167 | ret->pad=0; |
| 165 | ret->version=0; | 168 | ret->version=0; |
| @@ -181,8 +184,10 @@ RSA *RSA_new_method(ENGINE *engine) | |||
| 181 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); | 184 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); |
| 182 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) | 185 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) |
| 183 | { | 186 | { |
| 187 | #ifndef OPENSSL_NO_ENGINE | ||
| 184 | if (ret->engine) | 188 | if (ret->engine) |
| 185 | ENGINE_finish(ret->engine); | 189 | ENGINE_finish(ret->engine); |
| 190 | #endif | ||
| 186 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); | 191 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); |
| 187 | OPENSSL_free(ret); | 192 | OPENSSL_free(ret); |
| 188 | ret=NULL; | 193 | ret=NULL; |
| @@ -211,8 +216,10 @@ void RSA_free(RSA *r) | |||
| 211 | 216 | ||
| 212 | if (r->meth->finish) | 217 | if (r->meth->finish) |
| 213 | r->meth->finish(r); | 218 | r->meth->finish(r); |
| 219 | #ifndef OPENSSL_NO_ENGINE | ||
| 214 | if (r->engine) | 220 | if (r->engine) |
| 215 | ENGINE_finish(r->engine); | 221 | ENGINE_finish(r->engine); |
| 222 | #endif | ||
| 216 | 223 | ||
| 217 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); | 224 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); |
| 218 | 225 | ||
| @@ -303,7 +310,8 @@ void RSA_blinding_off(RSA *rsa) | |||
| 303 | BN_BLINDING_free(rsa->blinding); | 310 | BN_BLINDING_free(rsa->blinding); |
| 304 | rsa->blinding=NULL; | 311 | rsa->blinding=NULL; |
| 305 | } | 312 | } |
| 306 | rsa->flags&= ~RSA_FLAG_BLINDING; | 313 | rsa->flags &= ~RSA_FLAG_BLINDING; |
| 314 | rsa->flags |= RSA_FLAG_NO_BLINDING; | ||
| 307 | } | 315 | } |
| 308 | 316 | ||
| 309 | int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) | 317 | int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) |
| @@ -322,15 +330,32 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) | |||
| 322 | if (rsa->blinding != NULL) | 330 | if (rsa->blinding != NULL) |
| 323 | BN_BLINDING_free(rsa->blinding); | 331 | BN_BLINDING_free(rsa->blinding); |
| 324 | 332 | ||
| 333 | /* NB: similar code appears in setup_blinding (rsa_eay.c); | ||
| 334 | * this should be placed in a new function of its own, but for reasons | ||
| 335 | * of binary compatibility can't */ | ||
| 336 | |||
| 325 | BN_CTX_start(ctx); | 337 | BN_CTX_start(ctx); |
| 326 | A = BN_CTX_get(ctx); | 338 | A = BN_CTX_get(ctx); |
| 327 | if (!BN_rand_range(A,rsa->n)) goto err; | 339 | if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL) |
| 340 | { | ||
| 341 | /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */ | ||
| 342 | RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0); | ||
| 343 | if (!BN_pseudo_rand_range(A,rsa->n)) goto err; | ||
| 344 | } | ||
| 345 | else | ||
| 346 | { | ||
| 347 | if (!BN_rand_range(A,rsa->n)) goto err; | ||
| 348 | } | ||
| 328 | if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; | 349 | if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; |
| 329 | 350 | ||
| 330 | if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) | 351 | if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) |
| 331 | goto err; | 352 | goto err; |
| 332 | rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); | 353 | if ((rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n)) == NULL) goto err; |
| 333 | rsa->flags|=RSA_FLAG_BLINDING; | 354 | /* to make things thread-safe without excessive locking, |
| 355 | * rsa->blinding will be used just by the current thread: */ | ||
| 356 | rsa->blinding->thread_id = CRYPTO_thread_id(); | ||
| 357 | rsa->flags |= RSA_FLAG_BLINDING; | ||
| 358 | rsa->flags &= ~RSA_FLAG_NO_BLINDING; | ||
| 334 | BN_free(Ai); | 359 | BN_free(Ai); |
| 335 | ret=1; | 360 | ret=1; |
| 336 | err: | 361 | err: |
