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,40 @@
1
+ /* Copyright (C) 2007-2017 Thorsten Kukuk
2
+
3
+ This library is free software; you can redistribute it and/or
4
+ modify it under the terms of the GNU Lesser General Public License
5
+ as published by the Free Software Foundation; either version 2.1 of
6
+ the License, or (at your option) any later version.
7
+
8
+ This library is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU Lesser General Public License for more details.
12
+
13
+ You should have received a copy of the GNU Lesser General Public
14
+ License along with this library; if not, see
15
+ <https://www.gnu.org/licenses/>. */
16
+
17
+ #include "crypt-port.h"
18
+
19
+ /* The functions that use global state objects are isolated in their
20
+ own files so that a statically-linked program that doesn't use them
21
+ will not have the state objects in its data segment. */
22
+
23
+ #if INCLUDE_crypt_gensalt
24
+ char *
25
+ crypt_gensalt (const char *prefix, unsigned long count,
26
+ const char *rbytes, int nrbytes)
27
+ {
28
+ static char output[CRYPT_GENSALT_OUTPUT_SIZE];
29
+
30
+ return crypt_gensalt_rn (prefix, count,
31
+ rbytes, nrbytes, output, sizeof (output));
32
+ }
33
+ SYMVER_crypt_gensalt;
34
+ #endif
35
+
36
+ /* For code compatibility with older versions (v3.1.1 and earlier). */
37
+ #if INCLUDE_crypt_gensalt && INCLUDE_xcrypt_gensalt
38
+ strong_alias (crypt_gensalt, xcrypt_gensalt);
39
+ SYMVER_xcrypt_gensalt;
40
+ #endif
@@ -0,0 +1,182 @@
1
+ /* Copyright (C) 2018 vt@altlinux.org
2
+ * Copyright (C) 2018 Björn Esser besser82@fedoraproject.org
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted.
6
+ *
7
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
8
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
11
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
12
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
13
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
15
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
16
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
17
+ * SUCH DAMAGE.
18
+ */
19
+
20
+ #include "crypt-port.h"
21
+
22
+ #if INCLUDE_gost_yescrypt
23
+
24
+ #define YESCRYPT_INTERNAL
25
+ #include "alg-yescrypt.h"
26
+ #undef YESCRYPT_INTERNAL
27
+
28
+ #include "alg-gost3411-2012-hmac.h"
29
+
30
+ #include <errno.h>
31
+
32
+ /* upper level hmac for tests */
33
+ #ifndef outer_gost_hmac256
34
+ #define outer_gost_hmac256 gost_hmac256
35
+ #endif
36
+
37
+ /* For use in scratch space by crypt_gost_yescrypt_rn(). */
38
+ typedef struct
39
+ {
40
+ yescrypt_local_t local;
41
+ gost_hmac_256_t gostbuf;
42
+ uint8_t outbuf[CRYPT_OUTPUT_SIZE];
43
+ uint8_t gsetting[CRYPT_OUTPUT_SIZE];
44
+ uint8_t hk[32], interm[32], y[32];
45
+ uint8_t *retval;
46
+ } crypt_gost_yescrypt_internal_t;
47
+
48
+ static_assert (sizeof (crypt_gost_yescrypt_internal_t) <= ALG_SPECIFIC_SIZE,
49
+ "ALG_SPECIFIC_SIZE is too small for GOST-YESCRYPT.");
50
+
51
+ /*
52
+ * As OUTPUT is initialized with a failure token before gensalt_yescrypt_rn
53
+ * is called, in case of an error we could just set an appropriate errno
54
+ * and return.
55
+ */
56
+ void
57
+ gensalt_gost_yescrypt_rn (unsigned long count,
58
+ const uint8_t *rbytes, size_t nrbytes,
59
+ uint8_t *output, size_t o_size)
60
+ {
61
+ /* Up to 512 bits (64 bytes) of entropy for computing the salt portion
62
+ of the MCF-setting are supported. */
63
+ nrbytes = (nrbytes > 64 ? 64 : nrbytes);
64
+
65
+ if (o_size < 4 + 8 * 6 + BASE64_LEN (nrbytes) + 1 ||
66
+ CRYPT_GENSALT_OUTPUT_SIZE < 4 + 8 * 6 + BASE64_LEN (nrbytes) + 1)
67
+ {
68
+ errno = ERANGE;
69
+ return;
70
+ }
71
+
72
+ /* We pass 'o_size - 1' to gensalt, because we need to shift
73
+ the prefix by 1 char to insert the gost marker. */
74
+ gensalt_yescrypt_rn (count, rbytes, nrbytes, output, o_size - 1);
75
+
76
+ /* Check for failures. */
77
+ if (output[0] == '*')
78
+ return;
79
+
80
+ /* Shift output one byte further. */
81
+ memmove (output + 1, output, strlen ((const char *) output) + 1);
82
+
83
+ /* Insert the gost marker. */
84
+ output[1] = 'g';
85
+ }
86
+
87
+ void
88
+ crypt_gost_yescrypt_rn (const char *phrase, size_t phr_size,
89
+ const char *setting, size_t set_size,
90
+ uint8_t *output, size_t o_size,
91
+ void *scratch, size_t s_size)
92
+ {
93
+ if (o_size < set_size + 1 + 43 + 1 ||
94
+ CRYPT_OUTPUT_SIZE < set_size + 1 + 43 + 1 ||
95
+ s_size < sizeof (crypt_gost_yescrypt_internal_t))
96
+ {
97
+ errno = ERANGE;
98
+ return;
99
+ }
100
+
101
+ /* Fail when called with wrong prefix. */
102
+ if (strncmp (setting, "$gy$", 4))
103
+ {
104
+ errno = EINVAL;
105
+ return;
106
+ }
107
+
108
+ crypt_gost_yescrypt_internal_t *intbuf = scratch;
109
+
110
+ if (yescrypt_init_local (&intbuf->local))
111
+ return;
112
+
113
+ /* convert gost setting to yescrypt setting */
114
+ intbuf->gsetting[0] = '$';
115
+ intbuf->gsetting[1] = 'y';
116
+ intbuf->gsetting[2] = '$';
117
+ strcpy_or_abort (&intbuf->gsetting[3], set_size - 3, setting + 4);
118
+
119
+ intbuf->retval = yescrypt_r (NULL, &intbuf->local,
120
+ (const uint8_t *) phrase, phr_size,
121
+ intbuf->gsetting, NULL,
122
+ intbuf->outbuf + 1, o_size - 1);
123
+
124
+ if (!intbuf->retval)
125
+ errno = EINVAL;
126
+
127
+ if (yescrypt_free_local (&intbuf->local) || !intbuf->retval)
128
+ return;
129
+
130
+ intbuf->outbuf[0] = '$';
131
+ intbuf->outbuf[1] = 'g';
132
+
133
+ /* extract yescrypt output from "$y$param$salt$output" */
134
+ char *hptr = strchr ((const char *) intbuf->retval + 3, '$');
135
+ if (!hptr)
136
+ {
137
+ errno = EINVAL;
138
+ return;
139
+ }
140
+ hptr = strchr (hptr + 1, '$');
141
+ if (!hptr)
142
+ {
143
+ errno = EINVAL;
144
+ return;
145
+ }
146
+ hptr++; /* start of output */
147
+
148
+ /* decode yescrypt output into its raw 256-bit form */
149
+ size_t ylen = sizeof (intbuf->y);
150
+ if (!decode64 (intbuf->y, &ylen, (uint8_t *) hptr, strlen (hptr)) ||
151
+ ylen != sizeof (intbuf->y))
152
+ {
153
+ errno = EINVAL;
154
+ return;
155
+ }
156
+
157
+ /*
158
+ * HMAC_GOSTR3411_2012_256(
159
+ * HMAC_GOSTR3411_2012_256(GOST2012_256(K), S),
160
+ * yescrypt(K, S)
161
+ * )
162
+ * yescrypt output is used in place of message,
163
+ * thus, its crypto properties are superseded by GOST.
164
+ * Password is always hashed for inner hmac to avoid
165
+ * collisions between hashed and unhashed passwords.
166
+ */
167
+ gost_hash256 ((const uint8_t *) phrase, phr_size, intbuf->hk, &intbuf->gostbuf.ctx);
168
+ gost_hmac256 (intbuf->hk, sizeof (intbuf->hk),
169
+ (const uint8_t *) setting,
170
+ (size_t) ((uint8_t *) hptr - intbuf->retval),
171
+ intbuf->interm, &intbuf->gostbuf);
172
+ outer_gost_hmac256 (intbuf->interm, sizeof (intbuf->interm),
173
+ intbuf->y, sizeof (intbuf->y), intbuf->y, &intbuf->gostbuf);
174
+
175
+ encode64 ((uint8_t *) hptr, o_size - (size_t) ((uint8_t *) hptr - intbuf->retval),
176
+ intbuf->y, sizeof (intbuf->y));
177
+
178
+ strcpy_or_abort (output, o_size, intbuf->outbuf);
179
+ return;
180
+ }
181
+
182
+ #endif /* INCLUDE_gost_yescrypt */
@@ -0,0 +1,232 @@
1
+ /* One way encryption based on MD5 sum.
2
+ Compatible with the behavior of MD5 crypt introduced in FreeBSD 2.0.
3
+
4
+ Copyright (C) 1996-2017 Free Software Foundation, Inc.
5
+ Modified by Björn Esser <besser82 at fedoraproject.org> in 2020.
6
+
7
+ This library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Lesser General Public License
9
+ as published by the Free Software Foundation; either version 2.1 of
10
+ the License, or (at your option) any later version.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public
18
+ License along with this library; if not, see
19
+ <https://www.gnu.org/licenses/>. */
20
+
21
+ #include "crypt-port.h"
22
+ #include "alg-md5.h"
23
+
24
+ #include <errno.h>
25
+
26
+ #if INCLUDE_md5crypt
27
+
28
+ /* Define our magic string to mark salt for MD5 "encryption"
29
+ replacement. This is meant to be the same as for other MD5 based
30
+ encryption implementations. */
31
+ static const char md5_salt_prefix[] = "$1$";
32
+
33
+ /* The maximum length of an MD5 salt string (just the actual salt, not
34
+ the entire prefix). */
35
+ #define SALT_LEN_MAX 8
36
+
37
+ /* The length of an MD5-hashed password string, including the
38
+ terminating NUL character. Prefix (including its NUL) + 8 bytes of
39
+ salt + separator + 22 bytes of hashed password. */
40
+ #define MD5_HASH_LENGTH \
41
+ (sizeof (md5_salt_prefix) + SALT_LEN_MAX + 1 + 22)
42
+
43
+ static_assert (MD5_HASH_LENGTH <= CRYPT_OUTPUT_SIZE,
44
+ "CRYPT_OUTPUT_SIZE is too small for MD5");
45
+
46
+ /* An md5_buffer holds all of the sensitive intermediate data. */
47
+ struct md5_buffer
48
+ {
49
+ MD5_CTX ctx;
50
+ uint8_t result[16];
51
+ };
52
+
53
+ static_assert (sizeof (struct md5_buffer) <= ALG_SPECIFIC_SIZE,
54
+ "ALG_SPECIFIC_SIZE is too small for MD5");
55
+
56
+
57
+ /* This entry point is equivalent to the `crypt' function in Unix
58
+ libcs. */
59
+ void
60
+ crypt_md5crypt_rn (const char *phrase, size_t phr_size,
61
+ const char *setting, size_t ARG_UNUSED (set_size),
62
+ uint8_t *output, size_t out_size,
63
+ void *scratch, size_t scr_size)
64
+ {
65
+ /* This shouldn't ever happen, but... */
66
+ if (out_size < MD5_HASH_LENGTH || scr_size < sizeof (struct md5_buffer))
67
+ {
68
+ errno = ERANGE;
69
+ return;
70
+ }
71
+
72
+ struct md5_buffer *buf = scratch;
73
+ MD5_CTX *ctx = &buf->ctx;
74
+ uint8_t *result = buf->result;
75
+ char *cp = (char *)output;
76
+ const char *salt = setting;
77
+
78
+ size_t salt_size;
79
+ size_t cnt;
80
+
81
+ /* Find beginning of salt string. The prefix should normally always
82
+ be present. Just in case it is not. */
83
+ if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
84
+ /* Skip salt prefix. */
85
+ salt += sizeof (md5_salt_prefix) - 1;
86
+
87
+
88
+ /* The salt ends at the next '$' or the end of the string.
89
+ Ensure ':' does not appear in the salt (it is used as a separator in /etc/passwd).
90
+ Also check for '\n', as in /etc/passwd the whole parameters of the user data must
91
+ be on a single line. */
92
+ salt_size = strcspn (salt, "$:\n");
93
+ if (!(salt[salt_size] == '$' || !salt[salt_size]))
94
+ {
95
+ errno = EINVAL;
96
+ return;
97
+ }
98
+
99
+ /* Ensure we do not use more salt than SALT_LEN_MAX. */
100
+ if (salt_size > SALT_LEN_MAX)
101
+ salt_size = SALT_LEN_MAX;
102
+
103
+ /* Compute alternate MD5 sum with input PHRASE, SALT, and PHRASE. The
104
+ final result will be added to the first context. */
105
+ MD5_Init (ctx);
106
+
107
+ /* Add phrase. */
108
+ MD5_Update (ctx, phrase, phr_size);
109
+
110
+ /* Add salt. */
111
+ MD5_Update (ctx, salt, salt_size);
112
+
113
+ /* Add phrase again. */
114
+ MD5_Update (ctx, phrase, phr_size);
115
+
116
+ /* Now get result of this (16 bytes). */
117
+ MD5_Final (result, ctx);
118
+
119
+ /* Prepare for the real work. */
120
+ MD5_Init (ctx);
121
+
122
+ /* Add the phrase string. */
123
+ MD5_Update (ctx, phrase, phr_size);
124
+
125
+ /* Because the SALT argument need not always have the salt prefix we
126
+ add it separately. */
127
+ MD5_Update (ctx, md5_salt_prefix, sizeof (md5_salt_prefix) - 1);
128
+
129
+ /* The last part is the salt string. This must be at most 8
130
+ characters and it ends at the first `$' character (for
131
+ compatibility with existing implementations). */
132
+ MD5_Update (ctx, salt, salt_size);
133
+
134
+
135
+ /* Add for any character in the phrase one byte of the alternate sum. */
136
+ for (cnt = phr_size; cnt > 16; cnt -= 16)
137
+ MD5_Update (ctx, result, 16);
138
+ MD5_Update (ctx, result, cnt);
139
+
140
+ /* For the following code we need a NUL byte. */
141
+ *result = '\0';
142
+
143
+ /* The original implementation now does something weird: for every 1
144
+ bit in the phrase the first 0 is added to the buffer, for every 0
145
+ bit the first character of the phrase. This does not seem to be
146
+ what was intended but we have to follow this to be compatible. */
147
+ for (cnt = phr_size; cnt > 0; cnt >>= 1)
148
+ MD5_Update (ctx, (cnt & 1) != 0 ? (const char *) result : phrase, 1);
149
+
150
+ /* Create intermediate result. */
151
+ MD5_Final (result, ctx);
152
+
153
+ /* Now comes another weirdness. In fear of password crackers here
154
+ comes a quite long loop which just processes the output of the
155
+ previous round again. We cannot ignore this here. */
156
+ for (cnt = 0; cnt < 1000; ++cnt)
157
+ {
158
+ /* New context. */
159
+ MD5_Init (ctx);
160
+
161
+ /* Add phrase or last result. */
162
+ if ((cnt & 1) != 0)
163
+ MD5_Update (ctx, phrase, phr_size);
164
+ else
165
+ MD5_Update (ctx, result, 16);
166
+
167
+ /* Add salt for numbers not divisible by 3. */
168
+ if (cnt % 3 != 0)
169
+ MD5_Update (ctx, salt, salt_size);
170
+
171
+ /* Add phrase for numbers not divisible by 7. */
172
+ if (cnt % 7 != 0)
173
+ MD5_Update (ctx, phrase, phr_size);
174
+
175
+ /* Add phrase or last result. */
176
+ if ((cnt & 1) != 0)
177
+ MD5_Update (ctx, result, 16);
178
+ else
179
+ MD5_Update (ctx, phrase, phr_size);
180
+
181
+ /* Create intermediate result. */
182
+ MD5_Final (result, ctx);
183
+ }
184
+
185
+ /* Now we can construct the result string. It consists of three
186
+ parts. We already know that there is enough space at CP. */
187
+ memcpy (cp, md5_salt_prefix, sizeof (md5_salt_prefix) - 1);
188
+ cp += sizeof (md5_salt_prefix) - 1;
189
+
190
+ memcpy (cp, salt, salt_size);
191
+ cp += salt_size;
192
+ *cp++ = '$';
193
+
194
+ #define b64_from_24bit(B2, B1, B0, N) \
195
+ do { \
196
+ unsigned int w = ((((unsigned int)(B2)) << 16) | \
197
+ (((unsigned int)(B1)) << 8) | \
198
+ ((unsigned int)(B0))); \
199
+ int n = (N); \
200
+ while (n-- > 0) \
201
+ { \
202
+ *cp++ = b64t[w & 0x3f]; \
203
+ w >>= 6; \
204
+ } \
205
+ } while (0)
206
+
207
+
208
+ b64_from_24bit (result[0], result[6], result[12], 4);
209
+ b64_from_24bit (result[1], result[7], result[13], 4);
210
+ b64_from_24bit (result[2], result[8], result[14], 4);
211
+ b64_from_24bit (result[3], result[9], result[15], 4);
212
+ b64_from_24bit (result[4], result[10], result[5], 4);
213
+ b64_from_24bit (0, 0, result[11], 2);
214
+
215
+ *cp = '\0';
216
+ }
217
+
218
+ void
219
+ gensalt_md5crypt_rn (unsigned long count,
220
+ const uint8_t *rbytes, size_t nrbytes,
221
+ uint8_t *output, size_t output_size)
222
+ {
223
+ if (count != 0)
224
+ {
225
+ errno = EINVAL;
226
+ return;
227
+ }
228
+ gensalt_sha_rn ("1", 8, 1000, 1000, 1000, 1000,
229
+ rbytes, nrbytes, output, output_size);
230
+ }
231
+
232
+ #endif
@@ -0,0 +1,134 @@
1
+ /*-
2
+ * Copyright (c) 1998-1999 Whistle Communications, Inc.
3
+ * Copyright (c) 1998-1999 Archie Cobbs <archie@freebsd.org>
4
+ * Copyright (c) 2003 Michael Bretterklieber
5
+ * Copyright (c) 2017-2019 Björn Esser <besser82@fedoraproject.org>
6
+ * Copyright (c) 2017-2019 Zack Weinberg <zackw at panix.com>
7
+ * All rights reserved.
8
+ *
9
+ * Redistribution and use in source and binary forms, with or without
10
+ * modification, are permitted provided that the following conditions
11
+ * are met:
12
+ * 1. Redistributions of source code must retain the above copyright
13
+ * notice, this list of conditions and the following disclaimer.
14
+ * 2. Redistributions in binary form must reproduce the above copyright
15
+ * notice, this list of conditions and the following disclaimer in the
16
+ * documentation and/or other materials provided with the distribution.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
+ * SUCH DAMAGE.
29
+ */
30
+
31
+ #include "crypt-port.h"
32
+
33
+ #if INCLUDE_nt
34
+
35
+ #include "alg-md4.h"
36
+
37
+ #include <errno.h>
38
+ #include <stdlib.h>
39
+
40
+ #define MD4_HASHLEN 16
41
+
42
+ typedef struct
43
+ {
44
+ MD4_CTX ctx;
45
+ uint8_t unipw[CRYPT_MAX_PASSPHRASE_SIZE * 2];
46
+ unsigned char hash[MD4_HASHLEN];
47
+ } crypt_nt_internal_t;
48
+
49
+ static_assert (sizeof (crypt_nt_internal_t) <= ALG_SPECIFIC_SIZE,
50
+ "ALG_SPECIFIC_SIZE is too small for NTHASH.");
51
+
52
+ /*
53
+ * NT HASH = md4(str2unicode(phrase))
54
+ */
55
+
56
+ void
57
+ crypt_nt_rn (const char *phrase, size_t phr_size,
58
+ const char *setting, size_t ARG_UNUSED (set_size),
59
+ uint8_t *output, size_t out_size,
60
+ void *scratch, size_t scr_size)
61
+ {
62
+ static const char *magic = "$3$";
63
+ static const uint8_t *hexconvtab = (const uint8_t*) "0123456789abcdef";
64
+
65
+ if ((out_size < strlen (magic) + MD4_HASHLEN * 2 + 1) ||
66
+ (scr_size < sizeof (crypt_nt_internal_t)))
67
+ {
68
+ errno = ERANGE;
69
+ return;
70
+ }
71
+
72
+ if (strncmp (setting, magic, strlen (magic)))
73
+ {
74
+ errno = EINVAL;
75
+ return;
76
+ }
77
+
78
+ crypt_nt_internal_t *intbuf = scratch;
79
+
80
+ /* Convert the input to UCS-2LE, blindly assuming that it was
81
+ IANA ISO_8859-1:1987 to begin with (i.e. 0x00 .. 0xFF
82
+ encode U+0000 .. U+FFFF; technically this is a superset
83
+ of the original ISO 8859.1). Note that this does not
84
+ U+0000-terminate intbuf->unipw. */
85
+ for (size_t i = 0; i < phr_size; i++)
86
+ {
87
+ intbuf->unipw[2*i ] = (uint8_t)phrase[i];
88
+ intbuf->unipw[2*i + 1] = 0x00;
89
+ }
90
+
91
+ /* Compute MD4 of Unicode password. */
92
+ MD4_Init (&intbuf->ctx);
93
+ MD4_Update (&intbuf->ctx, intbuf->unipw, phr_size * 2);
94
+ MD4_Final (intbuf->hash, &intbuf->ctx);
95
+
96
+ /* Write the computed hash to the output buffer. */
97
+ output += strcpy_or_abort (output, out_size, magic);
98
+ *output++ = '$';
99
+ for (size_t i = 0; i < MD4_HASHLEN; i++)
100
+ {
101
+ *output++ = hexconvtab[intbuf->hash[i] >> 4];
102
+ *output++ = hexconvtab[intbuf->hash[i] & 0xf];
103
+ }
104
+ *output = '\0';
105
+ }
106
+
107
+ /* This function simply returns the magic string '$3$',
108
+ so it can be used as SETTING for the crypt function. */
109
+ void
110
+ gensalt_nt_rn (unsigned long count,
111
+ ARG_UNUSED(const uint8_t *rbytes),
112
+ ARG_UNUSED(size_t nrbytes),
113
+ uint8_t *output,
114
+ size_t o_size)
115
+ {
116
+ const char *prefix = "$3$";
117
+
118
+ /* Minimal O_SIZE to store the prefix. */
119
+ if (o_size < strlen (prefix) + 1)
120
+ {
121
+ errno = ERANGE;
122
+ return;
123
+ }
124
+
125
+ if (count != 0)
126
+ {
127
+ errno = EINVAL;
128
+ return;
129
+ }
130
+
131
+ strcpy_or_abort (output, o_size, prefix);
132
+ }
133
+
134
+ #endif
@@ -0,0 +1,40 @@
1
+ /* Prototypes for obsolete functions in libcrypt.
2
+
3
+ Copyright (C) 1991-2017 Free Software Foundation, Inc.
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public License
7
+ as published by the Free Software Foundation; either version 2.1 of
8
+ the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, see
17
+ <https://www.gnu.org/licenses/>. */
18
+
19
+ #ifndef _CRYPT_OBSOLETE_H
20
+ #define _CRYPT_OBSOLETE_H 1
21
+
22
+ /* These API functions are obsolete and provided for binary backward
23
+ compatibility only. New programs cannot be linked against them,
24
+ and we do not install this header, but we still need it to build the
25
+ library itself. */
26
+
27
+ /* Prepare to encrypt or decrypt data with DES, using KEY. */
28
+ extern void setkey (const char *key);
29
+
30
+ extern void setkey_r (const char *key,
31
+ struct crypt_data *restrict data);
32
+
33
+ /* Encrypt data in BLOCK in place if EDFLAG is zero; otherwise decrypt
34
+ block in place. */
35
+ extern void encrypt (char *block, int edflag);
36
+
37
+ extern void encrypt_r (char *block, int edflag,
38
+ struct crypt_data *restrict data);
39
+
40
+ #endif /* crypt-obsolete.h */