From c7ce970002c8f436ef8b85ef87c8efcba426571b Mon Sep 17 00:00:00 2001 From: tb Date: Thu, 3 Aug 2023 18:44:31 +0000 Subject: [PATCH] Retire the bn_rand_interval() test This test was never particularly useful. An upcoming API change for the internal bn_rand_interval() API would require some adjustments. It's not worth it. --- regress/lib/libcrypto/bn/Makefile | 4 +- regress/lib/libcrypto/bn/bn_rand_interval.c | 112 -------------------- 2 files changed, 1 insertion(+), 115 deletions(-) delete mode 100644 regress/lib/libcrypto/bn/bn_rand_interval.c diff --git a/regress/lib/libcrypto/bn/Makefile b/regress/lib/libcrypto/bn/Makefile index 1072f587e7d..8e4c74a129a 100644 --- a/regress/lib/libcrypto/bn/Makefile +++ b/regress/lib/libcrypto/bn/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.34 2023/07/06 15:08:54 tb Exp $ +# $OpenBSD: Makefile,v 1.35 2023/08/03 18:44:31 tb Exp $ PROGS += bn_add_sub PROGS += bn_cmp @@ -13,7 +13,6 @@ PROGS += bn_mont PROGS += bn_mul_div PROGS += bn_primes PROGS += bn_print -PROGS += bn_rand_interval PROGS += bn_shift PROGS += bn_test PROGS += bn_to_string @@ -24,7 +23,6 @@ STATIC_LINK += bn_gcd STATIC_LINK += bn_isqrt STATIC_LINK += bn_mod_exp STATIC_LINK += bn_print -STATIC_LINK += bn_rand_interval STATIC_LINK += bn_test LDADD = -lcrypto diff --git a/regress/lib/libcrypto/bn/bn_rand_interval.c b/regress/lib/libcrypto/bn/bn_rand_interval.c deleted file mode 100644 index 3c5eaac0412..00000000000 --- a/regress/lib/libcrypto/bn/bn_rand_interval.c +++ /dev/null @@ -1,112 +0,0 @@ -/* $OpenBSD: bn_rand_interval.c,v 1.2 2023/03/08 06:44:45 tb Exp $ */ -/* - * Copyright (c) 2018 Theo Buehler - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include - -#include - -#define NUM_TESTS 10000 - -int bn_rand_interval(BIGNUM *rnd, const BIGNUM *lower_incl, - const BIGNUM *upper_excl); -void print_triple(BIGNUM *a, BIGNUM *b, BIGNUM *x); - -void -print_triple(BIGNUM *a, BIGNUM *b, BIGNUM *x) { - if (a != NULL) { - printf("a = "); - BN_print_fp(stdout, a); - printf("\n"); - } - - if (b != NULL) { - printf("b = "); - BN_print_fp(stdout, b); - printf("\n"); - } - - if (x != NULL) { - printf("x = "); - BN_print_fp(stdout, x); - printf("\n"); - } -} - -int -main(int argc, char *argv[]) -{ - BIGNUM *a, *b, *x; - int i, success = 1; - - if ((a = BN_new()) == NULL) - errx(1, "BN_new(a)"); - if ((b = BN_new()) == NULL) - errx(1, "BN_new(b)"); - if ((x = BN_new()) == NULL) - errx(1, "BN_new(c)"); - - for (i = 0; i < NUM_TESTS; i++) { - if (!BN_rand(a, 256, 0, 0)) - errx(1, "BN_rand(a)"); - - if (bn_rand_interval(x, a, a) != 0) { - success = 0; - - printf("bn_rand_interval(a == a) succeeded\n"); - print_triple(a, NULL, x); - } - - if (!BN_rand(b, 256, 0, 0)) - errx(1, "BN_rand(b)"); - - switch(BN_cmp(a, b)) { - case 0: /* a == b */ - continue; - - case 1: /* a > b */ - BN_swap(a, b); - break; - - default: /* a < b */ - break; - } - - if (!bn_rand_interval(x, a, b)) - errx(1, "bn_rand_interval() failed"); - - if (BN_cmp(x, a) < 0 || BN_cmp(x, b) >= 0) { - success = 0; - - printf("generated number x not inside [a,b)\n"); - print_triple(a, b, x); - } - - if (bn_rand_interval(x, b, a) != 0) { - success = 0; - - printf("bn_rand_interval(x, b, a) succeeded\n"); - print_triple(a, b, x); - } - } - - BN_free(a); - BN_free(b); - BN_free(x); - - return 1 - success; -} -- 2.20.1