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.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +106 -0
  3. data/ext/libxcrypt/AUTHORS +38 -0
  4. data/ext/libxcrypt/COPYING.LIB +502 -0
  5. data/ext/libxcrypt/ChangeLog +239 -0
  6. data/ext/libxcrypt/INSTALL +380 -0
  7. data/ext/libxcrypt/LICENSING +152 -0
  8. data/ext/libxcrypt/Makefile.am +704 -0
  9. data/ext/libxcrypt/Makefile.in +4110 -0
  10. data/ext/libxcrypt/NEWS +630 -0
  11. data/ext/libxcrypt/README +1 -0
  12. data/ext/libxcrypt/README.md +179 -0
  13. data/ext/libxcrypt/THANKS +13 -0
  14. data/ext/libxcrypt/TODO +1 -0
  15. data/ext/libxcrypt/TODO.md +100 -0
  16. data/ext/libxcrypt/aclocal.m4 +2617 -0
  17. data/ext/libxcrypt/autogen.sh +33 -0
  18. data/ext/libxcrypt/autom4te.cache/output.0 +19884 -0
  19. data/ext/libxcrypt/autom4te.cache/output.1 +19884 -0
  20. data/ext/libxcrypt/autom4te.cache/output.2 +19884 -0
  21. data/ext/libxcrypt/autom4te.cache/output.3 +19885 -0
  22. data/ext/libxcrypt/autom4te.cache/requests +714 -0
  23. data/ext/libxcrypt/autom4te.cache/traces.0 +4088 -0
  24. data/ext/libxcrypt/autom4te.cache/traces.1 +1060 -0
  25. data/ext/libxcrypt/autom4te.cache/traces.2 +4088 -0
  26. data/ext/libxcrypt/autom4te.cache/traces.3 +1060 -0
  27. data/ext/libxcrypt/build-aux/ci/ci-log-dependency-versions +79 -0
  28. data/ext/libxcrypt/build-aux/ci/ci-log-logfiles +22 -0
  29. data/ext/libxcrypt/build-aux/ci/clang-gcov-wrapper +2 -0
  30. data/ext/libxcrypt/build-aux/ci/configure-wrapper +10 -0
  31. data/ext/libxcrypt/build-aux/ci/summarize-coverage +24 -0
  32. data/ext/libxcrypt/build-aux/m4/ax_append_compile_flags.m4 +46 -0
  33. data/ext/libxcrypt/build-aux/m4/ax_append_flag.m4 +50 -0
  34. data/ext/libxcrypt/build-aux/m4/ax_check_compile_flag.m4 +53 -0
  35. data/ext/libxcrypt/build-aux/m4/ax_check_vscript.m4 +142 -0
  36. data/ext/libxcrypt/build-aux/m4/ax_gcc_func_attribute.m4 +246 -0
  37. data/ext/libxcrypt/build-aux/m4/ax_require_defined.m4 +37 -0
  38. data/ext/libxcrypt/build-aux/m4/ax_valgrind_check.m4 +239 -0
  39. data/ext/libxcrypt/build-aux/m4/libtool.m4 +8488 -0
  40. data/ext/libxcrypt/build-aux/m4/ltoptions.m4 +467 -0
  41. data/ext/libxcrypt/build-aux/m4/ltsugar.m4 +124 -0
  42. data/ext/libxcrypt/build-aux/m4/ltversion.m4 +24 -0
  43. data/ext/libxcrypt/build-aux/m4/lt~obsolete.m4 +99 -0
  44. data/ext/libxcrypt/build-aux/m4/pkg_compat.m4 +88 -0
  45. data/ext/libxcrypt/build-aux/m4/zw_alignment.m4 +90 -0
  46. data/ext/libxcrypt/build-aux/m4/zw_automodern.m4 +307 -0
  47. data/ext/libxcrypt/build-aux/m4/zw_detect_asan.m4 +24 -0
  48. data/ext/libxcrypt/build-aux/m4/zw_endianness.m4 +152 -0
  49. data/ext/libxcrypt/build-aux/m4/zw_ld_wrap.m4 +47 -0
  50. data/ext/libxcrypt/build-aux/m4/zw_prog_perl.m4 +40 -0
  51. data/ext/libxcrypt/build-aux/m4/zw_simple_warnings.m4 +150 -0
  52. data/ext/libxcrypt/build-aux/m4/zw_static_assert.m4 +68 -0
  53. data/ext/libxcrypt/build-aux/m4-autogen/compile +364 -0
  54. data/ext/libxcrypt/build-aux/m4-autogen/config.guess +1815 -0
  55. data/ext/libxcrypt/build-aux/m4-autogen/config.sub +2354 -0
  56. data/ext/libxcrypt/build-aux/m4-autogen/depcomp +792 -0
  57. data/ext/libxcrypt/build-aux/m4-autogen/install-sh +541 -0
  58. data/ext/libxcrypt/build-aux/m4-autogen/ltmain.sh +11524 -0
  59. data/ext/libxcrypt/build-aux/m4-autogen/missing +236 -0
  60. data/ext/libxcrypt/build-aux/m4-autogen/test-driver +160 -0
  61. data/ext/libxcrypt/build-aux/scripts/BuildCommon.pm +712 -0
  62. data/ext/libxcrypt/build-aux/scripts/check-perlcritic-config +76 -0
  63. data/ext/libxcrypt/build-aux/scripts/compute-symver-floor +116 -0
  64. data/ext/libxcrypt/build-aux/scripts/expand-selected-hashes +80 -0
  65. data/ext/libxcrypt/build-aux/scripts/gen-crypt-h +131 -0
  66. data/ext/libxcrypt/build-aux/scripts/gen-crypt-hashes-h +141 -0
  67. data/ext/libxcrypt/build-aux/scripts/gen-crypt-symbol-vers-h +150 -0
  68. data/ext/libxcrypt/build-aux/scripts/gen-libcrypt-map +67 -0
  69. data/ext/libxcrypt/build-aux/scripts/move-if-change +84 -0
  70. data/ext/libxcrypt/build-aux/scripts/skip-if-exec-format-error +78 -0
  71. data/ext/libxcrypt/codecov.yml +4 -0
  72. data/ext/libxcrypt/config.h.in +303 -0
  73. data/ext/libxcrypt/configure +19885 -0
  74. data/ext/libxcrypt/configure.ac +549 -0
  75. data/ext/libxcrypt/doc/crypt.3 +512 -0
  76. data/ext/libxcrypt/doc/crypt.5 +343 -0
  77. data/ext/libxcrypt/doc/crypt_checksalt.3 +106 -0
  78. data/ext/libxcrypt/doc/crypt_gensalt.3 +285 -0
  79. data/ext/libxcrypt/doc/crypt_gensalt_ra.3 +1 -0
  80. data/ext/libxcrypt/doc/crypt_gensalt_rn.3 +1 -0
  81. data/ext/libxcrypt/doc/crypt_preferred_method.3 +68 -0
  82. data/ext/libxcrypt/doc/crypt_r.3 +1 -0
  83. data/ext/libxcrypt/doc/crypt_ra.3 +1 -0
  84. data/ext/libxcrypt/doc/crypt_rn.3 +1 -0
  85. data/ext/libxcrypt/lib/alg-des-tables.c +3858 -0
  86. data/ext/libxcrypt/lib/alg-des.c +269 -0
  87. data/ext/libxcrypt/lib/alg-des.h +74 -0
  88. data/ext/libxcrypt/lib/alg-gost3411-2012-const.h +313 -0
  89. data/ext/libxcrypt/lib/alg-gost3411-2012-core.c +238 -0
  90. data/ext/libxcrypt/lib/alg-gost3411-2012-core.h +51 -0
  91. data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.c +78 -0
  92. data/ext/libxcrypt/lib/alg-gost3411-2012-hmac.h +46 -0
  93. data/ext/libxcrypt/lib/alg-gost3411-2012-precalc.h +1426 -0
  94. data/ext/libxcrypt/lib/alg-gost3411-2012-ref.h +67 -0
  95. data/ext/libxcrypt/lib/alg-hmac-sha1.c +140 -0
  96. data/ext/libxcrypt/lib/alg-hmac-sha1.h +35 -0
  97. data/ext/libxcrypt/lib/alg-md4.c +270 -0
  98. data/ext/libxcrypt/lib/alg-md4.h +43 -0
  99. data/ext/libxcrypt/lib/alg-md5.c +291 -0
  100. data/ext/libxcrypt/lib/alg-md5.h +43 -0
  101. data/ext/libxcrypt/lib/alg-sha1.c +288 -0
  102. data/ext/libxcrypt/lib/alg-sha1.h +34 -0
  103. data/ext/libxcrypt/lib/alg-sha256.c +630 -0
  104. data/ext/libxcrypt/lib/alg-sha256.h +123 -0
  105. data/ext/libxcrypt/lib/alg-sha512.c +311 -0
  106. data/ext/libxcrypt/lib/alg-sha512.h +81 -0
  107. data/ext/libxcrypt/lib/alg-sm3-hmac.c +113 -0
  108. data/ext/libxcrypt/lib/alg-sm3-hmac.h +42 -0
  109. data/ext/libxcrypt/lib/alg-sm3.c +449 -0
  110. data/ext/libxcrypt/lib/alg-sm3.h +63 -0
  111. data/ext/libxcrypt/lib/alg-yescrypt-common.c +713 -0
  112. data/ext/libxcrypt/lib/alg-yescrypt-opt.c +1568 -0
  113. data/ext/libxcrypt/lib/alg-yescrypt-platform.c +106 -0
  114. data/ext/libxcrypt/lib/alg-yescrypt.h +360 -0
  115. data/ext/libxcrypt/lib/byteorder.h +164 -0
  116. data/ext/libxcrypt/lib/crypt-bcrypt.c +1061 -0
  117. data/ext/libxcrypt/lib/crypt-des-obsolete.c +215 -0
  118. data/ext/libxcrypt/lib/crypt-des.c +491 -0
  119. data/ext/libxcrypt/lib/crypt-gensalt-static.c +40 -0
  120. data/ext/libxcrypt/lib/crypt-gost-yescrypt.c +182 -0
  121. data/ext/libxcrypt/lib/crypt-md5.c +232 -0
  122. data/ext/libxcrypt/lib/crypt-nthash.c +134 -0
  123. data/ext/libxcrypt/lib/crypt-obsolete.h +40 -0
  124. data/ext/libxcrypt/lib/crypt-pbkdf1-sha1.c +260 -0
  125. data/ext/libxcrypt/lib/crypt-port.h +514 -0
  126. data/ext/libxcrypt/lib/crypt-scrypt.c +247 -0
  127. data/ext/libxcrypt/lib/crypt-sha256.c +308 -0
  128. data/ext/libxcrypt/lib/crypt-sha512.c +323 -0
  129. data/ext/libxcrypt/lib/crypt-sm3-yescrypt.c +189 -0
  130. data/ext/libxcrypt/lib/crypt-sm3.c +308 -0
  131. data/ext/libxcrypt/lib/crypt-static.c +44 -0
  132. data/ext/libxcrypt/lib/crypt-sunmd5.c +314 -0
  133. data/ext/libxcrypt/lib/crypt-yescrypt.c +177 -0
  134. data/ext/libxcrypt/lib/crypt.c +421 -0
  135. data/ext/libxcrypt/lib/crypt.h.in +249 -0
  136. data/ext/libxcrypt/lib/gen-des-tables.c +363 -0
  137. data/ext/libxcrypt/lib/hashes.conf +59 -0
  138. data/ext/libxcrypt/lib/libcrypt.map.in +48 -0
  139. data/ext/libxcrypt/lib/libcrypt.minver +97 -0
  140. data/ext/libxcrypt/lib/libxcrypt.pc.in +15 -0
  141. data/ext/libxcrypt/lib/util-base64.c +26 -0
  142. data/ext/libxcrypt/lib/util-gensalt-sha.c +88 -0
  143. data/ext/libxcrypt/lib/util-get-random-bytes.c +154 -0
  144. data/ext/libxcrypt/lib/util-make-failure-token.c +48 -0
  145. data/ext/libxcrypt/lib/util-xbzero.c +43 -0
  146. data/ext/libxcrypt/lib/util-xstrcpy.c +42 -0
  147. data/ext/libxcrypt/lib/xcrypt.h.in +58 -0
  148. data/ext/libxcrypt/libxcrypt.spec.rpkg +481 -0
  149. data/ext/libxcrypt/rpkg.conf +2 -0
  150. data/ext/libxcrypt/rpkg.macros +86 -0
  151. data/ext/libxcrypt/test/TestCommon.pm +326 -0
  152. data/ext/libxcrypt/test/alg-des.c +80 -0
  153. data/ext/libxcrypt/test/alg-gost3411-2012-hmac.c +90 -0
  154. data/ext/libxcrypt/test/alg-gost3411-2012.c +191 -0
  155. data/ext/libxcrypt/test/alg-hmac-sha1.c +187 -0
  156. data/ext/libxcrypt/test/alg-md4.c +111 -0
  157. data/ext/libxcrypt/test/alg-md5.c +134 -0
  158. data/ext/libxcrypt/test/alg-pbkdf-hmac-sha256.c +269 -0
  159. data/ext/libxcrypt/test/alg-sha1.c +111 -0
  160. data/ext/libxcrypt/test/alg-sha256.c +141 -0
  161. data/ext/libxcrypt/test/alg-sha512.c +170 -0
  162. data/ext/libxcrypt/test/alg-sm3-hmac.c +149 -0
  163. data/ext/libxcrypt/test/alg-sm3.c +168 -0
  164. data/ext/libxcrypt/test/alg-yescrypt.c +466 -0
  165. data/ext/libxcrypt/test/badsalt.c +726 -0
  166. data/ext/libxcrypt/test/badsetting.c +350 -0
  167. data/ext/libxcrypt/test/byteorder.c +254 -0
  168. data/ext/libxcrypt/test/checksalt.c +265 -0
  169. data/ext/libxcrypt/test/compile-strong-alias.c +43 -0
  170. data/ext/libxcrypt/test/crypt-badargs.c +392 -0
  171. data/ext/libxcrypt/test/crypt-gost-yescrypt.c +149 -0
  172. data/ext/libxcrypt/test/crypt-nested-call.c +180 -0
  173. data/ext/libxcrypt/test/crypt-sm3-yescrypt.c +149 -0
  174. data/ext/libxcrypt/test/crypt-too-long-phrase.c +157 -0
  175. data/ext/libxcrypt/test/des-cases.h +196 -0
  176. data/ext/libxcrypt/test/des-obsolete.c +206 -0
  177. data/ext/libxcrypt/test/des-obsolete_r.c +207 -0
  178. data/ext/libxcrypt/test/explicit-bzero.c +334 -0
  179. data/ext/libxcrypt/test/gensalt-bcrypt_x.c +54 -0
  180. data/ext/libxcrypt/test/gensalt-extradata.c +246 -0
  181. data/ext/libxcrypt/test/gensalt-nested-call.c +126 -0
  182. data/ext/libxcrypt/test/gensalt-nthash.c +65 -0
  183. data/ext/libxcrypt/test/gensalt.c +599 -0
  184. data/ext/libxcrypt/test/getrandom-fallbacks.c +295 -0
  185. data/ext/libxcrypt/test/getrandom-interface.c +211 -0
  186. data/ext/libxcrypt/test/ka-table-gen.py +945 -0
  187. data/ext/libxcrypt/test/ka-table.inc +5849 -0
  188. data/ext/libxcrypt/test/ka-tester.c +240 -0
  189. data/ext/libxcrypt/test/preferred-method.c +133 -0
  190. data/ext/libxcrypt/test/short-outbuf.c +119 -0
  191. data/ext/libxcrypt/test/special-char-salt.c +1160 -0
  192. data/ext/libxcrypt/test/symbols-compat.pl +137 -0
  193. data/ext/libxcrypt/test/symbols-renames.pl +107 -0
  194. data/ext/libxcrypt/test/symbols-static.pl +87 -0
  195. data/ext/xcrypt/xcrypt.c +9 -0
  196. data/lib/xcrypt/ffi.rb +76 -0
  197. data/lib/xcrypt/version.rb +5 -0
  198. data/lib/xcrypt.rb +89 -0
  199. metadata +267 -0
@@ -0,0 +1,240 @@
1
+ /* Test crypt() API with "known answer" hashes.
2
+
3
+ Written by Zack Weinberg <zackw at panix.com> in 2019.
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 <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <errno.h>
15
+
16
+ /* The precalculated hashes in ka-table.inc, and some of the
17
+ relationships among groups of test cases (see ka-table-gen.py)
18
+ are invalidated if the execution character set is not ASCII. */
19
+ static_assert(' ' == 0x20 && 'C' == 0x43 && '~' == 0x7E,
20
+ "Execution character set does not appear to be ASCII");
21
+
22
+ /* This test verifies three things at once:
23
+ - crypt, crypt_r, crypt_rn, and crypt_ra
24
+ all produce the same outputs for the same inputs.
25
+ - given hash <- crypt(phrase, setting),
26
+ then hash == crypt(phrase, hash) also.
27
+ - crypt(phrase, setting) == crypt'(phrase, setting)
28
+ where crypt' is an independent implementation of the same
29
+ hashing method. (This is the "known answer" part of the test.)
30
+
31
+ The independent implementations come from the Python 'passlib'
32
+ library: <https://passlib.readthedocs.io/en/stable/>.
33
+ See ka-table-gen.py for more detail.
34
+
35
+ This file is compiled once for each hash, with macros defined that
36
+ make ka-table.inc expose only the subset of the tests that are
37
+ relevant to that hash. This allows the test driver to run the
38
+ known-answer tests for each enabled hash in parallel. */
39
+
40
+ struct testcase
41
+ {
42
+ const char *salt;
43
+ const char *expected;
44
+ const char *input;
45
+ };
46
+
47
+ static const struct testcase tests[] =
48
+ {
49
+ #include "ka-table.inc"
50
+
51
+ /* Sentinel. */
52
+ { 0, 0, 0 },
53
+ };
54
+
55
+ /* Print out a string, using \xXX escapes for any characters that are
56
+ not printable ASCII. Backslash, single quote, and double quote are
57
+ also escaped, by preceding them with another backslash. If machine-
58
+ parsing the output, note that we use the Python semantics of \x, not
59
+ the C semantics: each \x consumes _exactly two_ subsequent hex digits.
60
+ (For instance, \x123 means 0x12 0x33.) */
61
+ static void
62
+ print_escaped (const char *s)
63
+ {
64
+ const unsigned char *p = (const unsigned char *)s;
65
+ for (; *p; p++)
66
+ {
67
+ unsigned char c = *p;
68
+ if (c == '\\' || c == '\"' || c == '\'')
69
+ {
70
+ putchar ('\\');
71
+ putchar (c);
72
+ }
73
+ else if (0x20 <= c && c <= 0x7E)
74
+ putchar (c);
75
+ else
76
+ printf ("\\x%02x", (unsigned int)c);
77
+ }
78
+ }
79
+
80
+ /* Subroutine of report_result. */
81
+ static void
82
+ begin_error_report (const struct testcase *tc, const char *tag)
83
+ {
84
+ printf ("FAIL: %s/", tc->salt);
85
+ print_escaped (tc->input);
86
+ printf (": %s ", tag);
87
+ }
88
+
89
+ /* Summarize the result of a single hashing operation.
90
+ If everything is as expected, prints nothing and returns 0.
91
+ Otherwise, prints a diagnostic message to stdout (not stderr!)
92
+ and returns 1. */
93
+ static int
94
+ report_result (const char *tag, const char *hash, int errnm,
95
+ const struct testcase *tc, bool expect_failure_tokens)
96
+ {
97
+ if (hash && hash[0] != '*')
98
+ {
99
+ /* We don't look at errno in this branch, because errno is
100
+ allowed to be set by successful operations. */
101
+ if (!strcmp (hash, tc->expected))
102
+ return 0;
103
+
104
+ begin_error_report (tc, tag);
105
+ printf ("mismatch: expected %s got %s\n", tc->expected, hash);
106
+ return 1;
107
+ }
108
+ else
109
+ {
110
+ /* Ill-formed setting string arguments to 'crypt' are tested in a
111
+ different program, so we never _expect_ a failure. However, if
112
+ we do get a failure, we want to log it in detail. */
113
+ begin_error_report (tc, tag);
114
+
115
+ if (hash == 0)
116
+ printf ("failure: got (null)");
117
+ else
118
+ printf ("failure: got %s", hash);
119
+
120
+ /* errno should have been set. */
121
+ if (errnm)
122
+ printf (", errno = %s", strerror (errnm));
123
+ else
124
+ printf (", errno not set");
125
+
126
+ /* Should the API used have generated a NULL or a failure token? */
127
+ if (hash == 0 && expect_failure_tokens)
128
+ printf (", failure token not generated");
129
+ if (hash != 0 && !expect_failure_tokens)
130
+ printf (", failure token wrongly generated");
131
+
132
+ /* A failure token must never compare equal to the setting string
133
+ that was used in the computation. N.B. recrypt uses crypt_rn,
134
+ which never produces failure tokens, so in this branch we can
135
+ safely assume that the setting string used was tc->salt
136
+ (if it generates one anyway that's an automatic failure). */
137
+ if (hash != 0 && !strcmp (tc->salt, hash))
138
+ printf (", failure token == salt");
139
+
140
+ putchar ('\n');
141
+ return 1;
142
+ }
143
+ }
144
+
145
+ static int
146
+ calc_hashes_crypt (void)
147
+ {
148
+ char *hash;
149
+ const struct testcase *t;
150
+ int status = 0;
151
+
152
+ for (t = tests; t->input != 0; t++)
153
+ {
154
+ errno = 0;
155
+ hash = crypt (t->input, t->salt);
156
+ status |= report_result ("crypt", hash, errno, t,
157
+ ENABLE_FAILURE_TOKENS);
158
+ }
159
+
160
+ return status;
161
+ }
162
+
163
+ static int
164
+ calc_hashes_crypt_r_rn (void)
165
+ {
166
+ char *hash;
167
+ union
168
+ {
169
+ char pass[CRYPT_MAX_PASSPHRASE_SIZE + 1];
170
+ int aligned;
171
+ } u;
172
+ const struct testcase *t;
173
+ struct crypt_data data;
174
+ int status = 0;
175
+
176
+ memset (&data, 0, sizeof data);
177
+ memset (u.pass, 0, CRYPT_MAX_PASSPHRASE_SIZE + 1);
178
+ for (t = tests; t->input != 0; t++)
179
+ {
180
+ strncpy(u.pass + 1, t->input, CRYPT_MAX_PASSPHRASE_SIZE);
181
+ printf("[%zu]: %s %s\n", strlen(t->input),
182
+ t->input, t->salt);
183
+ errno = 0;
184
+ hash = crypt_r (u.pass + 1, t->salt, &data);
185
+ status |= report_result ("crypt_r", hash, errno, t,
186
+ ENABLE_FAILURE_TOKENS);
187
+
188
+ errno = 0;
189
+ hash = crypt_rn (u.pass + 1, t->salt, &data, (int)sizeof data);
190
+ status |= report_result ("crypt_rn", hash, errno, t, false);
191
+ }
192
+
193
+ return status;
194
+ }
195
+
196
+ static int
197
+ calc_hashes_crypt_ra_recrypt (void)
198
+ {
199
+ char *hash;
200
+ const struct testcase *t;
201
+ void *datap = 0;
202
+ int datasz = 0;
203
+ int status = 0;
204
+
205
+ for (t = tests; t->input != 0; t++)
206
+ {
207
+ errno = 0;
208
+ hash = crypt_ra (t->input, t->salt, &datap, &datasz);
209
+ if (report_result ("crypt_ra", hash, errno, t, false))
210
+ status = 1;
211
+ else
212
+ {
213
+ /* if we get here, we know hash == t->expected */
214
+ errno = 0;
215
+ hash = crypt_ra (t->input, t->expected,
216
+ &datap, &datasz);
217
+ status |= report_result ("recrypt", hash, errno, t, false);
218
+ }
219
+ }
220
+
221
+ free (datap);
222
+ return status;
223
+ }
224
+
225
+ int
226
+ main (void)
227
+ {
228
+ int status = 0;
229
+
230
+ /* Mark this test SKIPPED if the very first entry in the table is the
231
+ sentinel; this happens only when the hash we would test is disabled. */
232
+ if (tests[0].input == 0)
233
+ return 77;
234
+
235
+ status |= calc_hashes_crypt ();
236
+ status |= calc_hashes_crypt_r_rn ();
237
+ status |= calc_hashes_crypt_ra_recrypt ();
238
+
239
+ return status;
240
+ }
@@ -0,0 +1,133 @@
1
+ /* Copyright (C) 2018 Björn Esser <besser82@fedoraproject.org>
2
+ *
3
+ * Redistribution and use in source and binary forms, with or without
4
+ * modification, are permitted.
5
+ *
6
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
7
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
10
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
11
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
12
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
14
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
16
+ * SUCH DAMAGE.
17
+ */
18
+
19
+ #include "crypt-port.h"
20
+ #include <stdio.h>
21
+
22
+ #define PASSPHRASE "Ob-La-Di, Ob-La-Da"
23
+
24
+ int
25
+ main (void)
26
+ {
27
+ const char *pm = crypt_preferred_method();
28
+ int retval = 0;
29
+
30
+ #if defined HASH_ALGORITHM_DEFAULT
31
+ if (pm == NULL)
32
+ {
33
+ printf ("FAIL: crypt_preferred_method returned NULL.\n");
34
+ retval = 1;
35
+ }
36
+ else
37
+ {
38
+ printf ("PASS: crypt_preferred_method returned \"%s\".\n", pm);
39
+
40
+ char gs[CRYPT_GENSALT_OUTPUT_SIZE];
41
+ struct crypt_data cd;
42
+
43
+ crypt_gensalt_rn (NULL, 0, NULL, 0, gs, sizeof (gs));
44
+
45
+ if (strncmp (gs, pm, strlen (pm)))
46
+ {
47
+ printf ("FAIL: crypt_preferred_method: \"%s\" ", pm);
48
+ printf ("differs from default prefix.\n");
49
+ printf ("crypt_gensalt returned: \"%s\".\n", gs);
50
+ retval = 1;
51
+ }
52
+ else
53
+ {
54
+ printf ("PASS: crypt_preferred_method: \"%s\" ", pm);
55
+ printf ("is the same as default prefix used by ");
56
+ printf ("crypt_gensalt.\n");
57
+ }
58
+
59
+ crypt_gensalt_rn (pm, 0, NULL, 0, gs, sizeof (gs));
60
+
61
+ if (gs[0] == '*')
62
+ {
63
+ printf ("FAIL: crypt_preferred_method: \"%s\" ", pm);
64
+ printf ("is not a valid prefix for crypt_gensalt.\n");
65
+ printf ("crypt_gensalt returned: \"%s\".\n", gs);
66
+ retval = 1;
67
+ }
68
+ else
69
+ {
70
+ printf ("PASS: crypt_preferred_method: \"%s\" ", pm);
71
+ printf ("is a valid prefix for crypt_gensalt.\n");
72
+ }
73
+
74
+ if (strncmp (gs, pm, strlen (pm)))
75
+ {
76
+ printf ("FAIL: crypt_preferred_method: \"%s\" ", pm);
77
+ printf ("does not generate a setting for ");
78
+ printf ("the intended method.\n");
79
+ printf ("crypt_gensalt returned: \"%s\".\n", gs);
80
+ retval = 1;
81
+ }
82
+ else
83
+ {
84
+ printf ("PASS: crypt_preferred_method: \"%s\" ", pm);
85
+ printf ("does generate a setting for ");
86
+ printf ("the intended method.\n");
87
+ }
88
+
89
+ crypt_r (PASSPHRASE, gs, &cd);
90
+
91
+ if (cd.output[0] == '*')
92
+ {
93
+ printf ("FAIL: crypt_preferred_method: \"%s\" ", pm);
94
+ printf ("is not a valid prefix for crypt.\n");
95
+ printf ("crypt returned: \"%s\".\n", gs);
96
+ retval = 1;
97
+ }
98
+ else
99
+ {
100
+ printf ("PASS: crypt_preferred_method: \"%s\" ", pm);
101
+ printf ("is a valid prefix for crypt.\n");
102
+ }
103
+
104
+ if (strncmp (cd.output, pm, strlen (pm)))
105
+ {
106
+ printf ("FAIL: crypt_preferred_method: \"%s\" ", pm);
107
+ printf ("does not generate a hash with ");
108
+ printf ("the intended method.\n");
109
+ printf ("crypt returned: \"%s\".\n", gs);
110
+ retval = 1;
111
+ }
112
+ else
113
+ {
114
+ printf ("PASS: crypt_preferred_method: \"%s\" ", pm);
115
+ printf ("does generate a hash with ");
116
+ printf ("the intended method.\n");
117
+ }
118
+ }
119
+ #else
120
+ if (pm != NULL)
121
+ {
122
+ printf ("FAIL: crypt_preferred_method returned: \"%s\" ", pm);
123
+ printf ("instead of NULL.\n");
124
+ retval = 1;
125
+ }
126
+ else
127
+ {
128
+ printf ("PASS: crypt_preferred_method returned NULL.");
129
+ }
130
+ #endif
131
+
132
+ return retval;
133
+ }
@@ -0,0 +1,119 @@
1
+ /* Copyright (C) 2018 Björn Esser <besser82@fedoraproject.org>
2
+ *
3
+ * Redistribution and use in source and binary forms, with or without
4
+ * modification, are permitted.
5
+ *
6
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
7
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
10
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
11
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
12
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
14
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
16
+ * SUCH DAMAGE.
17
+ */
18
+
19
+ #include "crypt-port.h"
20
+ #include <stdio.h>
21
+ #include <stdlib.h>
22
+ #include <string.h>
23
+
24
+ struct testcase
25
+ {
26
+ const char *exp_rn;
27
+ const char *exp_ra;
28
+ };
29
+
30
+ static const struct testcase testcases[] =
31
+ {
32
+ { "", "*0" },
33
+ { "*", "*0" },
34
+ { "*0", "*0" },
35
+ };
36
+
37
+ int
38
+ main (void)
39
+ {
40
+ bool ok = true;
41
+ char result[5];
42
+
43
+ for (size_t i = 0; i < ARRAY_SIZE (testcases); i++)
44
+ {
45
+ size_t s = i + 1;
46
+ int j = (int) s;
47
+ char *outbuf = malloc (sizeof (char) * s);
48
+
49
+ crypt_rn ("@@", "@@", outbuf, j);
50
+
51
+ if (!strncmp (testcases[i].exp_rn, outbuf, s))
52
+ {
53
+ strcpy (result, "PASS");
54
+ }
55
+ else
56
+ {
57
+ strcpy (result, "FAIL");
58
+ ok = false;
59
+ }
60
+
61
+ printf ("Test %zu.0: %s, expected: \"%-2s\", got: \"%-2s\"\n",
62
+ s, result, testcases[i].exp_rn, outbuf);
63
+
64
+ crypt_ra ("@@", "@@", (void **) &outbuf, &j);
65
+
66
+ if (!strncmp (testcases[i].exp_ra, outbuf, strlen(outbuf)))
67
+ {
68
+ strcpy (result, "PASS");
69
+ }
70
+ else
71
+ {
72
+ strcpy (result, "FAIL");
73
+ ok = false;
74
+ }
75
+
76
+ printf ("Test %zu.1: %s, expected: \"%-2s\", got: \"%-2s\"\n",
77
+ s, result, testcases[i].exp_ra, outbuf);
78
+
79
+ j = -1;
80
+
81
+ crypt_ra ("@@", "@@", (void **) &outbuf, &j);
82
+
83
+ if (!strncmp (testcases[i].exp_ra, outbuf, strlen(outbuf)))
84
+ {
85
+ strcpy (result, "PASS");
86
+ }
87
+ else
88
+ {
89
+ strcpy (result, "FAIL");
90
+ ok = false;
91
+ }
92
+
93
+ printf ("Test %zu.2: %s, expected: \"%-2s\", got: \"%-2s\"\n",
94
+ s, result, testcases[i].exp_ra, outbuf);
95
+
96
+ free (outbuf);
97
+ outbuf = NULL;
98
+ j = sizeof (struct crypt_data);
99
+
100
+ crypt_ra ("@@", "@@", (void **) &outbuf, &j);
101
+
102
+ if (!strncmp (testcases[i].exp_ra, outbuf, strlen(outbuf)))
103
+ {
104
+ strcpy (result, "PASS");
105
+ }
106
+ else
107
+ {
108
+ strcpy (result, "FAIL");
109
+ ok = false;
110
+ }
111
+
112
+ printf ("Test %zu.3: %s, expected: \"%-2s\", got: \"%-2s\"\n",
113
+ s, result, testcases[i].exp_ra, outbuf);
114
+
115
+ free (outbuf);
116
+ }
117
+
118
+ return ok ? 0 : 1;
119
+ }