summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-08-03 18:44:31 +0000
committertb <>2023-08-03 18:44:31 +0000
commit9110c93cd11bc18d800c645352c10a57e2ceea4b (patch)
tree5ef1da120da2942989f7bf5b684d6770349c0b32 /src
parent504c970f7055d5e4ff8638f6f4d62fd73e175d4b (diff)
downloadopenbsd-9110c93cd11bc18d800c645352c10a57e2ceea4b.tar.gz
openbsd-9110c93cd11bc18d800c645352c10a57e2ceea4b.tar.bz2
openbsd-9110c93cd11bc18d800c645352c10a57e2ceea4b.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/bn/Makefile4
-rw-r--r--src/regress/lib/libcrypto/bn/bn_rand_interval.c112
2 files changed, 1 insertions, 115 deletions
diff --git a/src/regress/lib/libcrypto/bn/Makefile b/src/regress/lib/libcrypto/bn/Makefile
index 1072f587e7..8e4c74a129 100644
--- a/src/regress/lib/libcrypto/bn/Makefile
+++ b/src/regress/lib/libcrypto/bn/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.34 2023/07/06 15:08:54 tb Exp $ 1# $OpenBSD: Makefile,v 1.35 2023/08/03 18:44:31 tb Exp $
2 2
3PROGS += bn_add_sub 3PROGS += bn_add_sub
4PROGS += bn_cmp 4PROGS += bn_cmp
@@ -13,7 +13,6 @@ PROGS += bn_mont
13PROGS += bn_mul_div 13PROGS += bn_mul_div
14PROGS += bn_primes 14PROGS += bn_primes
15PROGS += bn_print 15PROGS += bn_print
16PROGS += bn_rand_interval
17PROGS += bn_shift 16PROGS += bn_shift
18PROGS += bn_test 17PROGS += bn_test
19PROGS += bn_to_string 18PROGS += bn_to_string
@@ -24,7 +23,6 @@ STATIC_LINK += bn_gcd
24STATIC_LINK += bn_isqrt 23STATIC_LINK += bn_isqrt
25STATIC_LINK += bn_mod_exp 24STATIC_LINK += bn_mod_exp
26STATIC_LINK += bn_print 25STATIC_LINK += bn_print
27STATIC_LINK += bn_rand_interval
28STATIC_LINK += bn_test 26STATIC_LINK += bn_test
29 27
30LDADD = -lcrypto 28LDADD = -lcrypto
diff --git a/src/regress/lib/libcrypto/bn/bn_rand_interval.c b/src/regress/lib/libcrypto/bn/bn_rand_interval.c
deleted file mode 100644
index 3c5eaac041..0000000000
--- a/src/regress/lib/libcrypto/bn/bn_rand_interval.c
+++ /dev/null
@@ -1,112 +0,0 @@
1/* $OpenBSD: bn_rand_interval.c,v 1.2 2023/03/08 06:44:45 tb Exp $ */
2/*
3 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <err.h>
19#include <stdio.h>
20
21#include <openssl/bn.h>
22
23#define NUM_TESTS 10000
24
25int bn_rand_interval(BIGNUM *rnd, const BIGNUM *lower_incl,
26 const BIGNUM *upper_excl);
27void print_triple(BIGNUM *a, BIGNUM *b, BIGNUM *x);
28
29void
30print_triple(BIGNUM *a, BIGNUM *b, BIGNUM *x) {
31 if (a != NULL) {
32 printf("a = ");
33 BN_print_fp(stdout, a);
34 printf("\n");
35 }
36
37 if (b != NULL) {
38 printf("b = ");
39 BN_print_fp(stdout, b);
40 printf("\n");
41 }
42
43 if (x != NULL) {
44 printf("x = ");
45 BN_print_fp(stdout, x);
46 printf("\n");
47 }
48}
49
50int
51main(int argc, char *argv[])
52{
53 BIGNUM *a, *b, *x;
54 int i, success = 1;
55
56 if ((a = BN_new()) == NULL)
57 errx(1, "BN_new(a)");
58 if ((b = BN_new()) == NULL)
59 errx(1, "BN_new(b)");
60 if ((x = BN_new()) == NULL)
61 errx(1, "BN_new(c)");
62
63 for (i = 0; i < NUM_TESTS; i++) {
64 if (!BN_rand(a, 256, 0, 0))
65 errx(1, "BN_rand(a)");
66
67 if (bn_rand_interval(x, a, a) != 0) {
68 success = 0;
69
70 printf("bn_rand_interval(a == a) succeeded\n");
71 print_triple(a, NULL, x);
72 }
73
74 if (!BN_rand(b, 256, 0, 0))
75 errx(1, "BN_rand(b)");
76
77 switch(BN_cmp(a, b)) {
78 case 0: /* a == b */
79 continue;
80
81 case 1: /* a > b */
82 BN_swap(a, b);
83 break;
84
85 default: /* a < b */
86 break;
87 }
88
89 if (!bn_rand_interval(x, a, b))
90 errx(1, "bn_rand_interval() failed");
91
92 if (BN_cmp(x, a) < 0 || BN_cmp(x, b) >= 0) {
93 success = 0;
94
95 printf("generated number x not inside [a,b)\n");
96 print_triple(a, b, x);
97 }
98
99 if (bn_rand_interval(x, b, a) != 0) {
100 success = 0;
101
102 printf("bn_rand_interval(x, b, a) succeeded\n");
103 print_triple(a, b, x);
104 }
105 }
106
107 BN_free(a);
108 BN_free(b);
109 BN_free(x);
110
111 return 1 - success;
112}