diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/bn/bn_prime.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/bn/bn_prime.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_prime.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c index a5f01b92eb..918b9237c6 100644 --- a/src/lib/libcrypto/bn/bn_prime.c +++ b/src/lib/libcrypto/bn/bn_prime.c | |||
@@ -56,7 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | /* ==================================================================== | 58 | /* ==================================================================== |
59 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | 59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. |
60 | * | 60 | * |
61 | * Redistribution and use in source and binary forms, with or without | 61 | * Redistribution and use in source and binary forms, with or without |
62 | * modification, are permitted provided that the following conditions | 62 | * modification, are permitted provided that the following conditions |
@@ -125,12 +125,13 @@ static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1, | |||
125 | const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont); | 125 | const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont); |
126 | static int probable_prime(BIGNUM *rnd, int bits); | 126 | static int probable_prime(BIGNUM *rnd, int bits); |
127 | static int probable_prime_dh(BIGNUM *rnd, int bits, | 127 | static int probable_prime_dh(BIGNUM *rnd, int bits, |
128 | BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); | 128 | const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx); |
129 | static int probable_prime_dh_safe(BIGNUM *rnd, int bits, | 129 | static int probable_prime_dh_safe(BIGNUM *rnd, int bits, |
130 | BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); | 130 | const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx); |
131 | 131 | ||
132 | BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, BIGNUM *add, | 132 | BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, |
133 | BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg) | 133 | const BIGNUM *add, const BIGNUM *rem, |
134 | void (*callback)(int,int,void *), void *cb_arg) | ||
134 | { | 135 | { |
135 | BIGNUM *rnd=NULL; | 136 | BIGNUM *rnd=NULL; |
136 | BIGNUM t; | 137 | BIGNUM t; |
@@ -225,12 +226,15 @@ int BN_is_prime_fasttest(const BIGNUM *a, int checks, | |||
225 | BN_MONT_CTX *mont = NULL; | 226 | BN_MONT_CTX *mont = NULL; |
226 | const BIGNUM *A = NULL; | 227 | const BIGNUM *A = NULL; |
227 | 228 | ||
229 | if (BN_cmp(a, BN_value_one()) <= 0) | ||
230 | return 0; | ||
231 | |||
228 | if (checks == BN_prime_checks) | 232 | if (checks == BN_prime_checks) |
229 | checks = BN_prime_checks_for_size(BN_num_bits(a)); | 233 | checks = BN_prime_checks_for_size(BN_num_bits(a)); |
230 | 234 | ||
231 | /* first look for small factors */ | 235 | /* first look for small factors */ |
232 | if (!BN_is_odd(a)) | 236 | if (!BN_is_odd(a)) |
233 | return(0); | 237 | return 0; |
234 | if (do_trial_division) | 238 | if (do_trial_division) |
235 | { | 239 | { |
236 | for (i = 1; i < NUMPRIMES; i++) | 240 | for (i = 1; i < NUMPRIMES; i++) |
@@ -289,11 +293,8 @@ int BN_is_prime_fasttest(const BIGNUM *a, int checks, | |||
289 | 293 | ||
290 | for (i = 0; i < checks; i++) | 294 | for (i = 0; i < checks; i++) |
291 | { | 295 | { |
292 | if (!BN_pseudo_rand(check, BN_num_bits(A1), 0, 0)) | 296 | if (!BN_pseudo_rand_range(check, A1)) |
293 | goto err; | 297 | goto err; |
294 | if (BN_cmp(check, A1) >= 0) | ||
295 | if (!BN_sub(check, check, A1)) | ||
296 | goto err; | ||
297 | if (!BN_add_word(check, 1)) | 298 | if (!BN_add_word(check, 1)) |
298 | goto err; | 299 | goto err; |
299 | /* now 1 <= check < A */ | 300 | /* now 1 <= check < A */ |
@@ -376,8 +377,8 @@ again: | |||
376 | return(1); | 377 | return(1); |
377 | } | 378 | } |
378 | 379 | ||
379 | static int probable_prime_dh(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem, | 380 | static int probable_prime_dh(BIGNUM *rnd, int bits, |
380 | BN_CTX *ctx) | 381 | const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx) |
381 | { | 382 | { |
382 | int i,ret=0; | 383 | int i,ret=0; |
383 | BIGNUM *t1; | 384 | BIGNUM *t1; |
@@ -413,8 +414,8 @@ err: | |||
413 | return(ret); | 414 | return(ret); |
414 | } | 415 | } |
415 | 416 | ||
416 | static int probable_prime_dh_safe(BIGNUM *p, int bits, BIGNUM *padd, | 417 | static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd, |
417 | BIGNUM *rem, BN_CTX *ctx) | 418 | const BIGNUM *rem, BN_CTX *ctx) |
418 | { | 419 | { |
419 | int i,ret=0; | 420 | int i,ret=0; |
420 | BIGNUM *t1,*qadd,*q; | 421 | BIGNUM *t1,*qadd,*q; |