diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_x931p.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_x931p.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/src/lib/libcrypto/bn/bn_x931p.c b/src/lib/libcrypto/bn/bn_x931p.c index c64410dd3a..04c5c874ec 100644 --- a/src/lib/libcrypto/bn/bn_x931p.c +++ b/src/lib/libcrypto/bn/bn_x931p.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* bn_x931p.c */ | 1 | /* bn_x931p.c */ |
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2005. | 3 | * project 2005. |
4 | */ | 4 | */ |
5 | /* ==================================================================== | 5 | /* ==================================================================== |
@@ -59,18 +59,15 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <openssl/bn.h> | 60 | #include <openssl/bn.h> |
61 | 61 | ||
62 | #ifdef OPENSSL_FIPS | ||
63 | |||
64 | /* X9.31 routines for prime derivation */ | 62 | /* X9.31 routines for prime derivation */ |
65 | 63 | ||
66 | |||
67 | /* X9.31 prime derivation. This is used to generate the primes pi | 64 | /* X9.31 prime derivation. This is used to generate the primes pi |
68 | * (p1, p2, q1, q2) from a parameter Xpi by checking successive odd | 65 | * (p1, p2, q1, q2) from a parameter Xpi by checking successive odd |
69 | * integers. | 66 | * integers. |
70 | */ | 67 | */ |
71 | 68 | ||
72 | static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx, | 69 | static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx, |
73 | void (*cb)(int, int, void *), void *cb_arg) | 70 | BN_GENCB *cb) |
74 | { | 71 | { |
75 | int i = 0; | 72 | int i = 0; |
76 | if (!BN_copy(pi, Xpi)) | 73 | if (!BN_copy(pi, Xpi)) |
@@ -80,16 +77,14 @@ static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx, | |||
80 | for(;;) | 77 | for(;;) |
81 | { | 78 | { |
82 | i++; | 79 | i++; |
83 | if (cb) | 80 | BN_GENCB_call(cb, 0, i); |
84 | cb(0, i, cb_arg); | ||
85 | /* NB 27 MR is specificed in X9.31 */ | 81 | /* NB 27 MR is specificed in X9.31 */ |
86 | if (BN_is_prime_fasttest(pi, 27, cb, ctx, cb_arg, 1)) | 82 | if (BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb)) |
87 | break; | 83 | break; |
88 | if (!BN_add_word(pi, 2)) | 84 | if (!BN_add_word(pi, 2)) |
89 | return 0; | 85 | return 0; |
90 | } | 86 | } |
91 | if (cb) | 87 | BN_GENCB_call(cb, 2, i); |
92 | cb(2, i, cb_arg); | ||
93 | return 1; | 88 | return 1; |
94 | } | 89 | } |
95 | 90 | ||
@@ -98,10 +93,9 @@ static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx, | |||
98 | * not NULL they will be returned too: this is needed for testing. | 93 | * not NULL they will be returned too: this is needed for testing. |
99 | */ | 94 | */ |
100 | 95 | ||
101 | int BN_X931_derive_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | 96 | int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, |
102 | void (*cb)(int, int, void *), void *cb_arg, | ||
103 | const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2, | 97 | const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2, |
104 | const BIGNUM *e, BN_CTX *ctx) | 98 | const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb) |
105 | { | 99 | { |
106 | int ret = 0; | 100 | int ret = 0; |
107 | 101 | ||
@@ -124,10 +118,10 @@ int BN_X931_derive_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | |||
124 | 118 | ||
125 | pm1 = BN_CTX_get(ctx); | 119 | pm1 = BN_CTX_get(ctx); |
126 | 120 | ||
127 | if (!bn_x931_derive_pi(p1, Xp1, ctx, cb, cb_arg)) | 121 | if (!bn_x931_derive_pi(p1, Xp1, ctx, cb)) |
128 | goto err; | 122 | goto err; |
129 | 123 | ||
130 | if (!bn_x931_derive_pi(p2, Xp2, ctx, cb, cb_arg)) | 124 | if (!bn_x931_derive_pi(p2, Xp2, ctx, cb)) |
131 | goto err; | 125 | goto err; |
132 | 126 | ||
133 | if (!BN_mul(p1p2, p1, p2, ctx)) | 127 | if (!BN_mul(p1p2, p1, p2, ctx)) |
@@ -166,8 +160,7 @@ int BN_X931_derive_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | |||
166 | for (;;) | 160 | for (;;) |
167 | { | 161 | { |
168 | int i = 1; | 162 | int i = 1; |
169 | if (cb) | 163 | BN_GENCB_call(cb, 0, i++); |
170 | cb(0, i++, cb_arg); | ||
171 | if (!BN_copy(pm1, p)) | 164 | if (!BN_copy(pm1, p)) |
172 | goto err; | 165 | goto err; |
173 | if (!BN_sub_word(pm1, 1)) | 166 | if (!BN_sub_word(pm1, 1)) |
@@ -179,14 +172,13 @@ int BN_X931_derive_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | |||
179 | * offering similar or better guarantees 50 MR is considerably | 172 | * offering similar or better guarantees 50 MR is considerably |
180 | * better. | 173 | * better. |
181 | */ | 174 | */ |
182 | && BN_is_prime_fasttest(p, 50, cb, ctx, cb_arg, 1)) | 175 | && BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb)) |
183 | break; | 176 | break; |
184 | if (!BN_add(p, p, p1p2)) | 177 | if (!BN_add(p, p, p1p2)) |
185 | goto err; | 178 | goto err; |
186 | } | 179 | } |
187 | 180 | ||
188 | if (cb) | 181 | BN_GENCB_call(cb, 3, 0); |
189 | cb(3, 0, cb_arg); | ||
190 | 182 | ||
191 | ret = 1; | 183 | ret = 1; |
192 | 184 | ||
@@ -248,11 +240,11 @@ int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) | |||
248 | * are generated using the previous function and supplied as input. | 240 | * are generated using the previous function and supplied as input. |
249 | */ | 241 | */ |
250 | 242 | ||
251 | int BN_X931_generate_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | 243 | int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, |
252 | BIGNUM *Xp1, BIGNUM *Xp2, | 244 | BIGNUM *Xp1, BIGNUM *Xp2, |
253 | const BIGNUM *Xp, | 245 | const BIGNUM *Xp, |
254 | const BIGNUM *e, BN_CTX *ctx, | 246 | const BIGNUM *e, BN_CTX *ctx, |
255 | void (*cb)(int, int, void *), void *cb_arg) | 247 | BN_GENCB *cb) |
256 | { | 248 | { |
257 | int ret = 0; | 249 | int ret = 0; |
258 | 250 | ||
@@ -266,8 +258,7 @@ int BN_X931_generate_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | |||
266 | goto error; | 258 | goto error; |
267 | if (!BN_rand(Xp2, 101, 0, 0)) | 259 | if (!BN_rand(Xp2, 101, 0, 0)) |
268 | goto error; | 260 | goto error; |
269 | if (!BN_X931_derive_prime(p, p1, p2, cb, cb_arg, | 261 | if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb)) |
270 | Xp, Xp1, Xp2, e, ctx)) | ||
271 | goto error; | 262 | goto error; |
272 | 263 | ||
273 | ret = 1; | 264 | ret = 1; |
@@ -279,4 +270,3 @@ int BN_X931_generate_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | |||
279 | 270 | ||
280 | } | 271 | } |
281 | 272 | ||
282 | #endif | ||