diff options
Diffstat (limited to 'src/regress/lib')
| -rw-r--r-- | src/regress/lib/libcrypto/bn/general/Makefile | 8 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/bn/general/bn_unit.c | 88 |
2 files changed, 95 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/bn/general/Makefile b/src/regress/lib/libcrypto/bn/general/Makefile index b9282a1126..22f3e3f95f 100644 --- a/src/regress/lib/libcrypto/bn/general/Makefile +++ b/src/regress/lib/libcrypto/bn/general/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.15 2022/11/09 23:28:08 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.16 2022/11/22 08:56:33 tb Exp $ |
| 2 | 2 | ||
| 3 | .include "../../Makefile.inc" | 3 | .include "../../Makefile.inc" |
| 4 | 4 | ||
| @@ -8,6 +8,7 @@ PROGS += bn_mod_exp2_mont | |||
| 8 | PROGS += bn_mod_sqrt | 8 | PROGS += bn_mod_sqrt |
| 9 | PROGS += bn_primes | 9 | PROGS += bn_primes |
| 10 | PROGS += bn_to_string | 10 | PROGS += bn_to_string |
| 11 | PROGS += bn_unit | ||
| 11 | 12 | ||
| 12 | DPADD += ${LIBCRYPTO} | 13 | DPADD += ${LIBCRYPTO} |
| 13 | LDFLAGS += -lcrypto | 14 | LDFLAGS += -lcrypto |
| @@ -44,6 +45,11 @@ REGRESS_TARGETS += run-bn_to_string | |||
| 44 | run-bn_to_string: bn_to_string | 45 | run-bn_to_string: bn_to_string |
| 45 | ./bn_to_string | 46 | ./bn_to_string |
| 46 | 47 | ||
| 48 | REGRESS_TARGETS += run-bn_unit | ||
| 49 | run-bn_unit: bn_unit | ||
| 50 | ./bn_unit | ||
| 51 | |||
| 52 | |||
| 47 | LDADD_bn_isqrt = ${CRYPTO_INT} | 53 | LDADD_bn_isqrt = ${CRYPTO_INT} |
| 48 | REGRESS_TARGETS += run-bn_isqrt | 54 | REGRESS_TARGETS += run-bn_isqrt |
| 49 | run-bn_isqrt: bn_isqrt | 55 | run-bn_isqrt: bn_isqrt |
diff --git a/src/regress/lib/libcrypto/bn/general/bn_unit.c b/src/regress/lib/libcrypto/bn/general/bn_unit.c new file mode 100644 index 0000000000..fefbded107 --- /dev/null +++ b/src/regress/lib/libcrypto/bn/general/bn_unit.c | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /* $OpenBSD: bn_unit.c,v 1.1 2022/11/22 08:56:33 tb Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <sys/resource.h> | ||
| 20 | |||
| 21 | #include <err.h> | ||
| 22 | #include <limits.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <string.h> | ||
| 25 | |||
| 26 | #include <openssl/bn.h> | ||
| 27 | |||
| 28 | static int | ||
| 29 | test_bn_print_wrapper(char *a, size_t size, const char *descr, | ||
| 30 | int (*to_bn)(BIGNUM **, const char *)) | ||
| 31 | { | ||
| 32 | int ret; | ||
| 33 | |||
| 34 | ret = to_bn(NULL, a); | ||
| 35 | if (ret != 0 && (ret < 0 || (size_t)ret != size - 1)) { | ||
| 36 | fprintf(stderr, "unexpected %s() return" | ||
| 37 | "want 0 or %zu, got %d\n", descr, size - 1, ret); | ||
| 38 | return 1; | ||
| 39 | } | ||
| 40 | |||
| 41 | return 0; | ||
| 42 | } | ||
| 43 | |||
| 44 | static int | ||
| 45 | test_bn_print_null_derefs(void) | ||
| 46 | { | ||
| 47 | struct rlimit rlimit; | ||
| 48 | size_t size = INT_MAX / 4 + 4; | ||
| 49 | size_t datalimit = (size + 500 * 1024) / 1024; | ||
| 50 | char *a; | ||
| 51 | int failed = 0; | ||
| 52 | |||
| 53 | if (getrlimit(RLIMIT_DATA, &rlimit) != 0) | ||
| 54 | err(1, "getrlimit"); | ||
| 55 | |||
| 56 | if ((rlimit.rlim_cur + 1023) / 1024 < datalimit) { | ||
| 57 | printf("%s: Insufficient data limit\n", __func__); | ||
| 58 | printf("Need more than %zu kB\n", datalimit); | ||
| 59 | printf("SKIPPED\n"); | ||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | if ((a = malloc(size)) == NULL) | ||
| 64 | err(1, "malloc(%zu) failed", size); | ||
| 65 | |||
| 66 | memset(a, '0', size - 1); | ||
| 67 | a[size - 1] = '\0'; | ||
| 68 | |||
| 69 | failed |= test_bn_print_wrapper(a, size, "BN_dec2bn", BN_dec2bn); | ||
| 70 | failed |= test_bn_print_wrapper(a, size, "BN_hex2bn", BN_hex2bn); | ||
| 71 | |||
| 72 | free(a); | ||
| 73 | |||
| 74 | return failed; | ||
| 75 | } | ||
| 76 | |||
| 77 | int | ||
| 78 | main(void) | ||
| 79 | { | ||
| 80 | int failed = 0; | ||
| 81 | |||
| 82 | failed |= test_bn_print_null_derefs(); | ||
| 83 | |||
| 84 | if (!failed) | ||
| 85 | printf("SUCCESS\n"); | ||
| 86 | |||
| 87 | return failed; | ||
| 88 | } | ||
