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,291 @@
1
+ /*
2
+ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
3
+ * MD5 Message-Digest Algorithm (RFC 1321).
4
+ *
5
+ * Homepage:
6
+ * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
7
+ *
8
+ * Author:
9
+ * Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
10
+ *
11
+ * This software was written by Alexander Peslyak in 2001. No copyright is
12
+ * claimed, and the software is hereby placed in the public domain.
13
+ * In case this attempt to disclaim copyright and place the software in the
14
+ * public domain is deemed null and void, then the software is
15
+ * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
16
+ * general public under the following terms:
17
+ *
18
+ * Redistribution and use in source and binary forms, with or without
19
+ * modification, are permitted.
20
+ *
21
+ * There's ABSOLUTELY NO WARRANTY, express or implied.
22
+ *
23
+ * (This is a heavily cut-down "BSD license".)
24
+ *
25
+ * This differs from Colin Plumb's older public domain implementation in that
26
+ * no exactly 32-bit integer data type is required (any 32-bit or wider
27
+ * unsigned integer data type will do), there's no compile-time endianness
28
+ * configuration, and the function prototypes match OpenSSL's. No code from
29
+ * Colin Plumb's implementation has been reused; this comment merely compares
30
+ * the properties of the two independent implementations.
31
+ *
32
+ * The primary goals of this implementation are portability and ease of use.
33
+ * It is meant to be fast, but not as fast as possible. Some known
34
+ * optimizations are not included to reduce source code size and avoid
35
+ * compile-time configuration.
36
+ */
37
+
38
+ #include "crypt-port.h"
39
+
40
+ #if INCLUDE_md5crypt || INCLUDE_sunmd5
41
+
42
+ #include "alg-md5.h"
43
+
44
+ /*
45
+ * The basic MD5 functions.
46
+ *
47
+ * F and G are optimized compared to their RFC 1321 definitions for
48
+ * architectures that lack an AND-NOT instruction, just like in Colin Plumb's
49
+ * implementation.
50
+ */
51
+ #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
52
+ #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
53
+ #define H(x, y, z) (((x) ^ (y)) ^ (z))
54
+ #define H2(x, y, z) ((x) ^ ((y) ^ (z)))
55
+ #define I(x, y, z) ((y) ^ ((x) | ~(z)))
56
+
57
+ /*
58
+ * The MD5 transformation for all four rounds.
59
+ */
60
+ #define STEP(f, a, b, c, d, x, t, s) \
61
+ (a) += f((b), (c), (d)) + (x) + (t); \
62
+ (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
63
+ (a) += (b);
64
+
65
+ /*
66
+ * SET reads 4 input bytes in little-endian byte order and stores them in a
67
+ * properly aligned word in host byte order.
68
+ *
69
+ * The check for little-endian architectures that tolerate unaligned memory
70
+ * accesses is just an optimization. Nothing will break if it fails to detect
71
+ * a suitable architecture.
72
+ *
73
+ * Unfortunately, this optimization may be a C strict aliasing rules violation
74
+ * if the caller's data buffer has effective type that cannot be aliased by
75
+ * MD5_u32plus. In practice, this problem may occur if these MD5 routines are
76
+ * inlined into a calling function, or with future and dangerously advanced
77
+ * link-time optimizations. For the time being, keeping these MD5 routines in
78
+ * their own translation unit avoids the problem.
79
+ */
80
+ #if 0 /* defined(__i386__) || defined(__x86_64__) || defined(__vax__) */
81
+ #define SET(n) \
82
+ (*(const MD5_u32plus *)&ptr[(n) * 4])
83
+ #define GET(n) \
84
+ SET(n)
85
+ #else
86
+ #define SET(n) \
87
+ (ctx->block[(n)] = \
88
+ (MD5_u32plus)ptr[(n) * 4] | \
89
+ ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
90
+ ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
91
+ ((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
92
+ #define GET(n) \
93
+ (ctx->block[(n)])
94
+ #endif
95
+
96
+ /*
97
+ * This processes one or more 64-byte data blocks, but does NOT update the bit
98
+ * counters. There are no alignment requirements.
99
+ */
100
+ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
101
+ {
102
+ const unsigned char *ptr;
103
+ MD5_u32plus a, b, c, d;
104
+ MD5_u32plus saved_a, saved_b, saved_c, saved_d;
105
+
106
+ ptr = (const unsigned char *)data;
107
+
108
+ a = ctx->a;
109
+ b = ctx->b;
110
+ c = ctx->c;
111
+ d = ctx->d;
112
+
113
+ do {
114
+ saved_a = a;
115
+ saved_b = b;
116
+ saved_c = c;
117
+ saved_d = d;
118
+
119
+ /* Round 1 */
120
+ STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
121
+ STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
122
+ STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
123
+ STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
124
+ STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
125
+ STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
126
+ STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
127
+ STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
128
+ STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
129
+ STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
130
+ STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
131
+ STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
132
+ STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
133
+ STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
134
+ STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
135
+ STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
136
+
137
+ /* Round 2 */
138
+ STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
139
+ STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
140
+ STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
141
+ STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
142
+ STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
143
+ STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
144
+ STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
145
+ STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
146
+ STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
147
+ STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
148
+ STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
149
+ STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
150
+ STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
151
+ STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
152
+ STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
153
+ STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
154
+
155
+ /* Round 3 */
156
+ STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
157
+ STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
158
+ STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
159
+ STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
160
+ STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
161
+ STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
162
+ STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
163
+ STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
164
+ STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
165
+ STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
166
+ STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
167
+ STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
168
+ STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
169
+ STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
170
+ STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
171
+ STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
172
+
173
+ /* Round 4 */
174
+ STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
175
+ STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
176
+ STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
177
+ STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
178
+ STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
179
+ STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
180
+ STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
181
+ STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
182
+ STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
183
+ STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
184
+ STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
185
+ STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
186
+ STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
187
+ STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
188
+ STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
189
+ STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
190
+
191
+ a += saved_a;
192
+ b += saved_b;
193
+ c += saved_c;
194
+ d += saved_d;
195
+
196
+ ptr += 64;
197
+ } while (size -= 64);
198
+
199
+ ctx->a = a;
200
+ ctx->b = b;
201
+ ctx->c = c;
202
+ ctx->d = d;
203
+
204
+ return ptr;
205
+ }
206
+
207
+ void MD5_Init(MD5_CTX *ctx)
208
+ {
209
+ ctx->a = 0x67452301;
210
+ ctx->b = 0xefcdab89;
211
+ ctx->c = 0x98badcfe;
212
+ ctx->d = 0x10325476;
213
+
214
+ ctx->lo = 0;
215
+ ctx->hi = 0;
216
+ }
217
+
218
+ void MD5_Update(MD5_CTX *ctx, const void *data, size_t size)
219
+ {
220
+ MD5_u32plus saved_lo;
221
+ unsigned long used, available;
222
+
223
+ saved_lo = ctx->lo;
224
+ if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
225
+ ctx->hi++;
226
+ ctx->hi += (MD5_u32plus) size >> 29;
227
+
228
+ used = saved_lo & 0x3f;
229
+
230
+ if (used) {
231
+ available = 64 - used;
232
+
233
+ if (size < available) {
234
+ memcpy(&ctx->buffer[used], data, size);
235
+ return;
236
+ }
237
+
238
+ memcpy(&ctx->buffer[used], data, available);
239
+ data = (const unsigned char *)data + available;
240
+ size -= available;
241
+ body(ctx, ctx->buffer, 64);
242
+ }
243
+
244
+ if (size >= 64) {
245
+ data = body(ctx, data, size & ~(unsigned long)0x3f);
246
+ size &= 0x3f;
247
+ }
248
+
249
+ memcpy(ctx->buffer, data, size);
250
+ }
251
+
252
+ #define OUT(dst, src) \
253
+ (dst)[0] = (unsigned char)(src); \
254
+ (dst)[1] = (unsigned char)((src) >> 8); \
255
+ (dst)[2] = (unsigned char)((src) >> 16); \
256
+ (dst)[3] = (unsigned char)((src) >> 24);
257
+
258
+ void MD5_Final(uint8_t result[16], MD5_CTX *ctx)
259
+ {
260
+ unsigned long used, available;
261
+
262
+ used = ctx->lo & 0x3f;
263
+
264
+ ctx->buffer[used++] = 0x80;
265
+
266
+ available = 64 - used;
267
+
268
+ if (available < 8) {
269
+ memset(&ctx->buffer[used], 0, available);
270
+ body(ctx, ctx->buffer, 64);
271
+ used = 0;
272
+ available = 64;
273
+ }
274
+
275
+ memset(&ctx->buffer[used], 0, available - 8);
276
+
277
+ ctx->lo <<= 3;
278
+ OUT(&ctx->buffer[56], ctx->lo)
279
+ OUT(&ctx->buffer[60], ctx->hi)
280
+
281
+ body(ctx, ctx->buffer, 64);
282
+
283
+ OUT(&result[0], ctx->a)
284
+ OUT(&result[4], ctx->b)
285
+ OUT(&result[8], ctx->c)
286
+ OUT(&result[12], ctx->d)
287
+
288
+ explicit_bzero(ctx, sizeof(*ctx));
289
+ }
290
+
291
+ #endif
@@ -0,0 +1,43 @@
1
+ /*
2
+ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
3
+ * MD5 Message-Digest Algorithm (RFC 1321).
4
+ *
5
+ * Homepage:
6
+ * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
7
+ *
8
+ * Author:
9
+ * Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
10
+ *
11
+ * This software was written by Alexander Peslyak in 2001. No copyright is
12
+ * claimed, and the software is hereby placed in the public domain.
13
+ * In case this attempt to disclaim copyright and place the software in the
14
+ * public domain is deemed null and void, then the software is
15
+ * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
16
+ * general public under the following terms:
17
+ *
18
+ * Redistribution and use in source and binary forms, with or without
19
+ * modification, are permitted.
20
+ *
21
+ * There's ABSOLUTELY NO WARRANTY, express or implied.
22
+ *
23
+ * See md5.c for more information.
24
+ */
25
+
26
+ #ifndef _CRYPT_ALG_MD5_H
27
+ #define _CRYPT_ALG_MD5_H 1
28
+
29
+ /* Any 32-bit or wider unsigned integer data type will do */
30
+ typedef uint32_t MD5_u32plus;
31
+
32
+ typedef struct {
33
+ MD5_u32plus lo, hi;
34
+ MD5_u32plus a, b, c, d;
35
+ uint8_t buffer[64];
36
+ MD5_u32plus block[16];
37
+ } MD5_CTX;
38
+
39
+ extern void MD5_Init(MD5_CTX *ctx);
40
+ extern void MD5_Update(MD5_CTX *ctx, const void *data, size_t size);
41
+ extern void MD5_Final(uint8_t result[16], MD5_CTX *ctx);
42
+
43
+ #endif /* alg-md5.h */
@@ -0,0 +1,288 @@
1
+ /*
2
+ SHA-1 in C
3
+ By Steve Reid <sreid@sea-to-sky.net>
4
+ 100% Public Domain
5
+
6
+ -----------------
7
+ Modified 7/98
8
+ By James H. Brown <jbrown@burgoyne.com>
9
+ Still 100% Public Domain
10
+
11
+ Corrected a problem which generated improper hash values on 16 bit machines
12
+ Routine SHA1Update changed from
13
+ void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len)
14
+ to
15
+ void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned long len)
16
+
17
+ The 'len' parameter was declared an int which works fine on 32 bit machines.
18
+ However, on 16 bit machines an int is too small for the shifts being done
19
+ against
20
+ it. This caused the hash function to generate incorrect values if len was
21
+ greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
22
+
23
+ Since the file IO in main() reads 16K at a time, any file 8K or larger would
24
+ be guaranteed to generate the wrong hash (e.g. Test Vector #3,
25
+ a million "a"s).
26
+
27
+ I also changed the declaration of variables i & j in SHA1Update to
28
+ unsigned long from unsigned int for the same reason.
29
+
30
+ These changes should make no difference to any 32 bit implementations since
31
+ an int and a long are the same size in those environments.
32
+
33
+ --
34
+ I also corrected a few compiler warnings generated by Borland C.
35
+ 1. Added #include <process.h> for exit() prototype
36
+ 2. Removed unused variable 'j' in SHA1Final
37
+ 3. Changed exit(0) to return(0) at end of main.
38
+
39
+ ALL changes I made can be located by searching for comments containing 'JHB'
40
+ -----------------
41
+ Modified 8/98
42
+ By Steve Reid <sreid@sea-to-sky.net>
43
+ Still 100% public domain
44
+
45
+ 1- Removed #include <process.h> and used return() instead of exit()
46
+ 2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
47
+ 3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
48
+
49
+ -----------------
50
+ Modified 4/01
51
+ By Saul Kravitz <Saul.Kravitz@celera.com>
52
+ Still 100% PD
53
+ Modified to run on Compaq Alpha hardware.
54
+
55
+ -----------------
56
+ Modified 07/2002
57
+ By Ralph Giles <giles@ghostscript.com>
58
+ Still 100% public domain
59
+ modified for use with stdint types, autoconf
60
+ code cleanup, removed attribution comments
61
+ switched SHA1Final() argument order for consistency
62
+ use SHA1_ prefix for public api
63
+ move public api to sha1.h
64
+
65
+ -----------------
66
+ Modified 10/2017
67
+ By Björn Esser <besser82@fedoraproject.org>
68
+ Still 100% public domain
69
+ modified for use with libxcrypt
70
+ */
71
+
72
+ #include "crypt-port.h"
73
+ #include "alg-sha1.h"
74
+
75
+ #if INCLUDE_sha1crypt
76
+
77
+ #define SHA1_DIGEST_SIZE 20
78
+
79
+ #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
80
+
81
+ /* blk0() and blk() perform the initial expand. */
82
+ /* I got the idea of expanding during the round function from SSLeay */
83
+ /* FIXME: can we do this in an endian-proof way? */
84
+ #if XCRYPT_USE_BIGENDIAN
85
+ #define blk0(i) block.l[i]
86
+ #else
87
+ #define blk0(i) (block.l[i] = (rol(block.l[i],24)&0xFF00FF00) \
88
+ |(rol(block.l[i],8)&0x00FF00FF))
89
+ #endif
90
+ #define blk(i) (block.l[i&15] = rol(block.l[(i+13)&15]^block.l[(i+8)&15] \
91
+ ^block.l[(i+2)&15]^block.l[i&15],1))
92
+
93
+ /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
94
+ #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
95
+ #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
96
+ #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
97
+ #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
98
+ #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
99
+
100
+
101
+ /* Hash a single 512-bit block. This is the core of the algorithm. */
102
+ static void
103
+ sha1_do_transform (uint32_t state[5], const uint8_t buffer[64])
104
+ {
105
+ uint32_t a, b, c, d, e;
106
+ typedef union
107
+ {
108
+ uint8_t c[64];
109
+ uint32_t l[16];
110
+ } CHAR64LONG16;
111
+ CHAR64LONG16 block;
112
+
113
+ memcpy (&block, buffer, 64);
114
+
115
+ /* Copy context->state[] to working vars */
116
+ a = state[0];
117
+ b = state[1];
118
+ c = state[2];
119
+ d = state[3];
120
+ e = state[4];
121
+
122
+ /* 4 rounds of 20 operations each. Loop unrolled. */
123
+ R0(a,b,c,d,e, 0);
124
+ R0(e,a,b,c,d, 1);
125
+ R0(d,e,a,b,c, 2);
126
+ R0(c,d,e,a,b, 3);
127
+ R0(b,c,d,e,a, 4);
128
+ R0(a,b,c,d,e, 5);
129
+ R0(e,a,b,c,d, 6);
130
+ R0(d,e,a,b,c, 7);
131
+ R0(c,d,e,a,b, 8);
132
+ R0(b,c,d,e,a, 9);
133
+ R0(a,b,c,d,e,10);
134
+ R0(e,a,b,c,d,11);
135
+ R0(d,e,a,b,c,12);
136
+ R0(c,d,e,a,b,13);
137
+ R0(b,c,d,e,a,14);
138
+ R0(a,b,c,d,e,15);
139
+ R1(e,a,b,c,d,16);
140
+ R1(d,e,a,b,c,17);
141
+ R1(c,d,e,a,b,18);
142
+ R1(b,c,d,e,a,19);
143
+ R2(a,b,c,d,e,20);
144
+ R2(e,a,b,c,d,21);
145
+ R2(d,e,a,b,c,22);
146
+ R2(c,d,e,a,b,23);
147
+ R2(b,c,d,e,a,24);
148
+ R2(a,b,c,d,e,25);
149
+ R2(e,a,b,c,d,26);
150
+ R2(d,e,a,b,c,27);
151
+ R2(c,d,e,a,b,28);
152
+ R2(b,c,d,e,a,29);
153
+ R2(a,b,c,d,e,30);
154
+ R2(e,a,b,c,d,31);
155
+ R2(d,e,a,b,c,32);
156
+ R2(c,d,e,a,b,33);
157
+ R2(b,c,d,e,a,34);
158
+ R2(a,b,c,d,e,35);
159
+ R2(e,a,b,c,d,36);
160
+ R2(d,e,a,b,c,37);
161
+ R2(c,d,e,a,b,38);
162
+ R2(b,c,d,e,a,39);
163
+ R3(a,b,c,d,e,40);
164
+ R3(e,a,b,c,d,41);
165
+ R3(d,e,a,b,c,42);
166
+ R3(c,d,e,a,b,43);
167
+ R3(b,c,d,e,a,44);
168
+ R3(a,b,c,d,e,45);
169
+ R3(e,a,b,c,d,46);
170
+ R3(d,e,a,b,c,47);
171
+ R3(c,d,e,a,b,48);
172
+ R3(b,c,d,e,a,49);
173
+ R3(a,b,c,d,e,50);
174
+ R3(e,a,b,c,d,51);
175
+ R3(d,e,a,b,c,52);
176
+ R3(c,d,e,a,b,53);
177
+ R3(b,c,d,e,a,54);
178
+ R3(a,b,c,d,e,55);
179
+ R3(e,a,b,c,d,56);
180
+ R3(d,e,a,b,c,57);
181
+ R3(c,d,e,a,b,58);
182
+ R3(b,c,d,e,a,59);
183
+ R4(a,b,c,d,e,60);
184
+ R4(e,a,b,c,d,61);
185
+ R4(d,e,a,b,c,62);
186
+ R4(c,d,e,a,b,63);
187
+ R4(b,c,d,e,a,64);
188
+ R4(a,b,c,d,e,65);
189
+ R4(e,a,b,c,d,66);
190
+ R4(d,e,a,b,c,67);
191
+ R4(c,d,e,a,b,68);
192
+ R4(b,c,d,e,a,69);
193
+ R4(a,b,c,d,e,70);
194
+ R4(e,a,b,c,d,71);
195
+ R4(d,e,a,b,c,72);
196
+ R4(c,d,e,a,b,73);
197
+ R4(b,c,d,e,a,74);
198
+ R4(a,b,c,d,e,75);
199
+ R4(e,a,b,c,d,76);
200
+ R4(d,e,a,b,c,77);
201
+ R4(c,d,e,a,b,78);
202
+ R4(b,c,d,e,a,79);
203
+
204
+ /* Add the working vars back into context.state[] */
205
+ state[0] += a;
206
+ state[1] += b;
207
+ state[2] += c;
208
+ state[3] += d;
209
+ state[4] += e;
210
+
211
+ /* Wipe variables */
212
+ a = b = c = d = e = 0;
213
+ }
214
+
215
+
216
+ /* SHA1Init - Initialize new context */
217
+ void
218
+ sha1_init_ctx (struct sha1_ctx* ctx)
219
+ {
220
+ /* SHA1 initialization constants */
221
+ ctx->state[0] = 0x67452301;
222
+ ctx->state[1] = 0xEFCDAB89;
223
+ ctx->state[2] = 0x98BADCFE;
224
+ ctx->state[3] = 0x10325476;
225
+ ctx->state[4] = 0xC3D2E1F0;
226
+ ctx->count[0] = ctx->count[1] = 0;
227
+ }
228
+
229
+
230
+ /* Run your data through this. */
231
+ void
232
+ sha1_process_bytes (const void *buffer, struct sha1_ctx *ctx, size_t size)
233
+ {
234
+ const uint8_t *data = buffer;
235
+ size_t j = (ctx->count[0] >> 3) & 63;
236
+
237
+ if ((ctx->count[0] += (uint32_t)size << 3) < ((uint32_t)size << 3)) ctx->count[1]++;
238
+ ctx->count[1] += (uint32_t)(size >> 29);
239
+ if ((j + size) > 63)
240
+ {
241
+ const size_t i = 64 - j;
242
+ memcpy (&ctx->buffer[j], data, i);
243
+ sha1_do_transform (ctx->state, ctx->buffer);
244
+ j = 0;
245
+ size = size > i ? size - i : 0;
246
+ data += i;
247
+ while (size > 63)
248
+ {
249
+ sha1_do_transform (ctx->state, data);
250
+ size -= 64;
251
+ data += 64;
252
+ }
253
+ }
254
+ memcpy (&ctx->buffer[j], data, size);
255
+ }
256
+
257
+
258
+ /* Add padding and return the message digest. */
259
+ void *
260
+ sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
261
+ {
262
+ uint32_t i;
263
+ uint8_t finalcount[8];
264
+
265
+ for (i = 0; i < 8; i++)
266
+ {
267
+ finalcount[i] = (unsigned char)((ctx->count[(i >= 4 ? 0 : 1)]
268
+ >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
269
+ }
270
+ sha1_process_bytes ((const uint8_t *)"\200", ctx, 1);
271
+ while ((ctx->count[0] & 504) != 448)
272
+ sha1_process_bytes ((const uint8_t *)"\0", ctx, 1);
273
+ sha1_process_bytes (finalcount, ctx, 8); /* Should cause a sha1_do_transform() */
274
+ for (i = 0; i < SHA1_DIGEST_SIZE; i++)
275
+ {
276
+ *((uint8_t *)resbuf + i) = (uint8_t)((ctx->state[i>>2]
277
+ >> ((3-(i & 3)) * 8) ) & 255);
278
+ }
279
+
280
+ /* Wipe variables */
281
+ i = 0;
282
+ explicit_bzero (ctx, sizeof (struct sha1_ctx));
283
+ explicit_bzero (finalcount, 8); /* SWR */
284
+
285
+ return resbuf;
286
+ }
287
+
288
+ #endif
@@ -0,0 +1,34 @@
1
+ /*
2
+ * This is an implementation of the National Institute of Standards
3
+ * and Technology US Secure Hash Algorithm 1 (SHA1).
4
+ *
5
+ * Public api for steve reid's public domain SHA-1 implementation.
6
+ * This file is in the public domain.
7
+ */
8
+
9
+ #ifndef _CRYPT_ALG_SHA1_H
10
+ #define _CRYPT_ALG_SHA1_H 1
11
+
12
+ /* Structure to save state of computation between the single steps. */
13
+ struct sha1_ctx
14
+ {
15
+ uint32_t state[5];
16
+ uint32_t count[2];
17
+ uint8_t buffer[64];
18
+ };
19
+
20
+ /* Initialize structure containing state of computation.
21
+ (RFC 3174, 6.1) */
22
+ extern void sha1_init_ctx (struct sha1_ctx *ctx);
23
+
24
+ /* Starting with the result of former calls of this function (or the
25
+ initialization function) update the context for the next LEN bytes
26
+ starting at BUFFER. LEN does not need to be a multiple of 64. */
27
+ extern void sha1_process_bytes (const void *buffer, struct sha1_ctx *ctx, size_t size);
28
+
29
+ /* Process the remaining bytes in the buffer and write the finalized
30
+ hash to RESBUF, which should point to 20 bytes of storage. All
31
+ data written to CTX is erased before returning from the function. */
32
+ extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
33
+
34
+ #endif