summaryrefslogtreecommitdiff
path: root/src/regress/lib/libcrypto/bn/rand
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libcrypto/bn/rand')
-rw-r--r--src/regress/lib/libcrypto/bn/rand/Makefile11
-rw-r--r--src/regress/lib/libcrypto/bn/rand/bn_rand_interval.c117
2 files changed, 0 insertions, 128 deletions
diff --git a/src/regress/lib/libcrypto/bn/rand/Makefile b/src/regress/lib/libcrypto/bn/rand/Makefile
deleted file mode 100644
index 52d0835df4..0000000000
--- a/src/regress/lib/libcrypto/bn/rand/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
1# $OpenBSD: Makefile,v 1.1 2018/11/06 06:55:27 tb Exp $
2
3.include "../../Makefile.inc"
4
5PROG= bn_rand_interval
6LDADD= ${CRYPTO_INT}
7DPADD= ${LIBCRYPTO}
8WARNINGS= Yes
9CFLAGS+= -Werror
10
11.include <bsd.regress.mk>
diff --git a/src/regress/lib/libcrypto/bn/rand/bn_rand_interval.c b/src/regress/lib/libcrypto/bn/rand/bn_rand_interval.c
deleted file mode 100644
index b8b84bd8cc..0000000000
--- a/src/regress/lib/libcrypto/bn/rand/bn_rand_interval.c
+++ /dev/null
@@ -1,117 +0,0 @@
1/* $OpenBSD: bn_rand_interval.c,v 1.3 2018/11/10 01:39:35 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 1000000
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 err(1, "BN_new(a)");
58 if ((b = BN_new()) == NULL)
59 err(1, "BN_new(b)");
60 if ((x = BN_new()) == NULL)
61 err(1, "BN_new(c)");
62
63 for (i = 0; i < NUM_TESTS; i++) {
64 if (!BN_rand(a, 256, 0, 0))
65 err(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 err(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 err(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 if (success == 1)
108 printf("success\n");
109 else
110 printf("FAIL");
111
112 BN_free(a);
113 BN_free(b);
114 BN_free(x);
115
116 return 1 - success;
117}