argon2 1.1.1 → 1.1.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +7 -4
- data/Changelog.md +3 -0
- data/README.md +2 -0
- data/argon2.gemspec +1 -1
- data/ext/argon2_wrap/Makefile +6 -0
- data/ext/argon2_wrap/argon_wrap.c +1 -7
- data/ext/phc-winner-argon2/.gitignore +1 -0
- data/ext/phc-winner-argon2/Argon2.sln +64 -2
- data/ext/phc-winner-argon2/CHANGELOG.md +8 -1
- data/ext/phc-winner-argon2/LICENSE +301 -18
- data/ext/phc-winner-argon2/Makefile +85 -20
- data/ext/phc-winner-argon2/README.md +73 -30
- data/ext/phc-winner-argon2/argon2-specs.pdf +0 -0
- data/ext/phc-winner-argon2/include/argon2.h +73 -10
- data/ext/phc-winner-argon2/kats/argon2id +12304 -0
- data/ext/phc-winner-argon2/kats/argon2id.shasum +1 -0
- data/ext/phc-winner-argon2/kats/argon2id_v16 +12304 -0
- data/ext/phc-winner-argon2/kats/argon2id_v16.shasum +1 -0
- data/ext/phc-winner-argon2/kats/test.ps1 +1 -1
- data/ext/phc-winner-argon2/kats/test.sh +1 -1
- data/ext/phc-winner-argon2/latex/IEEEtran.cls +6347 -0
- data/ext/phc-winner-argon2/latex/argon2-spec.tex +920 -0
- data/ext/phc-winner-argon2/latex/pics/argon2-par.pdf +0 -0
- data/ext/phc-winner-argon2/latex/pics/compression.pdf +0 -0
- data/ext/phc-winner-argon2/latex/pics/generic.pdf +0 -0
- data/ext/phc-winner-argon2/latex/pics/power-distribution.jpg +0 -0
- data/ext/phc-winner-argon2/latex/tradeoff.bib +822 -0
- data/ext/phc-winner-argon2/libargon2.pc +16 -0
- data/ext/phc-winner-argon2/man/argon2.1 +13 -3
- data/ext/phc-winner-argon2/src/argon2.c +112 -68
- data/ext/phc-winner-argon2/src/bench.c +44 -27
- data/ext/phc-winner-argon2/src/blake2/blake2-impl.h +18 -5
- data/ext/phc-winner-argon2/src/blake2/blake2.h +17 -0
- data/ext/phc-winner-argon2/src/blake2/blake2b.c +25 -7
- data/ext/phc-winner-argon2/src/blake2/blamka-round-opt.h +17 -0
- data/ext/phc-winner-argon2/src/blake2/blamka-round-ref.h +17 -0
- data/ext/phc-winner-argon2/src/core.c +138 -110
- data/ext/phc-winner-argon2/src/core.h +41 -26
- data/ext/phc-winner-argon2/src/encoding.c +79 -55
- data/ext/phc-winner-argon2/src/encoding.h +25 -8
- data/ext/phc-winner-argon2/src/genkat.c +35 -39
- data/ext/phc-winner-argon2/src/genkat.h +11 -7
- data/ext/phc-winner-argon2/src/opt.c +65 -99
- data/ext/phc-winner-argon2/src/opt.h +15 -32
- data/ext/phc-winner-argon2/src/ref.c +50 -93
- data/ext/phc-winner-argon2/src/ref.h +15 -31
- data/ext/phc-winner-argon2/src/run.c +73 -30
- data/ext/phc-winner-argon2/src/test.c +33 -2
- data/ext/phc-winner-argon2/src/thread.c +21 -0
- data/ext/phc-winner-argon2/src/thread.h +21 -0
- data/ext/phc-winner-argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +225 -0
- data/ext/phc-winner-argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
- data/ext/phc-winner-argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +73 -1
- data/ext/phc-winner-argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +225 -0
- data/ext/phc-winner-argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
- data/ext/phc-winner-argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +69 -1
- data/ext/phc-winner-argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +69 -1
- data/lib/argon2.rb +3 -3
- data/lib/argon2/ffi_engine.rb +3 -3
- data/lib/argon2/version.rb +1 -1
- metadata +21 -5
|
@@ -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
|
|
@@ -19,9 +19,15 @@ hashing and password-based key derivation.
|
|
|
19
19
|
|
|
20
20
|
.SH OPTIONS
|
|
21
21
|
.TP
|
|
22
|
+
.B \-h
|
|
23
|
+
Display tool usage
|
|
24
|
+
.TP
|
|
22
25
|
.B \-d
|
|
23
26
|
Use Argon2d instead of Argon2i (Argon2i is the default)
|
|
24
27
|
.TP
|
|
28
|
+
.B \-id
|
|
29
|
+
Use Argon2id instead of Argon2i (Argon2i is the default)
|
|
30
|
+
.TP
|
|
25
31
|
.BI \-t " N"
|
|
26
32
|
Sets the number of iterations to N (default = 3)
|
|
27
33
|
.TP
|
|
@@ -31,7 +37,7 @@ Sets the memory usage of 2^N KiB (default = 12)
|
|
|
31
37
|
.BI \-p " N"
|
|
32
38
|
Sets parallelism to N threads (default = 1)
|
|
33
39
|
.TP
|
|
34
|
-
.BI \-
|
|
40
|
+
.BI \-l " N"
|
|
35
41
|
Sets hash output length to N bytes (default = 32)
|
|
36
42
|
.TP
|
|
37
43
|
.B \-e
|
|
@@ -39,9 +45,13 @@ Output only encoded hash
|
|
|
39
45
|
.TP
|
|
40
46
|
.B \-r
|
|
41
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)
|
|
42
51
|
|
|
43
52
|
.SH COPYRIGHT
|
|
44
53
|
This manpage was written by \fBDaniel Kahn Gillmor\fR for the Debian
|
|
45
54
|
distribution (but may be used by others). It is released, like the
|
|
46
|
-
rest of this Argon2 implementation, under
|
|
47
|
-
Commons 0
|
|
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.
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Argon2 source code package
|
|
2
|
+
* Argon2 reference source code package - reference C implementations
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Copyright 2015
|
|
5
|
+
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
|
|
5
6
|
*
|
|
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:
|
|
7
10
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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.
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
18
|
#include <string.h>
|
|
@@ -19,6 +23,18 @@
|
|
|
19
23
|
#include "encoding.h"
|
|
20
24
|
#include "core.h"
|
|
21
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
|
+
}
|
|
22
38
|
|
|
23
39
|
int argon2_ctx(argon2_context *context, argon2_type type) {
|
|
24
40
|
/* 1. Validate all inputs */
|
|
@@ -30,7 +46,7 @@ int argon2_ctx(argon2_context *context, argon2_type type) {
|
|
|
30
46
|
return result;
|
|
31
47
|
}
|
|
32
48
|
|
|
33
|
-
if (Argon2_d != type && Argon2_i != type) {
|
|
49
|
+
if (Argon2_d != type && Argon2_i != type && Argon2_id != type) {
|
|
34
50
|
return ARGON2_INCORRECT_TYPE;
|
|
35
51
|
}
|
|
36
52
|
|
|
@@ -81,7 +97,7 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
|
81
97
|
const uint32_t parallelism, const void *pwd,
|
|
82
98
|
const size_t pwdlen, const void *salt, const size_t saltlen,
|
|
83
99
|
void *hash, const size_t hashlen, char *encoded,
|
|
84
|
-
const size_t encodedlen, argon2_type type,
|
|
100
|
+
const size_t encodedlen, argon2_type type,
|
|
85
101
|
const uint32_t version){
|
|
86
102
|
|
|
87
103
|
argon2_context context;
|
|
@@ -123,7 +139,7 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
|
123
139
|
result = argon2_ctx(&context, type);
|
|
124
140
|
|
|
125
141
|
if (result != ARGON2_OK) {
|
|
126
|
-
|
|
142
|
+
clear_internal_memory(out, hashlen);
|
|
127
143
|
free(out);
|
|
128
144
|
return result;
|
|
129
145
|
}
|
|
@@ -136,13 +152,13 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
|
136
152
|
/* if encoding requested, write it */
|
|
137
153
|
if (encoded && encodedlen) {
|
|
138
154
|
if (encode_string(encoded, encodedlen, &context, type) != ARGON2_OK) {
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
clear_internal_memory(out, hashlen); /* wipe buffers if error */
|
|
156
|
+
clear_internal_memory(encoded, encodedlen);
|
|
141
157
|
free(out);
|
|
142
158
|
return ARGON2_ENCODING_FAIL;
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
|
-
|
|
161
|
+
clear_internal_memory(out, hashlen);
|
|
146
162
|
free(out);
|
|
147
163
|
|
|
148
164
|
return ARGON2_OK;
|
|
@@ -188,6 +204,26 @@ int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
|
|
188
204
|
hash, hashlen, NULL, 0, Argon2_d, ARGON2_VERSION_NUMBER);
|
|
189
205
|
}
|
|
190
206
|
|
|
207
|
+
int argon2id_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
|
|
208
|
+
const uint32_t parallelism, const void *pwd,
|
|
209
|
+
const size_t pwdlen, const void *salt,
|
|
210
|
+
const size_t saltlen, const size_t hashlen,
|
|
211
|
+
char *encoded, const size_t encodedlen) {
|
|
212
|
+
|
|
213
|
+
return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
214
|
+
NULL, hashlen, encoded, encodedlen, Argon2_id,
|
|
215
|
+
ARGON2_VERSION_NUMBER);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
int argon2id_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
|
219
|
+
const uint32_t parallelism, const void *pwd,
|
|
220
|
+
const size_t pwdlen, const void *salt,
|
|
221
|
+
const size_t saltlen, void *hash, const size_t hashlen) {
|
|
222
|
+
return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
223
|
+
hash, hashlen, NULL, 0, Argon2_id,
|
|
224
|
+
ARGON2_VERSION_NUMBER);
|
|
225
|
+
}
|
|
226
|
+
|
|
191
227
|
static int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
|
|
192
228
|
size_t i;
|
|
193
229
|
uint8_t d = 0U;
|
|
@@ -202,63 +238,60 @@ int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
|
|
|
202
238
|
argon2_type type) {
|
|
203
239
|
|
|
204
240
|
argon2_context ctx;
|
|
205
|
-
uint8_t *
|
|
206
|
-
|
|
207
|
-
int
|
|
208
|
-
uint32_t encoded_len;
|
|
241
|
+
uint8_t *desired_result = NULL;
|
|
242
|
+
|
|
243
|
+
int ret = ARGON2_OK;
|
|
209
244
|
|
|
210
|
-
|
|
245
|
+
size_t encoded_len;
|
|
246
|
+
uint32_t max_field_len;
|
|
247
|
+
|
|
248
|
+
if (encoded == NULL) {
|
|
211
249
|
return ARGON2_DECODING_FAIL;
|
|
212
250
|
}
|
|
213
251
|
|
|
214
|
-
/* max values, to be updated in decode_string */
|
|
215
252
|
encoded_len = strlen(encoded);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
ctx.
|
|
224
|
-
ctx.
|
|
225
|
-
|
|
253
|
+
if (encoded_len > UINT32_MAX) {
|
|
254
|
+
return ARGON2_DECODING_FAIL;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/* No field can be longer than the encoded length */
|
|
258
|
+
max_field_len = (uint32_t)encoded_len;
|
|
259
|
+
|
|
260
|
+
ctx.saltlen = max_field_len;
|
|
261
|
+
ctx.outlen = max_field_len;
|
|
262
|
+
|
|
226
263
|
ctx.salt = malloc(ctx.saltlen);
|
|
227
264
|
ctx.out = malloc(ctx.outlen);
|
|
228
|
-
if (!ctx.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
free(ctx.out);
|
|
232
|
-
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
|
265
|
+
if (!ctx.salt || !ctx.out) {
|
|
266
|
+
ret = ARGON2_MEMORY_ALLOCATION_ERROR;
|
|
267
|
+
goto fail;
|
|
233
268
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
269
|
+
|
|
270
|
+
ctx.pwd = (uint8_t *)pwd;
|
|
271
|
+
ctx.pwdlen = pwdlen;
|
|
272
|
+
|
|
273
|
+
ret = decode_string(&ctx, encoded, type);
|
|
274
|
+
if (ret != ARGON2_OK) {
|
|
275
|
+
goto fail;
|
|
240
276
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
277
|
+
|
|
278
|
+
/* Set aside the desired result, and get a new buffer. */
|
|
279
|
+
desired_result = ctx.out;
|
|
280
|
+
ctx.out = malloc(ctx.outlen);
|
|
281
|
+
if (!ctx.out) {
|
|
282
|
+
ret = ARGON2_MEMORY_ALLOCATION_ERROR;
|
|
283
|
+
goto fail;
|
|
248
284
|
}
|
|
249
285
|
|
|
250
|
-
ret =
|
|
251
|
-
|
|
252
|
-
|
|
286
|
+
ret = argon2_verify_ctx(&ctx, (char *)desired_result, type);
|
|
287
|
+
if (ret != ARGON2_OK) {
|
|
288
|
+
goto fail;
|
|
289
|
+
}
|
|
253
290
|
|
|
254
|
-
|
|
291
|
+
fail:
|
|
255
292
|
free(ctx.salt);
|
|
256
|
-
|
|
257
|
-
if (ret == ARGON2_OK && argon2_compare(out, ctx.out, ctx.outlen)) {
|
|
258
|
-
ret = ARGON2_VERIFY_MISMATCH;
|
|
259
|
-
}
|
|
260
|
-
free(out);
|
|
261
293
|
free(ctx.out);
|
|
294
|
+
free(desired_result);
|
|
262
295
|
|
|
263
296
|
return ret;
|
|
264
297
|
}
|
|
@@ -273,6 +306,11 @@ int argon2d_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
|
273
306
|
return argon2_verify(encoded, pwd, pwdlen, Argon2_d);
|
|
274
307
|
}
|
|
275
308
|
|
|
309
|
+
int argon2id_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
310
|
+
|
|
311
|
+
return argon2_verify(encoded, pwd, pwdlen, Argon2_id);
|
|
312
|
+
}
|
|
313
|
+
|
|
276
314
|
int argon2d_ctx(argon2_context *context) {
|
|
277
315
|
return argon2_ctx(context, Argon2_d);
|
|
278
316
|
}
|
|
@@ -281,20 +319,22 @@ int argon2i_ctx(argon2_context *context) {
|
|
|
281
319
|
return argon2_ctx(context, Argon2_i);
|
|
282
320
|
}
|
|
283
321
|
|
|
322
|
+
int argon2id_ctx(argon2_context *context) {
|
|
323
|
+
return argon2_ctx(context, Argon2_id);
|
|
324
|
+
}
|
|
325
|
+
|
|
284
326
|
int argon2_verify_ctx(argon2_context *context, const char *hash,
|
|
285
327
|
argon2_type type) {
|
|
286
|
-
int
|
|
287
|
-
if (
|
|
288
|
-
return
|
|
328
|
+
int ret = argon2_ctx(context, type);
|
|
329
|
+
if (ret != ARGON2_OK) {
|
|
330
|
+
return ret;
|
|
289
331
|
}
|
|
290
332
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (ARGON2_OK != result) {
|
|
294
|
-
return result;
|
|
333
|
+
if (argon2_compare((uint8_t *)hash, context->out, context->outlen)) {
|
|
334
|
+
return ARGON2_VERIFY_MISMATCH;
|
|
295
335
|
}
|
|
296
336
|
|
|
297
|
-
return
|
|
337
|
+
return ARGON2_OK;
|
|
298
338
|
}
|
|
299
339
|
|
|
300
340
|
int argon2d_verify_ctx(argon2_context *context, const char *hash) {
|
|
@@ -305,6 +345,10 @@ int argon2i_verify_ctx(argon2_context *context, const char *hash) {
|
|
|
305
345
|
return argon2_verify_ctx(context, hash, Argon2_i);
|
|
306
346
|
}
|
|
307
347
|
|
|
348
|
+
int argon2id_verify_ctx(argon2_context *context, const char *hash) {
|
|
349
|
+
return argon2_verify_ctx(context, hash, Argon2_id);
|
|
350
|
+
}
|
|
351
|
+
|
|
308
352
|
const char *argon2_error_message(int error_code) {
|
|
309
353
|
switch (error_code) {
|
|
310
354
|
case ARGON2_OK:
|
|
@@ -385,8 +429,8 @@ const char *argon2_error_message(int error_code) {
|
|
|
385
429
|
}
|
|
386
430
|
|
|
387
431
|
size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost, uint32_t parallelism,
|
|
388
|
-
uint32_t saltlen, uint32_t hashlen) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
432
|
+
uint32_t saltlen, uint32_t hashlen, argon2_type type) {
|
|
433
|
+
return strlen("$$v=$m=,t=,p=$$") + strlen(argon2_type2string(type, 0)) +
|
|
434
|
+
numlen(t_cost) + numlen(m_cost) + numlen(parallelism) +
|
|
435
|
+
b64len(saltlen) + b64len(hashlen) + numlen(ARGON2_VERSION_NUMBER) + 1;
|
|
392
436
|
}
|
|
@@ -1,3 +1,20 @@
|
|
|
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
|
+
|
|
1
18
|
#include <stdio.h>
|
|
2
19
|
#include <stdint.h>
|
|
3
20
|
#include <stdlib.h>
|
|
@@ -45,6 +62,7 @@ static void benchmark() {
|
|
|
45
62
|
uint32_t t_cost = 3;
|
|
46
63
|
uint32_t m_cost;
|
|
47
64
|
uint32_t thread_test[4] = {1, 2, 4, 8};
|
|
65
|
+
argon2_type types[3] = {Argon2_i, Argon2_d, Argon2_id};
|
|
48
66
|
|
|
49
67
|
memset(pwd_array, 0, inlen);
|
|
50
68
|
memset(salt_array, 1, inlen);
|
|
@@ -52,37 +70,36 @@ static void benchmark() {
|
|
|
52
70
|
for (m_cost = (uint32_t)1 << 10; m_cost <= (uint32_t)1 << 22; m_cost *= 2) {
|
|
53
71
|
unsigned i;
|
|
54
72
|
for (i = 0; i < 4; ++i) {
|
|
73
|
+
double run_time = 0;
|
|
55
74
|
uint32_t thread_n = thread_test[i];
|
|
56
|
-
uint64_t stop_cycles, stop_cycles_i;
|
|
57
|
-
clock_t stop_time;
|
|
58
|
-
uint64_t delta_d, delta_i;
|
|
59
|
-
double mcycles_d, mcycles_i, run_time;
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
unsigned j;
|
|
77
|
+
for (j = 0; j < 3; ++j) {
|
|
78
|
+
clock_t start_time, stop_time;
|
|
79
|
+
uint64_t start_cycles, stop_cycles;
|
|
80
|
+
uint64_t delta;
|
|
81
|
+
double mcycles;
|
|
82
|
+
|
|
83
|
+
argon2_type type = types[j];
|
|
84
|
+
start_time = clock();
|
|
85
|
+
start_cycles = rdtsc();
|
|
86
|
+
|
|
87
|
+
argon2_hash(t_cost, m_cost, thread_n, pwd_array, inlen,
|
|
88
|
+
salt_array, inlen, out, outlen, NULL, 0, type,
|
|
89
|
+
ARGON2_VERSION_NUMBER);
|
|
90
|
+
|
|
91
|
+
stop_cycles = rdtsc();
|
|
92
|
+
stop_time = clock();
|
|
93
|
+
|
|
94
|
+
delta = (stop_cycles - start_cycles) / (m_cost);
|
|
95
|
+
mcycles = (double)(stop_cycles - start_cycles) / (1UL << 20);
|
|
96
|
+
run_time += ((double)stop_time - start_time) / (CLOCKS_PER_SEC);
|
|
71
97
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
printf("Argon2d %d iterations %d MiB %d threads: %2.2f cpb %2.2f "
|
|
77
|
-
"Mcycles \n",
|
|
78
|
-
t_cost, m_cost >> 10, thread_n, (float)delta_d / 1024,
|
|
79
|
-
mcycles_d);
|
|
80
|
-
printf("Argon2i %d iterations %d MiB %d threads: %2.2f cpb %2.2f "
|
|
81
|
-
"Mcycles \n",
|
|
82
|
-
t_cost, m_cost >> 10, thread_n, (float)delta_i / 1024,
|
|
83
|
-
mcycles_i);
|
|
98
|
+
printf("%s %d iterations %d MiB %d threads: %2.2f cpb %2.2f "
|
|
99
|
+
"Mcycles \n", argon2_type2string(type, 1), t_cost,
|
|
100
|
+
m_cost >> 10, thread_n, (float)delta / 1024, mcycles);
|
|
101
|
+
}
|
|
84
102
|
|
|
85
|
-
run_time = ((double)stop_time - start_time) / (CLOCKS_PER_SEC);
|
|
86
103
|
printf("%2.4f seconds\n\n", run_time);
|
|
87
104
|
}
|
|
88
105
|
}
|
|
@@ -1,3 +1,20 @@
|
|
|
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
|
+
|
|
1
18
|
#ifndef PORTABLE_BLAKE2_IMPL_H
|
|
2
19
|
#define PORTABLE_BLAKE2_IMPL_H
|
|
3
20
|
|
|
@@ -134,10 +151,6 @@ static BLAKE2_INLINE uint64_t rotr64(const uint64_t w, const unsigned c) {
|
|
|
134
151
|
return (w >> c) | (w << (64 - c));
|
|
135
152
|
}
|
|
136
153
|
|
|
137
|
-
|
|
138
|
-
static BLAKE2_INLINE void burn(void *v, size_t n) {
|
|
139
|
-
static void *(*const volatile memset_v)(void *, int, size_t) = &memset;
|
|
140
|
-
memset_v(v, 0, n);
|
|
141
|
-
}
|
|
154
|
+
void clear_internal_memory(void *v, size_t n);
|
|
142
155
|
|
|
143
156
|
#endif
|