xcrypt 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +106 -0
- data/ext/libxcrypt/AUTHORS +38 -0
- data/ext/libxcrypt/COPYING.LIB +502 -0
- data/ext/libxcrypt/ChangeLog +239 -0
- data/ext/libxcrypt/INSTALL +380 -0
- data/ext/libxcrypt/LICENSING +152 -0
- data/ext/libxcrypt/Makefile.am +704 -0
- data/ext/libxcrypt/Makefile.in +4110 -0
- data/ext/libxcrypt/NEWS +630 -0
- data/ext/libxcrypt/README +1 -0
- data/ext/libxcrypt/README.md +179 -0
- data/ext/libxcrypt/THANKS +13 -0
- data/ext/libxcrypt/TODO +1 -0
- data/ext/libxcrypt/TODO.md +100 -0
- data/ext/libxcrypt/aclocal.m4 +2617 -0
- data/ext/libxcrypt/autogen.sh +33 -0
- data/ext/libxcrypt/autom4te.cache/output.0 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.1 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.2 +19884 -0
- data/ext/libxcrypt/autom4te.cache/output.3 +19885 -0
- data/ext/libxcrypt/autom4te.cache/requests +714 -0
- data/ext/libxcrypt/autom4te.cache/traces.0 +4088 -0
- data/ext/libxcrypt/autom4te.cache/traces.1 +1060 -0
- data/ext/libxcrypt/autom4te.cache/traces.2 +4088 -0
- data/ext/libxcrypt/autom4te.cache/traces.3 +1060 -0
- data/ext/libxcrypt/build-aux/ci/ci-log-dependency-versions +79 -0
- data/ext/libxcrypt/build-aux/ci/ci-log-logfiles +22 -0
- data/ext/libxcrypt/build-aux/ci/clang-gcov-wrapper +2 -0
- data/ext/libxcrypt/build-aux/ci/configure-wrapper +10 -0
- data/ext/libxcrypt/build-aux/ci/summarize-coverage +24 -0
- data/ext/libxcrypt/build-aux/m4/ax_append_compile_flags.m4 +46 -0
- data/ext/libxcrypt/build-aux/m4/ax_append_flag.m4 +50 -0
- data/ext/libxcrypt/build-aux/m4/ax_check_compile_flag.m4 +53 -0
- data/ext/libxcrypt/build-aux/m4/ax_check_vscript.m4 +142 -0
- data/ext/libxcrypt/build-aux/m4/ax_gcc_func_attribute.m4 +246 -0
- data/ext/libxcrypt/build-aux/m4/ax_require_defined.m4 +37 -0
- data/ext/libxcrypt/build-aux/m4/ax_valgrind_check.m4 +239 -0
- data/ext/libxcrypt/build-aux/m4/libtool.m4 +8488 -0
- data/ext/libxcrypt/build-aux/m4/ltoptions.m4 +467 -0
- data/ext/libxcrypt/build-aux/m4/ltsugar.m4 +124 -0
- data/ext/libxcrypt/build-aux/m4/ltversion.m4 +24 -0
- data/ext/libxcrypt/build-aux/m4/lt~obsolete.m4 +99 -0
- data/ext/libxcrypt/build-aux/m4/pkg_compat.m4 +88 -0
- data/ext/libxcrypt/build-aux/m4/zw_alignment.m4 +90 -0
- data/ext/libxcrypt/build-aux/m4/zw_automodern.m4 +307 -0
- data/ext/libxcrypt/build-aux/m4/zw_detect_asan.m4 +24 -0
- data/ext/libxcrypt/build-aux/m4/zw_endianness.m4 +152 -0
- data/ext/libxcrypt/build-aux/m4/zw_ld_wrap.m4 +47 -0
- data/ext/libxcrypt/build-aux/m4/zw_prog_perl.m4 +40 -0
- data/ext/libxcrypt/build-aux/m4/zw_simple_warnings.m4 +150 -0
- data/ext/libxcrypt/build-aux/m4/zw_static_assert.m4 +68 -0
- data/ext/libxcrypt/build-aux/m4-autogen/compile +364 -0
- data/ext/libxcrypt/build-aux/m4-autogen/config.guess +1815 -0
- data/ext/libxcrypt/build-aux/m4-autogen/config.sub +2354 -0
- data/ext/libxcrypt/build-aux/m4-autogen/depcomp +792 -0
- data/ext/libxcrypt/build-aux/m4-autogen/install-sh +541 -0
- data/ext/libxcrypt/build-aux/m4-autogen/ltmain.sh +11524 -0
- data/ext/libxcrypt/build-aux/m4-autogen/missing +236 -0
- data/ext/libxcrypt/build-aux/m4-autogen/test-driver +160 -0
- data/ext/libxcrypt/build-aux/scripts/BuildCommon.pm +712 -0
- data/ext/libxcrypt/build-aux/scripts/check-perlcritic-config +76 -0
- data/ext/libxcrypt/build-aux/scripts/compute-symver-floor +116 -0
- data/ext/libxcrypt/build-aux/scripts/expand-selected-hashes +80 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-h +131 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-hashes-h +141 -0
- data/ext/libxcrypt/build-aux/scripts/gen-crypt-symbol-vers-h +150 -0
- data/ext/libxcrypt/build-aux/scripts/gen-libcrypt-map +67 -0
- data/ext/libxcrypt/build-aux/scripts/move-if-change +84 -0
- data/ext/libxcrypt/build-aux/scripts/skip-if-exec-format-error +78 -0
- data/ext/libxcrypt/codecov.yml +4 -0
- data/ext/libxcrypt/config.h.in +303 -0
- data/ext/libxcrypt/configure +19885 -0
- data/ext/libxcrypt/configure.ac +549 -0
- data/ext/libxcrypt/doc/crypt.3 +512 -0
- data/ext/libxcrypt/doc/crypt.5 +343 -0
- data/ext/libxcrypt/doc/crypt_checksalt.3 +106 -0
- data/ext/libxcrypt/doc/crypt_gensalt.3 +285 -0
- data/ext/libxcrypt/doc/crypt_gensalt_ra.3 +1 -0
- data/ext/libxcrypt/doc/crypt_gensalt_rn.3 +1 -0
- data/ext/libxcrypt/doc/crypt_preferred_method.3 +68 -0
- data/ext/libxcrypt/doc/crypt_r.3 +1 -0
- data/ext/libxcrypt/doc/crypt_ra.3 +1 -0
- data/ext/libxcrypt/doc/crypt_rn.3 +1 -0
- data/ext/libxcrypt/lib/alg-des-tables.c +3858 -0
- data/ext/libxcrypt/lib/alg-des.c +269 -0
- data/ext/libxcrypt/lib/alg-des.h +74 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-const.h +313 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-core.c +238 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-core.h +51 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.c +78 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.h +46 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-precalc.h +1426 -0
- data/ext/libxcrypt/lib/alg-gost3411-2012-ref.h +67 -0
- data/ext/libxcrypt/lib/alg-hmac-sha1.c +140 -0
- data/ext/libxcrypt/lib/alg-hmac-sha1.h +35 -0
- data/ext/libxcrypt/lib/alg-md4.c +270 -0
- data/ext/libxcrypt/lib/alg-md4.h +43 -0
- data/ext/libxcrypt/lib/alg-md5.c +291 -0
- data/ext/libxcrypt/lib/alg-md5.h +43 -0
- data/ext/libxcrypt/lib/alg-sha1.c +288 -0
- data/ext/libxcrypt/lib/alg-sha1.h +34 -0
- data/ext/libxcrypt/lib/alg-sha256.c +630 -0
- data/ext/libxcrypt/lib/alg-sha256.h +123 -0
- data/ext/libxcrypt/lib/alg-sha512.c +311 -0
- data/ext/libxcrypt/lib/alg-sha512.h +81 -0
- data/ext/libxcrypt/lib/alg-sm3-hmac.c +113 -0
- data/ext/libxcrypt/lib/alg-sm3-hmac.h +42 -0
- data/ext/libxcrypt/lib/alg-sm3.c +449 -0
- data/ext/libxcrypt/lib/alg-sm3.h +63 -0
- data/ext/libxcrypt/lib/alg-yescrypt-common.c +713 -0
- data/ext/libxcrypt/lib/alg-yescrypt-opt.c +1568 -0
- data/ext/libxcrypt/lib/alg-yescrypt-platform.c +106 -0
- data/ext/libxcrypt/lib/alg-yescrypt.h +360 -0
- data/ext/libxcrypt/lib/byteorder.h +164 -0
- data/ext/libxcrypt/lib/crypt-bcrypt.c +1061 -0
- data/ext/libxcrypt/lib/crypt-des-obsolete.c +215 -0
- data/ext/libxcrypt/lib/crypt-des.c +491 -0
- data/ext/libxcrypt/lib/crypt-gensalt-static.c +40 -0
- data/ext/libxcrypt/lib/crypt-gost-yescrypt.c +182 -0
- data/ext/libxcrypt/lib/crypt-md5.c +232 -0
- data/ext/libxcrypt/lib/crypt-nthash.c +134 -0
- data/ext/libxcrypt/lib/crypt-obsolete.h +40 -0
- data/ext/libxcrypt/lib/crypt-pbkdf1-sha1.c +260 -0
- data/ext/libxcrypt/lib/crypt-port.h +514 -0
- data/ext/libxcrypt/lib/crypt-scrypt.c +247 -0
- data/ext/libxcrypt/lib/crypt-sha256.c +308 -0
- data/ext/libxcrypt/lib/crypt-sha512.c +323 -0
- data/ext/libxcrypt/lib/crypt-sm3-yescrypt.c +189 -0
- data/ext/libxcrypt/lib/crypt-sm3.c +308 -0
- data/ext/libxcrypt/lib/crypt-static.c +44 -0
- data/ext/libxcrypt/lib/crypt-sunmd5.c +314 -0
- data/ext/libxcrypt/lib/crypt-yescrypt.c +177 -0
- data/ext/libxcrypt/lib/crypt.c +421 -0
- data/ext/libxcrypt/lib/crypt.h.in +249 -0
- data/ext/libxcrypt/lib/gen-des-tables.c +363 -0
- data/ext/libxcrypt/lib/hashes.conf +59 -0
- data/ext/libxcrypt/lib/libcrypt.map.in +48 -0
- data/ext/libxcrypt/lib/libcrypt.minver +97 -0
- data/ext/libxcrypt/lib/libxcrypt.pc.in +15 -0
- data/ext/libxcrypt/lib/util-base64.c +26 -0
- data/ext/libxcrypt/lib/util-gensalt-sha.c +88 -0
- data/ext/libxcrypt/lib/util-get-random-bytes.c +154 -0
- data/ext/libxcrypt/lib/util-make-failure-token.c +48 -0
- data/ext/libxcrypt/lib/util-xbzero.c +43 -0
- data/ext/libxcrypt/lib/util-xstrcpy.c +42 -0
- data/ext/libxcrypt/lib/xcrypt.h.in +58 -0
- data/ext/libxcrypt/libxcrypt.spec.rpkg +481 -0
- data/ext/libxcrypt/rpkg.conf +2 -0
- data/ext/libxcrypt/rpkg.macros +86 -0
- data/ext/libxcrypt/test/TestCommon.pm +326 -0
- data/ext/libxcrypt/test/alg-des.c +80 -0
- data/ext/libxcrypt/test/alg-gost3411-2012-hmac.c +90 -0
- data/ext/libxcrypt/test/alg-gost3411-2012.c +191 -0
- data/ext/libxcrypt/test/alg-hmac-sha1.c +187 -0
- data/ext/libxcrypt/test/alg-md4.c +111 -0
- data/ext/libxcrypt/test/alg-md5.c +134 -0
- data/ext/libxcrypt/test/alg-pbkdf-hmac-sha256.c +269 -0
- data/ext/libxcrypt/test/alg-sha1.c +111 -0
- data/ext/libxcrypt/test/alg-sha256.c +141 -0
- data/ext/libxcrypt/test/alg-sha512.c +170 -0
- data/ext/libxcrypt/test/alg-sm3-hmac.c +149 -0
- data/ext/libxcrypt/test/alg-sm3.c +168 -0
- data/ext/libxcrypt/test/alg-yescrypt.c +466 -0
- data/ext/libxcrypt/test/badsalt.c +726 -0
- data/ext/libxcrypt/test/badsetting.c +350 -0
- data/ext/libxcrypt/test/byteorder.c +254 -0
- data/ext/libxcrypt/test/checksalt.c +265 -0
- data/ext/libxcrypt/test/compile-strong-alias.c +43 -0
- data/ext/libxcrypt/test/crypt-badargs.c +392 -0
- data/ext/libxcrypt/test/crypt-gost-yescrypt.c +149 -0
- data/ext/libxcrypt/test/crypt-nested-call.c +180 -0
- data/ext/libxcrypt/test/crypt-sm3-yescrypt.c +149 -0
- data/ext/libxcrypt/test/crypt-too-long-phrase.c +157 -0
- data/ext/libxcrypt/test/des-cases.h +196 -0
- data/ext/libxcrypt/test/des-obsolete.c +206 -0
- data/ext/libxcrypt/test/des-obsolete_r.c +207 -0
- data/ext/libxcrypt/test/explicit-bzero.c +334 -0
- data/ext/libxcrypt/test/gensalt-bcrypt_x.c +54 -0
- data/ext/libxcrypt/test/gensalt-extradata.c +246 -0
- data/ext/libxcrypt/test/gensalt-nested-call.c +126 -0
- data/ext/libxcrypt/test/gensalt-nthash.c +65 -0
- data/ext/libxcrypt/test/gensalt.c +599 -0
- data/ext/libxcrypt/test/getrandom-fallbacks.c +295 -0
- data/ext/libxcrypt/test/getrandom-interface.c +211 -0
- data/ext/libxcrypt/test/ka-table-gen.py +945 -0
- data/ext/libxcrypt/test/ka-table.inc +5849 -0
- data/ext/libxcrypt/test/ka-tester.c +240 -0
- data/ext/libxcrypt/test/preferred-method.c +133 -0
- data/ext/libxcrypt/test/short-outbuf.c +119 -0
- data/ext/libxcrypt/test/special-char-salt.c +1160 -0
- data/ext/libxcrypt/test/symbols-compat.pl +137 -0
- data/ext/libxcrypt/test/symbols-renames.pl +107 -0
- data/ext/libxcrypt/test/symbols-static.pl +87 -0
- data/ext/xcrypt/xcrypt.c +9 -0
- data/lib/xcrypt/ffi.rb +76 -0
- data/lib/xcrypt/version.rb +5 -0
- data/lib/xcrypt.rb +89 -0
- metadata +267 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/* Test rejection of ill-formed setting strings.
|
|
2
|
+
|
|
3
|
+
Written by Zack Weinberg <zackw at panix.com> in 2018.
|
|
4
|
+
To the extent possible under law, Zack Weinberg has waived all
|
|
5
|
+
copyright and related or neighboring rights to this work.
|
|
6
|
+
|
|
7
|
+
See https://creativecommons.org/publicdomain/zero/1.0/ for further
|
|
8
|
+
details. */
|
|
9
|
+
|
|
10
|
+
#include "crypt-port.h"
|
|
11
|
+
|
|
12
|
+
#include <errno.h>
|
|
13
|
+
#include <stdio.h>
|
|
14
|
+
#include <stdlib.h>
|
|
15
|
+
|
|
16
|
+
/* Supply 64 bytes of "random" data to each gensalt call, for
|
|
17
|
+
determinism. */
|
|
18
|
+
static const char rbytes[] =
|
|
19
|
+
"yC8S8E7o+tmofM3L3DgKRwBy+RjWygAXIda7CAghZeXR9ZSl0UZh3kvt2XHg+aKo";
|
|
20
|
+
|
|
21
|
+
struct testcase
|
|
22
|
+
{
|
|
23
|
+
const char *prefix;
|
|
24
|
+
unsigned long count;
|
|
25
|
+
int rbytes; /* 0 = use sizeof rbytes - 1 */
|
|
26
|
+
int osize; /* 0 = use CRYPT_GENSALT_OUTPUT_SIZE */
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/* For each included hash, test malformed versions of its prefix
|
|
30
|
+
and invalid combinations of other arguments to gensalt.
|
|
31
|
+
For each excluded hash, test that a correct gensalt invocation
|
|
32
|
+
will still be rejected. */
|
|
33
|
+
static const struct testcase testcases[] =
|
|
34
|
+
{
|
|
35
|
+
/* DES (traditional and/or bigcrypt) -- count is ignored */
|
|
36
|
+
#if INCLUDE_descrypt || INCLUDE_bigcrypt
|
|
37
|
+
{ "!a", 0, 0, 0 }, // invalid first character
|
|
38
|
+
{ "a!", 0, 0, 0 }, // invalid second character
|
|
39
|
+
{ "xx", 1, 0, 0 }, // doesn't accept variable counts
|
|
40
|
+
{ "xx", 0, 1, 0 }, // inadequate rbytes
|
|
41
|
+
{ "xx", 0, 0, 1 }, // inadequate osize
|
|
42
|
+
#else
|
|
43
|
+
{ "", 0, 0, 0 },
|
|
44
|
+
{ "xx", 0, 0, 0 },
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
/* BSDi extended DES */
|
|
48
|
+
#if INCLUDE_bsdicrypt
|
|
49
|
+
{ "_", 0, 2, 0 }, // inadequate rbytes
|
|
50
|
+
{ "_", 0, 0, 4 }, // inadequate osize
|
|
51
|
+
#else
|
|
52
|
+
{ "_", 0, 0, 0 },
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
/* MD5 (FreeBSD) */
|
|
56
|
+
#if INCLUDE_md5crypt
|
|
57
|
+
{ "$1", 0, 0, 0 }, // truncated prefix
|
|
58
|
+
{ "$1$", 1, 0, 0 }, // doesn't accept variable counts
|
|
59
|
+
{ "$1$", 0, 2, 0 }, // inadequate rbytes
|
|
60
|
+
{ "$1$", 0, 0, 4 }, // inadequate osize
|
|
61
|
+
#else
|
|
62
|
+
{ "$1$", 0, 0, 0 },
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
/* MD5 (Sun) */
|
|
66
|
+
#if INCLUDE_sunmd5
|
|
67
|
+
{ "$m", 0, 0, 0 }, // truncated prefix
|
|
68
|
+
{ "$md", 0, 0, 0 },
|
|
69
|
+
{ "$md5", 0, 2, 0 }, // inadequate rbytes
|
|
70
|
+
{ "$md5", 0, 0, 4 }, // inadequate osize
|
|
71
|
+
#else
|
|
72
|
+
{ "$md5", 0, 0, 0 },
|
|
73
|
+
#endif
|
|
74
|
+
|
|
75
|
+
/* NTHASH */
|
|
76
|
+
#if INCLUDE_nt
|
|
77
|
+
{ "$3", 0, 0, 0 }, // truncated prefix
|
|
78
|
+
{ "$3$", 1, 0, 0 }, // doesn't accept variable counts
|
|
79
|
+
{ "$3$", 0, 0, 3 }, // inadequate osize
|
|
80
|
+
#else
|
|
81
|
+
{ "$3$", 0, 0, 0 },
|
|
82
|
+
#endif
|
|
83
|
+
|
|
84
|
+
/* SM3 */
|
|
85
|
+
#if INCLUDE_sm3crypt
|
|
86
|
+
{ "$sm3", 0, 0, 0 }, // truncated prefix
|
|
87
|
+
{ "$sm3$", 0, 2, 0 }, // inadequate rbytes
|
|
88
|
+
{ "$sm3$", 0, 0, 4 }, // inadequate osize
|
|
89
|
+
#else
|
|
90
|
+
{ "$sm3$", 0, 0, 0 },
|
|
91
|
+
#endif
|
|
92
|
+
|
|
93
|
+
/* SHA1 */
|
|
94
|
+
#if INCLUDE_sha1crypt
|
|
95
|
+
{ "$s", 0, 0, 0 }, // truncated prefix
|
|
96
|
+
{ "$sh", 0, 0, 0 },
|
|
97
|
+
{ "$sha", 0, 0, 0 },
|
|
98
|
+
{ "$sha1", 0, 2, 0 }, // inadequate rbytes
|
|
99
|
+
{ "$sha1", 0, 0, 4 }, // inadequate osize
|
|
100
|
+
#else
|
|
101
|
+
{ "$sha1", 0, 0, 0 },
|
|
102
|
+
#endif
|
|
103
|
+
|
|
104
|
+
/* SHA256 */
|
|
105
|
+
#if INCLUDE_sha256crypt
|
|
106
|
+
{ "$5", 0, 0, 0 }, // truncated prefix
|
|
107
|
+
{ "$5$", 0, 2, 0 }, // inadequate rbytes
|
|
108
|
+
{ "$5$", 0, 0, 4 }, // inadequate osize
|
|
109
|
+
#else
|
|
110
|
+
{ "$5$", 0, 0, 0 },
|
|
111
|
+
#endif
|
|
112
|
+
|
|
113
|
+
/* SHA512 */
|
|
114
|
+
#if INCLUDE_sha512crypt
|
|
115
|
+
{ "$6", 0, 0, 0 }, // truncated prefix
|
|
116
|
+
{ "$6$", 0, 2, 0 }, // inadequate rbytes
|
|
117
|
+
{ "$6$", 0, 0, 4 }, // inadequate osize
|
|
118
|
+
#else
|
|
119
|
+
{ "$6$", 0, 0, 0 },
|
|
120
|
+
#endif
|
|
121
|
+
|
|
122
|
+
/* bcrypt */
|
|
123
|
+
#if INCLUDE_bcrypt
|
|
124
|
+
{ "$2", 0, 0, 0 }, // truncated prefix
|
|
125
|
+
{ "$2a", 0, 0, 0 },
|
|
126
|
+
{ "$2b", 0, 0, 0 },
|
|
127
|
+
{ "$2x", 0, 0, 0 },
|
|
128
|
+
{ "$2y", 0, 0, 0 },
|
|
129
|
+
{ "$2b$", 3, 0, 0 }, // too small
|
|
130
|
+
{ "$2b$", 32, 0, 0 }, // too large
|
|
131
|
+
{ "$2b$", 0, 2, 0 }, // inadequate rbytes
|
|
132
|
+
{ "$2b$", 0, 0, 4 }, // inadequate osize
|
|
133
|
+
#else
|
|
134
|
+
{ "$2b$", 0, 0, 0 },
|
|
135
|
+
#endif
|
|
136
|
+
#if INCLUDE_bcrypt_a
|
|
137
|
+
{ "$2", 0, 0, 0 }, // truncated prefix
|
|
138
|
+
{ "$2a", 0, 0, 0 },
|
|
139
|
+
{ "$2b", 0, 0, 0 },
|
|
140
|
+
{ "$2x", 0, 0, 0 },
|
|
141
|
+
{ "$2y", 0, 0, 0 },
|
|
142
|
+
{ "$2a$", 3, 0, 0 }, // too small
|
|
143
|
+
{ "$2a$", 32, 0, 0 }, // too large
|
|
144
|
+
{ "$2a$", 0, 2, 0 }, // inadequate rbytes
|
|
145
|
+
{ "$2a$", 0, 0, 4 }, // inadequate osize
|
|
146
|
+
#else
|
|
147
|
+
{ "$2a$", 0, 0, 0 },
|
|
148
|
+
#endif
|
|
149
|
+
#if INCLUDE_bcrypt_x
|
|
150
|
+
{ "$2", 0, 0, 0 }, // truncated prefix
|
|
151
|
+
{ "$2a", 0, 0, 0 },
|
|
152
|
+
{ "$2b", 0, 0, 0 },
|
|
153
|
+
{ "$2x", 0, 0, 0 },
|
|
154
|
+
{ "$2y", 0, 0, 0 },
|
|
155
|
+
{ "$2x$", 0, 0, 0 }, // cannot be used
|
|
156
|
+
#else
|
|
157
|
+
{ "$2x$", 0, 0, 0 },
|
|
158
|
+
#endif
|
|
159
|
+
#if INCLUDE_bcrypt_y
|
|
160
|
+
{ "$2", 0, 0, 0 }, // truncated prefix
|
|
161
|
+
{ "$2a", 0, 0, 0 },
|
|
162
|
+
{ "$2b", 0, 0, 0 },
|
|
163
|
+
{ "$2x", 0, 0, 0 },
|
|
164
|
+
{ "$2y", 0, 0, 0 },
|
|
165
|
+
{ "$2y$", 3, 0, 0 }, // too small
|
|
166
|
+
{ "$2y$", 32, 0, 0 }, // too large
|
|
167
|
+
{ "$2y$", 0, 2, 0 }, // inadequate rbytes
|
|
168
|
+
{ "$2y$", 0, 0, 4 }, // inadequate osize
|
|
169
|
+
#else
|
|
170
|
+
{ "$2y$", 0, 0, 0 },
|
|
171
|
+
#endif
|
|
172
|
+
|
|
173
|
+
/* yescrypt */
|
|
174
|
+
#if INCLUDE_yescrypt
|
|
175
|
+
{ "$y", 0, 0, 0 }, // truncated prefix
|
|
176
|
+
{ "$y$", 32, 0, 0 }, // too large
|
|
177
|
+
{ "$y$", 0, 2, 0 }, // inadequate rbytes
|
|
178
|
+
{ "$y$", 0, 0, 4 }, // inadequate osize
|
|
179
|
+
#else
|
|
180
|
+
{ "$y$", 0, 0, 0 },
|
|
181
|
+
#endif
|
|
182
|
+
|
|
183
|
+
/* scrypt */
|
|
184
|
+
#if INCLUDE_scrypt
|
|
185
|
+
{ "$7", 0, 0, 0 }, // truncated prefix
|
|
186
|
+
{ "$7$", 3, 0, 0 }, // too small
|
|
187
|
+
{ "$7$", 32, 0, 0 }, // too large
|
|
188
|
+
{ "$7$", 0, 2, 0 }, // inadequate rbytes
|
|
189
|
+
{ "$7$", 0, 0, 4 }, // inadequate osize
|
|
190
|
+
#else
|
|
191
|
+
{ "$7$", 0, 0, 0 },
|
|
192
|
+
#endif
|
|
193
|
+
|
|
194
|
+
/* gost-yescrypt */
|
|
195
|
+
#if INCLUDE_gost_yescrypt
|
|
196
|
+
{ "$gy", 0, 0, 0 }, // truncated prefix
|
|
197
|
+
{ "$gy$", 32, 0, 0 }, // too large
|
|
198
|
+
{ "$gy$", 0, 2, 0 }, // inadequate rbytes
|
|
199
|
+
{ "$gy$", 0, 0, 4 }, // inadequate osize
|
|
200
|
+
#else
|
|
201
|
+
{ "$gy$", 0, 0, 0 },
|
|
202
|
+
#endif
|
|
203
|
+
|
|
204
|
+
/* sm3-yescrypt */
|
|
205
|
+
#if INCLUDE_sm3_yescrypt
|
|
206
|
+
{ "$sm3y", 0, 0, 0 }, // truncated prefix
|
|
207
|
+
{ "$sm3y$", 32, 0, 0 }, // too large
|
|
208
|
+
{ "$sm3y$", 0, 2, 0 }, // inadequate rbytes
|
|
209
|
+
{ "$sm3y$", 0, 0, 4 }, // inadequate osize
|
|
210
|
+
#else
|
|
211
|
+
{ "$sm3y$", 0, 0, 0 },
|
|
212
|
+
#endif
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
static void
|
|
216
|
+
print_escaped_string (const char *s)
|
|
217
|
+
{
|
|
218
|
+
putchar ('"');
|
|
219
|
+
for (const char *p = s; *p; p++)
|
|
220
|
+
if (*p >= ' ' && *p <= '~')
|
|
221
|
+
{
|
|
222
|
+
if (*p == '\\' || *p == '\"')
|
|
223
|
+
putchar ('\\');
|
|
224
|
+
putchar (*p);
|
|
225
|
+
}
|
|
226
|
+
else
|
|
227
|
+
printf ("\\x%02x", (unsigned int)(unsigned char)*p);
|
|
228
|
+
putchar ('"');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static bool error_occurred = false;
|
|
232
|
+
static void
|
|
233
|
+
report_error (const char *fn, const struct testcase *tc,
|
|
234
|
+
int err, const char *output)
|
|
235
|
+
{
|
|
236
|
+
error_occurred = true;
|
|
237
|
+
printf ("%s(", fn);
|
|
238
|
+
print_escaped_string (tc->prefix);
|
|
239
|
+
printf (", %lu, nrbytes=%d, osize=%d):\n", tc->count,
|
|
240
|
+
tc->rbytes > 0 ? tc->rbytes : (int) sizeof rbytes - 1,
|
|
241
|
+
tc->osize > 0 ? tc->osize : CRYPT_GENSALT_OUTPUT_SIZE);
|
|
242
|
+
|
|
243
|
+
if (output)
|
|
244
|
+
{
|
|
245
|
+
if (err)
|
|
246
|
+
printf ("\toutput with errno = %s\n", strerror (err));
|
|
247
|
+
printf ("\texpected NULL, got ");
|
|
248
|
+
print_escaped_string (output);
|
|
249
|
+
putchar ('\n');
|
|
250
|
+
}
|
|
251
|
+
else if (err != (tc->osize > 0 ? ERANGE : EINVAL))
|
|
252
|
+
printf ("\tno output with errno = %s\n",
|
|
253
|
+
err ? strerror (err) : "0");
|
|
254
|
+
else
|
|
255
|
+
printf ("\tno output with errno = %s"
|
|
256
|
+
"(shouldn't have been called)\n", strerror (err));
|
|
257
|
+
putchar ('\n');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
static void
|
|
261
|
+
test_one (const struct testcase *tc)
|
|
262
|
+
{
|
|
263
|
+
char obuf[CRYPT_GENSALT_OUTPUT_SIZE];
|
|
264
|
+
char *s;
|
|
265
|
+
int nrbytes = tc->rbytes > 0 ? tc->rbytes : (int)(sizeof rbytes - 1);
|
|
266
|
+
int osize = tc->osize > 0 ? tc->osize : CRYPT_GENSALT_OUTPUT_SIZE;
|
|
267
|
+
|
|
268
|
+
/* It is only possible to provide a variant osize to crypt_gensalt_rn. */
|
|
269
|
+
if (tc->osize == 0)
|
|
270
|
+
{
|
|
271
|
+
errno = 0;
|
|
272
|
+
s = crypt_gensalt (tc->prefix, tc->count, rbytes, nrbytes);
|
|
273
|
+
if (s || errno != EINVAL)
|
|
274
|
+
report_error ("gensalt", tc, errno, s);
|
|
275
|
+
|
|
276
|
+
errno = 0;
|
|
277
|
+
s = crypt_gensalt_ra (tc->prefix, tc->count, rbytes, nrbytes);
|
|
278
|
+
if (s || errno != EINVAL)
|
|
279
|
+
report_error ("gensalt_ra", tc, errno, s);
|
|
280
|
+
free (s);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
errno = 0;
|
|
284
|
+
s = crypt_gensalt_rn (tc->prefix, tc->count, rbytes, nrbytes, obuf, osize);
|
|
285
|
+
if (s || errno != (tc->osize > 0 ? ERANGE : EINVAL))
|
|
286
|
+
report_error ("gensalt_rn", tc, errno, s);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/* All single-character strings (except "_" when BSDi extended DES
|
|
290
|
+
is enabled) are invalid prefixes, either because the character
|
|
291
|
+
cannot be the first character of any valid prefix, or because the
|
|
292
|
+
string is too short. */
|
|
293
|
+
static void
|
|
294
|
+
test_single_characters (void)
|
|
295
|
+
{
|
|
296
|
+
char s[2];
|
|
297
|
+
struct testcase tc;
|
|
298
|
+
s[1] = '\0';
|
|
299
|
+
tc.prefix = s;
|
|
300
|
+
tc.count = 0;
|
|
301
|
+
tc.rbytes = 0;
|
|
302
|
+
tc.osize = 0;
|
|
303
|
+
|
|
304
|
+
for (int i = 1; i < 256; i++)
|
|
305
|
+
{
|
|
306
|
+
#ifdef INCLUDE_bsdicrypt
|
|
307
|
+
if (i == '_') continue;
|
|
308
|
+
#endif
|
|
309
|
+
s[0] = (char)i;
|
|
310
|
+
test_one (&tc);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* '$' followed by any non-ASCII-isalnum character is also always
|
|
315
|
+
invalid. */
|
|
316
|
+
static void
|
|
317
|
+
test_dollar_nonalphanum (void)
|
|
318
|
+
{
|
|
319
|
+
char s[3];
|
|
320
|
+
struct testcase tc;
|
|
321
|
+
s[0] = '$';
|
|
322
|
+
s[2] = '\0';
|
|
323
|
+
tc.prefix = s;
|
|
324
|
+
tc.count = 0;
|
|
325
|
+
tc.rbytes = 0;
|
|
326
|
+
tc.osize = 0;
|
|
327
|
+
|
|
328
|
+
for (int i = 1; i < 256; i++)
|
|
329
|
+
{
|
|
330
|
+
if (('0' >= i && i <= '9') ||
|
|
331
|
+
('A' >= i && i <= 'Z') ||
|
|
332
|
+
('a' >= i && i <= 'z'))
|
|
333
|
+
continue;
|
|
334
|
+
s[1] = (char)i;
|
|
335
|
+
test_one (&tc);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
int
|
|
340
|
+
main(void)
|
|
341
|
+
{
|
|
342
|
+
test_single_characters();
|
|
343
|
+
test_dollar_nonalphanum();
|
|
344
|
+
|
|
345
|
+
/* Hand-crafted arguments for each supported algorithm. */
|
|
346
|
+
for (size_t i = 0; i < ARRAY_SIZE (testcases); i++)
|
|
347
|
+
test_one (&testcases[i]);
|
|
348
|
+
|
|
349
|
+
return error_occurred;
|
|
350
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/* Test the functions defined in byteorder.h.
|
|
2
|
+
*
|
|
3
|
+
* Written by Zack Weinberg <zackw at panix.com> in 2017.
|
|
4
|
+
*
|
|
5
|
+
* No copyright is claimed, and the software is hereby placed in the public
|
|
6
|
+
* domain. In case this attempt to disclaim copyright and place the software
|
|
7
|
+
* in the public domain is deemed null and void, then the software is
|
|
8
|
+
* Copyright (c) 2017 Zack Weinberg and it is hereby released to the
|
|
9
|
+
* general public under the following terms:
|
|
10
|
+
*
|
|
11
|
+
* Redistribution and use in source and binary forms, with or without
|
|
12
|
+
* modification, are permitted.
|
|
13
|
+
*
|
|
14
|
+
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include "crypt-port.h"
|
|
18
|
+
#include "byteorder.h"
|
|
19
|
+
|
|
20
|
+
#include <inttypes.h>
|
|
21
|
+
#include <stdio.h>
|
|
22
|
+
|
|
23
|
+
struct test_32
|
|
24
|
+
{
|
|
25
|
+
uint32_t val;
|
|
26
|
+
unsigned char bytes[4 + 1];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
struct test_64
|
|
30
|
+
{
|
|
31
|
+
uint64_t val;
|
|
32
|
+
unsigned char bytes[8 + 1];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
#define Z(x) ((unsigned int)(unsigned char)(x)) /* zero extend char */
|
|
36
|
+
|
|
37
|
+
static int
|
|
38
|
+
test_le32 (void)
|
|
39
|
+
{
|
|
40
|
+
static const struct test_32 cases[] =
|
|
41
|
+
{
|
|
42
|
+
{ 0x00000000, "\x00\x00\x00\x00" },
|
|
43
|
+
{ 0xFF000000, "\x00\x00\x00\xFF" },
|
|
44
|
+
{ 0x00FF0000, "\x00\x00\xFF\x00" },
|
|
45
|
+
{ 0x0000FF00, "\x00\xFF\x00\x00" },
|
|
46
|
+
{ 0x000000FF, "\xFF\x00\x00\x00" },
|
|
47
|
+
{ 0x01234567, "\x67\x45\x23\x01" },
|
|
48
|
+
};
|
|
49
|
+
size_t n_cases = ARRAY_SIZE (cases);
|
|
50
|
+
size_t i;
|
|
51
|
+
uint32_t v;
|
|
52
|
+
unsigned char x[4];
|
|
53
|
+
int status = 0;
|
|
54
|
+
|
|
55
|
+
for (i = 0; i < n_cases; i++)
|
|
56
|
+
{
|
|
57
|
+
v = le32_to_cpu (cases[i].bytes);
|
|
58
|
+
if (v != cases[i].val)
|
|
59
|
+
{
|
|
60
|
+
printf ("FAIL: le32_to_cpu: %02x %02x %02x %02x -> "
|
|
61
|
+
"%08"PRIx32" != %08"PRIx32"\n",
|
|
62
|
+
Z(cases[i].bytes[0]), Z(cases[i].bytes[1]),
|
|
63
|
+
Z(cases[i].bytes[2]), Z(cases[i].bytes[3]),
|
|
64
|
+
v, cases[i].val);
|
|
65
|
+
status = 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
cpu_to_le32 (x, cases[i].val);
|
|
69
|
+
if (memcmp (x, cases[i].bytes, 4))
|
|
70
|
+
{
|
|
71
|
+
printf ("FAIL: cpu_to_le32: %08"PRIx32" -> "
|
|
72
|
+
"%02x %02x %02x %02x != %02x %02x %02x %02x\n",
|
|
73
|
+
cases[i].val,
|
|
74
|
+
Z(x[0]), Z(x[1]), Z(x[2]), Z(x[3]),
|
|
75
|
+
Z(cases[i].bytes[0]), Z(cases[i].bytes[1]),
|
|
76
|
+
Z(cases[i].bytes[2]), Z(cases[i].bytes[3]));
|
|
77
|
+
status = 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return status;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static int
|
|
85
|
+
test_be32 (void)
|
|
86
|
+
{
|
|
87
|
+
static const struct test_32 cases[] =
|
|
88
|
+
{
|
|
89
|
+
{ 0x00000000, "\x00\x00\x00\x00" },
|
|
90
|
+
{ 0xFF000000, "\xFF\x00\x00\x00" },
|
|
91
|
+
{ 0x00FF0000, "\x00\xFF\x00\x00" },
|
|
92
|
+
{ 0x0000FF00, "\x00\x00\xFF\x00" },
|
|
93
|
+
{ 0x000000FF, "\x00\x00\x00\xFF" },
|
|
94
|
+
{ 0x01234567, "\x01\x23\x45\x67" },
|
|
95
|
+
};
|
|
96
|
+
size_t n_cases = ARRAY_SIZE (cases);
|
|
97
|
+
size_t i;
|
|
98
|
+
uint32_t v;
|
|
99
|
+
unsigned char x[4];
|
|
100
|
+
int status = 0;
|
|
101
|
+
|
|
102
|
+
for (i = 0; i < n_cases; i++)
|
|
103
|
+
{
|
|
104
|
+
v = be32_to_cpu (cases[i].bytes);
|
|
105
|
+
if (v != cases[i].val)
|
|
106
|
+
{
|
|
107
|
+
printf ("FAIL: be32_to_cpu: %02x %02x %02x %02x -> "
|
|
108
|
+
"%08"PRIx32" != %08"PRIx32"\n",
|
|
109
|
+
Z(cases[i].bytes[0]), Z(cases[i].bytes[1]),
|
|
110
|
+
Z(cases[i].bytes[2]), Z(cases[i].bytes[3]),
|
|
111
|
+
v, cases[i].val);
|
|
112
|
+
status = 1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
cpu_to_be32 (x, cases[i].val);
|
|
116
|
+
if (memcmp (x, cases[i].bytes, 4))
|
|
117
|
+
{
|
|
118
|
+
printf ("FAIL: cpu_to_be32: %08"PRIx32" -> "
|
|
119
|
+
"%02x %02x %02x %02x != %02x %02x %02x %02x\n",
|
|
120
|
+
cases[i].val,
|
|
121
|
+
Z(x[0]), Z(x[1]), Z(x[2]), Z(x[3]),
|
|
122
|
+
Z(cases[i].bytes[0]), Z(cases[i].bytes[1]),
|
|
123
|
+
Z(cases[i].bytes[2]), Z(cases[i].bytes[3]));
|
|
124
|
+
status = 1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return status;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static int
|
|
132
|
+
test_le64 (void)
|
|
133
|
+
{
|
|
134
|
+
static const struct test_64 cases[] =
|
|
135
|
+
{
|
|
136
|
+
{ 0x0000000000000000ull, "\x00\x00\x00\x00\x00\x00\x00\x00" },
|
|
137
|
+
{ 0x00000000000000FFull, "\xFF\x00\x00\x00\x00\x00\x00\x00" },
|
|
138
|
+
{ 0x000000000000FF00ull, "\x00\xFF\x00\x00\x00\x00\x00\x00" },
|
|
139
|
+
{ 0x0000000000FF0000ull, "\x00\x00\xFF\x00\x00\x00\x00\x00" },
|
|
140
|
+
{ 0x00000000FF000000ull, "\x00\x00\x00\xFF\x00\x00\x00\x00" },
|
|
141
|
+
{ 0x000000FF00000000ull, "\x00\x00\x00\x00\xFF\x00\x00\x00" },
|
|
142
|
+
{ 0x0000FF0000000000ull, "\x00\x00\x00\x00\x00\xFF\x00\x00" },
|
|
143
|
+
{ 0x00FF000000000000ull, "\x00\x00\x00\x00\x00\x00\xFF\x00" },
|
|
144
|
+
{ 0xFF00000000000000ull, "\x00\x00\x00\x00\x00\x00\x00\xFF" },
|
|
145
|
+
{ 0x0123456789ABCDEFull, "\xEF\xCD\xAB\x89\x67\x45\x23\x01" },
|
|
146
|
+
};
|
|
147
|
+
size_t n_cases = ARRAY_SIZE (cases);
|
|
148
|
+
size_t i;
|
|
149
|
+
uint64_t v;
|
|
150
|
+
unsigned char x[8];
|
|
151
|
+
int status = 0;
|
|
152
|
+
|
|
153
|
+
for (i = 0; i < n_cases; i++)
|
|
154
|
+
{
|
|
155
|
+
v = le64_to_cpu (cases[i].bytes);
|
|
156
|
+
if (v != cases[i].val)
|
|
157
|
+
{
|
|
158
|
+
printf ("FAIL: le64_to_cpu: %02x%02x %02x%02x %02x%02x %02x%02x "
|
|
159
|
+
"-> %016"PRIx64" != %016"PRIx64"\n",
|
|
160
|
+
Z(cases[i].bytes[0]), Z(cases[i].bytes[1]),
|
|
161
|
+
Z(cases[i].bytes[2]), Z(cases[i].bytes[3]),
|
|
162
|
+
Z(cases[i].bytes[4]), Z(cases[i].bytes[5]),
|
|
163
|
+
Z(cases[i].bytes[6]), Z(cases[i].bytes[7]),
|
|
164
|
+
v, cases[i].val);
|
|
165
|
+
status = 1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
cpu_to_le64 (x, cases[i].val);
|
|
169
|
+
if (memcmp (x, cases[i].bytes, 8))
|
|
170
|
+
{
|
|
171
|
+
printf ("FAIL: cpu_to_le64: %016"PRIx64" -> "
|
|
172
|
+
"%02x%02x %02x%02x %02x%02x %02x%02x != "
|
|
173
|
+
"%02x%02x %02x%02x %02x%02x %02x%02x\n",
|
|
174
|
+
cases[i].val,
|
|
175
|
+
Z(x[0]), Z(x[1]), Z(x[2]), Z(x[3]),
|
|
176
|
+
Z(x[4]), Z(x[5]), Z(x[6]), Z(x[7]),
|
|
177
|
+
Z(cases[i].bytes[0]), Z(cases[i].bytes[1]),
|
|
178
|
+
Z(cases[i].bytes[2]), Z(cases[i].bytes[3]),
|
|
179
|
+
Z(cases[i].bytes[4]), Z(cases[i].bytes[5]),
|
|
180
|
+
Z(cases[i].bytes[6]), Z(cases[i].bytes[7]));
|
|
181
|
+
status = 1;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return status;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static int
|
|
189
|
+
test_be64 (void)
|
|
190
|
+
{
|
|
191
|
+
static const struct test_64 cases[] =
|
|
192
|
+
{
|
|
193
|
+
{ 0x0000000000000000ull, "\x00\x00\x00\x00\x00\x00\x00\x00" },
|
|
194
|
+
{ 0x00000000000000FFull, "\x00\x00\x00\x00\x00\x00\x00\xFF" },
|
|
195
|
+
{ 0x000000000000FF00ull, "\x00\x00\x00\x00\x00\x00\xFF\x00" },
|
|
196
|
+
{ 0x0000000000FF0000ull, "\x00\x00\x00\x00\x00\xFF\x00\x00" },
|
|
197
|
+
{ 0x00000000FF000000ull, "\x00\x00\x00\x00\xFF\x00\x00\x00" },
|
|
198
|
+
{ 0x000000FF00000000ull, "\x00\x00\x00\xFF\x00\x00\x00\x00" },
|
|
199
|
+
{ 0x0000FF0000000000ull, "\x00\x00\xFF\x00\x00\x00\x00\x00" },
|
|
200
|
+
{ 0x00FF000000000000ull, "\x00\xFF\x00\x00\x00\x00\x00\x00" },
|
|
201
|
+
{ 0xFF00000000000000ull, "\xFF\x00\x00\x00\x00\x00\x00\x00" },
|
|
202
|
+
{ 0x0123456789ABCDEFull, "\x01\x23\x45\x67\x89\xAB\xCD\xEF" },
|
|
203
|
+
};
|
|
204
|
+
size_t n_cases = ARRAY_SIZE (cases);
|
|
205
|
+
size_t i;
|
|
206
|
+
uint64_t v;
|
|
207
|
+
unsigned char x[8];
|
|
208
|
+
int status = 0;
|
|
209
|
+
|
|
210
|
+
for (i = 0; i < n_cases; i++)
|
|
211
|
+
{
|
|
212
|
+
v = be64_to_cpu (cases[i].bytes);
|
|
213
|
+
if (v != cases[i].val)
|
|
214
|
+
{
|
|
215
|
+
printf ("FAIL: be64_to_cpu: %02x%02x %02x%02x %02x%02x %02x%02x "
|
|
216
|
+
"-> %016"PRIx64" != %016"PRIx64"\n",
|
|
217
|
+
Z(cases[i].bytes[0]), Z(cases[i].bytes[1]),
|
|
218
|
+
Z(cases[i].bytes[2]), Z(cases[i].bytes[3]),
|
|
219
|
+
Z(cases[i].bytes[4]), Z(cases[i].bytes[5]),
|
|
220
|
+
Z(cases[i].bytes[6]), Z(cases[i].bytes[7]),
|
|
221
|
+
v, cases[i].val);
|
|
222
|
+
status = 1;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
cpu_to_be64 (x, cases[i].val);
|
|
226
|
+
if (memcmp (x, cases[i].bytes, 8))
|
|
227
|
+
{
|
|
228
|
+
printf ("FAIL: cpu_to_be64: %016"PRIx64" -> "
|
|
229
|
+
"%02x%02x %02x%02x %02x%02x %02x%02x != "
|
|
230
|
+
"%02x%02x %02x%02x %02x%02x %02x%02x\n",
|
|
231
|
+
cases[i].val,
|
|
232
|
+
Z(x[0]), Z(x[1]), Z(x[2]), Z(x[3]),
|
|
233
|
+
Z(x[4]), Z(x[5]), Z(x[6]), Z(x[7]),
|
|
234
|
+
Z(cases[i].bytes[0]), Z(cases[i].bytes[1]),
|
|
235
|
+
Z(cases[i].bytes[2]), Z(cases[i].bytes[3]),
|
|
236
|
+
Z(cases[i].bytes[4]), Z(cases[i].bytes[5]),
|
|
237
|
+
Z(cases[i].bytes[6]), Z(cases[i].bytes[7]));
|
|
238
|
+
status = 1;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return status;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
int
|
|
246
|
+
main (void)
|
|
247
|
+
{
|
|
248
|
+
int status = 0;
|
|
249
|
+
status |= test_le32 ();
|
|
250
|
+
status |= test_be32 ();
|
|
251
|
+
status |= test_le64 ();
|
|
252
|
+
status |= test_be64 ();
|
|
253
|
+
return status;
|
|
254
|
+
}
|