diff options
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libcrypto/bn/general/Makefile | 23 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/bn/general/bn_to_string.c | 116 |
2 files changed, 133 insertions, 6 deletions
diff --git a/src/regress/lib/libcrypto/bn/general/Makefile b/src/regress/lib/libcrypto/bn/general/Makefile index d578d0fe12..d1a73a3769 100644 --- a/src/regress/lib/libcrypto/bn/general/Makefile +++ b/src/regress/lib/libcrypto/bn/general/Makefile | |||
| @@ -1,11 +1,22 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2017/01/21 09:38:58 beck Exp $ | 1 | # $OpenBSD: Makefile,v 1.5 2019/04/13 22:06:31 tb Exp $ |
| 2 | 2 | ||
| 3 | .include "../../Makefile.inc" | 3 | .include "../../Makefile.inc" |
| 4 | 4 | ||
| 5 | PROG= bntest | 5 | PROGS += bntest |
| 6 | LDADD= ${CRYPTO_INT} | 6 | PROGS += bn_to_string |
| 7 | DPADD= ${LIBCRYPTO} | 7 | |
| 8 | WARNINGS= Yes | 8 | LDADD = ${CRYPTO_INT} |
| 9 | CFLAGS+= -Werror | 9 | DPADD = ${LIBCRYPTO} |
| 10 | WARNINGS = Yes | ||
| 11 | CFLAGS += -Werror | ||
| 12 | |||
| 13 | .for p in ${PROGS} | ||
| 14 | REGRESS_TARGETS += run-$p | ||
| 15 | |||
| 16 | run-$p: $p | ||
| 17 | ./$p | ||
| 18 | |||
| 19 | .PHONY: run-$p | ||
| 20 | .endfor | ||
| 10 | 21 | ||
| 11 | .include <bsd.regress.mk> | 22 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libcrypto/bn/general/bn_to_string.c b/src/regress/lib/libcrypto/bn/general/bn_to_string.c new file mode 100644 index 0000000000..60b3ea3137 --- /dev/null +++ b/src/regress/lib/libcrypto/bn/general/bn_to_string.c | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* $OpenBSD: bn_to_string.c,v 1.1 2019/04/13 22:06:31 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2019 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 | #include <string.h> | ||
| 21 | |||
| 22 | #include <openssl/bn.h> | ||
| 23 | |||
| 24 | char *bn_to_string(const BIGNUM *bn); | ||
| 25 | |||
| 26 | struct convert_st { | ||
| 27 | const char *input; | ||
| 28 | const char *expected; | ||
| 29 | }; | ||
| 30 | |||
| 31 | struct convert_st testcases[] = { | ||
| 32 | {"0", "0"}, | ||
| 33 | {"-0", "-0"}, | ||
| 34 | {"7", "7"}, | ||
| 35 | {"-7", "-7"}, | ||
| 36 | {"8", "8"}, | ||
| 37 | {"-8", "-8"}, | ||
| 38 | {"F", "15"}, | ||
| 39 | {"-F", "-15"}, | ||
| 40 | {"10", "16"}, | ||
| 41 | {"-10", "-16"}, | ||
| 42 | {"7F", "127"}, | ||
| 43 | {"-7F", "-127"}, | ||
| 44 | {"80", "128"}, | ||
| 45 | {"-80", "-128"}, | ||
| 46 | {"FF", "255"}, | ||
| 47 | {"-FF", "-255"}, | ||
| 48 | {"100", "256"}, | ||
| 49 | {"7FFF", "32767"}, | ||
| 50 | {"-7FFF", "-32767"}, | ||
| 51 | {"8000", "32768"}, | ||
| 52 | {"-8000", "-32768"}, | ||
| 53 | {"FFFF", "65535"}, | ||
| 54 | {"-FFFF", "-65535"}, | ||
| 55 | {"10000", "65536"}, | ||
| 56 | {"-10000", "-65536"}, | ||
| 57 | {"7FFFFFFF", "2147483647"}, | ||
| 58 | {"-7FFFFFFF", "-2147483647"}, | ||
| 59 | {"80000000", "2147483648"}, | ||
| 60 | {"-80000000", "-2147483648"}, | ||
| 61 | {"FFFFFFFF", "4294967295"}, | ||
| 62 | {"-FFFFFFFF", "-4294967295"}, | ||
| 63 | {"100000000", "4294967296"}, | ||
| 64 | {"-100000000", "-4294967296"}, | ||
| 65 | {"7FFFFFFFFFFFFFFF", "9223372036854775807"}, | ||
| 66 | {"-7FFFFFFFFFFFFFFF", "-9223372036854775807"}, | ||
| 67 | {"8000000000000000", "9223372036854775808"}, | ||
| 68 | {"-8000000000000000", "-9223372036854775808"}, | ||
| 69 | {"FFFFFFFFFFFFFFFF", "18446744073709551615"}, | ||
| 70 | {"-FFFFFFFFFFFFFFFF", "-18446744073709551615"}, | ||
| 71 | {"10000000000000000", "18446744073709551616"}, | ||
| 72 | {"-10000000000000000", "-18446744073709551616"}, | ||
| 73 | {"7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | ||
| 74 | "170141183460469231731687303715884105727"}, | ||
| 75 | {"-7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | ||
| 76 | "-170141183460469231731687303715884105727"}, | ||
| 77 | {"80000000000000000000000000000000", | ||
| 78 | "0x80000000000000000000000000000000"}, | ||
| 79 | {"-80000000000000000000000000000000", | ||
| 80 | "-0x80000000000000000000000000000000"}, | ||
| 81 | {"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | ||
| 82 | "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"}, | ||
| 83 | {"-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | ||
| 84 | "-0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"}, | ||
| 85 | {"100000000000000000000000000000000", | ||
| 86 | "0x0100000000000000000000000000000000"}, | ||
| 87 | {"-100000000000000000000000000000000", | ||
| 88 | "-0x0100000000000000000000000000000000"}, | ||
| 89 | { NULL, NULL }, | ||
| 90 | }; | ||
| 91 | |||
| 92 | int | ||
| 93 | main(int argc, char *argv[]) | ||
| 94 | { | ||
| 95 | struct convert_st *test; | ||
| 96 | BIGNUM *bn = NULL; | ||
| 97 | char *bnstr; | ||
| 98 | int failed = 0; | ||
| 99 | |||
| 100 | for (test = testcases; test->input != NULL; test++) { | ||
| 101 | if (!BN_hex2bn(&bn, test->input)) | ||
| 102 | errx(1, "BN_hex2bn(%s)", test->input); | ||
| 103 | if ((bnstr = bn_to_string(bn)) == NULL) | ||
| 104 | errx(1, "bn_to_string(%s)", test->input); | ||
| 105 | if (strcmp(bnstr, test->expected) != 0) { | ||
| 106 | warnx("%s != %s", bnstr, test->expected); | ||
| 107 | failed = 1; | ||
| 108 | } | ||
| 109 | free(bnstr); | ||
| 110 | } | ||
| 111 | |||
| 112 | BN_free(bn); | ||
| 113 | |||
| 114 | printf("%s\n", failed ? "FAILED" : "SUCCESS"); | ||
| 115 | return failed; | ||
| 116 | } | ||
