diff options
author | tb <> | 2022-12-01 20:50:10 +0000 |
---|---|---|
committer | tb <> | 2022-12-01 20:50:10 +0000 |
commit | 1ee4f78484654f244b792d02de8a59790eaa8d57 (patch) | |
tree | 9c919d8b5975d41dccaa87e47c91d601f9dd9857 /src/regress/lib/libcrypto/bn/bn_to_string.c | |
parent | 27a426a371fafd6a5de905f5335425a4f20844fb (diff) | |
download | openbsd-1ee4f78484654f244b792d02de8a59790eaa8d57.tar.gz openbsd-1ee4f78484654f244b792d02de8a59790eaa8d57.tar.bz2 openbsd-1ee4f78484654f244b792d02de8a59790eaa8d57.zip |
Flatten structure of libcrypto/bn tests
The bn tests were distributed into three subdirectories rather randomly.
It's cleaner and easier to maintain if all this is in a single directory.
Use consistent names for the .c files, unify handling of the tests with
the exception of bn_test, which is special.
Discussed with jsing
Diffstat (limited to 'src/regress/lib/libcrypto/bn/bn_to_string.c')
-rw-r--r-- | src/regress/lib/libcrypto/bn/bn_to_string.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_to_string.c b/src/regress/lib/libcrypto/bn/bn_to_string.c new file mode 100644 index 0000000000..ca5ca2f08d --- /dev/null +++ b/src/regress/lib/libcrypto/bn/bn_to_string.c | |||
@@ -0,0 +1,115 @@ | |||
1 | /* $OpenBSD: bn_to_string.c,v 1.1 2022/12/01 20:50:10 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 | return failed; | ||
115 | } | ||