summaryrefslogtreecommitdiff
path: root/regress/lib/libcrypto
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2018-11-06 13:17:43 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2018-11-06 13:17:43 +0000
commitce79af513bef1298c5c0072990f7b30a7abc9198 (patch)
treecb19471c043a6b2145bf00ced04f7ead22e89ddb /regress/lib/libcrypto
parentb83bf81f4f0ac060a34dca8fa9c32a3a89617777 (diff)
better failure printing, add more checks
Diffstat (limited to 'regress/lib/libcrypto')
-rw-r--r--regress/lib/libcrypto/bn/rand/bn_rand_interval.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/regress/lib/libcrypto/bn/rand/bn_rand_interval.c b/regress/lib/libcrypto/bn/rand/bn_rand_interval.c
index 57c55f04963..09b1a34eea5 100644
--- a/regress/lib/libcrypto/bn/rand/bn_rand_interval.c
+++ b/regress/lib/libcrypto/bn/rand/bn_rand_interval.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn_rand_interval.c,v 1.1 2018/11/06 06:55:27 tb Exp $ */
+/* $OpenBSD: bn_rand_interval.c,v 1.2 2018/11/06 13:17:42 tb Exp $ */
/*
* Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
*
@@ -24,7 +24,28 @@
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[])
@@ -45,7 +66,9 @@ main(int argc, char *argv[])
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))
@@ -67,14 +90,17 @@ main(int argc, char *argv[])
err(1, "bn_rand_interval() failed");
if (BN_cmp(x, a) < 0 || BN_cmp(x, b) >= 0) {
- printf("generated number xnot inside [a,b)\n");
- printf("a = ");
- BN_print_fp(stdout, a);
- printf("\nb = ");
- BN_print_fp(stdout, b);
- printf("\nx = ");
- BN_print_fp(stdout, x);
- printf("\n");
+ 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);
}
}