diff options
| author | djm <> | 2012-01-05 23:01:39 +0000 |
|---|---|---|
| committer | djm <> | 2012-01-05 23:01:39 +0000 |
| commit | f48d9d4a955d7e4c1c692099ab67e1dbfeb51137 (patch) | |
| tree | 866512933d8f0c1ea5465d0169915b36c1ca3cae /src/lib/libcrypto/bn | |
| parent | 35dadfe897866818c3fd0350efefc5caae349fb6 (diff) | |
| download | openbsd-f48d9d4a955d7e4c1c692099ab67e1dbfeb51137.tar.gz openbsd-f48d9d4a955d7e4c1c692099ab67e1dbfeb51137.tar.bz2 openbsd-f48d9d4a955d7e4c1c692099ab67e1dbfeb51137.zip | |
OpenSSL 1.0.0f: merge
Diffstat (limited to 'src/lib/libcrypto/bn')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_blind.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c index e060592fdc..9ed8bc2b40 100644 --- a/src/lib/libcrypto/bn/bn_blind.c +++ b/src/lib/libcrypto/bn/bn_blind.c | |||
| @@ -126,7 +126,7 @@ struct bn_blinding_st | |||
| 126 | * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */ | 126 | * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */ |
| 127 | #endif | 127 | #endif |
| 128 | CRYPTO_THREADID tid; | 128 | CRYPTO_THREADID tid; |
| 129 | unsigned int counter; | 129 | int counter; |
| 130 | unsigned long flags; | 130 | unsigned long flags; |
| 131 | BN_MONT_CTX *m_ctx; | 131 | BN_MONT_CTX *m_ctx; |
| 132 | int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 132 | int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| @@ -160,7 +160,10 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod) | |||
| 160 | if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0) | 160 | if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0) |
| 161 | BN_set_flags(ret->mod, BN_FLG_CONSTTIME); | 161 | BN_set_flags(ret->mod, BN_FLG_CONSTTIME); |
| 162 | 162 | ||
| 163 | ret->counter = BN_BLINDING_COUNTER; | 163 | /* Set the counter to the special value -1 |
| 164 | * to indicate that this is never-used fresh blinding | ||
| 165 | * that does not need updating before first use. */ | ||
| 166 | ret->counter = -1; | ||
| 164 | CRYPTO_THREADID_current(&ret->tid); | 167 | CRYPTO_THREADID_current(&ret->tid); |
| 165 | return(ret); | 168 | return(ret); |
| 166 | err: | 169 | err: |
| @@ -190,7 +193,10 @@ int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx) | |||
| 190 | goto err; | 193 | goto err; |
| 191 | } | 194 | } |
| 192 | 195 | ||
| 193 | if (--(b->counter) == 0 && b->e != NULL && | 196 | if (b->counter == -1) |
| 197 | b->counter = 0; | ||
| 198 | |||
| 199 | if (++b->counter == BN_BLINDING_COUNTER && b->e != NULL && | ||
| 194 | !(b->flags & BN_BLINDING_NO_RECREATE)) | 200 | !(b->flags & BN_BLINDING_NO_RECREATE)) |
| 195 | { | 201 | { |
| 196 | /* re-create blinding parameters */ | 202 | /* re-create blinding parameters */ |
| @@ -205,8 +211,8 @@ int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx) | |||
| 205 | 211 | ||
| 206 | ret=1; | 212 | ret=1; |
| 207 | err: | 213 | err: |
| 208 | if (b->counter == 0) | 214 | if (b->counter == BN_BLINDING_COUNTER) |
| 209 | b->counter = BN_BLINDING_COUNTER; | 215 | b->counter = 0; |
| 210 | return(ret); | 216 | return(ret); |
| 211 | } | 217 | } |
| 212 | 218 | ||
| @@ -227,6 +233,12 @@ int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx) | |||
| 227 | return(0); | 233 | return(0); |
| 228 | } | 234 | } |
| 229 | 235 | ||
| 236 | if (b->counter == -1) | ||
| 237 | /* Fresh blinding, doesn't need updating. */ | ||
| 238 | b->counter = 0; | ||
| 239 | else if (!BN_BLINDING_update(b,ctx)) | ||
| 240 | return(0); | ||
| 241 | |||
| 230 | if (r != NULL) | 242 | if (r != NULL) |
| 231 | { | 243 | { |
| 232 | if (!BN_copy(r, b->Ai)) ret=0; | 244 | if (!BN_copy(r, b->Ai)) ret=0; |
| @@ -247,22 +259,19 @@ int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *ct | |||
| 247 | int ret; | 259 | int ret; |
| 248 | 260 | ||
| 249 | bn_check_top(n); | 261 | bn_check_top(n); |
| 250 | if ((b->A == NULL) || (b->Ai == NULL)) | ||
| 251 | { | ||
| 252 | BNerr(BN_F_BN_BLINDING_INVERT_EX,BN_R_NOT_INITIALIZED); | ||
| 253 | return(0); | ||
| 254 | } | ||
| 255 | 262 | ||
| 256 | if (r != NULL) | 263 | if (r != NULL) |
| 257 | ret = BN_mod_mul(n, n, r, b->mod, ctx); | 264 | ret = BN_mod_mul(n, n, r, b->mod, ctx); |
| 258 | else | 265 | else |
| 259 | ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx); | ||
| 260 | |||
| 261 | if (ret >= 0) | ||
| 262 | { | 266 | { |
| 263 | if (!BN_BLINDING_update(b,ctx)) | 267 | if (b->Ai == NULL) |
| 268 | { | ||
| 269 | BNerr(BN_F_BN_BLINDING_INVERT_EX,BN_R_NOT_INITIALIZED); | ||
| 264 | return(0); | 270 | return(0); |
| 271 | } | ||
| 272 | ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx); | ||
| 265 | } | 273 | } |
| 274 | |||
| 266 | bn_check_top(n); | 275 | bn_check_top(n); |
| 267 | return(ret); | 276 | return(ret); |
| 268 | } | 277 | } |
