argon2 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -9
- data/.travis.yml +0 -1
- data/CONTRIBUTING.md +12 -0
- data/Changelog.md +10 -11
- data/README.md +23 -14
- data/ext/argon2_wrap/Makefile +8 -6
- data/ext/argon2_wrap/argon_wrap.c +23 -12
- data/ext/argon2_wrap/test.c +14 -42
- data/ext/phc-winner-argon2/.gitignore +5 -1
- data/ext/phc-winner-argon2/.travis.yml +14 -0
- data/ext/phc-winner-argon2/Makefile +33 -12
- data/ext/phc-winner-argon2/README.md +48 -19
- data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
- data/ext/phc-winner-argon2/{src → include}/argon2.h +137 -137
- data/ext/phc-winner-argon2/kats/argon2d +12290 -12290
- data/ext/phc-winner-argon2/kats/argon2d.shasum +1 -1
- data/ext/phc-winner-argon2/kats/argon2i +12290 -12290
- data/ext/phc-winner-argon2/kats/argon2i.shasum +1 -1
- data/ext/phc-winner-argon2/opt.o +0 -0
- data/ext/phc-winner-argon2/src/argon2.c +125 -145
- data/ext/phc-winner-argon2/src/bench.c +5 -5
- data/ext/phc-winner-argon2/src/core.c +15 -20
- data/ext/phc-winner-argon2/src/core.h +5 -2
- data/ext/phc-winner-argon2/src/encoding.c +45 -72
- data/ext/phc-winner-argon2/src/encoding.h +24 -0
- data/ext/phc-winner-argon2/src/genkat.c +2 -2
- data/ext/phc-winner-argon2/src/opt.c +19 -10
- data/ext/phc-winner-argon2/src/opt.h +5 -17
- data/ext/phc-winner-argon2/src/ref.c +12 -9
- data/ext/phc-winner-argon2/src/ref.h +4 -12
- data/ext/phc-winner-argon2/src/run.c +67 -42
- data/ext/phc-winner-argon2/src/test.c +131 -0
- data/lib/argon2.rb +6 -5
- data/lib/argon2/constants.rb +3 -2
- data/lib/argon2/engine.rb +1 -0
- data/lib/argon2/errors.rb +37 -36
- data/lib/argon2/ffi_engine.rb +10 -10
- data/lib/argon2/version.rb +2 -1
- metadata +7 -12
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
0d703f555eb72b8b36b4f486333aa130a5ebe32f39a96bbc439def0db569115a argon2i
|
Binary file
|
@@ -11,102 +11,16 @@
|
|
11
11
|
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
12
12
|
*/
|
13
13
|
|
14
|
-
#include <stdint.h>
|
15
14
|
#include <string.h>
|
16
15
|
#include <stdlib.h>
|
17
16
|
#include <stdio.h>
|
18
|
-
#include <limits.h>
|
19
17
|
|
20
18
|
#include "argon2.h"
|
21
19
|
#include "encoding.h"
|
22
20
|
#include "core.h"
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
/*{ARGON2_OK, */ "OK",
|
27
|
-
/*},
|
28
|
-
|
29
|
-
{ARGON2_OUTPUT_PTR_NULL, */ "Output pointer is NULL",
|
30
|
-
/*},
|
31
|
-
|
32
|
-
{ARGON2_OUTPUT_TOO_SHORT, */ "Output is too short",
|
33
|
-
/*},
|
34
|
-
{ARGON2_OUTPUT_TOO_LONG, */ "Output is too long",
|
35
|
-
/*},
|
36
|
-
|
37
|
-
{ARGON2_PWD_TOO_SHORT, */ "Password is too short",
|
38
|
-
/*},
|
39
|
-
{ARGON2_PWD_TOO_LONG, */ "Password is too long",
|
40
|
-
/*},
|
41
|
-
|
42
|
-
{ARGON2_SALT_TOO_SHORT, */ "Salt is too short",
|
43
|
-
/*},
|
44
|
-
{ARGON2_SALT_TOO_LONG, */ "Salt is too long",
|
45
|
-
/*},
|
46
|
-
|
47
|
-
{ARGON2_AD_TOO_SHORT, */ "Associated data is too short",
|
48
|
-
/*},
|
49
|
-
{ARGON2_AD_TOO_LONG, */ "Associated date is too long",
|
50
|
-
/*},
|
51
|
-
|
52
|
-
{ARGON2_SECRET_TOO_SHORT, */ "Secret is too short",
|
53
|
-
/*},
|
54
|
-
{ARGON2_SECRET_TOO_LONG, */ "Secret is too long",
|
55
|
-
/*},
|
56
|
-
|
57
|
-
{ARGON2_TIME_TOO_SMALL, */ "Time cost is too small",
|
58
|
-
/*},
|
59
|
-
{ARGON2_TIME_TOO_LARGE, */ "Time cost is too large",
|
60
|
-
/*},
|
61
|
-
|
62
|
-
{ARGON2_MEMORY_TOO_LITTLE, */ "Memory cost is too small",
|
63
|
-
/*},
|
64
|
-
{ARGON2_MEMORY_TOO_MUCH, */ "Memory cost is too large",
|
65
|
-
/*},
|
66
|
-
|
67
|
-
{ARGON2_LANES_TOO_FEW, */ "Too few lanes",
|
68
|
-
/*},
|
69
|
-
{ARGON2_LANES_TOO_MANY, */ "Too many lanes",
|
70
|
-
/*},
|
71
|
-
|
72
|
-
{ARGON2_PWD_PTR_MISMATCH, */ "Password pointer is NULL, but password length is not 0",
|
73
|
-
/*},
|
74
|
-
{ARGON2_SALT_PTR_MISMATCH, */ "Salt pointer is NULL, but salt length is not 0",
|
75
|
-
/*},
|
76
|
-
{ARGON2_SECRET_PTR_MISMATCH, */ "Secret pointer is NULL, but secret length is not 0",
|
77
|
-
/*},
|
78
|
-
{ARGON2_AD_PTR_MISMATCH, */ "Associated data pointer is NULL, but ad length is not 0",
|
79
|
-
/*},
|
80
|
-
|
81
|
-
{ARGON2_MEMORY_ALLOCATION_ERROR, */ "Memory allocation error",
|
82
|
-
/*},
|
83
|
-
|
84
|
-
{ARGON2_FREE_MEMORY_CBK_NULL, */ "The free memory callback is NULL",
|
85
|
-
/*},
|
86
|
-
{ARGON2_ALLOCATE_MEMORY_CBK_NULL, */ "The allocate memory callback is NULL",
|
87
|
-
/*},
|
88
|
-
|
89
|
-
{ARGON2_INCORRECT_PARAMETER, */ "Argon2_Context context is NULL",
|
90
|
-
/*},
|
91
|
-
{ARGON2_INCORRECT_TYPE, */ "There is no such version of Argon2",
|
92
|
-
/*},
|
93
|
-
|
94
|
-
{ARGON2_OUT_PTR_MISMATCH, */ "Output pointer mismatch",
|
95
|
-
/*},
|
96
|
-
|
97
|
-
{ARGON2_THREADS_TOO_FEW, */ "Not enough threads",
|
98
|
-
/*},
|
99
|
-
{ARGON2_THREADS_TOO_MANY, */ "Too many threads",
|
100
|
-
/*},
|
101
|
-
{ARGON2_MISSING_ARGS, */ "Missing arguments",
|
102
|
-
/*},
|
103
|
-
{ARGON2_ENCODING_FAIL, */ "Encoding failed",
|
104
|
-
/*},
|
105
|
-
{ARGON2_DECODING_FAIL, */ "Decoding failed", /*},*/
|
106
|
-
};
|
107
|
-
|
108
|
-
|
109
|
-
int argon2_core(argon2_context *context, argon2_type type) {
|
22
|
+
|
23
|
+
int argon2_ctx(argon2_context *context, argon2_type type) {
|
110
24
|
/* 1. Validate all inputs */
|
111
25
|
int result = validate_inputs(context);
|
112
26
|
uint32_t memory_blocks, segment_length;
|
@@ -151,15 +65,17 @@ int argon2_core(argon2_context *context, argon2_type type) {
|
|
151
65
|
}
|
152
66
|
|
153
67
|
/* 4. Filling memory */
|
154
|
-
fill_memory_blocks(&instance);
|
68
|
+
result = fill_memory_blocks(&instance);
|
155
69
|
|
70
|
+
if (ARGON2_OK != result) {
|
71
|
+
return result;
|
72
|
+
}
|
156
73
|
/* 5. Finalization */
|
157
74
|
finalize(context, &instance);
|
158
75
|
|
159
76
|
return ARGON2_OK;
|
160
77
|
}
|
161
78
|
|
162
|
-
|
163
79
|
int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
164
80
|
const uint32_t parallelism, const void *pwd,
|
165
81
|
const size_t pwdlen, const void *salt, const size_t saltlen,
|
@@ -172,15 +88,15 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
172
88
|
|
173
89
|
/* Detect and reject overflowing sizes */
|
174
90
|
/* TODO: This should probably be fixed in the function signature */
|
175
|
-
if (pwdlen >
|
91
|
+
if (pwdlen > ARGON2_MAX_PWD_LENGTH) {
|
176
92
|
return ARGON2_PWD_TOO_LONG;
|
177
93
|
}
|
178
94
|
|
179
|
-
if (hashlen >
|
95
|
+
if (hashlen > ARGON2_MAX_OUTLEN) {
|
180
96
|
return ARGON2_OUTPUT_TOO_LONG;
|
181
97
|
}
|
182
98
|
|
183
|
-
if (saltlen >
|
99
|
+
if (saltlen > ARGON2_MAX_SALT_LENGTH) {
|
184
100
|
return ARGON2_SALT_TOO_LONG;
|
185
101
|
}
|
186
102
|
|
@@ -191,9 +107,9 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
191
107
|
|
192
108
|
context.out = (uint8_t *)out;
|
193
109
|
context.outlen = (uint32_t)hashlen;
|
194
|
-
context.pwd = (uint8_t *)pwd;
|
110
|
+
context.pwd = CONST_CAST(uint8_t *)pwd;
|
195
111
|
context.pwdlen = (uint32_t)pwdlen;
|
196
|
-
context.salt = (uint8_t *)salt;
|
112
|
+
context.salt = CONST_CAST(uint8_t *)salt;
|
197
113
|
context.saltlen = (uint32_t)saltlen;
|
198
114
|
context.secret = NULL;
|
199
115
|
context.secretlen = 0;
|
@@ -207,10 +123,10 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
207
123
|
context.free_cbk = NULL;
|
208
124
|
context.flags = ARGON2_DEFAULT_FLAGS;
|
209
125
|
|
210
|
-
result =
|
126
|
+
result = argon2_ctx(&context, type);
|
211
127
|
|
212
128
|
if (result != ARGON2_OK) {
|
213
|
-
|
129
|
+
secure_wipe_memory(out, hashlen);
|
214
130
|
free(out);
|
215
131
|
return result;
|
216
132
|
}
|
@@ -222,14 +138,14 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
222
138
|
|
223
139
|
/* if encoding requested, write it */
|
224
140
|
if (encoded && encodedlen) {
|
225
|
-
if (
|
226
|
-
|
227
|
-
|
141
|
+
if (encode_string(encoded, encodedlen, &context, type) != ARGON2_OK) {
|
142
|
+
secure_wipe_memory(out, hashlen); /* wipe buffers if error */
|
143
|
+
secure_wipe_memory(encoded, encodedlen);
|
228
144
|
free(out);
|
229
145
|
return ARGON2_ENCODING_FAIL;
|
230
146
|
}
|
231
147
|
}
|
232
|
-
|
148
|
+
secure_wipe_memory(out, hashlen);
|
233
149
|
free(out);
|
234
150
|
|
235
151
|
return ARGON2_OK;
|
@@ -273,7 +189,7 @@ int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
|
273
189
|
hash, hashlen, NULL, 0, Argon2_d);
|
274
190
|
}
|
275
191
|
|
276
|
-
int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
|
192
|
+
static int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
|
277
193
|
size_t i;
|
278
194
|
uint8_t d = 0U;
|
279
195
|
|
@@ -289,12 +205,17 @@ int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
|
|
289
205
|
argon2_context ctx;
|
290
206
|
uint8_t *out;
|
291
207
|
int ret;
|
208
|
+
int decode_result;
|
292
209
|
|
293
210
|
/* max values, to be updated in decode_string */
|
294
|
-
|
295
|
-
ctx.
|
296
|
-
ctx.
|
297
|
-
|
211
|
+
uint32_t encoded_len = strlen(encoded);
|
212
|
+
ctx.adlen = encoded_len;
|
213
|
+
ctx.saltlen = encoded_len;
|
214
|
+
ctx.outlen = encoded_len;
|
215
|
+
ctx.allocate_cbk = NULL;
|
216
|
+
ctx.free_cbk = NULL;
|
217
|
+
ctx.secret = NULL;
|
218
|
+
ctx.secretlen = 0;
|
298
219
|
ctx.ad = malloc(ctx.adlen);
|
299
220
|
ctx.salt = malloc(ctx.saltlen);
|
300
221
|
ctx.out = malloc(ctx.outlen);
|
@@ -311,30 +232,28 @@ int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
|
|
311
232
|
free(ctx.out);
|
312
233
|
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
313
234
|
}
|
314
|
-
|
315
|
-
if(
|
235
|
+
decode_result = decode_string(&ctx, encoded, type);
|
236
|
+
if (decode_result != ARGON2_OK) {
|
316
237
|
free(ctx.ad);
|
317
238
|
free(ctx.salt);
|
318
239
|
free(ctx.out);
|
319
240
|
free(out);
|
320
|
-
return
|
241
|
+
return decode_result;
|
321
242
|
}
|
322
243
|
|
323
|
-
ret = argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen,
|
324
|
-
|
244
|
+
ret = argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen,
|
245
|
+
ctx.salt, ctx.saltlen, out, ctx.outlen, NULL, 0, type);
|
325
246
|
|
326
247
|
free(ctx.ad);
|
327
248
|
free(ctx.salt);
|
328
249
|
|
329
|
-
if (ret
|
330
|
-
|
331
|
-
free(ctx.out);
|
332
|
-
return ARGON2_DECODING_FAIL;
|
250
|
+
if (ret == ARGON2_OK && argon2_compare(out, ctx.out, ctx.outlen)) {
|
251
|
+
ret = ARGON2_VERIFY_MISMATCH;
|
333
252
|
}
|
334
253
|
free(out);
|
335
254
|
free(ctx.out);
|
336
255
|
|
337
|
-
return
|
256
|
+
return ret;
|
338
257
|
}
|
339
258
|
|
340
259
|
int argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
@@ -347,17 +266,22 @@ int argon2d_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
347
266
|
return argon2_verify(encoded, pwd, pwdlen, Argon2_d);
|
348
267
|
}
|
349
268
|
|
350
|
-
int
|
269
|
+
int argon2d_ctx(argon2_context *context) {
|
270
|
+
return argon2_ctx(context, Argon2_d);
|
271
|
+
}
|
351
272
|
|
352
|
-
int
|
273
|
+
int argon2i_ctx(argon2_context *context) {
|
274
|
+
return argon2_ctx(context, Argon2_i);
|
275
|
+
}
|
353
276
|
|
354
|
-
int
|
277
|
+
int argon2_verify_ctx(argon2_context *context, const char *hash,
|
278
|
+
argon2_type type) {
|
355
279
|
int result;
|
356
280
|
if (0 == context->outlen || NULL == hash) {
|
357
281
|
return ARGON2_OUT_PTR_MISMATCH;
|
358
282
|
}
|
359
283
|
|
360
|
-
result =
|
284
|
+
result = argon2_ctx(context, type);
|
361
285
|
|
362
286
|
if (ARGON2_OK != result) {
|
363
287
|
return result;
|
@@ -366,33 +290,89 @@ int verify_d(argon2_context *context, const char *hash) {
|
|
366
290
|
return 0 == memcmp(hash, context->out, context->outlen);
|
367
291
|
}
|
368
292
|
|
369
|
-
int
|
370
|
-
|
371
|
-
if (0 == context->outlen || NULL == hash) {
|
372
|
-
return ARGON2_OUT_PTR_MISMATCH;
|
373
|
-
}
|
374
|
-
|
375
|
-
result = argon2_core(context, Argon2_i);
|
376
|
-
|
377
|
-
if (ARGON2_OK != result) {
|
378
|
-
return result;
|
379
|
-
}
|
380
|
-
|
381
|
-
return 0 == memcmp(hash, context->out, context->outlen);
|
293
|
+
int argon2d_verify_ctx(argon2_context *context, const char *hash) {
|
294
|
+
return argon2_verify_ctx(context, hash, Argon2_d);
|
382
295
|
}
|
383
296
|
|
297
|
+
int argon2i_verify_ctx(argon2_context *context, const char *hash) {
|
298
|
+
return argon2_verify_ctx(context, hash, Argon2_i);
|
299
|
+
}
|
384
300
|
|
385
|
-
const char *
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
301
|
+
const char *argon2_error_message(int error_code) {
|
302
|
+
switch (error_code) {
|
303
|
+
case ARGON2_OK:
|
304
|
+
return "OK";
|
305
|
+
case ARGON2_OUTPUT_PTR_NULL:
|
306
|
+
return "Output pointer is NULL";
|
307
|
+
case ARGON2_OUTPUT_TOO_SHORT:
|
308
|
+
return "Output is too short";
|
309
|
+
case ARGON2_OUTPUT_TOO_LONG:
|
310
|
+
return "Output is too long";
|
311
|
+
case ARGON2_PWD_TOO_SHORT:
|
312
|
+
return "Password is too short";
|
313
|
+
case ARGON2_PWD_TOO_LONG:
|
314
|
+
return "Password is too long";
|
315
|
+
case ARGON2_SALT_TOO_SHORT:
|
316
|
+
return "Salt is too short";
|
317
|
+
case ARGON2_SALT_TOO_LONG:
|
318
|
+
return "Salt is too long";
|
319
|
+
case ARGON2_AD_TOO_SHORT:
|
320
|
+
return "Associated data is too short";
|
321
|
+
case ARGON2_AD_TOO_LONG:
|
322
|
+
return "Associated data is too long";
|
323
|
+
case ARGON2_SECRET_TOO_SHORT:
|
324
|
+
return "Secret is too short";
|
325
|
+
case ARGON2_SECRET_TOO_LONG:
|
326
|
+
return "Secret is too long";
|
327
|
+
case ARGON2_TIME_TOO_SMALL:
|
328
|
+
return "Time cost is too small";
|
329
|
+
case ARGON2_TIME_TOO_LARGE:
|
330
|
+
return "Time cost is too large";
|
331
|
+
case ARGON2_MEMORY_TOO_LITTLE:
|
332
|
+
return "Memory cost is too small";
|
333
|
+
case ARGON2_MEMORY_TOO_MUCH:
|
334
|
+
return "Memory cost is too large";
|
335
|
+
case ARGON2_LANES_TOO_FEW:
|
336
|
+
return "Too few lanes";
|
337
|
+
case ARGON2_LANES_TOO_MANY:
|
338
|
+
return "Too many lanes";
|
339
|
+
case ARGON2_PWD_PTR_MISMATCH:
|
340
|
+
return "Password pointer is NULL, but password length is not 0";
|
341
|
+
case ARGON2_SALT_PTR_MISMATCH:
|
342
|
+
return "Salt pointer is NULL, but salt length is not 0";
|
343
|
+
case ARGON2_SECRET_PTR_MISMATCH:
|
344
|
+
return "Secret pointer is NULL, but secret length is not 0";
|
345
|
+
case ARGON2_AD_PTR_MISMATCH:
|
346
|
+
return "Associated data pointer is NULL, but ad length is not 0";
|
347
|
+
case ARGON2_MEMORY_ALLOCATION_ERROR:
|
348
|
+
return "Memory allocation error";
|
349
|
+
case ARGON2_FREE_MEMORY_CBK_NULL:
|
350
|
+
return "The free memory callback is NULL";
|
351
|
+
case ARGON2_ALLOCATE_MEMORY_CBK_NULL:
|
352
|
+
return "The allocate memory callback is NULL";
|
353
|
+
case ARGON2_INCORRECT_PARAMETER:
|
354
|
+
return "Argon2_Context context is NULL";
|
355
|
+
case ARGON2_INCORRECT_TYPE:
|
356
|
+
return "There is no such version of Argon2";
|
357
|
+
case ARGON2_OUT_PTR_MISMATCH:
|
358
|
+
return "Output pointer mismatch";
|
359
|
+
case ARGON2_THREADS_TOO_FEW:
|
360
|
+
return "Not enough threads";
|
361
|
+
case ARGON2_THREADS_TOO_MANY:
|
362
|
+
return "Too many threads";
|
363
|
+
case ARGON2_MISSING_ARGS:
|
364
|
+
return "Missing arguments";
|
365
|
+
case ARGON2_ENCODING_FAIL:
|
366
|
+
return "Encoding failed";
|
367
|
+
case ARGON2_DECODING_FAIL:
|
368
|
+
return "Decoding failed";
|
369
|
+
case ARGON2_THREAD_FAIL:
|
370
|
+
return "Threading failure";
|
371
|
+
case ARGON2_DECODING_LENGTH_FAIL:
|
372
|
+
return "Some of encoded parameters are too long or too short";
|
373
|
+
case ARGON2_VERIFY_MISMATCH:
|
374
|
+
return "The password does not match the supplied hash";
|
375
|
+
default:
|
376
|
+
return "Unknown error code";
|
396
377
|
}
|
397
|
-
return "Unknown error code.";
|
398
378
|
}
|
@@ -42,16 +42,16 @@ static void benchmark() {
|
|
42
42
|
#undef BENCH_INLEN
|
43
43
|
#undef BENCH_OUTLEN
|
44
44
|
|
45
|
-
uint32_t t_cost =
|
45
|
+
uint32_t t_cost = 3;
|
46
46
|
uint32_t m_cost;
|
47
|
-
uint32_t thread_test[
|
47
|
+
uint32_t thread_test[4] = {1, 2, 4, 8};
|
48
48
|
|
49
49
|
memset(pwd_array, 0, inlen);
|
50
50
|
memset(salt_array, 1, inlen);
|
51
51
|
|
52
52
|
for (m_cost = (uint32_t)1 << 10; m_cost <= (uint32_t)1 << 22; m_cost *= 2) {
|
53
53
|
unsigned i;
|
54
|
-
for (i = 0; i <
|
54
|
+
for (i = 0; i < 4; ++i) {
|
55
55
|
argon2_context context;
|
56
56
|
uint32_t thread_n = thread_test[i];
|
57
57
|
uint64_t stop_cycles, stop_cycles_i;
|
@@ -80,9 +80,9 @@ static void benchmark() {
|
|
80
80
|
context.free_cbk = NULL;
|
81
81
|
context.flags = 0;
|
82
82
|
|
83
|
-
|
83
|
+
argon2d_ctx(&context);
|
84
84
|
stop_cycles = rdtsc();
|
85
|
-
|
85
|
+
argon2i_ctx(&context);
|
86
86
|
stop_cycles_i = rdtsc();
|
87
87
|
stop_time = clock();
|
88
88
|
|
@@ -88,12 +88,11 @@ int allocate_memory(block **memory, uint32_t m_cost) {
|
|
88
88
|
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
89
89
|
}
|
90
90
|
|
91
|
-
*memory = (block *)
|
91
|
+
*memory = (block *)calloc(memory_size, 1); /*2. Try to allocate*/
|
92
92
|
|
93
93
|
if (!*memory) {
|
94
94
|
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
95
95
|
}
|
96
|
-
|
97
96
|
return ARGON2_OK;
|
98
97
|
} else {
|
99
98
|
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
@@ -249,25 +248,25 @@ static void *fill_segment_thr(void *thread_data)
|
|
249
248
|
return 0;
|
250
249
|
}
|
251
250
|
|
252
|
-
|
251
|
+
int fill_memory_blocks(argon2_instance_t *instance) {
|
253
252
|
uint32_t r, s;
|
254
253
|
argon2_thread_handle_t *thread = NULL;
|
255
254
|
argon2_thread_data *thr_data = NULL;
|
256
255
|
|
257
256
|
if (instance == NULL || instance->lanes == 0) {
|
258
|
-
return;
|
257
|
+
return ARGON2_THREAD_FAIL;
|
259
258
|
}
|
260
259
|
|
261
260
|
/* 1. Allocating space for threads */
|
262
261
|
thread = calloc(instance->lanes, sizeof(argon2_thread_handle_t));
|
263
262
|
if (thread == NULL) {
|
264
|
-
return;
|
263
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
265
264
|
}
|
266
265
|
|
267
266
|
thr_data = calloc(instance->lanes, sizeof(argon2_thread_data));
|
268
267
|
if (thr_data == NULL) {
|
269
268
|
free(thread);
|
270
|
-
return;
|
269
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
271
270
|
}
|
272
271
|
|
273
272
|
for (r = 0; r < instance->passes; ++r) {
|
@@ -283,10 +282,9 @@ void fill_memory_blocks(argon2_instance_t *instance) {
|
|
283
282
|
if (l >= instance->threads) {
|
284
283
|
rc = argon2_thread_join(thread[l - instance->threads]);
|
285
284
|
if (rc) {
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
exit(-1);
|
285
|
+
free(thr_data);
|
286
|
+
free(thread);
|
287
|
+
return ARGON2_THREAD_FAIL;
|
290
288
|
}
|
291
289
|
}
|
292
290
|
|
@@ -302,13 +300,12 @@ void fill_memory_blocks(argon2_instance_t *instance) {
|
|
302
300
|
rc = argon2_thread_create(&thread[l], &fill_segment_thr,
|
303
301
|
(void *)&thr_data[l]);
|
304
302
|
if (rc) {
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
exit(-1);
|
303
|
+
free(thr_data);
|
304
|
+
free(thread);
|
305
|
+
return ARGON2_THREAD_FAIL;
|
309
306
|
}
|
310
307
|
|
311
|
-
/*
|
308
|
+
/* fill_segment(instance, position); */
|
312
309
|
/*Non-thread equivalent of the lines above */
|
313
310
|
}
|
314
311
|
|
@@ -317,9 +314,7 @@ void fill_memory_blocks(argon2_instance_t *instance) {
|
|
317
314
|
++l) {
|
318
315
|
rc = argon2_thread_join(thread[l]);
|
319
316
|
if (rc) {
|
320
|
-
|
321
|
-
rc);
|
322
|
-
exit(-1);
|
317
|
+
return ARGON2_THREAD_FAIL;
|
323
318
|
}
|
324
319
|
}
|
325
320
|
}
|
@@ -335,6 +330,7 @@ void fill_memory_blocks(argon2_instance_t *instance) {
|
|
335
330
|
if (thr_data != NULL) {
|
336
331
|
free(thr_data);
|
337
332
|
}
|
333
|
+
return ARGON2_OK;
|
338
334
|
}
|
339
335
|
|
340
336
|
int validate_inputs(const argon2_context *context) {
|
@@ -424,7 +420,7 @@ int validate_inputs(const argon2_context *context) {
|
|
424
420
|
return ARGON2_MEMORY_TOO_MUCH;
|
425
421
|
}
|
426
422
|
|
427
|
-
if (context->m_cost < 8*context->lanes) {
|
423
|
+
if (context->m_cost < 8 * context->lanes) {
|
428
424
|
return ARGON2_MEMORY_TOO_LITTLE;
|
429
425
|
}
|
430
426
|
|
@@ -609,4 +605,3 @@ int initialize(argon2_instance_t *instance, argon2_context *context) {
|
|
609
605
|
|
610
606
|
return ARGON2_OK;
|
611
607
|
}
|
612
|
-
|