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,67 @@
1
+ /*
2
+ * Copyright (c) 2013, Alexey Degtyarev <alexey@renatasystems.org>.
3
+ * All rights reserved.
4
+ *
5
+ * Portable and simple (thus sometimes slow) implementation of core functions.
6
+ *
7
+ * $Id$
8
+ */
9
+
10
+ #ifdef __GOST3411_HAS_SSE2__
11
+ #error "portable implementation disabled in config.h"
12
+ #endif
13
+
14
+ #ifdef __GOST3411_HAS_MMX__
15
+ #error "portable implementation disabled in config.h"
16
+ #endif
17
+
18
+ #define X(x, y, z) { \
19
+ z->QWORD[0] = x->QWORD[0] ^ y->QWORD[0]; \
20
+ z->QWORD[1] = x->QWORD[1] ^ y->QWORD[1]; \
21
+ z->QWORD[2] = x->QWORD[2] ^ y->QWORD[2]; \
22
+ z->QWORD[3] = x->QWORD[3] ^ y->QWORD[3]; \
23
+ z->QWORD[4] = x->QWORD[4] ^ y->QWORD[4]; \
24
+ z->QWORD[5] = x->QWORD[5] ^ y->QWORD[5]; \
25
+ z->QWORD[6] = x->QWORD[6] ^ y->QWORD[6]; \
26
+ z->QWORD[7] = x->QWORD[7] ^ y->QWORD[7]; \
27
+ }
28
+
29
+ #ifndef __GOST3411_BIG_ENDIAN__
30
+ #define __XLPS_FOR for (_i = 0; _i <= 7; _i++)
31
+ #define _datai _i
32
+ #else
33
+ #define __XLPS_FOR for (_i = 7; _i >= 0; _i--)
34
+ #define _datai 7 - _i
35
+ #endif
36
+
37
+ #define XLPS(x, y, data) { \
38
+ register unsigned long long r0, r1, r2, r3, r4, r5, r6, r7; \
39
+ int _i; \
40
+ \
41
+ r0 = x->QWORD[0] ^ y->QWORD[0]; \
42
+ r1 = x->QWORD[1] ^ y->QWORD[1]; \
43
+ r2 = x->QWORD[2] ^ y->QWORD[2]; \
44
+ r3 = x->QWORD[3] ^ y->QWORD[3]; \
45
+ r4 = x->QWORD[4] ^ y->QWORD[4]; \
46
+ r5 = x->QWORD[5] ^ y->QWORD[5]; \
47
+ r6 = x->QWORD[6] ^ y->QWORD[6]; \
48
+ r7 = x->QWORD[7] ^ y->QWORD[7]; \
49
+ \
50
+ \
51
+ __XLPS_FOR \
52
+ {\
53
+ data->QWORD[_datai] = Ax[0][(r0 >> (_i << 3)) & 0xFF]; \
54
+ data->QWORD[_datai] ^= Ax[1][(r1 >> (_i << 3)) & 0xFF]; \
55
+ data->QWORD[_datai] ^= Ax[2][(r2 >> (_i << 3)) & 0xFF]; \
56
+ data->QWORD[_datai] ^= Ax[3][(r3 >> (_i << 3)) & 0xFF]; \
57
+ data->QWORD[_datai] ^= Ax[4][(r4 >> (_i << 3)) & 0xFF]; \
58
+ data->QWORD[_datai] ^= Ax[5][(r5 >> (_i << 3)) & 0xFF]; \
59
+ data->QWORD[_datai] ^= Ax[6][(r6 >> (_i << 3)) & 0xFF]; \
60
+ data->QWORD[_datai] ^= Ax[7][(r7 >> (_i << 3)) & 0xFF]; \
61
+ }\
62
+ }
63
+
64
+ #define ROUND(i, Ki, data) { \
65
+ XLPS(Ki, (&C[i]), Ki); \
66
+ XLPS(Ki, data, data); \
67
+ }
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Copyright (c) 2017, Björn Esser <besser82@fedoraproject.org>
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ *
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ *
12
+ * 2. Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in the
14
+ * documentation and/or other materials provided with the distribution.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+ /*
30
+ * Implement HMAC as described in RFC 2104
31
+ *
32
+ */
33
+
34
+ #include "crypt-port.h"
35
+ #include "alg-hmac-sha1.h"
36
+ #include "alg-sha1.h"
37
+
38
+ #include <stdlib.h>
39
+
40
+ #if INCLUDE_sha1crypt
41
+
42
+ /* Don't change these */
43
+ #define HMAC_IPAD 0x36
44
+ #define HMAC_OPAD 0x5c
45
+
46
+ /* Nor this */
47
+ #ifndef HMAC_BLOCKSZ
48
+ # define HMAC_BLOCKSZ 64
49
+ # define HASH_LENGTH 20
50
+ #endif
51
+
52
+ /*
53
+ * The logic here is lifted straight from RFC 2104 except that
54
+ * rather than filling the pads with 0, copying in the key and then
55
+ * XOR with the pad byte, we just fill with the pad byte and
56
+ * XOR with the key.
57
+ */
58
+ void
59
+ hmac_sha1_process_data (const uint8_t *text, size_t text_len,
60
+ const uint8_t *key, size_t key_len,
61
+ void *resbuf)
62
+ {
63
+ struct sha1_ctx ctx;
64
+ /* Inner padding key XOR'd with ipad */
65
+ uint8_t k_ipad[HMAC_BLOCKSZ];
66
+ /* Outer padding key XOR'd with opad */
67
+ uint8_t k_opad[HMAC_BLOCKSZ];
68
+ /* HASH(key) if needed */
69
+ unsigned char tk[HASH_LENGTH];
70
+ size_t i;
71
+
72
+ /*
73
+ * If key is longer than HMAC_BLOCKSZ bytes
74
+ * reset it to key=HASH(key)
75
+ */
76
+ if (key_len > HMAC_BLOCKSZ)
77
+ {
78
+ struct sha1_ctx tctx;
79
+
80
+ sha1_init_ctx (&tctx);
81
+ sha1_process_bytes (key, &tctx, key_len);
82
+ sha1_finish_ctx(&tctx, &tk);
83
+
84
+ key = tk;
85
+ key_len = HASH_LENGTH;
86
+ }
87
+
88
+ /*
89
+ * The HMAC_ transform looks like:
90
+ *
91
+ * HASH(K XOR opad, HASH(K XOR ipad, text))
92
+ *
93
+ * where K is an n byte key
94
+ * ipad is the byte HMAC_IPAD repeated HMAC_BLOCKSZ times
95
+ * opad is the byte HMAC_OPAD repeated HMAC_BLOCKSZ times
96
+ * and text is the data being protected
97
+ */
98
+
99
+ /*
100
+ * Fill the pads and XOR in the key
101
+ */
102
+ memset (k_ipad, HMAC_IPAD, sizeof k_ipad);
103
+ memset (k_opad, HMAC_OPAD, sizeof k_opad);
104
+ for (i = 0; i < key_len; i++)
105
+ {
106
+ k_ipad[i] ^= key[i];
107
+ k_opad[i] ^= key[i];
108
+ }
109
+
110
+ /* Clean the stack. */
111
+ explicit_bzero (tk, HASH_LENGTH);
112
+
113
+ /*
114
+ * Perform inner HASH.
115
+ * Start with inner pad,
116
+ * then the text.
117
+ */
118
+ sha1_init_ctx (&ctx);
119
+ sha1_process_bytes (k_ipad, &ctx, HMAC_BLOCKSZ);
120
+ sha1_process_bytes (text, &ctx, text_len);
121
+ sha1_finish_ctx(&ctx, resbuf);
122
+
123
+ /* Clean the stack. */
124
+ explicit_bzero (k_ipad, HMAC_BLOCKSZ);
125
+
126
+ /*
127
+ * Perform outer HASH.
128
+ * Start with the outer pad,
129
+ * then the result of the inner hash.
130
+ */
131
+ sha1_init_ctx (&ctx);
132
+ sha1_process_bytes (k_opad, &ctx, HMAC_BLOCKSZ);
133
+ sha1_process_bytes (resbuf, &ctx, HASH_LENGTH);
134
+ sha1_finish_ctx(&ctx, resbuf);
135
+
136
+ /* Clean the stack. */
137
+ explicit_bzero (k_opad, HMAC_BLOCKSZ);
138
+ }
139
+
140
+ #endif
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (c) 2017, Björn Esser <besser82@fedoraproject.org>
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ *
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ *
12
+ * 2. Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in the
14
+ * documentation and/or other materials provided with the distribution.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+ /* Generate the keyed-hash message authentication code of TEXT and KEY.
30
+ The resulting HMAC is written into RESBUF, which should point to 20
31
+ bytes of storage. */
32
+ extern void
33
+ hmac_sha1_process_data (const uint8_t *text, size_t text_len,
34
+ const uint8_t *key, size_t key_len,
35
+ void *resbuf);
@@ -0,0 +1,270 @@
1
+ /*
2
+ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
3
+ * MD4 Message-Digest Algorithm (RFC 1320).
4
+ *
5
+ * Homepage:
6
+ * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
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_nt
41
+
42
+ #include "alg-md4.h"
43
+
44
+ /*
45
+ * The basic MD4 functions.
46
+ *
47
+ * F and G are optimized compared to their RFC 1320 definitions, with the
48
+ * optimization for F borrowed from Colin Plumb's MD5 implementation.
49
+ */
50
+ #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
51
+ #define G(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
52
+ #define H(x, y, z) ((x) ^ (y) ^ (z))
53
+
54
+ /*
55
+ * The MD4 transformation for all three rounds.
56
+ */
57
+ #define STEP(f, a, b, c, d, x, s) \
58
+ (a) += f((b), (c), (d)) + (x); \
59
+ (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));
60
+
61
+ /*
62
+ * SET reads 4 input bytes in little-endian byte order and stores them in a
63
+ * properly aligned word in host byte order.
64
+ *
65
+ * The check for little-endian architectures that tolerate unaligned memory
66
+ * accesses is just an optimization. Nothing will break if it fails to detect
67
+ * a suitable architecture.
68
+ *
69
+ * Unfortunately, this optimization may be a C strict aliasing rules violation
70
+ * if the caller's data buffer has effective type that cannot be aliased by
71
+ * MD4_u32plus. In practice, this problem may occur if these MD4 routines are
72
+ * inlined into a calling function, or with future and dangerously advanced
73
+ * link-time optimizations. For the time being, keeping these MD4 routines in
74
+ * their own translation unit avoids the problem.
75
+ */
76
+ #if 0 /* defined(__i386__) || defined(__x86_64__) || defined(__vax__) */
77
+ #define SET(n) \
78
+ (*(const MD4_u32plus *)&ptr[(n) * 4])
79
+ #define GET(n) \
80
+ SET(n)
81
+ #else
82
+ #define SET(n) \
83
+ (ctx->block[(n)] = \
84
+ (MD4_u32plus)ptr[(n) * 4] | \
85
+ ((MD4_u32plus)ptr[(n) * 4 + 1] << 8) | \
86
+ ((MD4_u32plus)ptr[(n) * 4 + 2] << 16) | \
87
+ ((MD4_u32plus)ptr[(n) * 4 + 3] << 24))
88
+ #define GET(n) \
89
+ (ctx->block[(n)])
90
+ #endif
91
+
92
+ /*
93
+ * This processes one or more 64-byte data blocks, but does NOT update the bit
94
+ * counters. There are no alignment requirements.
95
+ */
96
+ static const void *body(MD4_CTX *ctx, const void *data, unsigned long size)
97
+ {
98
+ const unsigned char *ptr;
99
+ MD4_u32plus a, b, c, d;
100
+ MD4_u32plus saved_a, saved_b, saved_c, saved_d;
101
+ const MD4_u32plus ac1 = 0x5a827999, ac2 = 0x6ed9eba1;
102
+
103
+ ptr = (const unsigned char *)data;
104
+
105
+ a = ctx->a;
106
+ b = ctx->b;
107
+ c = ctx->c;
108
+ d = ctx->d;
109
+
110
+ do {
111
+ saved_a = a;
112
+ saved_b = b;
113
+ saved_c = c;
114
+ saved_d = d;
115
+
116
+ /* Round 1 */
117
+ STEP(F, a, b, c, d, SET(0), 3)
118
+ STEP(F, d, a, b, c, SET(1), 7)
119
+ STEP(F, c, d, a, b, SET(2), 11)
120
+ STEP(F, b, c, d, a, SET(3), 19)
121
+ STEP(F, a, b, c, d, SET(4), 3)
122
+ STEP(F, d, a, b, c, SET(5), 7)
123
+ STEP(F, c, d, a, b, SET(6), 11)
124
+ STEP(F, b, c, d, a, SET(7), 19)
125
+ STEP(F, a, b, c, d, SET(8), 3)
126
+ STEP(F, d, a, b, c, SET(9), 7)
127
+ STEP(F, c, d, a, b, SET(10), 11)
128
+ STEP(F, b, c, d, a, SET(11), 19)
129
+ STEP(F, a, b, c, d, SET(12), 3)
130
+ STEP(F, d, a, b, c, SET(13), 7)
131
+ STEP(F, c, d, a, b, SET(14), 11)
132
+ STEP(F, b, c, d, a, SET(15), 19)
133
+
134
+ /* Round 2 */
135
+ STEP(G, a, b, c, d, GET(0) + ac1, 3)
136
+ STEP(G, d, a, b, c, GET(4) + ac1, 5)
137
+ STEP(G, c, d, a, b, GET(8) + ac1, 9)
138
+ STEP(G, b, c, d, a, GET(12) + ac1, 13)
139
+ STEP(G, a, b, c, d, GET(1) + ac1, 3)
140
+ STEP(G, d, a, b, c, GET(5) + ac1, 5)
141
+ STEP(G, c, d, a, b, GET(9) + ac1, 9)
142
+ STEP(G, b, c, d, a, GET(13) + ac1, 13)
143
+ STEP(G, a, b, c, d, GET(2) + ac1, 3)
144
+ STEP(G, d, a, b, c, GET(6) + ac1, 5)
145
+ STEP(G, c, d, a, b, GET(10) + ac1, 9)
146
+ STEP(G, b, c, d, a, GET(14) + ac1, 13)
147
+ STEP(G, a, b, c, d, GET(3) + ac1, 3)
148
+ STEP(G, d, a, b, c, GET(7) + ac1, 5)
149
+ STEP(G, c, d, a, b, GET(11) + ac1, 9)
150
+ STEP(G, b, c, d, a, GET(15) + ac1, 13)
151
+
152
+ /* Round 3 */
153
+ STEP(H, a, b, c, d, GET(0) + ac2, 3)
154
+ STEP(H, d, a, b, c, GET(8) + ac2, 9)
155
+ STEP(H, c, d, a, b, GET(4) + ac2, 11)
156
+ STEP(H, b, c, d, a, GET(12) + ac2, 15)
157
+ STEP(H, a, b, c, d, GET(2) + ac2, 3)
158
+ STEP(H, d, a, b, c, GET(10) + ac2, 9)
159
+ STEP(H, c, d, a, b, GET(6) + ac2, 11)
160
+ STEP(H, b, c, d, a, GET(14) + ac2, 15)
161
+ STEP(H, a, b, c, d, GET(1) + ac2, 3)
162
+ STEP(H, d, a, b, c, GET(9) + ac2, 9)
163
+ STEP(H, c, d, a, b, GET(5) + ac2, 11)
164
+ STEP(H, b, c, d, a, GET(13) + ac2, 15)
165
+ STEP(H, a, b, c, d, GET(3) + ac2, 3)
166
+ STEP(H, d, a, b, c, GET(11) + ac2, 9)
167
+ STEP(H, c, d, a, b, GET(7) + ac2, 11)
168
+ STEP(H, b, c, d, a, GET(15) + ac2, 15)
169
+
170
+ a += saved_a;
171
+ b += saved_b;
172
+ c += saved_c;
173
+ d += saved_d;
174
+
175
+ ptr += 64;
176
+ } while (size -= 64);
177
+
178
+ ctx->a = a;
179
+ ctx->b = b;
180
+ ctx->c = c;
181
+ ctx->d = d;
182
+
183
+ return ptr;
184
+ }
185
+
186
+ void MD4_Init(MD4_CTX *ctx)
187
+ {
188
+ ctx->a = 0x67452301;
189
+ ctx->b = 0xefcdab89;
190
+ ctx->c = 0x98badcfe;
191
+ ctx->d = 0x10325476;
192
+
193
+ ctx->lo = 0;
194
+ ctx->hi = 0;
195
+ }
196
+
197
+ void MD4_Update(MD4_CTX *ctx, const void *data, size_t size)
198
+ {
199
+ MD4_u32plus saved_lo;
200
+ unsigned long used, available;
201
+
202
+ saved_lo = ctx->lo;
203
+ if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
204
+ ctx->hi++;
205
+ ctx->hi += (MD4_u32plus) size >> 29;
206
+
207
+ used = saved_lo & 0x3f;
208
+
209
+ if (used) {
210
+ available = 64 - used;
211
+
212
+ if (size < available) {
213
+ memcpy(&ctx->buffer[used], data, size);
214
+ return;
215
+ }
216
+
217
+ memcpy(&ctx->buffer[used], data, available);
218
+ data = (const unsigned char *)data + available;
219
+ size -= available;
220
+ body(ctx, ctx->buffer, 64);
221
+ }
222
+
223
+ if (size >= 64) {
224
+ data = body(ctx, data, size & ~(unsigned long)0x3f);
225
+ size &= 0x3f;
226
+ }
227
+
228
+ memcpy(ctx->buffer, data, size);
229
+ }
230
+
231
+ #define OUT(dst, src) \
232
+ (dst)[0] = (unsigned char)(src); \
233
+ (dst)[1] = (unsigned char)((src) >> 8); \
234
+ (dst)[2] = (unsigned char)((src) >> 16); \
235
+ (dst)[3] = (unsigned char)((src) >> 24);
236
+
237
+ void MD4_Final(uint8_t result[16], MD4_CTX *ctx)
238
+ {
239
+ unsigned long used, available;
240
+
241
+ used = ctx->lo & 0x3f;
242
+
243
+ ctx->buffer[used++] = 0x80;
244
+
245
+ available = 64 - used;
246
+
247
+ if (available < 8) {
248
+ memset(&ctx->buffer[used], 0, available);
249
+ body(ctx, ctx->buffer, 64);
250
+ used = 0;
251
+ available = 64;
252
+ }
253
+
254
+ memset(&ctx->buffer[used], 0, available - 8);
255
+
256
+ ctx->lo <<= 3;
257
+ OUT(&ctx->buffer[56], ctx->lo)
258
+ OUT(&ctx->buffer[60], ctx->hi)
259
+
260
+ body(ctx, ctx->buffer, 64);
261
+
262
+ OUT(&result[0], ctx->a)
263
+ OUT(&result[4], ctx->b)
264
+ OUT(&result[8], ctx->c)
265
+ OUT(&result[12], ctx->d)
266
+
267
+ explicit_bzero(ctx, sizeof(*ctx));
268
+ }
269
+
270
+ #endif
@@ -0,0 +1,43 @@
1
+ /*
2
+ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
3
+ * MD4 Message-Digest Algorithm (RFC 1320).
4
+ *
5
+ * Homepage:
6
+ * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
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 md4.c for more information.
24
+ */
25
+
26
+ #ifndef _CRYPT_ALG_MD4_H
27
+ #define _CRYPT_ALG_MD4_H 1
28
+
29
+ /* Any 32-bit or wider unsigned integer data type will do */
30
+ typedef uint32_t MD4_u32plus;
31
+
32
+ typedef struct {
33
+ MD4_u32plus lo, hi;
34
+ MD4_u32plus a, b, c, d;
35
+ uint8_t buffer[64];
36
+ MD4_u32plus block[16];
37
+ } MD4_CTX;
38
+
39
+ extern void MD4_Init(MD4_CTX *ctx);
40
+ extern void MD4_Update(MD4_CTX *ctx, const void *data, size_t size);
41
+ extern void MD4_Final(uint8_t result[16], MD4_CTX *ctx);
42
+
43
+ #endif /* alg-md4.h */