argon2 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -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
|
#ifndef ARGON2_CORE_H
|
@@ -26,8 +30,7 @@
|
|
26
30
|
|
27
31
|
#define CONST_CAST(x) (x)(uintptr_t)
|
28
32
|
|
29
|
-
|
30
|
-
* constants**************************************************/
|
33
|
+
/**********************Argon2 internal constants*******************************/
|
31
34
|
|
32
35
|
enum argon2_core_constants {
|
33
36
|
/* Memory block size in bytes */
|
@@ -45,8 +48,7 @@ enum argon2_core_constants {
|
|
45
48
|
ARGON2_PREHASH_SEED_LENGTH = 72
|
46
49
|
};
|
47
50
|
|
48
|
-
/*************************Argon2 internal data
|
49
|
-
* types**************************************************/
|
51
|
+
/*************************Argon2 internal data types***********************/
|
50
52
|
|
51
53
|
/*
|
52
54
|
* Structure for the (1KB) memory block implemented as 128 64-bit words.
|
@@ -83,6 +85,7 @@ typedef struct Argon2_instance_t {
|
|
83
85
|
uint32_t threads;
|
84
86
|
argon2_type type;
|
85
87
|
int print_internals; /* whether to print the memory blocks */
|
88
|
+
argon2_context *context_ptr; /* points back to original context */
|
86
89
|
} argon2_instance_t;
|
87
90
|
|
88
91
|
/*
|
@@ -102,32 +105,43 @@ typedef struct Argon2_thread_data {
|
|
102
105
|
argon2_position_t pos;
|
103
106
|
} argon2_thread_data;
|
104
107
|
|
105
|
-
/*************************Argon2 core
|
106
|
-
* functions**************************************************/
|
108
|
+
/*************************Argon2 core functions********************************/
|
107
109
|
|
108
|
-
/* Allocates memory to the given pointer
|
110
|
+
/* Allocates memory to the given pointer, uses the appropriate allocator as
|
111
|
+
* specified in the context. Total allocated memory is num*size.
|
112
|
+
* @param context argon2_context which specifies the allocator
|
109
113
|
* @param memory pointer to the pointer to the memory
|
110
|
-
* @param
|
114
|
+
* @param size the size in bytes for each element to be allocated
|
115
|
+
* @param num the number of elements to be allocated
|
111
116
|
* @return ARGON2_OK if @memory is a valid pointer and memory is allocated
|
112
117
|
*/
|
113
|
-
int allocate_memory(
|
118
|
+
int allocate_memory(const argon2_context *context, uint8_t **memory,
|
119
|
+
size_t num, size_t size);
|
114
120
|
|
115
|
-
/*
|
121
|
+
/*
|
122
|
+
* Frees memory at the given pointer, uses the appropriate deallocator as
|
123
|
+
* specified in the context. Also cleans the memory using clear_internal_memory.
|
124
|
+
* @param context argon2_context which specifies the deallocator
|
125
|
+
* @param memory pointer to buffer to be freed
|
126
|
+
* @param size the size in bytes for each element to be deallocated
|
127
|
+
* @param num the number of elements to be deallocated
|
128
|
+
*/
|
129
|
+
void free_memory(const argon2_context *context, uint8_t *memory,
|
130
|
+
size_t num, size_t size);
|
131
|
+
|
132
|
+
/* Function that securely cleans the memory. This ignores any flags set
|
133
|
+
* regarding clearing memory. Usually one just calls clear_internal_memory.
|
116
134
|
* @param mem Pointer to the memory
|
117
135
|
* @param s Memory size in bytes
|
118
136
|
*/
|
119
137
|
void secure_wipe_memory(void *v, size_t n);
|
120
138
|
|
121
|
-
/*
|
122
|
-
*
|
123
|
-
* @param
|
124
|
-
|
125
|
-
void clear_memory(argon2_instance_t *instance, int clear);
|
126
|
-
|
127
|
-
/* Deallocates memory
|
128
|
-
* @param memory pointer to the blocks
|
139
|
+
/* Function that securely clears the memory if FLAG_clear_internal_memory is
|
140
|
+
* set. If the flag isn't set, this function does nothing.
|
141
|
+
* @param mem Pointer to the memory
|
142
|
+
* @param s Memory size in bytes
|
129
143
|
*/
|
130
|
-
void
|
144
|
+
void clear_internal_memory(void *v, size_t n);
|
131
145
|
|
132
146
|
/*
|
133
147
|
* Computes absolute position of reference block in the lane following a skewed
|
@@ -201,6 +215,7 @@ void finalize(const argon2_context *context, argon2_instance_t *instance);
|
|
201
215
|
/*
|
202
216
|
* Function that fills the segment using previous segments also from other
|
203
217
|
* threads
|
218
|
+
* @param context current context
|
204
219
|
* @param instance Pointer to the current instance
|
205
220
|
* @param position Current position
|
206
221
|
* @pre all block pointers must be valid
|
@@ -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 <stdlib.h>
|
3
20
|
#include <string.h>
|
@@ -22,11 +39,6 @@
|
|
22
39
|
* the parameters, salts and outputs. It does not compute the hash
|
23
40
|
* itself.
|
24
41
|
*
|
25
|
-
* -- The third section is test code, with a main() function. With
|
26
|
-
* this section, the whole file compiles as a stand-alone program
|
27
|
-
* that exercises the encoding and decoding functions with some
|
28
|
-
* test vectors.
|
29
|
-
*
|
30
42
|
* The code was originally written by Thomas Pornin <pornin@bolet.org>,
|
31
43
|
* to whom comments and remarks may be sent. It is released under what
|
32
44
|
* should amount to Public Domain or its closest equivalent; the
|
@@ -229,19 +241,18 @@ static const char *decode_decimal(const char *str, unsigned long *v) {
|
|
229
241
|
*
|
230
242
|
* The code below applies the following format:
|
231
243
|
*
|
232
|
-
* $argon2<T>[$v=<num>]$m=<num>,t=<num>,p=<num
|
244
|
+
* $argon2<T>[$v=<num>]$m=<num>,t=<num>,p=<num>$<bin>$<bin>
|
233
245
|
*
|
234
|
-
* where <T> is either 'd' or 'i', <num> is a decimal integer (positive,
|
235
|
-
* an 'unsigned long'), and <bin> is Base64-encoded data (no '=' padding
|
246
|
+
* where <T> is either 'd', 'id', or 'i', <num> is a decimal integer (positive,
|
247
|
+
* fits in an 'unsigned long'), and <bin> is Base64-encoded data (no '=' padding
|
236
248
|
* characters, no newline or whitespace).
|
237
|
-
* The "keyid" is a binary identifier for a key (up to 8 bytes);
|
238
|
-
* "data" is associated data (up to 32 bytes). When the 'keyid'
|
239
|
-
* (resp. the 'data') is empty, then it is ommitted from the output.
|
240
249
|
*
|
241
250
|
* The last two binary chunks (encoded in Base64) are, in that order,
|
242
|
-
* the salt and the output. Both are
|
243
|
-
* output
|
244
|
-
*
|
251
|
+
* the salt and the output. Both are required. The binary salt length and the
|
252
|
+
* output length must be in the allowed ranges defined in argon2.h.
|
253
|
+
*
|
254
|
+
* The ctx struct must contain buffers large enough to hold the salt and pwd
|
255
|
+
* when it is fed into decode_string.
|
245
256
|
*/
|
246
257
|
|
247
258
|
int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
|
@@ -256,7 +267,7 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
|
|
256
267
|
str += cc_len; \
|
257
268
|
} while ((void)0, 0)
|
258
269
|
|
259
|
-
/* prefix checking with supplied code */
|
270
|
+
/* optional prefix checking with supplied code */
|
260
271
|
#define CC_opt(prefix, code) \
|
261
272
|
do { \
|
262
273
|
size_t cc_len = strlen(prefix); \
|
@@ -266,7 +277,7 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
|
|
266
277
|
} \
|
267
278
|
} while ((void)0, 0)
|
268
279
|
|
269
|
-
/* Decoding
|
280
|
+
/* Decoding prefix into decimal */
|
270
281
|
#define DECIMAL(x) \
|
271
282
|
do { \
|
272
283
|
unsigned long dec_x; \
|
@@ -277,6 +288,7 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
|
|
277
288
|
(x) = dec_x; \
|
278
289
|
} while ((void)0, 0)
|
279
290
|
|
291
|
+
/* Decoding base64 into a binary buffer */
|
280
292
|
#define BIN(buf, max_len, len) \
|
281
293
|
do { \
|
282
294
|
size_t bin_len = (max_len); \
|
@@ -287,25 +299,24 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
|
|
287
299
|
(len) = (uint32_t)bin_len; \
|
288
300
|
} while ((void)0, 0)
|
289
301
|
|
290
|
-
size_t maxadlen = ctx->adlen;
|
291
302
|
size_t maxsaltlen = ctx->saltlen;
|
292
303
|
size_t maxoutlen = ctx->outlen;
|
293
304
|
int validation_result;
|
305
|
+
const char* type_string;
|
294
306
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
ctx->pwdlen = 0;
|
299
|
-
|
300
|
-
if (type == Argon2_i)
|
301
|
-
CC("$argon2i");
|
302
|
-
else if (type == Argon2_d)
|
303
|
-
CC("$argon2d");
|
304
|
-
else
|
307
|
+
/* We should start with the argon2_type we are using */
|
308
|
+
type_string = argon2_type2string(type, 0);
|
309
|
+
if (!type_string) {
|
305
310
|
return ARGON2_INCORRECT_TYPE;
|
306
|
-
|
311
|
+
}
|
312
|
+
|
313
|
+
CC("$");
|
314
|
+
CC(type_string);
|
315
|
+
|
307
316
|
/* Reading the version number if the default is suppressed */
|
317
|
+
ctx->version = ARGON2_VERSION_10;
|
308
318
|
CC_opt("$v=", DECIMAL(ctx->version));
|
319
|
+
|
309
320
|
CC("$m=");
|
310
321
|
DECIMAL(ctx->m_cost);
|
311
322
|
CC(",t=");
|
@@ -314,21 +325,27 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
|
|
314
325
|
DECIMAL(ctx->lanes);
|
315
326
|
ctx->threads = ctx->lanes;
|
316
327
|
|
317
|
-
CC_opt(",data=", BIN(ctx->ad, maxadlen, ctx->adlen));
|
318
|
-
if (*str == 0) {
|
319
|
-
return ARGON2_OK;
|
320
|
-
}
|
321
328
|
CC("$");
|
322
329
|
BIN(ctx->salt, maxsaltlen, ctx->saltlen);
|
323
|
-
if (*str == 0) {
|
324
|
-
return ARGON2_OK;
|
325
|
-
}
|
326
330
|
CC("$");
|
327
331
|
BIN(ctx->out, maxoutlen, ctx->outlen);
|
332
|
+
|
333
|
+
/* The rest of the fields get the default values */
|
334
|
+
ctx->secret = NULL;
|
335
|
+
ctx->secretlen = 0;
|
336
|
+
ctx->ad = NULL;
|
337
|
+
ctx->adlen = 0;
|
338
|
+
ctx->allocate_cbk = NULL;
|
339
|
+
ctx->free_cbk = NULL;
|
340
|
+
ctx->flags = ARGON2_DEFAULT_FLAGS;
|
341
|
+
|
342
|
+
/* On return, must have valid context */
|
328
343
|
validation_result = validate_inputs(ctx);
|
329
344
|
if (validation_result != ARGON2_OK) {
|
330
345
|
return validation_result;
|
331
346
|
}
|
347
|
+
|
348
|
+
/* Can't have any additional characters */
|
332
349
|
if (*str == 0) {
|
333
350
|
return ARGON2_OK;
|
334
351
|
} else {
|
@@ -370,17 +387,24 @@ int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
|
|
370
387
|
dst_len -= sb_len; \
|
371
388
|
} while ((void)0, 0)
|
372
389
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
390
|
+
const char* type_string = argon2_type2string(type, 0);
|
391
|
+
int validation_result = validate_inputs(ctx);
|
392
|
+
|
393
|
+
if (!type_string) {
|
394
|
+
return ARGON2_ENCODING_FAIL;
|
395
|
+
}
|
379
396
|
|
380
|
-
if (
|
381
|
-
|
397
|
+
if (validation_result != ARGON2_OK) {
|
398
|
+
return validation_result;
|
382
399
|
}
|
400
|
+
|
401
|
+
|
402
|
+
SS("$");
|
403
|
+
SS(type_string);
|
404
|
+
|
405
|
+
SS("$v=");
|
383
406
|
SX(ctx->version);
|
407
|
+
|
384
408
|
SS("$m=");
|
385
409
|
SX(ctx->m_cost);
|
386
410
|
SS(",t=");
|
@@ -388,20 +412,9 @@ int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
|
|
388
412
|
SS(",p=");
|
389
413
|
SX(ctx->lanes);
|
390
414
|
|
391
|
-
if (ctx->adlen > 0) {
|
392
|
-
SS(",data=");
|
393
|
-
SB(ctx->ad, ctx->adlen);
|
394
|
-
}
|
395
|
-
|
396
|
-
if (ctx->saltlen == 0)
|
397
|
-
return ARGON2_OK;
|
398
|
-
|
399
415
|
SS("$");
|
400
416
|
SB(ctx->salt, ctx->saltlen);
|
401
417
|
|
402
|
-
if (ctx->outlen == 0)
|
403
|
-
return ARGON2_OK;
|
404
|
-
|
405
418
|
SS("$");
|
406
419
|
SB(ctx->out, ctx->outlen);
|
407
420
|
return ARGON2_OK;
|
@@ -412,7 +425,18 @@ int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
|
|
412
425
|
}
|
413
426
|
|
414
427
|
size_t b64len(uint32_t len) {
|
415
|
-
|
428
|
+
size_t olen = ((size_t)len / 3) << 2;
|
429
|
+
|
430
|
+
switch (len % 3) {
|
431
|
+
case 2:
|
432
|
+
olen++;
|
433
|
+
/* fall through */
|
434
|
+
case 1:
|
435
|
+
olen += 2;
|
436
|
+
break;
|
437
|
+
}
|
438
|
+
|
439
|
+
return olen;
|
416
440
|
}
|
417
441
|
|
418
442
|
size_t numlen(uint32_t num) {
|
@@ -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 ENCODING_H
|
2
19
|
#define ENCODING_H
|
3
20
|
#include "argon2.h"
|
@@ -12,21 +29,21 @@
|
|
12
29
|
* is less than the number of required characters (including the
|
13
30
|
* terminating 0), then this function returns ARGON2_ENCODING_ERROR.
|
14
31
|
*
|
15
|
-
* if ctx->outlen is 0, then the hash string will be a salt string
|
16
|
-
* (no output). if ctx->saltlen is also 0, then the string will be a
|
17
|
-
* parameter-only string (no salt and no output).
|
18
|
-
*
|
19
32
|
* on success, ARGON2_OK is returned.
|
20
|
-
*
|
21
|
-
* No other parameters are checked
|
22
33
|
*/
|
23
34
|
int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
|
24
35
|
argon2_type type);
|
25
36
|
|
26
37
|
/*
|
27
38
|
* Decodes an Argon2 hash string into the provided structure 'ctx'.
|
28
|
-
* The fields
|
29
|
-
*
|
39
|
+
* The only fields that must be set prior to this call are ctx.saltlen and
|
40
|
+
* ctx.outlen (which must be the maximal salt and out length values that are
|
41
|
+
* allowed), ctx.salt and ctx.out (which must be buffers of the specified
|
42
|
+
* length), and ctx.pwd and ctx.pwdlen which must hold a valid password.
|
43
|
+
*
|
44
|
+
* Invalid input string causes an error. On success, the ctx is valid and all
|
45
|
+
* fields have been initialized.
|
46
|
+
*
|
30
47
|
* Returned value is ARGON2_OK on success, other ARGON2_ codes on error.
|
31
48
|
*/
|
32
49
|
int decode_string(argon2_context *ctx, const char *str, argon2_type type);
|
@@ -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 <inttypes.h>
|
@@ -25,18 +29,8 @@ void initial_kat(const uint8_t *blockhash, const argon2_context *context,
|
|
25
29
|
if (blockhash != NULL && context != NULL) {
|
26
30
|
printf("=======================================\n");
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
printf("Argon2d version number %d\n", context->version);
|
31
|
-
break;
|
32
|
-
|
33
|
-
case Argon2_i:
|
34
|
-
printf("Argon2i version number %d\n", context->version);
|
35
|
-
break;
|
36
|
-
|
37
|
-
default:
|
38
|
-
break;
|
39
|
-
}
|
32
|
+
printf("%s version number %d\n", argon2_type2string(type, 1),
|
33
|
+
context->version);
|
40
34
|
|
41
35
|
printf("=======================================\n");
|
42
36
|
|
@@ -133,7 +127,7 @@ static void fatal(const char *error) {
|
|
133
127
|
exit(1);
|
134
128
|
}
|
135
129
|
|
136
|
-
static void generate_testvectors(
|
130
|
+
static void generate_testvectors(argon2_type type, const uint32_t version) {
|
137
131
|
#define TEST_OUTLEN 32
|
138
132
|
#define TEST_PWDLEN 32
|
139
133
|
#define TEST_SALTLEN 16
|
@@ -160,7 +154,7 @@ static void generate_testvectors(const char *type, const uint32_t version) {
|
|
160
154
|
|
161
155
|
context.out = out;
|
162
156
|
context.outlen = TEST_OUTLEN;
|
163
|
-
context.version =
|
157
|
+
context.version = version;
|
164
158
|
context.pwd = pwd;
|
165
159
|
context.pwdlen = TEST_PWDLEN;
|
166
160
|
context.salt = salt;
|
@@ -175,13 +169,7 @@ static void generate_testvectors(const char *type, const uint32_t version) {
|
|
175
169
|
context.threads = lanes;
|
176
170
|
context.allocate_cbk = myown_allocator;
|
177
171
|
context.free_cbk = myown_deallocator;
|
178
|
-
context.flags =
|
179
|
-
|
180
|
-
if(ARGON2_VERSION_10 == version || ARGON2_VERSION_NUMBER == version) {
|
181
|
-
context.version = version;
|
182
|
-
} else {
|
183
|
-
fatal("wrong Argon2 version number");
|
184
|
-
}
|
172
|
+
context.flags = ARGON2_DEFAULT_FLAGS;
|
185
173
|
|
186
174
|
#undef TEST_OUTLEN
|
187
175
|
#undef TEST_PWDLEN
|
@@ -189,23 +177,31 @@ static void generate_testvectors(const char *type, const uint32_t version) {
|
|
189
177
|
#undef TEST_SECRETLEN
|
190
178
|
#undef TEST_ADLEN
|
191
179
|
|
192
|
-
|
193
|
-
argon2d_ctx(&context);
|
194
|
-
} else if (!strcmp(type, "i")) {
|
195
|
-
argon2i_ctx(&context);
|
196
|
-
} else
|
197
|
-
fatal("wrong Argon2 type");
|
180
|
+
argon2_ctx(&context, type);
|
198
181
|
}
|
199
182
|
|
200
183
|
int main(int argc, char *argv[]) {
|
201
|
-
/* Argon2 type */
|
202
|
-
const char *
|
203
|
-
|
204
|
-
/* Argon2 version number */
|
184
|
+
/* Get and check Argon2 type */
|
185
|
+
const char *type_str = (argc > 1) ? argv[1] : "i";
|
186
|
+
argon2_type type = Argon2_i;
|
205
187
|
uint32_t version = ARGON2_VERSION_NUMBER;
|
206
|
-
if(
|
188
|
+
if (!strcmp(type_str, "d")) {
|
189
|
+
type = Argon2_d;
|
190
|
+
} else if (!strcmp(type_str, "i")) {
|
191
|
+
type = Argon2_i;
|
192
|
+
} else if (!strcmp(type_str, "id")) {
|
193
|
+
type = Argon2_id;
|
194
|
+
} else {
|
195
|
+
fatal("wrong Argon2 type");
|
196
|
+
}
|
197
|
+
|
198
|
+
/* Get and check Argon2 version number */
|
199
|
+
if (argc > 2) {
|
207
200
|
version = strtoul(argv[2], NULL, 10);
|
208
201
|
}
|
202
|
+
if (ARGON2_VERSION_10 != version && ARGON2_VERSION_NUMBER != version) {
|
203
|
+
fatal("wrong Argon2 version number");
|
204
|
+
}
|
209
205
|
|
210
206
|
generate_testvectors(type, version);
|
211
207
|
return ARGON2_OK;
|