diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/bn/Makefile | 4 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/bn/bn_rand_interval.c | 112 |
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 | ||
| 3 | PROGS += bn_add_sub | 3 | PROGS += bn_add_sub |
| 4 | PROGS += bn_cmp | 4 | PROGS += bn_cmp |
| @@ -13,7 +13,6 @@ PROGS += bn_mont | |||
| 13 | PROGS += bn_mul_div | 13 | PROGS += bn_mul_div |
| 14 | PROGS += bn_primes | 14 | PROGS += bn_primes |
| 15 | PROGS += bn_print | 15 | PROGS += bn_print |
| 16 | PROGS += bn_rand_interval | ||
| 17 | PROGS += bn_shift | 16 | PROGS += bn_shift |
| 18 | PROGS += bn_test | 17 | PROGS += bn_test |
| 19 | PROGS += bn_to_string | 18 | PROGS += bn_to_string |
| @@ -24,7 +23,6 @@ STATIC_LINK += bn_gcd | |||
| 24 | STATIC_LINK += bn_isqrt | 23 | STATIC_LINK += bn_isqrt |
| 25 | STATIC_LINK += bn_mod_exp | 24 | STATIC_LINK += bn_mod_exp |
| 26 | STATIC_LINK += bn_print | 25 | STATIC_LINK += bn_print |
| 27 | STATIC_LINK += bn_rand_interval | ||
| 28 | STATIC_LINK += bn_test | 26 | STATIC_LINK += bn_test |
| 29 | 27 | ||
| 30 | LDADD = -lcrypto | 28 | LDADD = -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 | |||
| 25 | int bn_rand_interval(BIGNUM *rnd, const BIGNUM *lower_incl, | ||
| 26 | const BIGNUM *upper_excl); | ||
| 27 | void print_triple(BIGNUM *a, BIGNUM *b, BIGNUM *x); | ||
| 28 | |||
| 29 | void | ||
| 30 | print_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 | |||
| 50 | int | ||
| 51 | main(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 | } | ||
