enzoic 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +5 -0
  7. data/README.md +90 -0
  8. data/Rakefile +28 -0
  9. data/enzoic.gemspec +36 -0
  10. data/ext/.DS_Store +0 -0
  11. data/ext/argon2-wrapper/Makefile +74 -0
  12. data/ext/argon2-wrapper/argon2-wrapper.c +165 -0
  13. data/ext/argon2-wrapper/extconf.rb +1 -0
  14. data/ext/argon2_import/.DS_Store +0 -0
  15. data/ext/digest/whirlpool/extconf.rb +10 -0
  16. data/ext/digest/whirlpool/whirlpool-algorithm.c +476 -0
  17. data/ext/digest/whirlpool/whirlpool-algorithm.h +86 -0
  18. data/ext/digest/whirlpool/whirlpool-constants.h +1116 -0
  19. data/ext/digest/whirlpool/whirlpool-portability.h +142 -0
  20. data/ext/digest/whirlpool/whirlpool.c +51 -0
  21. data/ext/phc-winner-argon2/.gitattributes +10 -0
  22. data/ext/phc-winner-argon2/.gitignore +21 -0
  23. data/ext/phc-winner-argon2/.travis.yml +14 -0
  24. data/ext/phc-winner-argon2/Argon2.sln +160 -0
  25. data/ext/phc-winner-argon2/CHANGELOG.md +25 -0
  26. data/ext/phc-winner-argon2/LICENSE +314 -0
  27. data/ext/phc-winner-argon2/Makefile +187 -0
  28. data/ext/phc-winner-argon2/README.md +290 -0
  29. data/ext/phc-winner-argon2/appveyor.yml +25 -0
  30. data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
  31. data/ext/phc-winner-argon2/export.sh +7 -0
  32. data/ext/phc-winner-argon2/include/argon2.h +435 -0
  33. data/ext/phc-winner-argon2/kats/argon2d +12304 -0
  34. data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -0
  35. data/ext/phc-winner-argon2/kats/argon2d_v16 +12304 -0
  36. data/ext/phc-winner-argon2/kats/argon2d_v16.shasum +1 -0
  37. data/ext/phc-winner-argon2/kats/argon2i +12304 -0
  38. data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -0
  39. data/ext/phc-winner-argon2/kats/argon2i_v16 +12304 -0
  40. data/ext/phc-winner-argon2/kats/argon2i_v16.shasum +1 -0
  41. data/ext/phc-winner-argon2/kats/argon2id +12304 -0
  42. data/ext/phc-winner-argon2/kats/argon2id.shasum +1 -0
  43. data/ext/phc-winner-argon2/kats/argon2id_v16 +12304 -0
  44. data/ext/phc-winner-argon2/kats/argon2id_v16.shasum +1 -0
  45. data/ext/phc-winner-argon2/kats/check-sums.ps1 +42 -0
  46. data/ext/phc-winner-argon2/kats/check-sums.sh +13 -0
  47. data/ext/phc-winner-argon2/kats/test.ps1 +50 -0
  48. data/ext/phc-winner-argon2/kats/test.sh +49 -0
  49. data/ext/phc-winner-argon2/latex/IEEEtran.cls +6347 -0
  50. data/ext/phc-winner-argon2/latex/Makefile +18 -0
  51. data/ext/phc-winner-argon2/latex/argon2-specs.tex +920 -0
  52. data/ext/phc-winner-argon2/latex/pics/argon2-par.pdf +0 -0
  53. data/ext/phc-winner-argon2/latex/pics/compression.pdf +0 -0
  54. data/ext/phc-winner-argon2/latex/pics/generic.pdf +0 -0
  55. data/ext/phc-winner-argon2/latex/pics/power-distribution.jpg +0 -0
  56. data/ext/phc-winner-argon2/latex/tradeoff.bib +822 -0
  57. data/ext/phc-winner-argon2/libargon2.pc +16 -0
  58. data/ext/phc-winner-argon2/man/argon2.1 +57 -0
  59. data/ext/phc-winner-argon2/src/argon2.c +452 -0
  60. data/ext/phc-winner-argon2/src/bench.c +111 -0
  61. data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +156 -0
  62. data/ext/phc-winner-argon2/src/blake2/blake2.h +91 -0
  63. data/ext/phc-winner-argon2/src/blake2/blake2b.c +390 -0
  64. data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +328 -0
  65. data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +56 -0
  66. data/ext/phc-winner-argon2/src/core.c +635 -0
  67. data/ext/phc-winner-argon2/src/core.h +227 -0
  68. data/ext/phc-winner-argon2/src/encoding.c +463 -0
  69. data/ext/phc-winner-argon2/src/encoding.h +57 -0
  70. data/ext/phc-winner-argon2/src/genkat.c +208 -0
  71. data/ext/phc-winner-argon2/src/genkat.h +49 -0
  72. data/ext/phc-winner-argon2/src/opt.c +241 -0
  73. data/ext/phc-winner-argon2/src/ref.c +194 -0
  74. data/ext/phc-winner-argon2/src/run.c +317 -0
  75. data/ext/phc-winner-argon2/src/test.c +254 -0
  76. data/ext/phc-winner-argon2/src/thread.c +57 -0
  77. data/ext/phc-winner-argon2/src/thread.h +67 -0
  78. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +226 -0
  79. data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj.filters +69 -0
  80. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +226 -0
  81. data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj.filters +69 -0
  82. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +225 -0
  83. data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
  84. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +239 -0
  85. data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj.filters +72 -0
  86. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +227 -0
  87. data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj.filters +69 -0
  88. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +226 -0
  89. data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj.filters +69 -0
  90. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +226 -0
  91. data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj.filters +69 -0
  92. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +225 -0
  93. data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
  94. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +227 -0
  95. data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj.filters +72 -0
  96. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +226 -0
  97. data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj.filters +69 -0
  98. data/lib/enzoic.rb +189 -0
  99. data/lib/enzoic/argon2_errors.rb +39 -0
  100. data/lib/enzoic/argon2_wrapper_ffi.rb +89 -0
  101. data/lib/enzoic/constants.rb +10 -0
  102. data/lib/enzoic/errors.rb +3 -0
  103. data/lib/enzoic/hashing.rb +258 -0
  104. data/lib/enzoic/password_type.rb +25 -0
  105. data/lib/enzoic/version.rb +5 -0
  106. metadata +354 -0
@@ -0,0 +1,254 @@
1
+ /*
2
+ * Argon2 reference source code package - reference C implementations
3
+ *
4
+ * Copyright 2015
5
+ * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
6
+ *
7
+ * You may use this work under the terms of a Creative Commons CC0 1.0
8
+ * License/Waiver or the Apache Public License 2.0, at your option. The terms of
9
+ * these licenses can be found at:
10
+ *
11
+ * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
12
+ * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * You should have received a copy of both of these licenses along with this
15
+ * software. If not, they may be obtained at the above URLs.
16
+ */
17
+
18
+ #include <stdio.h>
19
+ #include <stdint.h>
20
+ #include <inttypes.h>
21
+ #include <stdlib.h>
22
+ #include <string.h>
23
+ #include <time.h>
24
+ #include <assert.h>
25
+
26
+ #include "argon2.h"
27
+
28
+ #define OUT_LEN 32
29
+ #define ENCODED_LEN 108
30
+
31
+ /* Test harness will assert:
32
+ * argon2_hash() returns ARGON2_OK
33
+ * HEX output matches expected
34
+ * encoded output matches expected
35
+ * argon2_verify() correctly verifies value
36
+ */
37
+
38
+ void hashtest(uint32_t version, uint32_t t, uint32_t m, uint32_t p, char *pwd,
39
+ char *salt, char *hexref, char *mcfref) {
40
+ unsigned char out[OUT_LEN];
41
+ unsigned char hex_out[OUT_LEN * 2 + 4];
42
+ char encoded[ENCODED_LEN];
43
+ int ret, i;
44
+
45
+ printf("Hash test: $v=%d t=%d, m=%d, p=%d, pass=%s, salt=%s: ", version,
46
+ t, m, p, pwd, salt);
47
+
48
+ ret = argon2_hash(t, 1 << m, p, pwd, strlen(pwd), salt, strlen(salt), out,
49
+ OUT_LEN, encoded, ENCODED_LEN, Argon2_i, version);
50
+ assert(ret == ARGON2_OK);
51
+
52
+ for (i = 0; i < OUT_LEN; ++i)
53
+ sprintf((char *)(hex_out + i * 2), "%02x", out[i]);
54
+
55
+ assert(memcmp(hex_out, hexref, OUT_LEN * 2) == 0);
56
+
57
+ if (ARGON2_VERSION_NUMBER == version) {
58
+ assert(memcmp(encoded, mcfref, strlen(mcfref)) == 0);
59
+ }
60
+
61
+ ret = argon2_verify(encoded, pwd, strlen(pwd), Argon2_i);
62
+ assert(ret == ARGON2_OK);
63
+ ret = argon2_verify(mcfref, pwd, strlen(pwd), Argon2_i);
64
+ assert(ret == ARGON2_OK);
65
+
66
+ printf("PASS\n");
67
+ }
68
+
69
+ int main() {
70
+ int ret;
71
+ unsigned char out[OUT_LEN];
72
+ char const *msg;
73
+ int version;
74
+
75
+ version = ARGON2_VERSION_10;
76
+ printf("Test Argon2i version number: %02x\n", version);
77
+
78
+ /* Multiple test cases for various input values */
79
+ hashtest(version, 2, 16, 1, "password", "somesalt",
80
+ "f6c4db4a54e2a370627aff3db6176b94a2a209a62c8e36152711802f7b30c694",
81
+ "$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ"
82
+ "$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ");
83
+ #ifdef TEST_LARGE_RAM
84
+ hashtest(version, 2, 20, 1, "password", "somesalt",
85
+ "9690ec55d28d3ed32562f2e73ea62b02b018757643a2ae6e79528459de8106e9",
86
+ "$argon2i$m=1048576,t=2,p=1$c29tZXNhbHQ"
87
+ "$lpDsVdKNPtMlYvLnPqYrArAYdXZDoq5ueVKEWd6BBuk");
88
+ #endif
89
+ hashtest(version, 2, 18, 1, "password", "somesalt",
90
+ "3e689aaa3d28a77cf2bc72a51ac53166761751182f1ee292e3f677a7da4c2467",
91
+ "$argon2i$m=262144,t=2,p=1$c29tZXNhbHQ"
92
+ "$Pmiaqj0op3zyvHKlGsUxZnYXURgvHuKS4/Z3p9pMJGc");
93
+ hashtest(version, 2, 8, 1, "password", "somesalt",
94
+ "fd4dd83d762c49bdeaf57c47bdcd0c2f1babf863fdeb490df63ede9975fccf06",
95
+ "$argon2i$m=256,t=2,p=1$c29tZXNhbHQ"
96
+ "$/U3YPXYsSb3q9XxHvc0MLxur+GP960kN9j7emXX8zwY");
97
+ hashtest(version, 2, 8, 2, "password", "somesalt",
98
+ "b6c11560a6a9d61eac706b79a2f97d68b4463aa3ad87e00c07e2b01e90c564fb",
99
+ "$argon2i$m=256,t=2,p=2$c29tZXNhbHQ"
100
+ "$tsEVYKap1h6scGt5ovl9aLRGOqOth+AMB+KwHpDFZPs");
101
+ hashtest(version, 1, 16, 1, "password", "somesalt",
102
+ "81630552b8f3b1f48cdb1992c4c678643d490b2b5eb4ff6c4b3438b5621724b2",
103
+ "$argon2i$m=65536,t=1,p=1$c29tZXNhbHQ"
104
+ "$gWMFUrjzsfSM2xmSxMZ4ZD1JCytetP9sSzQ4tWIXJLI");
105
+ hashtest(version, 4, 16, 1, "password", "somesalt",
106
+ "f212f01615e6eb5d74734dc3ef40ade2d51d052468d8c69440a3a1f2c1c2847b",
107
+ "$argon2i$m=65536,t=4,p=1$c29tZXNhbHQ"
108
+ "$8hLwFhXm6110c03D70Ct4tUdBSRo2MaUQKOh8sHChHs");
109
+ hashtest(version, 2, 16, 1, "differentpassword", "somesalt",
110
+ "e9c902074b6754531a3a0be519e5baf404b30ce69b3f01ac3bf21229960109a3",
111
+ "$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ"
112
+ "$6ckCB0tnVFMaOgvlGeW69ASzDOabPwGsO/ISKZYBCaM");
113
+ hashtest(version, 2, 16, 1, "password", "diffsalt",
114
+ "79a103b90fe8aef8570cb31fc8b22259778916f8336b7bdac3892569d4f1c497",
115
+ "$argon2i$m=65536,t=2,p=1$ZGlmZnNhbHQ"
116
+ "$eaEDuQ/orvhXDLMfyLIiWXeJFvgza3vaw4kladTxxJc");
117
+
118
+ /* Error state tests */
119
+
120
+ /* Handle an invalid encoding correctly (it is missing a $) */
121
+ ret = argon2_verify("$argon2i$m=65536,t=2,p=1c29tZXNhbHQ"
122
+ "$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
123
+ "password", strlen("password"), Argon2_i);
124
+ assert(ret == ARGON2_DECODING_FAIL);
125
+ printf("Recognise an invalid encoding: PASS\n");
126
+
127
+ /* Handle an invalid encoding correctly (it is missing a $) */
128
+ ret = argon2_verify("$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ"
129
+ "9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
130
+ "password", strlen("password"), Argon2_i);
131
+ assert(ret == ARGON2_DECODING_FAIL);
132
+ printf("Recognise an invalid encoding: PASS\n");
133
+
134
+ /* Handle an invalid encoding correctly (salt is too short) */
135
+ ret = argon2_verify("$argon2i$m=65536,t=2,p=1$"
136
+ "$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
137
+ "password", strlen("password"), Argon2_i);
138
+ assert(ret == ARGON2_SALT_TOO_SHORT);
139
+ printf("Recognise an invalid salt in encoding: PASS\n");
140
+
141
+ /* Handle an mismatching hash (the encoded password is "passwore") */
142
+ ret = argon2_verify("$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ"
143
+ "$b2G3seW+uPzerwQQC+/E1K50CLLO7YXy0JRcaTuswRo",
144
+ "password", strlen("password"), Argon2_i);
145
+ assert(ret == ARGON2_VERIFY_MISMATCH);
146
+ printf("Verify with mismatched password: PASS\n");
147
+
148
+ msg = argon2_error_message(ARGON2_DECODING_FAIL);
149
+ assert(strcmp(msg, "Decoding failed") == 0);
150
+ printf("Decode an error message: PASS\n");
151
+
152
+ printf("\n");
153
+
154
+ version = ARGON2_VERSION_NUMBER;
155
+ printf("Test Argon2i version number: %02x\n", version);
156
+
157
+ /* Multiple test cases for various input values */
158
+ hashtest(version, 2, 16, 1, "password", "somesalt",
159
+ "c1628832147d9720c5bd1cfd61367078729f6dfb6f8fea9ff98158e0d7816ed0",
160
+ "$argon2i$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
161
+ "$wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA");
162
+ #ifdef TEST_LARGE_RAM
163
+ hashtest(version, 2, 20, 1, "password", "somesalt",
164
+ "d1587aca0922c3b5d6a83edab31bee3c4ebaef342ed6127a55d19b2351ad1f41",
165
+ "$argon2i$v=19$m=1048576,t=2,p=1$c29tZXNhbHQ"
166
+ "$0Vh6ygkiw7XWqD7asxvuPE667zQu1hJ6VdGbI1GtH0E");
167
+ #endif
168
+ hashtest(version, 2, 18, 1, "password", "somesalt",
169
+ "296dbae80b807cdceaad44ae741b506f14db0959267b183b118f9b24229bc7cb",
170
+ "$argon2i$v=19$m=262144,t=2,p=1$c29tZXNhbHQ"
171
+ "$KW266AuAfNzqrUSudBtQbxTbCVkmexg7EY+bJCKbx8s");
172
+ hashtest(version, 2, 8, 1, "password", "somesalt",
173
+ "89e9029f4637b295beb027056a7336c414fadd43f6b208645281cb214a56452f",
174
+ "$argon2i$v=19$m=256,t=2,p=1$c29tZXNhbHQ"
175
+ "$iekCn0Y3spW+sCcFanM2xBT63UP2sghkUoHLIUpWRS8");
176
+ hashtest(version, 2, 8, 2, "password", "somesalt",
177
+ "4ff5ce2769a1d7f4c8a491df09d41a9fbe90e5eb02155a13e4c01e20cd4eab61",
178
+ "$argon2i$v=19$m=256,t=2,p=2$c29tZXNhbHQ"
179
+ "$T/XOJ2mh1/TIpJHfCdQan76Q5esCFVoT5MAeIM1Oq2E");
180
+ hashtest(version, 1, 16, 1, "password", "somesalt",
181
+ "d168075c4d985e13ebeae560cf8b94c3b5d8a16c51916b6f4ac2da3ac11bbecf",
182
+ "$argon2i$v=19$m=65536,t=1,p=1$c29tZXNhbHQ"
183
+ "$0WgHXE2YXhPr6uVgz4uUw7XYoWxRkWtvSsLaOsEbvs8");
184
+ hashtest(version, 4, 16, 1, "password", "somesalt",
185
+ "aaa953d58af3706ce3df1aefd4a64a84e31d7f54175231f1285259f88174ce5b",
186
+ "$argon2i$v=19$m=65536,t=4,p=1$c29tZXNhbHQ"
187
+ "$qqlT1YrzcGzj3xrv1KZKhOMdf1QXUjHxKFJZ+IF0zls");
188
+ hashtest(version, 2, 16, 1, "differentpassword", "somesalt",
189
+ "14ae8da01afea8700c2358dcef7c5358d9021282bd88663a4562f59fb74d22ee",
190
+ "$argon2i$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
191
+ "$FK6NoBr+qHAMI1jc73xTWNkCEoK9iGY6RWL1n7dNIu4");
192
+ hashtest(version, 2, 16, 1, "password", "diffsalt",
193
+ "b0357cccfbef91f3860b0dba447b2348cbefecadaf990abfe9cc40726c521271",
194
+ "$argon2i$v=19$m=65536,t=2,p=1$ZGlmZnNhbHQ"
195
+ "$sDV8zPvvkfOGCw26RHsjSMvv7K2vmQq/6cxAcmxSEnE");
196
+
197
+ /* Error state tests */
198
+
199
+ /* Handle an invalid encoding correctly (it is missing a $) */
200
+ ret = argon2_verify("$argon2i$v=19$m=65536,t=2,p=1c29tZXNhbHQ"
201
+ "$wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA",
202
+ "password", strlen("password"), Argon2_i);
203
+ assert(ret == ARGON2_DECODING_FAIL);
204
+ printf("Recognise an invalid encoding: PASS\n");
205
+
206
+ /* Handle an invalid encoding correctly (it is missing a $) */
207
+ ret = argon2_verify("$argon2i$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
208
+ "wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA",
209
+ "password", strlen("password"), Argon2_i);
210
+ assert(ret == ARGON2_DECODING_FAIL);
211
+ printf("Recognise an invalid encoding: PASS\n");
212
+
213
+ /* Handle an invalid encoding correctly (salt is too short) */
214
+ ret = argon2_verify("$argon2i$v=19$m=65536,t=2,p=1$"
215
+ "$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
216
+ "password", strlen("password"), Argon2_i);
217
+ assert(ret == ARGON2_SALT_TOO_SHORT);
218
+ printf("Recognise an invalid salt in encoding: PASS\n");
219
+
220
+ /* Handle an mismatching hash (the encoded password is "passwore") */
221
+ ret = argon2_verify("$argon2i$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
222
+ "$8iIuixkI73Js3G1uMbezQXD0b8LG4SXGsOwoQkdAQIM",
223
+ "password", strlen("password"), Argon2_i);
224
+ assert(ret == ARGON2_VERIFY_MISMATCH);
225
+ printf("Verify with mismatched password: PASS\n");
226
+
227
+ msg = argon2_error_message(ARGON2_DECODING_FAIL);
228
+ assert(strcmp(msg, "Decoding failed") == 0);
229
+ printf("Decode an error message: PASS\n");
230
+
231
+ /* Common error state tests */
232
+
233
+ printf("\n");
234
+ printf("Common error state tests\n");
235
+
236
+ ret = argon2_hash(2, 1, 1, "password", strlen("password"),
237
+ "diffsalt", strlen("diffsalt"),
238
+ out, OUT_LEN, NULL, 0, Argon2_i, version);
239
+ assert(ret == ARGON2_MEMORY_TOO_LITTLE);
240
+ printf("Fail on invalid memory: PASS\n");
241
+
242
+ ret = argon2_hash(2, 1 << 12, 1, NULL, strlen("password"),
243
+ "diffsalt", strlen("diffsalt"),
244
+ out, OUT_LEN, NULL, 0, Argon2_i, version);
245
+ assert(ret == ARGON2_PWD_PTR_MISMATCH);
246
+ printf("Fail on invalid null pointer: PASS\n");
247
+
248
+ ret = argon2_hash(2, 1 << 12, 1, "password", strlen("password"), "s", 1,
249
+ out, OUT_LEN, NULL, 0, Argon2_i, version);
250
+ assert(ret == ARGON2_SALT_TOO_SHORT);
251
+ printf("Fail on salt too short: PASS\n");
252
+
253
+ return 0;
254
+ }
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Argon2 reference source code package - reference C implementations
3
+ *
4
+ * Copyright 2015
5
+ * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
6
+ *
7
+ * You may use this work under the terms of a Creative Commons CC0 1.0
8
+ * License/Waiver or the Apache Public License 2.0, at your option. The terms of
9
+ * these licenses can be found at:
10
+ *
11
+ * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
12
+ * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * You should have received a copy of both of these licenses along with this
15
+ * software. If not, they may be obtained at the above URLs.
16
+ */
17
+
18
+ #if !defined(ARGON2_NO_THREADS)
19
+
20
+ #include "thread.h"
21
+ #if defined(_WIN32)
22
+ #include <windows.h>
23
+ #endif
24
+
25
+ int argon2_thread_create(argon2_thread_handle_t *handle,
26
+ argon2_thread_func_t func, void *args) {
27
+ if (NULL == handle || func == NULL) {
28
+ return -1;
29
+ }
30
+ #if defined(_WIN32)
31
+ *handle = _beginthreadex(NULL, 0, func, args, 0, NULL);
32
+ return *handle != 0 ? 0 : -1;
33
+ #else
34
+ return pthread_create(handle, NULL, func, args);
35
+ #endif
36
+ }
37
+
38
+ int argon2_thread_join(argon2_thread_handle_t handle) {
39
+ #if defined(_WIN32)
40
+ if (WaitForSingleObject((HANDLE)handle, INFINITE) == WAIT_OBJECT_0) {
41
+ return CloseHandle((HANDLE)handle) != 0 ? 0 : -1;
42
+ }
43
+ return -1;
44
+ #else
45
+ return pthread_join(handle, NULL);
46
+ #endif
47
+ }
48
+
49
+ void argon2_thread_exit(void) {
50
+ #if defined(_WIN32)
51
+ _endthreadex(0);
52
+ #else
53
+ pthread_exit(NULL);
54
+ #endif
55
+ }
56
+
57
+ #endif /* ARGON2_NO_THREADS */
@@ -0,0 +1,67 @@
1
+ /*
2
+ * Argon2 reference source code package - reference C implementations
3
+ *
4
+ * Copyright 2015
5
+ * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
6
+ *
7
+ * You may use this work under the terms of a Creative Commons CC0 1.0
8
+ * License/Waiver or the Apache Public License 2.0, at your option. The terms of
9
+ * these licenses can be found at:
10
+ *
11
+ * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
12
+ * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * You should have received a copy of both of these licenses along with this
15
+ * software. If not, they may be obtained at the above URLs.
16
+ */
17
+
18
+ #ifndef ARGON2_THREAD_H
19
+ #define ARGON2_THREAD_H
20
+
21
+ #if !defined(ARGON2_NO_THREADS)
22
+
23
+ /*
24
+ Here we implement an abstraction layer for the simpĺe requirements
25
+ of the Argon2 code. We only require 3 primitives---thread creation,
26
+ joining, and termination---so full emulation of the pthreads API
27
+ is unwarranted. Currently we wrap pthreads and Win32 threads.
28
+
29
+ The API defines 2 types: the function pointer type,
30
+ argon2_thread_func_t,
31
+ and the type of the thread handle---argon2_thread_handle_t.
32
+ */
33
+ #if defined(_WIN32)
34
+ #include <process.h>
35
+ typedef unsigned(__stdcall *argon2_thread_func_t)(void *);
36
+ typedef uintptr_t argon2_thread_handle_t;
37
+ #else
38
+ #include <pthread.h>
39
+ typedef void *(*argon2_thread_func_t)(void *);
40
+ typedef pthread_t argon2_thread_handle_t;
41
+ #endif
42
+
43
+ /* Creates a thread
44
+ * @param handle pointer to a thread handle, which is the output of this
45
+ * function. Must not be NULL.
46
+ * @param func A function pointer for the thread's entry point. Must not be
47
+ * NULL.
48
+ * @param args Pointer that is passed as an argument to @func. May be NULL.
49
+ * @return 0 if @handle and @func are valid pointers and a thread is successfuly
50
+ * created.
51
+ */
52
+ int argon2_thread_create(argon2_thread_handle_t *handle,
53
+ argon2_thread_func_t func, void *args);
54
+
55
+ /* Waits for a thread to terminate
56
+ * @param handle Handle to a thread created with argon2_thread_create.
57
+ * @return 0 if @handle is a valid handle, and joining completed successfully.
58
+ */
59
+ int argon2_thread_join(argon2_thread_handle_t handle);
60
+
61
+ /* Terminate the current thread. Must be run inside a thread created by
62
+ * argon2_thread_create.
63
+ */
64
+ void argon2_thread_exit(void);
65
+
66
+ #endif /* ARGON2_NO_THREADS */
67
+ #endif
@@ -0,0 +1,226 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <ItemGroup Label="ProjectConfigurations">
4
+ <ProjectConfiguration Include="Debug|Win32">
5
+ <Configuration>Debug</Configuration>
6
+ <Platform>Win32</Platform>
7
+ </ProjectConfiguration>
8
+ <ProjectConfiguration Include="ReleaseStatic|Win32">
9
+ <Configuration>ReleaseStatic</Configuration>
10
+ <Platform>Win32</Platform>
11
+ </ProjectConfiguration>
12
+ <ProjectConfiguration Include="ReleaseStatic|x64">
13
+ <Configuration>ReleaseStatic</Configuration>
14
+ <Platform>x64</Platform>
15
+ </ProjectConfiguration>
16
+ <ProjectConfiguration Include="Release|Win32">
17
+ <Configuration>Release</Configuration>
18
+ <Platform>Win32</Platform>
19
+ </ProjectConfiguration>
20
+ <ProjectConfiguration Include="Debug|x64">
21
+ <Configuration>Debug</Configuration>
22
+ <Platform>x64</Platform>
23
+ </ProjectConfiguration>
24
+ <ProjectConfiguration Include="Release|x64">
25
+ <Configuration>Release</Configuration>
26
+ <Platform>x64</Platform>
27
+ </ProjectConfiguration>
28
+ </ItemGroup>
29
+ <PropertyGroup Label="Globals">
30
+ <ProjectGuid>{CAA75C57-998C-494E-B8A5-5894EF0FC528}</ProjectGuid>
31
+ <RootNamespace>Argon2Opt</RootNamespace>
32
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
33
+ </PropertyGroup>
34
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
35
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
36
+ <ConfigurationType>Application</ConfigurationType>
37
+ <UseDebugLibraries>true</UseDebugLibraries>
38
+ <PlatformToolset>v140</PlatformToolset>
39
+ <CharacterSet>MultiByte</CharacterSet>
40
+ </PropertyGroup>
41
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
42
+ <ConfigurationType>Application</ConfigurationType>
43
+ <UseDebugLibraries>false</UseDebugLibraries>
44
+ <PlatformToolset>v140</PlatformToolset>
45
+ <WholeProgramOptimization>true</WholeProgramOptimization>
46
+ <CharacterSet>MultiByte</CharacterSet>
47
+ </PropertyGroup>
48
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'" Label="Configuration">
49
+ <ConfigurationType>Application</ConfigurationType>
50
+ <UseDebugLibraries>false</UseDebugLibraries>
51
+ <PlatformToolset>v140</PlatformToolset>
52
+ <WholeProgramOptimization>true</WholeProgramOptimization>
53
+ <CharacterSet>MultiByte</CharacterSet>
54
+ </PropertyGroup>
55
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
56
+ <ConfigurationType>Application</ConfigurationType>
57
+ <UseDebugLibraries>true</UseDebugLibraries>
58
+ <PlatformToolset>v140</PlatformToolset>
59
+ <CharacterSet>MultiByte</CharacterSet>
60
+ </PropertyGroup>
61
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
62
+ <ConfigurationType>Application</ConfigurationType>
63
+ <UseDebugLibraries>false</UseDebugLibraries>
64
+ <PlatformToolset>v140</PlatformToolset>
65
+ <WholeProgramOptimization>true</WholeProgramOptimization>
66
+ <CharacterSet>MultiByte</CharacterSet>
67
+ </PropertyGroup>
68
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'" Label="Configuration">
69
+ <ConfigurationType>Application</ConfigurationType>
70
+ <UseDebugLibraries>false</UseDebugLibraries>
71
+ <PlatformToolset>v140</PlatformToolset>
72
+ <WholeProgramOptimization>true</WholeProgramOptimization>
73
+ <CharacterSet>MultiByte</CharacterSet>
74
+ </PropertyGroup>
75
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
76
+ <ImportGroup Label="ExtensionSettings">
77
+ </ImportGroup>
78
+ <ImportGroup Label="Shared">
79
+ </ImportGroup>
80
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
81
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
82
+ </ImportGroup>
83
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
84
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
85
+ </ImportGroup>
86
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'" Label="PropertySheets">
87
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
88
+ </ImportGroup>
89
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
90
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
91
+ </ImportGroup>
92
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
93
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
94
+ </ImportGroup>
95
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'" Label="PropertySheets">
96
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
97
+ </ImportGroup>
98
+ <PropertyGroup Label="UserMacros" />
99
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
100
+ <OutDir>$(SolutionDir)vs2015\build\</OutDir>
101
+ <IntDir>$(SolutionDir)vs2015\build\$(ProjectName)\</IntDir>
102
+ <IncludePath>$(SolutionDir)include;$(IncludePath)</IncludePath>
103
+ </PropertyGroup>
104
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
105
+ <OutDir>$(SolutionDir)vs2015\build\</OutDir>
106
+ <IntDir>$(SolutionDir)vs2015\build\$(ProjectName)\</IntDir>
107
+ <IncludePath>$(SolutionDir)include;$(IncludePath)</IncludePath>
108
+ </PropertyGroup>
109
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">
110
+ <OutDir>$(SolutionDir)vs2015\build\</OutDir>
111
+ <IntDir>$(SolutionDir)vs2015\build\$(ProjectName)\</IntDir>
112
+ <IncludePath>$(SolutionDir)include;$(IncludePath)</IncludePath>
113
+ </PropertyGroup>
114
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
115
+ <OutDir>$(SolutionDir)vs2015\build\</OutDir>
116
+ <IntDir>$(SolutionDir)vs2015\build\$(ProjectName)\</IntDir>
117
+ <IncludePath>$(SolutionDir)include;$(IncludePath)</IncludePath>
118
+ </PropertyGroup>
119
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
120
+ <OutDir>$(SolutionDir)vs2015\build\</OutDir>
121
+ <IntDir>$(SolutionDir)vs2015\build\$(ProjectName)\</IntDir>
122
+ <IncludePath>$(SolutionDir)include;$(IncludePath)</IncludePath>
123
+ </PropertyGroup>
124
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'">
125
+ <OutDir>$(SolutionDir)vs2015\build\</OutDir>
126
+ <IntDir>$(SolutionDir)vs2015\build\$(ProjectName)\</IntDir>
127
+ <IncludePath>$(SolutionDir)include;$(IncludePath)</IncludePath>
128
+ </PropertyGroup>
129
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
130
+ <ClCompile>
131
+ <WarningLevel>Level3</WarningLevel>
132
+ <Optimization>Disabled</Optimization>
133
+ <SDLCheck>true</SDLCheck>
134
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
135
+ </ClCompile>
136
+ </ItemDefinitionGroup>
137
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
138
+ <ClCompile>
139
+ <WarningLevel>Level3</WarningLevel>
140
+ <Optimization>Disabled</Optimization>
141
+ <SDLCheck>true</SDLCheck>
142
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
143
+ </ClCompile>
144
+ </ItemDefinitionGroup>
145
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
146
+ <ClCompile>
147
+ <WarningLevel>Level3</WarningLevel>
148
+ <Optimization>MaxSpeed</Optimization>
149
+ <FunctionLevelLinking>true</FunctionLevelLinking>
150
+ <IntrinsicFunctions>true</IntrinsicFunctions>
151
+ <SDLCheck>true</SDLCheck>
152
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
153
+ </ClCompile>
154
+ <Link>
155
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
156
+ <OptimizeReferences>true</OptimizeReferences>
157
+ </Link>
158
+ </ItemDefinitionGroup>
159
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">
160
+ <ClCompile>
161
+ <WarningLevel>Level3</WarningLevel>
162
+ <Optimization>MaxSpeed</Optimization>
163
+ <FunctionLevelLinking>true</FunctionLevelLinking>
164
+ <IntrinsicFunctions>true</IntrinsicFunctions>
165
+ <SDLCheck>true</SDLCheck>
166
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
167
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
168
+ </ClCompile>
169
+ <Link>
170
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
171
+ <OptimizeReferences>true</OptimizeReferences>
172
+ </Link>
173
+ </ItemDefinitionGroup>
174
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
175
+ <ClCompile>
176
+ <WarningLevel>Level3</WarningLevel>
177
+ <Optimization>MaxSpeed</Optimization>
178
+ <FunctionLevelLinking>true</FunctionLevelLinking>
179
+ <IntrinsicFunctions>true</IntrinsicFunctions>
180
+ <SDLCheck>true</SDLCheck>
181
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
182
+ </ClCompile>
183
+ <Link>
184
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
185
+ <OptimizeReferences>true</OptimizeReferences>
186
+ </Link>
187
+ </ItemDefinitionGroup>
188
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'">
189
+ <ClCompile>
190
+ <WarningLevel>Level3</WarningLevel>
191
+ <Optimization>MaxSpeed</Optimization>
192
+ <FunctionLevelLinking>true</FunctionLevelLinking>
193
+ <IntrinsicFunctions>true</IntrinsicFunctions>
194
+ <SDLCheck>true</SDLCheck>
195
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
196
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
197
+ </ClCompile>
198
+ <Link>
199
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
200
+ <OptimizeReferences>true</OptimizeReferences>
201
+ </Link>
202
+ </ItemDefinitionGroup>
203
+ <ItemGroup>
204
+ <ClInclude Include="..\..\include\argon2.h" />
205
+ <ClInclude Include="..\..\src\blake2\blake2-impl.h" />
206
+ <ClInclude Include="..\..\src\blake2\blake2.h" />
207
+ <ClInclude Include="..\..\src\blake2\blamka-round-opt.h" />
208
+ <ClInclude Include="..\..\src\blake2\blamka-round-ref.h" />
209
+ <ClInclude Include="..\..\src\core.h" />
210
+ <ClInclude Include="..\..\src\encoding.h" />
211
+ <ClInclude Include="..\..\src\opt.h" />
212
+ <ClInclude Include="..\..\src\thread.h" />
213
+ </ItemGroup>
214
+ <ItemGroup>
215
+ <ClCompile Include="..\..\src\argon2.c" />
216
+ <ClCompile Include="..\..\src\blake2\blake2b.c" />
217
+ <ClCompile Include="..\..\src\core.c" />
218
+ <ClCompile Include="..\..\src\encoding.c" />
219
+ <ClCompile Include="..\..\src\opt.c" />
220
+ <ClCompile Include="..\..\src\run.c" />
221
+ <ClCompile Include="..\..\src\thread.c" />
222
+ </ItemGroup>
223
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
224
+ <ImportGroup Label="ExtensionTargets">
225
+ </ImportGroup>
226
+ </Project>