summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_prime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_prime.c')
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
index f5e4597f9b..a4b50eb3fc 100644
--- a/src/lib/libcrypto/bn/bn_prime.c
+++ b/src/lib/libcrypto/bn/bn_prime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_prime.c,v 1.28 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: bn_prime.c,v 1.29 2023/01/28 17:09:00 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -156,6 +156,35 @@ BN_GENCB_call(BN_GENCB *cb, int a, int b)
156 return 0; 156 return 0;
157} 157}
158 158
159#ifndef OPENSSL_NO_DEPRECATED
160BIGNUM *
161BN_generate_prime(BIGNUM *ret, int bits, int safe, const BIGNUM *add,
162 const BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg)
163{
164 BN_GENCB cb;
165 BIGNUM *rnd = NULL;
166 int found = 0;
167
168 BN_GENCB_set_old(&cb, callback, cb_arg);
169
170 if (ret == NULL) {
171 if ((rnd = BN_new()) == NULL)
172 goto err;
173 } else
174 rnd = ret;
175 if (!BN_generate_prime_ex(rnd, bits, safe, add, rem, &cb))
176 goto err;
177
178 /* we have a prime :-) */
179 found = 1;
180
181err:
182 if (!found && (ret == NULL) && (rnd != NULL))
183 BN_free(rnd);
184 return (found ? rnd : NULL);
185}
186#endif
187
159int 188int
160BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, 189BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add,
161 const BIGNUM *rem, BN_GENCB *cb) 190 const BIGNUM *rem, BN_GENCB *cb)
@@ -236,12 +265,38 @@ BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add,
236 return found; 265 return found;
237} 266}
238 267
268#ifndef OPENSSL_NO_DEPRECATED
269int
270BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int, int, void *),
271 BN_CTX *ctx_passed, void *cb_arg)
272{
273 BN_GENCB cb;
274
275 BN_GENCB_set_old(&cb, callback, cb_arg);
276 return BN_is_prime_ex(a, checks, ctx_passed, &cb);
277}
278#endif
279
239int 280int
240BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, BN_GENCB *cb) 281BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, BN_GENCB *cb)
241{ 282{
242 return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb); 283 return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);
243} 284}
244 285
286#ifndef OPENSSL_NO_DEPRECATED
287int
288BN_is_prime_fasttest(const BIGNUM *a, int checks,
289 void (*callback)(int, int, void *), BN_CTX *ctx_passed, void *cb_arg,
290 int do_trial_division)
291{
292 BN_GENCB cb;
293
294 BN_GENCB_set_old(&cb, callback, cb_arg);
295 return BN_is_prime_fasttest_ex(a, checks, ctx_passed,
296 do_trial_division, &cb);
297}
298#endif
299
245int 300int
246BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, 301BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
247 int do_trial_division, BN_GENCB *cb) 302 int do_trial_division, BN_GENCB *cb)