From: jsing Date: Sat, 28 Jan 2023 17:09:00 +0000 (+0000) Subject: Move the three functions that are in bn_depr.c back to bn_prime.c. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f8cd819d9d7613c38b47003e22a6db9d8911348f;p=openbsd Move the three functions that are in bn_depr.c back to bn_prime.c. They should go away, but they have not yet disappeared and this consolidates the source files. Discussed with tb@ --- diff --git a/lib/libcrypto/bn/bn_depr.c b/lib/libcrypto/bn/bn_depr.c index 0e9f6225866..f8b01b7bf6a 100644 --- a/lib/libcrypto/bn/bn_depr.c +++ b/lib/libcrypto/bn/bn_depr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_depr.c,v 1.8 2022/11/26 16:08:51 tb Exp $ */ +/* $OpenBSD: bn_depr.c,v 1.9 2023/01/28 17:09:00 jsing Exp $ */ /* ==================================================================== * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. * @@ -62,54 +62,3 @@ #include #include "bn_local.h" - -#ifndef OPENSSL_NO_DEPRECATED -BIGNUM * -BN_generate_prime(BIGNUM *ret, int bits, int safe, const BIGNUM *add, - const BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg) -{ - BN_GENCB cb; - BIGNUM *rnd = NULL; - int found = 0; - - BN_GENCB_set_old(&cb, callback, cb_arg); - - if (ret == NULL) { - if ((rnd = BN_new()) == NULL) - goto err; - } else - rnd = ret; - if (!BN_generate_prime_ex(rnd, bits, safe, add, rem, &cb)) - goto err; - - /* we have a prime :-) */ - found = 1; - -err: - if (!found && (ret == NULL) && (rnd != NULL)) - BN_free(rnd); - return (found ? rnd : NULL); -} - -int -BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int, int, void *), - BN_CTX *ctx_passed, void *cb_arg) -{ - BN_GENCB cb; - - BN_GENCB_set_old(&cb, callback, cb_arg); - return BN_is_prime_ex(a, checks, ctx_passed, &cb); -} - -int -BN_is_prime_fasttest(const BIGNUM *a, int checks, - void (*callback)(int, int, void *), BN_CTX *ctx_passed, void *cb_arg, - int do_trial_division) -{ - BN_GENCB cb; - - BN_GENCB_set_old(&cb, callback, cb_arg); - return BN_is_prime_fasttest_ex(a, checks, ctx_passed, - do_trial_division, &cb); -} -#endif diff --git a/lib/libcrypto/bn/bn_prime.c b/lib/libcrypto/bn/bn_prime.c index f5e4597f9ba..a4b50eb3fcc 100644 --- a/lib/libcrypto/bn/bn_prime.c +++ b/lib/libcrypto/bn/bn_prime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_prime.c,v 1.28 2022/11/26 16:08:51 tb Exp $ */ +/* $OpenBSD: bn_prime.c,v 1.29 2023/01/28 17:09:00 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -156,6 +156,35 @@ BN_GENCB_call(BN_GENCB *cb, int a, int b) return 0; } +#ifndef OPENSSL_NO_DEPRECATED +BIGNUM * +BN_generate_prime(BIGNUM *ret, int bits, int safe, const BIGNUM *add, + const BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg) +{ + BN_GENCB cb; + BIGNUM *rnd = NULL; + int found = 0; + + BN_GENCB_set_old(&cb, callback, cb_arg); + + if (ret == NULL) { + if ((rnd = BN_new()) == NULL) + goto err; + } else + rnd = ret; + if (!BN_generate_prime_ex(rnd, bits, safe, add, rem, &cb)) + goto err; + + /* we have a prime :-) */ + found = 1; + +err: + if (!found && (ret == NULL) && (rnd != NULL)) + BN_free(rnd); + return (found ? rnd : NULL); +} +#endif + int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb) @@ -236,12 +265,38 @@ BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, return found; } +#ifndef OPENSSL_NO_DEPRECATED +int +BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int, int, void *), + BN_CTX *ctx_passed, void *cb_arg) +{ + BN_GENCB cb; + + BN_GENCB_set_old(&cb, callback, cb_arg); + return BN_is_prime_ex(a, checks, ctx_passed, &cb); +} +#endif + int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, BN_GENCB *cb) { return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb); } +#ifndef OPENSSL_NO_DEPRECATED +int +BN_is_prime_fasttest(const BIGNUM *a, int checks, + void (*callback)(int, int, void *), BN_CTX *ctx_passed, void *cb_arg, + int do_trial_division) +{ + BN_GENCB cb; + + BN_GENCB_set_old(&cb, callback, cb_arg); + return BN_is_prime_fasttest_ex(a, checks, ctx_passed, + do_trial_division, &cb); +} +#endif + int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, int do_trial_division, BN_GENCB *cb)