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,16 @@
1
+ # libargon2 info for pkg-config
2
+ ## Template for downstream installers:
3
+ ## - replace @HOST_MULTIARCH@ with target arch, eg 'x86_64-linux-gnu'
4
+ ## - replace @UPSTREAM_VER@ with current version, eg '20160406'
5
+
6
+ prefix=/usr
7
+ exec_prefix=${prefix}
8
+ libdir=${prefix}/lib/@HOST_MULTIARCH@
9
+ includedir=${prefix}/include
10
+
11
+ Name: libargon2
12
+ Description: Development libraries for libargon2
13
+ Version: @UPSTREAM_VER@
14
+ Libs: -L${libdir} -largon2 -lrt -ldl
15
+ Cflags:
16
+ URL: https://github.com/P-H-C/phc-winner-argon2
@@ -0,0 +1,57 @@
1
+ .TH ARGON2 "1" "April 2016" "argon2 " "User Commands"
2
+
3
+ .SH NAME
4
+ argon2 \- generate argon2 hashes
5
+
6
+ .SH SYNOPSIS
7
+ .B argon2 salt
8
+ .RB [ OPTIONS ]
9
+
10
+ .SH DESCRIPTION
11
+ Generate Argon2 hashes from the command line.
12
+
13
+ The supplied salt (the first argument to the command) must be at least
14
+ 8 octets in length, and the password is supplied on standard input.
15
+
16
+ By default, this uses Argon2i variant (where memory access is
17
+ independent of secret data) which is the preferred one for password
18
+ hashing and password-based key derivation.
19
+
20
+ .SH OPTIONS
21
+ .TP
22
+ .B \-h
23
+ Display tool usage
24
+ .TP
25
+ .B \-d
26
+ Use Argon2d instead of Argon2i (Argon2i is the default)
27
+ .TP
28
+ .B \-id
29
+ Use Argon2id instead of Argon2i (Argon2i is the default)
30
+ .TP
31
+ .BI \-t " N"
32
+ Sets the number of iterations to N (default = 3)
33
+ .TP
34
+ .BI \-m " N"
35
+ Sets the memory usage of 2^N KiB (default = 12)
36
+ .TP
37
+ .BI \-p " N"
38
+ Sets parallelism to N threads (default = 1)
39
+ .TP
40
+ .BI \-l " N"
41
+ Sets hash output length to N bytes (default = 32)
42
+ .TP
43
+ .B \-e
44
+ Output only encoded hash
45
+ .TP
46
+ .B \-r
47
+ Output only the raw bytes of the hash
48
+ .TP
49
+ .B \-v (10|13)
50
+ Argon2 version (defaults to the most recent version, currently 13)
51
+
52
+ .SH COPYRIGHT
53
+ This manpage was written by \fBDaniel Kahn Gillmor\fR for the Debian
54
+ distribution (but may be used by others). It is released, like the
55
+ rest of this Argon2 implementation, under a dual license. You may use this work
56
+ under the terms of a Creative Commons CC0 1.0 License/Waiver or the Apache
57
+ Public License 2.0, at your option.
@@ -0,0 +1,452 @@
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 <string.h>
19
+ #include <stdlib.h>
20
+ #include <stdio.h>
21
+
22
+ #include "argon2.h"
23
+ #include "encoding.h"
24
+ #include "core.h"
25
+
26
+ const char *argon2_type2string(argon2_type type, int uppercase) {
27
+ switch (type) {
28
+ case Argon2_d:
29
+ return uppercase ? "Argon2d" : "argon2d";
30
+ case Argon2_i:
31
+ return uppercase ? "Argon2i" : "argon2i";
32
+ case Argon2_id:
33
+ return uppercase ? "Argon2id" : "argon2id";
34
+ }
35
+
36
+ return NULL;
37
+ }
38
+
39
+ int argon2_ctx(argon2_context *context, argon2_type type) {
40
+ /* 1. Validate all inputs */
41
+ int result = validate_inputs(context);
42
+ uint32_t memory_blocks, segment_length;
43
+ argon2_instance_t instance;
44
+
45
+ if (ARGON2_OK != result) {
46
+ return result;
47
+ }
48
+
49
+ if (Argon2_d != type && Argon2_i != type && Argon2_id != type) {
50
+ return ARGON2_INCORRECT_TYPE;
51
+ }
52
+
53
+ /* 2. Align memory size */
54
+ /* Minimum memory_blocks = 8L blocks, where L is the number of lanes */
55
+ memory_blocks = context->m_cost;
56
+
57
+ if (memory_blocks < 2 * ARGON2_SYNC_POINTS * context->lanes) {
58
+ memory_blocks = 2 * ARGON2_SYNC_POINTS * context->lanes;
59
+ }
60
+
61
+ segment_length = memory_blocks / (context->lanes * ARGON2_SYNC_POINTS);
62
+ /* Ensure that all segments have equal length */
63
+ memory_blocks = segment_length * (context->lanes * ARGON2_SYNC_POINTS);
64
+
65
+ instance.version = context->version;
66
+ instance.memory = NULL;
67
+ instance.passes = context->t_cost;
68
+ instance.memory_blocks = memory_blocks;
69
+ instance.segment_length = segment_length;
70
+ instance.lane_length = segment_length * ARGON2_SYNC_POINTS;
71
+ instance.lanes = context->lanes;
72
+ instance.threads = context->threads;
73
+ instance.type = type;
74
+
75
+ if (instance.threads > instance.lanes) {
76
+ instance.threads = instance.lanes;
77
+ }
78
+
79
+ /* 3. Initialization: Hashing inputs, allocating memory, filling first
80
+ * blocks
81
+ */
82
+ result = initialize(&instance, context);
83
+
84
+ if (ARGON2_OK != result) {
85
+ return result;
86
+ }
87
+
88
+ /* 4. Filling memory */
89
+ result = fill_memory_blocks(&instance);
90
+
91
+ if (ARGON2_OK != result) {
92
+ return result;
93
+ }
94
+ /* 5. Finalization */
95
+ finalize(context, &instance);
96
+
97
+ return ARGON2_OK;
98
+ }
99
+
100
+ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
101
+ const uint32_t parallelism, const void *pwd,
102
+ const size_t pwdlen, const void *salt, const size_t saltlen,
103
+ void *hash, const size_t hashlen, char *encoded,
104
+ const size_t encodedlen, argon2_type type,
105
+ const uint32_t version){
106
+
107
+ argon2_context context;
108
+ int result;
109
+ uint8_t *out;
110
+
111
+ if (pwdlen > ARGON2_MAX_PWD_LENGTH) {
112
+ return ARGON2_PWD_TOO_LONG;
113
+ }
114
+
115
+ if (saltlen > ARGON2_MAX_SALT_LENGTH) {
116
+ return ARGON2_SALT_TOO_LONG;
117
+ }
118
+
119
+ if (hashlen > ARGON2_MAX_OUTLEN) {
120
+ return ARGON2_OUTPUT_TOO_LONG;
121
+ }
122
+
123
+ if (hashlen < ARGON2_MIN_OUTLEN) {
124
+ return ARGON2_OUTPUT_TOO_SHORT;
125
+ }
126
+
127
+ out = malloc(hashlen);
128
+ if (!out) {
129
+ return ARGON2_MEMORY_ALLOCATION_ERROR;
130
+ }
131
+
132
+ context.out = (uint8_t *)out;
133
+ context.outlen = (uint32_t)hashlen;
134
+ context.pwd = CONST_CAST(uint8_t *)pwd;
135
+ context.pwdlen = (uint32_t)pwdlen;
136
+ context.salt = CONST_CAST(uint8_t *)salt;
137
+ context.saltlen = (uint32_t)saltlen;
138
+ context.secret = NULL;
139
+ context.secretlen = 0;
140
+ context.ad = NULL;
141
+ context.adlen = 0;
142
+ context.t_cost = t_cost;
143
+ context.m_cost = m_cost;
144
+ context.lanes = parallelism;
145
+ context.threads = parallelism;
146
+ context.allocate_cbk = NULL;
147
+ context.free_cbk = NULL;
148
+ context.flags = ARGON2_DEFAULT_FLAGS;
149
+ context.version = version;
150
+
151
+ result = argon2_ctx(&context, type);
152
+
153
+ if (result != ARGON2_OK) {
154
+ clear_internal_memory(out, hashlen);
155
+ free(out);
156
+ return result;
157
+ }
158
+
159
+ /* if raw hash requested, write it */
160
+ if (hash) {
161
+ memcpy(hash, out, hashlen);
162
+ }
163
+
164
+ /* if encoding requested, write it */
165
+ if (encoded && encodedlen) {
166
+ if (encode_string(encoded, encodedlen, &context, type) != ARGON2_OK) {
167
+ clear_internal_memory(out, hashlen); /* wipe buffers if error */
168
+ clear_internal_memory(encoded, encodedlen);
169
+ free(out);
170
+ return ARGON2_ENCODING_FAIL;
171
+ }
172
+ }
173
+ clear_internal_memory(out, hashlen);
174
+ free(out);
175
+
176
+ return ARGON2_OK;
177
+ }
178
+
179
+ int argon2i_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
180
+ const uint32_t parallelism, const void *pwd,
181
+ const size_t pwdlen, const void *salt,
182
+ const size_t saltlen, const size_t hashlen,
183
+ char *encoded, const size_t encodedlen) {
184
+
185
+ return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
186
+ NULL, hashlen, encoded, encodedlen, Argon2_i,
187
+ ARGON2_VERSION_NUMBER);
188
+ }
189
+
190
+ int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
191
+ const uint32_t parallelism, const void *pwd,
192
+ const size_t pwdlen, const void *salt,
193
+ const size_t saltlen, void *hash, const size_t hashlen) {
194
+
195
+ return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
196
+ hash, hashlen, NULL, 0, Argon2_i, ARGON2_VERSION_NUMBER);
197
+ }
198
+
199
+ int argon2d_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
200
+ const uint32_t parallelism, const void *pwd,
201
+ const size_t pwdlen, const void *salt,
202
+ const size_t saltlen, const size_t hashlen,
203
+ char *encoded, const size_t encodedlen) {
204
+
205
+ return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
206
+ NULL, hashlen, encoded, encodedlen, Argon2_d,
207
+ ARGON2_VERSION_NUMBER);
208
+ }
209
+
210
+ int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
211
+ const uint32_t parallelism, const void *pwd,
212
+ const size_t pwdlen, const void *salt,
213
+ const size_t saltlen, void *hash, const size_t hashlen) {
214
+
215
+ return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
216
+ hash, hashlen, NULL, 0, Argon2_d, ARGON2_VERSION_NUMBER);
217
+ }
218
+
219
+ int argon2id_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
220
+ const uint32_t parallelism, const void *pwd,
221
+ const size_t pwdlen, const void *salt,
222
+ const size_t saltlen, const size_t hashlen,
223
+ char *encoded, const size_t encodedlen) {
224
+
225
+ return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
226
+ NULL, hashlen, encoded, encodedlen, Argon2_id,
227
+ ARGON2_VERSION_NUMBER);
228
+ }
229
+
230
+ int argon2id_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
231
+ const uint32_t parallelism, const void *pwd,
232
+ const size_t pwdlen, const void *salt,
233
+ const size_t saltlen, void *hash, const size_t hashlen) {
234
+ return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
235
+ hash, hashlen, NULL, 0, Argon2_id,
236
+ ARGON2_VERSION_NUMBER);
237
+ }
238
+
239
+ static int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
240
+ size_t i;
241
+ uint8_t d = 0U;
242
+
243
+ for (i = 0U; i < len; i++) {
244
+ d |= b1[i] ^ b2[i];
245
+ }
246
+ return (int)((1 & ((d - 1) >> 8)) - 1);
247
+ }
248
+
249
+ int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
250
+ argon2_type type) {
251
+
252
+ argon2_context ctx;
253
+ uint8_t *desired_result = NULL;
254
+
255
+ int ret = ARGON2_OK;
256
+
257
+ size_t encoded_len;
258
+ uint32_t max_field_len;
259
+
260
+ if (pwdlen > ARGON2_MAX_PWD_LENGTH) {
261
+ return ARGON2_PWD_TOO_LONG;
262
+ }
263
+
264
+ if (encoded == NULL) {
265
+ return ARGON2_DECODING_FAIL;
266
+ }
267
+
268
+ encoded_len = strlen(encoded);
269
+ if (encoded_len > UINT32_MAX) {
270
+ return ARGON2_DECODING_FAIL;
271
+ }
272
+
273
+ /* No field can be longer than the encoded length */
274
+ max_field_len = (uint32_t)encoded_len;
275
+
276
+ ctx.saltlen = max_field_len;
277
+ ctx.outlen = max_field_len;
278
+
279
+ ctx.salt = malloc(ctx.saltlen);
280
+ ctx.out = malloc(ctx.outlen);
281
+ if (!ctx.salt || !ctx.out) {
282
+ ret = ARGON2_MEMORY_ALLOCATION_ERROR;
283
+ goto fail;
284
+ }
285
+
286
+ ctx.pwd = (uint8_t *)pwd;
287
+ ctx.pwdlen = (uint32_t)pwdlen;
288
+
289
+ ret = decode_string(&ctx, encoded, type);
290
+ if (ret != ARGON2_OK) {
291
+ goto fail;
292
+ }
293
+
294
+ /* Set aside the desired result, and get a new buffer. */
295
+ desired_result = ctx.out;
296
+ ctx.out = malloc(ctx.outlen);
297
+ if (!ctx.out) {
298
+ ret = ARGON2_MEMORY_ALLOCATION_ERROR;
299
+ goto fail;
300
+ }
301
+
302
+ ret = argon2_verify_ctx(&ctx, (char *)desired_result, type);
303
+ if (ret != ARGON2_OK) {
304
+ goto fail;
305
+ }
306
+
307
+ fail:
308
+ free(ctx.salt);
309
+ free(ctx.out);
310
+ free(desired_result);
311
+
312
+ return ret;
313
+ }
314
+
315
+ int argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
316
+
317
+ return argon2_verify(encoded, pwd, pwdlen, Argon2_i);
318
+ }
319
+
320
+ int argon2d_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
321
+
322
+ return argon2_verify(encoded, pwd, pwdlen, Argon2_d);
323
+ }
324
+
325
+ int argon2id_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
326
+
327
+ return argon2_verify(encoded, pwd, pwdlen, Argon2_id);
328
+ }
329
+
330
+ int argon2d_ctx(argon2_context *context) {
331
+ return argon2_ctx(context, Argon2_d);
332
+ }
333
+
334
+ int argon2i_ctx(argon2_context *context) {
335
+ return argon2_ctx(context, Argon2_i);
336
+ }
337
+
338
+ int argon2id_ctx(argon2_context *context) {
339
+ return argon2_ctx(context, Argon2_id);
340
+ }
341
+
342
+ int argon2_verify_ctx(argon2_context *context, const char *hash,
343
+ argon2_type type) {
344
+ int ret = argon2_ctx(context, type);
345
+ if (ret != ARGON2_OK) {
346
+ return ret;
347
+ }
348
+
349
+ if (argon2_compare((uint8_t *)hash, context->out, context->outlen)) {
350
+ return ARGON2_VERIFY_MISMATCH;
351
+ }
352
+
353
+ return ARGON2_OK;
354
+ }
355
+
356
+ int argon2d_verify_ctx(argon2_context *context, const char *hash) {
357
+ return argon2_verify_ctx(context, hash, Argon2_d);
358
+ }
359
+
360
+ int argon2i_verify_ctx(argon2_context *context, const char *hash) {
361
+ return argon2_verify_ctx(context, hash, Argon2_i);
362
+ }
363
+
364
+ int argon2id_verify_ctx(argon2_context *context, const char *hash) {
365
+ return argon2_verify_ctx(context, hash, Argon2_id);
366
+ }
367
+
368
+ const char *argon2_error_message(int error_code) {
369
+ switch (error_code) {
370
+ case ARGON2_OK:
371
+ return "OK";
372
+ case ARGON2_OUTPUT_PTR_NULL:
373
+ return "Output pointer is NULL";
374
+ case ARGON2_OUTPUT_TOO_SHORT:
375
+ return "Output is too short";
376
+ case ARGON2_OUTPUT_TOO_LONG:
377
+ return "Output is too long";
378
+ case ARGON2_PWD_TOO_SHORT:
379
+ return "Password is too short";
380
+ case ARGON2_PWD_TOO_LONG:
381
+ return "Password is too long";
382
+ case ARGON2_SALT_TOO_SHORT:
383
+ return "Salt is too short";
384
+ case ARGON2_SALT_TOO_LONG:
385
+ return "Salt is too long";
386
+ case ARGON2_AD_TOO_SHORT:
387
+ return "Associated data is too short";
388
+ case ARGON2_AD_TOO_LONG:
389
+ return "Associated data is too long";
390
+ case ARGON2_SECRET_TOO_SHORT:
391
+ return "Secret is too short";
392
+ case ARGON2_SECRET_TOO_LONG:
393
+ return "Secret is too long";
394
+ case ARGON2_TIME_TOO_SMALL:
395
+ return "Time cost is too small";
396
+ case ARGON2_TIME_TOO_LARGE:
397
+ return "Time cost is too large";
398
+ case ARGON2_MEMORY_TOO_LITTLE:
399
+ return "Memory cost is too small";
400
+ case ARGON2_MEMORY_TOO_MUCH:
401
+ return "Memory cost is too large";
402
+ case ARGON2_LANES_TOO_FEW:
403
+ return "Too few lanes";
404
+ case ARGON2_LANES_TOO_MANY:
405
+ return "Too many lanes";
406
+ case ARGON2_PWD_PTR_MISMATCH:
407
+ return "Password pointer is NULL, but password length is not 0";
408
+ case ARGON2_SALT_PTR_MISMATCH:
409
+ return "Salt pointer is NULL, but salt length is not 0";
410
+ case ARGON2_SECRET_PTR_MISMATCH:
411
+ return "Secret pointer is NULL, but secret length is not 0";
412
+ case ARGON2_AD_PTR_MISMATCH:
413
+ return "Associated data pointer is NULL, but ad length is not 0";
414
+ case ARGON2_MEMORY_ALLOCATION_ERROR:
415
+ return "Memory allocation error";
416
+ case ARGON2_FREE_MEMORY_CBK_NULL:
417
+ return "The free memory callback is NULL";
418
+ case ARGON2_ALLOCATE_MEMORY_CBK_NULL:
419
+ return "The allocate memory callback is NULL";
420
+ case ARGON2_INCORRECT_PARAMETER:
421
+ return "Argon2_Context context is NULL";
422
+ case ARGON2_INCORRECT_TYPE:
423
+ return "There is no such version of Argon2";
424
+ case ARGON2_OUT_PTR_MISMATCH:
425
+ return "Output pointer mismatch";
426
+ case ARGON2_THREADS_TOO_FEW:
427
+ return "Not enough threads";
428
+ case ARGON2_THREADS_TOO_MANY:
429
+ return "Too many threads";
430
+ case ARGON2_MISSING_ARGS:
431
+ return "Missing arguments";
432
+ case ARGON2_ENCODING_FAIL:
433
+ return "Encoding failed";
434
+ case ARGON2_DECODING_FAIL:
435
+ return "Decoding failed";
436
+ case ARGON2_THREAD_FAIL:
437
+ return "Threading failure";
438
+ case ARGON2_DECODING_LENGTH_FAIL:
439
+ return "Some of encoded parameters are too long or too short";
440
+ case ARGON2_VERIFY_MISMATCH:
441
+ return "The password does not match the supplied hash";
442
+ default:
443
+ return "Unknown error code";
444
+ }
445
+ }
446
+
447
+ size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost, uint32_t parallelism,
448
+ uint32_t saltlen, uint32_t hashlen, argon2_type type) {
449
+ return strlen("$$v=$m=,t=,p=$$") + strlen(argon2_type2string(type, 0)) +
450
+ numlen(t_cost) + numlen(m_cost) + numlen(parallelism) +
451
+ b64len(saltlen) + b64len(hashlen) + numlen(ARGON2_VERSION_NUMBER) + 1;
452
+ }