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,599 @@
|
|
|
1
|
+
#include "crypt-port.h"
|
|
2
|
+
|
|
3
|
+
#include <errno.h>
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
|
|
7
|
+
static const char *const entropy[] =
|
|
8
|
+
{
|
|
9
|
+
"\x58\x35\xcd\x26\x03\xab\x2c\x14\x92\x13\x1e\x59\xb0\xbc\xfe\xd5",
|
|
10
|
+
"\x9b\x35\xa2\x45\xeb\x68\x9e\x8f\xd9\xa9\x09\x71\xcc\x4d\x21\x44",
|
|
11
|
+
"\x25\x13\xc5\x94\xc3\x93\x1d\xf4\xfd\xd4\x4f\xbd\x10\xe5\x28\x08",
|
|
12
|
+
"\xa0\x2d\x35\x70\xa8\x0b\xc3\xad\xdf\x61\x69\xb3\x19\xda\x7e\x8d",
|
|
13
|
+
0
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
#if INCLUDE_descrypt
|
|
17
|
+
static const char *const des_expected_output[] = { "Mp", "Pp", "ZH", "Uh"};
|
|
18
|
+
#endif
|
|
19
|
+
#if INCLUDE_bigcrypt && !INCLUDE_descrypt
|
|
20
|
+
static const char *const big_expected_output[] =
|
|
21
|
+
{
|
|
22
|
+
"Mp............",
|
|
23
|
+
"Pp............",
|
|
24
|
+
"ZH............",
|
|
25
|
+
"Uh............"
|
|
26
|
+
};
|
|
27
|
+
#endif
|
|
28
|
+
#if INCLUDE_bsdicrypt
|
|
29
|
+
static const char *const bsdi_expected_output[] =
|
|
30
|
+
{
|
|
31
|
+
"_J9..MJHn",
|
|
32
|
+
"_J9..PKXc",
|
|
33
|
+
"_J9..ZAFl",
|
|
34
|
+
"_J9..UqGB"
|
|
35
|
+
};
|
|
36
|
+
static const char *const bsdi_expected_output_r[] =
|
|
37
|
+
{
|
|
38
|
+
"_/.2.MJHn",
|
|
39
|
+
"_/.2.PKXc",
|
|
40
|
+
"_/.2.ZAFl",
|
|
41
|
+
"_/.2.UqGB"
|
|
42
|
+
};
|
|
43
|
+
static const char *const bsdi_expected_output_l[] =
|
|
44
|
+
{
|
|
45
|
+
"_/...MJHn",
|
|
46
|
+
"_/...PKXc",
|
|
47
|
+
"_/...ZAFl",
|
|
48
|
+
"_/...UqGB"
|
|
49
|
+
};
|
|
50
|
+
static const char *const bsdi_expected_output_h[] =
|
|
51
|
+
{
|
|
52
|
+
"_zzzzMJHn",
|
|
53
|
+
"_zzzzPKXc",
|
|
54
|
+
"_zzzzZAFl",
|
|
55
|
+
"_zzzzUqGB"
|
|
56
|
+
};
|
|
57
|
+
#endif
|
|
58
|
+
#if INCLUDE_md5crypt
|
|
59
|
+
static const char *const md5_expected_output[] =
|
|
60
|
+
{
|
|
61
|
+
"$1$MJHnaAke",
|
|
62
|
+
"$1$PKXc3hCO",
|
|
63
|
+
"$1$ZAFlICwY",
|
|
64
|
+
"$1$UqGBkVu0"
|
|
65
|
+
};
|
|
66
|
+
#endif
|
|
67
|
+
#if INCLUDE_sunmd5
|
|
68
|
+
static const char *const sunmd5_expected_output[] =
|
|
69
|
+
{
|
|
70
|
+
"$md5,rounds=55349$BPm.fm03$",
|
|
71
|
+
"$md5,rounds=72501$WKoucttX$",
|
|
72
|
+
"$md5,rounds=42259$3HtkHq/x$",
|
|
73
|
+
"$md5,rounds=73773$p.5e9AQf$",
|
|
74
|
+
};
|
|
75
|
+
static const char *const sunmd5_expected_output_l[] =
|
|
76
|
+
{
|
|
77
|
+
"$md5,rounds=55349$BPm.fm03$",
|
|
78
|
+
"$md5,rounds=72501$WKoucttX$",
|
|
79
|
+
"$md5,rounds=42259$3HtkHq/x$",
|
|
80
|
+
"$md5,rounds=73773$p.5e9AQf$",
|
|
81
|
+
};
|
|
82
|
+
static const char *const sunmd5_expected_output_h[] =
|
|
83
|
+
{
|
|
84
|
+
"$md5,rounds=4294924340$BPm.fm03$",
|
|
85
|
+
"$md5,rounds=4294941492$WKoucttX$",
|
|
86
|
+
"$md5,rounds=4294911250$3HtkHq/x$",
|
|
87
|
+
"$md5,rounds=4294942764$p.5e9AQf$",
|
|
88
|
+
};
|
|
89
|
+
#endif
|
|
90
|
+
#if INCLUDE_sha1crypt
|
|
91
|
+
static const char *const sha1_expected_output[] =
|
|
92
|
+
{
|
|
93
|
+
"$sha1$248488$ggu.H673kaZ5$",
|
|
94
|
+
"$sha1$248421$SWqudaxXA5L0$",
|
|
95
|
+
"$sha1$257243$RAtkIrDxEovH$",
|
|
96
|
+
"$sha1$250464$1j.eVxRfNAPO$",
|
|
97
|
+
};
|
|
98
|
+
static const char *const sha1_expected_output_l[] =
|
|
99
|
+
{
|
|
100
|
+
"$sha1$4$ggu.H673kaZ5$",
|
|
101
|
+
"$sha1$4$SWqudaxXA5L0$",
|
|
102
|
+
"$sha1$4$RAtkIrDxEovH$",
|
|
103
|
+
"$sha1$4$1j.eVxRfNAPO$",
|
|
104
|
+
};
|
|
105
|
+
static const char *const sha1_expected_output_h[] =
|
|
106
|
+
{
|
|
107
|
+
"$sha1$3643984551$ggu.H673kaZ5$",
|
|
108
|
+
"$sha1$4200450659$SWqudaxXA5L0$",
|
|
109
|
+
"$sha1$3946507480$RAtkIrDxEovH$",
|
|
110
|
+
"$sha1$3486175838$1j.eVxRfNAPO$",
|
|
111
|
+
};
|
|
112
|
+
#endif
|
|
113
|
+
#if INCLUDE_sha256crypt
|
|
114
|
+
static const char *const sha256_expected_output[] =
|
|
115
|
+
{
|
|
116
|
+
"$5$MJHnaAkegEVYHsFK",
|
|
117
|
+
"$5$PKXc3hCOSyMqdaEQ",
|
|
118
|
+
"$5$ZAFlICwYRETzIzIj",
|
|
119
|
+
"$5$UqGBkVu01rurVZqg"
|
|
120
|
+
};
|
|
121
|
+
static const char *const sha256_expected_output_r[] =
|
|
122
|
+
{
|
|
123
|
+
"$5$rounds=10191$MJHnaAkegEVYHsFK",
|
|
124
|
+
"$5$rounds=10191$PKXc3hCOSyMqdaEQ",
|
|
125
|
+
"$5$rounds=10191$ZAFlICwYRETzIzIj",
|
|
126
|
+
"$5$rounds=10191$UqGBkVu01rurVZqg"
|
|
127
|
+
};
|
|
128
|
+
static const char *const sha256_expected_output_l[] =
|
|
129
|
+
{
|
|
130
|
+
"$5$rounds=1000$MJHnaAkegEVYHsFK",
|
|
131
|
+
"$5$rounds=1000$PKXc3hCOSyMqdaEQ",
|
|
132
|
+
"$5$rounds=1000$ZAFlICwYRETzIzIj",
|
|
133
|
+
"$5$rounds=1000$UqGBkVu01rurVZqg"
|
|
134
|
+
};
|
|
135
|
+
static const char *const sha256_expected_output_h[] =
|
|
136
|
+
{
|
|
137
|
+
"$5$rounds=999999999$MJHnaAkegEVYHsFK",
|
|
138
|
+
"$5$rounds=999999999$PKXc3hCOSyMqdaEQ",
|
|
139
|
+
"$5$rounds=999999999$ZAFlICwYRETzIzIj",
|
|
140
|
+
"$5$rounds=999999999$UqGBkVu01rurVZqg"
|
|
141
|
+
};
|
|
142
|
+
#endif
|
|
143
|
+
#if INCLUDE_sha512crypt
|
|
144
|
+
static const char *const sha512_expected_output[] =
|
|
145
|
+
{
|
|
146
|
+
"$6$MJHnaAkegEVYHsFK",
|
|
147
|
+
"$6$PKXc3hCOSyMqdaEQ",
|
|
148
|
+
"$6$ZAFlICwYRETzIzIj",
|
|
149
|
+
"$6$UqGBkVu01rurVZqg"
|
|
150
|
+
};
|
|
151
|
+
static const char *const sha512_expected_output_r[] =
|
|
152
|
+
{
|
|
153
|
+
"$6$rounds=10191$MJHnaAkegEVYHsFK",
|
|
154
|
+
"$6$rounds=10191$PKXc3hCOSyMqdaEQ",
|
|
155
|
+
"$6$rounds=10191$ZAFlICwYRETzIzIj",
|
|
156
|
+
"$6$rounds=10191$UqGBkVu01rurVZqg"
|
|
157
|
+
};
|
|
158
|
+
static const char *const sha512_expected_output_l[] =
|
|
159
|
+
{
|
|
160
|
+
"$6$rounds=1000$MJHnaAkegEVYHsFK",
|
|
161
|
+
"$6$rounds=1000$PKXc3hCOSyMqdaEQ",
|
|
162
|
+
"$6$rounds=1000$ZAFlICwYRETzIzIj",
|
|
163
|
+
"$6$rounds=1000$UqGBkVu01rurVZqg"
|
|
164
|
+
};
|
|
165
|
+
static const char *const sha512_expected_output_h[] =
|
|
166
|
+
{
|
|
167
|
+
"$6$rounds=999999999$MJHnaAkegEVYHsFK",
|
|
168
|
+
"$6$rounds=999999999$PKXc3hCOSyMqdaEQ",
|
|
169
|
+
"$6$rounds=999999999$ZAFlICwYRETzIzIj",
|
|
170
|
+
"$6$rounds=999999999$UqGBkVu01rurVZqg"
|
|
171
|
+
};
|
|
172
|
+
#endif
|
|
173
|
+
#if INCLUDE_sm3crypt
|
|
174
|
+
static const char *const sm3_expected_output[] =
|
|
175
|
+
{
|
|
176
|
+
"$sm3$MJHnaAkegEVYHsFK",
|
|
177
|
+
"$sm3$PKXc3hCOSyMqdaEQ",
|
|
178
|
+
"$sm3$ZAFlICwYRETzIzIj",
|
|
179
|
+
"$sm3$UqGBkVu01rurVZqg"
|
|
180
|
+
};
|
|
181
|
+
static const char *const sm3_expected_output_r[] =
|
|
182
|
+
{
|
|
183
|
+
"$sm3$rounds=10191$MJHnaAkegEVYHsFK",
|
|
184
|
+
"$sm3$rounds=10191$PKXc3hCOSyMqdaEQ",
|
|
185
|
+
"$sm3$rounds=10191$ZAFlICwYRETzIzIj",
|
|
186
|
+
"$sm3$rounds=10191$UqGBkVu01rurVZqg"
|
|
187
|
+
};
|
|
188
|
+
static const char *const sm3_expected_output_l[] =
|
|
189
|
+
{
|
|
190
|
+
"$sm3$rounds=1000$MJHnaAkegEVYHsFK",
|
|
191
|
+
"$sm3$rounds=1000$PKXc3hCOSyMqdaEQ",
|
|
192
|
+
"$sm3$rounds=1000$ZAFlICwYRETzIzIj",
|
|
193
|
+
"$sm3$rounds=1000$UqGBkVu01rurVZqg"
|
|
194
|
+
};
|
|
195
|
+
static const char *const sm3_expected_output_h[] =
|
|
196
|
+
{
|
|
197
|
+
"$sm3$rounds=999999999$MJHnaAkegEVYHsFK",
|
|
198
|
+
"$sm3$rounds=999999999$PKXc3hCOSyMqdaEQ",
|
|
199
|
+
"$sm3$rounds=999999999$ZAFlICwYRETzIzIj",
|
|
200
|
+
"$sm3$rounds=999999999$UqGBkVu01rurVZqg"
|
|
201
|
+
};
|
|
202
|
+
#endif
|
|
203
|
+
#if INCLUDE_bcrypt
|
|
204
|
+
static const char *const bcrypt_b_expected_output[] =
|
|
205
|
+
{
|
|
206
|
+
"$2b$05$UBVLHeMpJ/QQCv3XqJx8zO",
|
|
207
|
+
"$2b$05$kxUgPcrmlm9XoOjvxCyfP.",
|
|
208
|
+
"$2b$05$HPNDjKMRFdR7zC87CMSmA.",
|
|
209
|
+
"$2b$05$mAyzaIeJu41dWUkxEbn8hO"
|
|
210
|
+
};
|
|
211
|
+
static const char *const bcrypt_b_expected_output_l[] =
|
|
212
|
+
{
|
|
213
|
+
"$2b$04$UBVLHeMpJ/QQCv3XqJx8zO",
|
|
214
|
+
"$2b$04$kxUgPcrmlm9XoOjvxCyfP.",
|
|
215
|
+
"$2b$04$HPNDjKMRFdR7zC87CMSmA.",
|
|
216
|
+
"$2b$04$mAyzaIeJu41dWUkxEbn8hO"
|
|
217
|
+
};
|
|
218
|
+
static const char *const bcrypt_b_expected_output_h[] =
|
|
219
|
+
{
|
|
220
|
+
"$2b$31$UBVLHeMpJ/QQCv3XqJx8zO",
|
|
221
|
+
"$2b$31$kxUgPcrmlm9XoOjvxCyfP.",
|
|
222
|
+
"$2b$31$HPNDjKMRFdR7zC87CMSmA.",
|
|
223
|
+
"$2b$31$mAyzaIeJu41dWUkxEbn8hO"
|
|
224
|
+
};
|
|
225
|
+
#endif
|
|
226
|
+
#if INCLUDE_bcrypt_a
|
|
227
|
+
static const char *const bcrypt_a_expected_output[] =
|
|
228
|
+
{
|
|
229
|
+
"$2a$05$UBVLHeMpJ/QQCv3XqJx8zO",
|
|
230
|
+
"$2a$05$kxUgPcrmlm9XoOjvxCyfP.",
|
|
231
|
+
"$2a$05$HPNDjKMRFdR7zC87CMSmA.",
|
|
232
|
+
"$2a$05$mAyzaIeJu41dWUkxEbn8hO"
|
|
233
|
+
};
|
|
234
|
+
#endif
|
|
235
|
+
#if INCLUDE_bcrypt_y
|
|
236
|
+
static const char *const bcrypt_y_expected_output[] =
|
|
237
|
+
{
|
|
238
|
+
"$2y$05$UBVLHeMpJ/QQCv3XqJx8zO",
|
|
239
|
+
"$2y$05$kxUgPcrmlm9XoOjvxCyfP.",
|
|
240
|
+
"$2y$05$HPNDjKMRFdR7zC87CMSmA.",
|
|
241
|
+
"$2y$05$mAyzaIeJu41dWUkxEbn8hO"
|
|
242
|
+
};
|
|
243
|
+
#endif
|
|
244
|
+
#if INCLUDE_yescrypt
|
|
245
|
+
static const char *yescrypt_expected_output[] =
|
|
246
|
+
{
|
|
247
|
+
"$y$j9T$MJHnaAkegEVYHsFKkmfzJ1",
|
|
248
|
+
"$y$j9T$PKXc3hCOSyMqdaEQArI62/",
|
|
249
|
+
"$y$j9T$ZAFlICwYRETzIzIjEIC86.",
|
|
250
|
+
"$y$j9T$UqGBkVu01rurVZqgNchTB0"
|
|
251
|
+
};
|
|
252
|
+
static const char *yescrypt_expected_output_l[] =
|
|
253
|
+
{
|
|
254
|
+
"$y$j75$MJHnaAkegEVYHsFKkmfzJ1",
|
|
255
|
+
"$y$j75$PKXc3hCOSyMqdaEQArI62/",
|
|
256
|
+
"$y$j75$ZAFlICwYRETzIzIjEIC86.",
|
|
257
|
+
"$y$j75$UqGBkVu01rurVZqgNchTB0"
|
|
258
|
+
};
|
|
259
|
+
static const char *yescrypt_expected_output_h[] =
|
|
260
|
+
{
|
|
261
|
+
"$y$jFT$MJHnaAkegEVYHsFKkmfzJ1",
|
|
262
|
+
"$y$jFT$PKXc3hCOSyMqdaEQArI62/",
|
|
263
|
+
"$y$jFT$ZAFlICwYRETzIzIjEIC86.",
|
|
264
|
+
"$y$jFT$UqGBkVu01rurVZqgNchTB0"
|
|
265
|
+
};
|
|
266
|
+
#endif
|
|
267
|
+
#if INCLUDE_scrypt
|
|
268
|
+
static const char *scrypt_expected_output[] =
|
|
269
|
+
{
|
|
270
|
+
"$7$CU..../....MJHnaAkegEVYHsFKkmfzJ1",
|
|
271
|
+
"$7$CU..../....PKXc3hCOSyMqdaEQArI62/",
|
|
272
|
+
"$7$CU..../....ZAFlICwYRETzIzIjEIC86.",
|
|
273
|
+
"$7$CU..../....UqGBkVu01rurVZqgNchTB0"
|
|
274
|
+
};
|
|
275
|
+
static const char *scrypt_expected_output_l[] =
|
|
276
|
+
{
|
|
277
|
+
"$7$BU..../....MJHnaAkegEVYHsFKkmfzJ1",
|
|
278
|
+
"$7$BU..../....PKXc3hCOSyMqdaEQArI62/",
|
|
279
|
+
"$7$BU..../....ZAFlICwYRETzIzIjEIC86.",
|
|
280
|
+
"$7$BU..../....UqGBkVu01rurVZqgNchTB0"
|
|
281
|
+
};
|
|
282
|
+
static const char *scrypt_expected_output_h[] =
|
|
283
|
+
{
|
|
284
|
+
"$7$GU..../....MJHnaAkegEVYHsFKkmfzJ1",
|
|
285
|
+
"$7$GU..../....PKXc3hCOSyMqdaEQArI62/",
|
|
286
|
+
"$7$GU..../....ZAFlICwYRETzIzIjEIC86.",
|
|
287
|
+
"$7$GU..../....UqGBkVu01rurVZqgNchTB0"
|
|
288
|
+
};
|
|
289
|
+
#endif
|
|
290
|
+
#if INCLUDE_gost_yescrypt
|
|
291
|
+
static const char *gost_yescrypt_expected_output[] =
|
|
292
|
+
{
|
|
293
|
+
"$gy$j9T$MJHnaAkegEVYHsFKkmfzJ1",
|
|
294
|
+
"$gy$j9T$PKXc3hCOSyMqdaEQArI62/",
|
|
295
|
+
"$gy$j9T$ZAFlICwYRETzIzIjEIC86.",
|
|
296
|
+
"$gy$j9T$UqGBkVu01rurVZqgNchTB0"
|
|
297
|
+
};
|
|
298
|
+
static const char *gost_yescrypt_expected_output_l[] =
|
|
299
|
+
{
|
|
300
|
+
"$gy$j75$MJHnaAkegEVYHsFKkmfzJ1",
|
|
301
|
+
"$gy$j75$PKXc3hCOSyMqdaEQArI62/",
|
|
302
|
+
"$gy$j75$ZAFlICwYRETzIzIjEIC86.",
|
|
303
|
+
"$gy$j75$UqGBkVu01rurVZqgNchTB0"
|
|
304
|
+
};
|
|
305
|
+
static const char *gost_yescrypt_expected_output_h[] =
|
|
306
|
+
{
|
|
307
|
+
"$gy$jFT$MJHnaAkegEVYHsFKkmfzJ1",
|
|
308
|
+
"$gy$jFT$PKXc3hCOSyMqdaEQArI62/",
|
|
309
|
+
"$gy$jFT$ZAFlICwYRETzIzIjEIC86.",
|
|
310
|
+
"$gy$jFT$UqGBkVu01rurVZqgNchTB0"
|
|
311
|
+
};
|
|
312
|
+
#endif
|
|
313
|
+
#if INCLUDE_sm3_yescrypt
|
|
314
|
+
static const char *const sm3_yescrypt_expected_output[] =
|
|
315
|
+
{
|
|
316
|
+
"$sm3y$j9T$MJHnaAkegEVYHsFKkmfzJ1",
|
|
317
|
+
"$sm3y$j9T$PKXc3hCOSyMqdaEQArI62/",
|
|
318
|
+
"$sm3y$j9T$ZAFlICwYRETzIzIjEIC86.",
|
|
319
|
+
"$sm3y$j9T$UqGBkVu01rurVZqgNchTB0"
|
|
320
|
+
};
|
|
321
|
+
static const char *const sm3_yescrypt_expected_output_l[] =
|
|
322
|
+
{
|
|
323
|
+
"$sm3y$j75$MJHnaAkegEVYHsFKkmfzJ1",
|
|
324
|
+
"$sm3y$j75$PKXc3hCOSyMqdaEQArI62/",
|
|
325
|
+
"$sm3y$j75$ZAFlICwYRETzIzIjEIC86.",
|
|
326
|
+
"$sm3y$j75$UqGBkVu01rurVZqgNchTB0"
|
|
327
|
+
};
|
|
328
|
+
static const char *const sm3_yescrypt_expected_output_h[] =
|
|
329
|
+
{
|
|
330
|
+
"$sm3y$jFT$MJHnaAkegEVYHsFKkmfzJ1",
|
|
331
|
+
"$sm3y$jFT$PKXc3hCOSyMqdaEQArI62/",
|
|
332
|
+
"$sm3y$jFT$ZAFlICwYRETzIzIjEIC86.",
|
|
333
|
+
"$sm3y$jFT$UqGBkVu01rurVZqgNchTB0"
|
|
334
|
+
};
|
|
335
|
+
#endif
|
|
336
|
+
|
|
337
|
+
struct testcase
|
|
338
|
+
{
|
|
339
|
+
const char *prefix;
|
|
340
|
+
const char *const *expected_output;
|
|
341
|
+
unsigned int expected_len;
|
|
342
|
+
unsigned int expected_auto_len;
|
|
343
|
+
unsigned long rounds;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// For all hashing methods with a linear cost parameter (that is,
|
|
347
|
+
// DES/BSD, MD5/Sun, SM3, SHA1, SHA256, and SHA512), crypt_gensalt will
|
|
348
|
+
// accept any value in the range of 'unsigned long' and clip it to the
|
|
349
|
+
// actual valid range.
|
|
350
|
+
#define MIN_LINEAR_COST 1
|
|
351
|
+
#define MAX_LINEAR_COST ULONG_MAX
|
|
352
|
+
|
|
353
|
+
static const struct testcase testcases[] =
|
|
354
|
+
{
|
|
355
|
+
#if INCLUDE_descrypt
|
|
356
|
+
{ "", des_expected_output, 2, 0, 0 },
|
|
357
|
+
// DES doesn't have variable round count.
|
|
358
|
+
#endif
|
|
359
|
+
#if INCLUDE_bigcrypt && !INCLUDE_descrypt
|
|
360
|
+
{ "", big_expected_output, 14, 0, 0 },
|
|
361
|
+
// bigcrypt doesn't have variable round count.
|
|
362
|
+
#endif
|
|
363
|
+
#if INCLUDE_bsdicrypt
|
|
364
|
+
{ "_", bsdi_expected_output, 9, 0, 0 },
|
|
365
|
+
// BSDI/DES always emits a round count.
|
|
366
|
+
// The _r expectation is used to verify that even inputs are
|
|
367
|
+
// made odd, rather than rejected.
|
|
368
|
+
{ "_", bsdi_expected_output_r, 9, 0, 16384 },
|
|
369
|
+
{ "_", bsdi_expected_output_l, 9, 0, MIN_LINEAR_COST },
|
|
370
|
+
{ "_", bsdi_expected_output_h, 9, 0, MAX_LINEAR_COST },
|
|
371
|
+
#endif
|
|
372
|
+
#if INCLUDE_md5crypt
|
|
373
|
+
{ "$1$", md5_expected_output, 11, 0, 0 },
|
|
374
|
+
// MD5/BSD doesn't have variable round count.
|
|
375
|
+
#endif
|
|
376
|
+
#if INCLUDE_sunmd5
|
|
377
|
+
{ "$md5", sunmd5_expected_output, 27, 0, 0 },
|
|
378
|
+
// MD5/Sun always emits a round count.
|
|
379
|
+
{ "$md5", sunmd5_expected_output_l, 27, 0, MIN_LINEAR_COST },
|
|
380
|
+
{ "$md5", sunmd5_expected_output_h, 32, 0, MAX_LINEAR_COST },
|
|
381
|
+
#endif
|
|
382
|
+
#if INCLUDE_sm3crypt
|
|
383
|
+
{ "$sm3$", sm3_expected_output, 21, 0, 0 },
|
|
384
|
+
{ "$sm3$", sm3_expected_output_r, 34, 0, 10191 },
|
|
385
|
+
{ "$sm3$", sm3_expected_output_l, 33, 0, MIN_LINEAR_COST },
|
|
386
|
+
{ "$sm3$", sm3_expected_output_h, 38, 0, MAX_LINEAR_COST },
|
|
387
|
+
#endif
|
|
388
|
+
#if INCLUDE_sha1crypt
|
|
389
|
+
{ "$sha1", sha1_expected_output, 26, 34, 0 },
|
|
390
|
+
// SHA1/PBKDF always emits a round count.
|
|
391
|
+
{ "$sha1", sha1_expected_output_l, 21, 29, MIN_LINEAR_COST },
|
|
392
|
+
{ "$sha1", sha1_expected_output_h, 30, 38, MAX_LINEAR_COST },
|
|
393
|
+
#endif
|
|
394
|
+
#if INCLUDE_sha256crypt
|
|
395
|
+
{ "$5$", sha256_expected_output, 19, 0, 0 },
|
|
396
|
+
{ "$5$", sha256_expected_output_r, 32, 0, 10191 },
|
|
397
|
+
{ "$5$", sha256_expected_output_l, 31, 0, MIN_LINEAR_COST },
|
|
398
|
+
{ "$5$", sha256_expected_output_h, 36, 0, MAX_LINEAR_COST },
|
|
399
|
+
#endif
|
|
400
|
+
#if INCLUDE_sha512crypt
|
|
401
|
+
{ "$6$", sha512_expected_output, 19, 0, 0 },
|
|
402
|
+
{ "$6$", sha512_expected_output_r, 32, 0, 10191 },
|
|
403
|
+
{ "$6$", sha512_expected_output_l, 31, 0, MIN_LINEAR_COST },
|
|
404
|
+
{ "$6$", sha512_expected_output_h, 36, 0, MAX_LINEAR_COST },
|
|
405
|
+
#endif
|
|
406
|
+
#if INCLUDE_bcrypt
|
|
407
|
+
{ "$2b$", bcrypt_b_expected_output, 29, 0, 0 },
|
|
408
|
+
// bcrypt always emits a cost parameter.
|
|
409
|
+
// bcrypt's cost parameter is exponential, not linear, and
|
|
410
|
+
// values outside the documented range are errors.
|
|
411
|
+
{ "$2b$", bcrypt_b_expected_output_l, 29, 0, 4 },
|
|
412
|
+
{ "$2b$", bcrypt_b_expected_output_h, 29, 0, 31 },
|
|
413
|
+
#endif
|
|
414
|
+
// Salt generation for legacy bcrypt variants uses the same code as
|
|
415
|
+
// the 'b' variant, so we don't bother testing them on non-default
|
|
416
|
+
// rounds.
|
|
417
|
+
#if INCLUDE_bcrypt_a
|
|
418
|
+
{ "$2a$", bcrypt_a_expected_output, 29, 0, 0 },
|
|
419
|
+
#endif
|
|
420
|
+
#if INCLUDE_bcrypt_y
|
|
421
|
+
{ "$2y$", bcrypt_y_expected_output, 29, 0, 0 },
|
|
422
|
+
#endif
|
|
423
|
+
#if INCLUDE_yescrypt
|
|
424
|
+
{ "$y$", yescrypt_expected_output, 29, 29, 0 },
|
|
425
|
+
{ "$y$", yescrypt_expected_output_l, 29, 29, 1 },
|
|
426
|
+
{ "$y$", yescrypt_expected_output_h, 29, 29, 11 },
|
|
427
|
+
#endif
|
|
428
|
+
#if INCLUDE_scrypt
|
|
429
|
+
{ "$7$", scrypt_expected_output, 36, 36, 0 },
|
|
430
|
+
{ "$7$", scrypt_expected_output_l, 36, 36, 6 },
|
|
431
|
+
{ "$7$", scrypt_expected_output_h, 36, 36, 11 },
|
|
432
|
+
#endif
|
|
433
|
+
#if INCLUDE_gost_yescrypt
|
|
434
|
+
{ "$gy$", gost_yescrypt_expected_output, 30, 30, 0 },
|
|
435
|
+
{ "$gy$", gost_yescrypt_expected_output_l, 30, 30, 1 },
|
|
436
|
+
{ "$gy$", gost_yescrypt_expected_output_h, 30, 30, 11 },
|
|
437
|
+
#endif
|
|
438
|
+
#if INCLUDE_sm3_yescrypt
|
|
439
|
+
{ "$sm3y$", sm3_yescrypt_expected_output, 32, 32, 0 },
|
|
440
|
+
{ "$sm3y$", sm3_yescrypt_expected_output_l, 32, 32, 1 },
|
|
441
|
+
{ "$sm3y$", sm3_yescrypt_expected_output_h, 32, 32, 11 },
|
|
442
|
+
#endif
|
|
443
|
+
{ 0, 0, 0, 0, 0 }
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
/* The "best available" hashing method. */
|
|
447
|
+
#if INCLUDE_yescrypt
|
|
448
|
+
# define EXPECTED_DEFAULT_PREFIX "$y$"
|
|
449
|
+
#elif INCLUDE_bcrypt
|
|
450
|
+
# define EXPECTED_DEFAULT_PREFIX "$2b$"
|
|
451
|
+
#elif INCLUDE_sha512crypt
|
|
452
|
+
# define EXPECTED_DEFAULT_PREFIX "$6$"
|
|
453
|
+
#endif
|
|
454
|
+
|
|
455
|
+
#if CRYPT_GENSALT_IMPLEMENTS_DEFAULT_PREFIX
|
|
456
|
+
# ifndef EXPECTED_DEFAULT_PREFIX
|
|
457
|
+
# error "Which hashing algorithm is the default?"
|
|
458
|
+
# endif
|
|
459
|
+
#else
|
|
460
|
+
# ifdef EXPECTED_DEFAULT_PREFIX
|
|
461
|
+
# error "Default hashing algorithm should be available"
|
|
462
|
+
# endif
|
|
463
|
+
#endif
|
|
464
|
+
|
|
465
|
+
int
|
|
466
|
+
main (void)
|
|
467
|
+
{
|
|
468
|
+
int status = 0;
|
|
469
|
+
unsigned int ent;
|
|
470
|
+
const struct testcase *tcase;
|
|
471
|
+
char output[CRYPT_GENSALT_OUTPUT_SIZE];
|
|
472
|
+
char prev_output[CRYPT_GENSALT_OUTPUT_SIZE];
|
|
473
|
+
|
|
474
|
+
for (tcase = testcases; tcase->prefix; tcase++)
|
|
475
|
+
{
|
|
476
|
+
memset (prev_output, 0, CRYPT_GENSALT_OUTPUT_SIZE);
|
|
477
|
+
for (ent = 0; ent < ARRAY_SIZE (entropy); ent++)
|
|
478
|
+
{
|
|
479
|
+
memset (output, 0, CRYPT_GENSALT_OUTPUT_SIZE);
|
|
480
|
+
char *salt = crypt_gensalt_rn (tcase->prefix, tcase->rounds,
|
|
481
|
+
entropy[ent], 16,
|
|
482
|
+
output, CRYPT_GENSALT_OUTPUT_SIZE);
|
|
483
|
+
if (salt == 0)
|
|
484
|
+
{
|
|
485
|
+
if (entropy[ent] == 0 && errno == ENOSYS)
|
|
486
|
+
{
|
|
487
|
+
fprintf (stderr,
|
|
488
|
+
"UNSUPPORTED: %s/%lu/auto-entropy -> ENOSYS\n",
|
|
489
|
+
tcase->prefix, tcase->rounds);
|
|
490
|
+
}
|
|
491
|
+
else
|
|
492
|
+
{
|
|
493
|
+
fprintf (stderr, "ERROR: %s/%lu/%u -> 0\n",
|
|
494
|
+
tcase->prefix, tcase->rounds, ent);
|
|
495
|
+
status = 1;
|
|
496
|
+
}
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
size_t slen = strlen (salt);
|
|
500
|
+
unsigned int expected_len =
|
|
501
|
+
(!entropy[ent] && tcase->expected_auto_len) ?
|
|
502
|
+
tcase->expected_auto_len : tcase->expected_len;
|
|
503
|
+
if (slen != expected_len)
|
|
504
|
+
{
|
|
505
|
+
fprintf (stderr,
|
|
506
|
+
"ERROR: %s/%lu/%u -> %s (expected len=%u got %zu)\n",
|
|
507
|
+
tcase->prefix, tcase->rounds, ent, salt,
|
|
508
|
+
expected_len, slen);
|
|
509
|
+
status = 1;
|
|
510
|
+
}
|
|
511
|
+
else if (strncmp (salt, tcase->prefix, strlen (tcase->prefix)))
|
|
512
|
+
{
|
|
513
|
+
fprintf (stderr, "ERROR: %s/%lu/%u -> %s (prefix wrong)\n",
|
|
514
|
+
tcase->prefix, tcase->rounds, ent, salt);
|
|
515
|
+
status = 1;
|
|
516
|
+
}
|
|
517
|
+
else if (!strcmp (salt, prev_output))
|
|
518
|
+
{
|
|
519
|
+
fprintf (stderr, "ERROR: %s/%lu/%u -> %s (same as prev)\n",
|
|
520
|
+
tcase->prefix, tcase->rounds, ent, salt);
|
|
521
|
+
status = 1;
|
|
522
|
+
}
|
|
523
|
+
else if (entropy[ent] && strcmp (salt, tcase->expected_output[ent]))
|
|
524
|
+
{
|
|
525
|
+
fprintf (stderr, "ERROR: %s/%lu/%u -> %s (expected %s)\n",
|
|
526
|
+
tcase->prefix, tcase->rounds, ent, salt,
|
|
527
|
+
tcase->expected_output[ent]);
|
|
528
|
+
status = 1;
|
|
529
|
+
}
|
|
530
|
+
else
|
|
531
|
+
fprintf (stderr, " ok: %s/%lu/%u -> %s\n",
|
|
532
|
+
tcase->prefix, tcase->rounds, ent, salt);
|
|
533
|
+
|
|
534
|
+
strcpy_or_abort (prev_output, CRYPT_GENSALT_OUTPUT_SIZE, salt);
|
|
535
|
+
|
|
536
|
+
/* Test if crypt works with this salt. */
|
|
537
|
+
if (!tcase->rounds)
|
|
538
|
+
{
|
|
539
|
+
#define PASSW "alexander"
|
|
540
|
+
static struct crypt_data a, b;
|
|
541
|
+
if (!crypt_rn (PASSW, salt, &a, sizeof(a)))
|
|
542
|
+
{
|
|
543
|
+
fprintf (stderr, "ERROR: %s/%u -> crypt(gensalt) fail\n",
|
|
544
|
+
tcase->prefix, ent);
|
|
545
|
+
status = 1;
|
|
546
|
+
}
|
|
547
|
+
else if (!crypt_rn (PASSW, a.output, &b, sizeof(b)))
|
|
548
|
+
{
|
|
549
|
+
fprintf (stderr, "ERROR: %s/%u -> crypt(crypt(gensalt)) fail\n",
|
|
550
|
+
tcase->prefix, ent);
|
|
551
|
+
status = 1;
|
|
552
|
+
}
|
|
553
|
+
else if (strcmp (a.output, b.output))
|
|
554
|
+
{
|
|
555
|
+
fprintf (stderr, "ERROR: %s/%u -> crypt(gensalt) != crypt(crypt(gensalt))\n",
|
|
556
|
+
tcase->prefix, ent);
|
|
557
|
+
status = 1;
|
|
558
|
+
}
|
|
559
|
+
else
|
|
560
|
+
{
|
|
561
|
+
fprintf (stderr, " ok: %s/%u -> crypt works with this salt\n",
|
|
562
|
+
tcase->prefix, ent);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
#if CRYPT_GENSALT_IMPLEMENTS_DEFAULT_PREFIX
|
|
568
|
+
/* Passing a null pointer as the prefix argument to crypt_gensalt is
|
|
569
|
+
supposed to tell it to use the "best available" hashing method. */
|
|
570
|
+
{
|
|
571
|
+
char *setting1, *setting2;
|
|
572
|
+
setting1 = crypt_gensalt_ra (EXPECTED_DEFAULT_PREFIX, 0, entropy[0], 16);
|
|
573
|
+
setting2 = crypt_gensalt_ra (0, 0, entropy[0], 16);
|
|
574
|
+
if ((setting1 == 0 && setting2 != 0) ||
|
|
575
|
+
(setting1 != 0 && setting2 == 0) ||
|
|
576
|
+
(setting1 != 0 && setting2 != 0 && strcmp (setting1, setting2)))
|
|
577
|
+
{
|
|
578
|
+
printf ("FAILED: crypt_gensalt defaulting to $y$\n"
|
|
579
|
+
" $y$ -> %s\n"
|
|
580
|
+
" null -> %s\n",
|
|
581
|
+
setting1, setting2);
|
|
582
|
+
status = 1;
|
|
583
|
+
}
|
|
584
|
+
free (setting1);
|
|
585
|
+
free (setting2);
|
|
586
|
+
}
|
|
587
|
+
#else
|
|
588
|
+
{
|
|
589
|
+
char *setting = crypt_gensalt_ra (0, 0, entropy[0], 16);
|
|
590
|
+
if (setting)
|
|
591
|
+
{
|
|
592
|
+
printf ("FAILED: crypt_gensalt null -> %s (null expected)\n", setting);
|
|
593
|
+
status = 1;
|
|
594
|
+
}
|
|
595
|
+
free (setting);
|
|
596
|
+
}
|
|
597
|
+
#endif
|
|
598
|
+
return status;
|
|
599
|
+
}
|