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,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_H
|
2
19
|
#define PORTABLE_BLAKE2_H
|
3
20
|
|
@@ -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 <stdint.h>
|
2
19
|
#include <string.h>
|
3
20
|
#include <stdio.h>
|
@@ -44,7 +61,7 @@ static BLAKE2_INLINE void blake2b_increment_counter(blake2b_state *S,
|
|
44
61
|
}
|
45
62
|
|
46
63
|
static BLAKE2_INLINE void blake2b_invalidate_state(blake2b_state *S) {
|
47
|
-
|
64
|
+
clear_internal_memory(S, sizeof(*S)); /* wipe */
|
48
65
|
blake2b_set_lastblock(S); /* invalidate for further use */
|
49
66
|
}
|
50
67
|
|
@@ -140,7 +157,8 @@ int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key,
|
|
140
157
|
memset(block, 0, BLAKE2B_BLOCKBYTES);
|
141
158
|
memcpy(block, key, keylen);
|
142
159
|
blake2b_update(S, block, BLAKE2B_BLOCKBYTES);
|
143
|
-
|
160
|
+
/* Burn the key from stack */
|
161
|
+
clear_internal_memory(block, BLAKE2B_BLOCKBYTES);
|
144
162
|
}
|
145
163
|
return 0;
|
146
164
|
}
|
@@ -267,9 +285,9 @@ int blake2b_final(blake2b_state *S, void *out, size_t outlen) {
|
|
267
285
|
}
|
268
286
|
|
269
287
|
memcpy(out, buffer, S->outlen);
|
270
|
-
|
271
|
-
|
272
|
-
|
288
|
+
clear_internal_memory(buffer, sizeof(buffer));
|
289
|
+
clear_internal_memory(S->buf, sizeof(S->buf));
|
290
|
+
clear_internal_memory(S->h, sizeof(S->h));
|
273
291
|
return 0;
|
274
292
|
}
|
275
293
|
|
@@ -307,7 +325,7 @@ int blake2b(void *out, size_t outlen, const void *in, size_t inlen,
|
|
307
325
|
ret = blake2b_final(&S, out, outlen);
|
308
326
|
|
309
327
|
fail:
|
310
|
-
|
328
|
+
clear_internal_memory(&S, sizeof(S));
|
311
329
|
return ret;
|
312
330
|
}
|
313
331
|
|
@@ -365,7 +383,7 @@ int blake2b_long(void *pout, size_t outlen, const void *in, size_t inlen) {
|
|
365
383
|
memcpy(out, out_buffer, toproduce);
|
366
384
|
}
|
367
385
|
fail:
|
368
|
-
|
386
|
+
clear_internal_memory(&blake_state, sizeof(blake_state));
|
369
387
|
return ret;
|
370
388
|
#undef TRY
|
371
389
|
}
|
@@ -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 BLAKE_ROUND_MKA_OPT_H
|
2
19
|
#define BLAKE_ROUND_MKA_OPT_H
|
3
20
|
|
@@ -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 BLAKE_ROUND_MKA_H
|
2
19
|
#define BLAKE_ROUND_MKA_H
|
3
20
|
|
@@ -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
|
/*For memory wiping*/
|
@@ -78,25 +82,43 @@ static void store_block(void *output, const block *src) {
|
|
78
82
|
}
|
79
83
|
}
|
80
84
|
|
81
|
-
/***************Memory
|
82
|
-
int allocate_memory(block **memory, uint32_t m_cost) {
|
83
|
-
if (memory != NULL) {
|
84
|
-
size_t memory_size = sizeof(block) * m_cost;
|
85
|
-
if (m_cost != 0 &&
|
86
|
-
memory_size / m_cost !=
|
87
|
-
sizeof(block)) { /*1. Check for multiplication overflow*/
|
88
|
-
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
89
|
-
}
|
85
|
+
/***************Memory functions*****************/
|
90
86
|
|
91
|
-
|
87
|
+
int allocate_memory(const argon2_context *context, uint8_t **memory,
|
88
|
+
size_t num, size_t size) {
|
89
|
+
size_t memory_size = num*size;
|
90
|
+
if (memory == NULL) {
|
91
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
92
|
+
}
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
/* 1. Check for multiplication overflow */
|
95
|
+
if (size != 0 && memory_size / size != num) {
|
96
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
97
|
+
}
|
98
|
+
|
99
|
+
/* 2. Try to allocate with appropriate allocator */
|
100
|
+
if (context->allocate_cbk) {
|
101
|
+
(context->allocate_cbk)(memory, memory_size);
|
97
102
|
} else {
|
103
|
+
*memory = malloc(memory_size);
|
104
|
+
}
|
105
|
+
|
106
|
+
if (*memory == NULL) {
|
98
107
|
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
99
108
|
}
|
109
|
+
|
110
|
+
return ARGON2_OK;
|
111
|
+
}
|
112
|
+
|
113
|
+
void free_memory(const argon2_context *context, uint8_t *memory,
|
114
|
+
size_t num, size_t size) {
|
115
|
+
size_t memory_size = num*size;
|
116
|
+
clear_internal_memory(memory, memory_size);
|
117
|
+
if (context->free_cbk) {
|
118
|
+
(context->free_cbk)(memory, memory_size);
|
119
|
+
} else {
|
120
|
+
free(memory);
|
121
|
+
}
|
100
122
|
}
|
101
123
|
|
102
124
|
void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
|
@@ -112,17 +134,14 @@ void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
|
|
112
134
|
#endif
|
113
135
|
}
|
114
136
|
|
115
|
-
|
116
|
-
|
117
|
-
void
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
}
|
137
|
+
/* Memory clear flag defaults to true. */
|
138
|
+
int FLAG_clear_internal_memory = 1;
|
139
|
+
void clear_internal_memory(void *v, size_t n) {
|
140
|
+
if (FLAG_clear_internal_memory && v) {
|
141
|
+
secure_wipe_memory(v, n);
|
142
|
+
}
|
122
143
|
}
|
123
144
|
|
124
|
-
void free_memory(block *memory) { free(memory); }
|
125
|
-
|
126
145
|
void finalize(const argon2_context *context, argon2_instance_t *instance) {
|
127
146
|
if (context != NULL && instance != NULL) {
|
128
147
|
block blockhash;
|
@@ -143,26 +162,17 @@ void finalize(const argon2_context *context, argon2_instance_t *instance) {
|
|
143
162
|
store_block(blockhash_bytes, &blockhash);
|
144
163
|
blake2b_long(context->out, context->outlen, blockhash_bytes,
|
145
164
|
ARGON2_BLOCK_SIZE);
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
ARGON2_BLOCK_SIZE); /* clear blockhash_bytes */
|
165
|
+
/* clear blockhash and blockhash_bytes */
|
166
|
+
clear_internal_memory(blockhash.v, ARGON2_BLOCK_SIZE);
|
167
|
+
clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE);
|
150
168
|
}
|
151
169
|
|
152
170
|
#ifdef GENKAT
|
153
171
|
print_tag(context->out, context->outlen);
|
154
172
|
#endif
|
155
173
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
/* Deallocate the memory */
|
160
|
-
if (NULL != context->free_cbk) {
|
161
|
-
context->free_cbk((uint8_t *)instance->memory,
|
162
|
-
instance->memory_blocks * sizeof(block));
|
163
|
-
} else {
|
164
|
-
free_memory(instance->memory);
|
165
|
-
}
|
174
|
+
free_memory(context, (uint8_t *)instance->memory,
|
175
|
+
instance->memory_blocks, sizeof(block));
|
166
176
|
}
|
167
177
|
}
|
168
178
|
|
@@ -236,42 +246,60 @@ uint32_t index_alpha(const argon2_instance_t *instance,
|
|
236
246
|
return absolute_position;
|
237
247
|
}
|
238
248
|
|
249
|
+
/* Single-threaded version for p=1 case */
|
250
|
+
static int fill_memory_blocks_st(argon2_instance_t *instance) {
|
251
|
+
uint32_t r, s, l;
|
252
|
+
|
253
|
+
for (r = 0; r < instance->passes; ++r) {
|
254
|
+
for (s = 0; s < ARGON2_SYNC_POINTS; ++s) {
|
255
|
+
for (l = 0; l < instance->lanes; ++l) {
|
256
|
+
argon2_position_t position = {r, l, (uint8_t)s, 0};
|
257
|
+
fill_segment(instance, position);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
#ifdef GENKAT
|
261
|
+
internal_kat(instance, r); /* Print all memory blocks */
|
262
|
+
#endif
|
263
|
+
}
|
264
|
+
return ARGON2_OK;
|
265
|
+
}
|
266
|
+
|
267
|
+
#if !defined(ARGON2_NO_THREADS)
|
268
|
+
|
239
269
|
#ifdef _WIN32
|
240
270
|
static unsigned __stdcall fill_segment_thr(void *thread_data)
|
241
271
|
#else
|
242
272
|
static void *fill_segment_thr(void *thread_data)
|
243
273
|
#endif
|
244
274
|
{
|
245
|
-
argon2_thread_data *my_data =
|
275
|
+
argon2_thread_data *my_data = thread_data;
|
246
276
|
fill_segment(my_data->instance_ptr, my_data->pos);
|
247
277
|
argon2_thread_exit();
|
248
278
|
return 0;
|
249
279
|
}
|
250
280
|
|
251
|
-
|
281
|
+
/* Multi-threaded version for p > 1 case */
|
282
|
+
static int fill_memory_blocks_mt(argon2_instance_t *instance) {
|
252
283
|
uint32_t r, s;
|
253
284
|
argon2_thread_handle_t *thread = NULL;
|
254
285
|
argon2_thread_data *thr_data = NULL;
|
255
|
-
|
256
|
-
if (instance == NULL || instance->lanes == 0) {
|
257
|
-
return ARGON2_THREAD_FAIL;
|
258
|
-
}
|
286
|
+
int rc = ARGON2_OK;
|
259
287
|
|
260
288
|
/* 1. Allocating space for threads */
|
261
289
|
thread = calloc(instance->lanes, sizeof(argon2_thread_handle_t));
|
262
290
|
if (thread == NULL) {
|
263
|
-
|
291
|
+
rc = ARGON2_MEMORY_ALLOCATION_ERROR;
|
292
|
+
goto fail;
|
264
293
|
}
|
265
294
|
|
266
295
|
thr_data = calloc(instance->lanes, sizeof(argon2_thread_data));
|
267
296
|
if (thr_data == NULL) {
|
268
|
-
|
269
|
-
|
297
|
+
rc = ARGON2_MEMORY_ALLOCATION_ERROR;
|
298
|
+
goto fail;
|
270
299
|
}
|
271
300
|
|
272
301
|
for (r = 0; r < instance->passes; ++r) {
|
273
302
|
for (s = 0; s < ARGON2_SYNC_POINTS; ++s) {
|
274
|
-
int rc;
|
275
303
|
uint32_t l;
|
276
304
|
|
277
305
|
/* 2. Calling threads */
|
@@ -280,11 +308,9 @@ int fill_memory_blocks(argon2_instance_t *instance) {
|
|
280
308
|
|
281
309
|
/* 2.1 Join a thread if limit is exceeded */
|
282
310
|
if (l >= instance->threads) {
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
free(thread);
|
287
|
-
return ARGON2_THREAD_FAIL;
|
311
|
+
if (argon2_thread_join(thread[l - instance->threads])) {
|
312
|
+
rc = ARGON2_THREAD_FAIL;
|
313
|
+
goto fail;
|
288
314
|
}
|
289
315
|
}
|
290
316
|
|
@@ -297,12 +323,10 @@ int fill_memory_blocks(argon2_instance_t *instance) {
|
|
297
323
|
instance; /* preparing the thread input */
|
298
324
|
memcpy(&(thr_data[l].pos), &position,
|
299
325
|
sizeof(argon2_position_t));
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
free(thread);
|
305
|
-
return ARGON2_THREAD_FAIL;
|
326
|
+
if (argon2_thread_create(&thread[l], &fill_segment_thr,
|
327
|
+
(void *)&thr_data[l])) {
|
328
|
+
rc = ARGON2_THREAD_FAIL;
|
329
|
+
goto fail;
|
306
330
|
}
|
307
331
|
|
308
332
|
/* fill_segment(instance, position); */
|
@@ -312,9 +336,9 @@ int fill_memory_blocks(argon2_instance_t *instance) {
|
|
312
336
|
/* 3. Joining remaining threads */
|
313
337
|
for (l = instance->lanes - instance->threads; l < instance->lanes;
|
314
338
|
++l) {
|
315
|
-
|
316
|
-
|
317
|
-
|
339
|
+
if (argon2_thread_join(thread[l])) {
|
340
|
+
rc = ARGON2_THREAD_FAIL;
|
341
|
+
goto fail;
|
318
342
|
}
|
319
343
|
}
|
320
344
|
}
|
@@ -324,13 +348,28 @@ int fill_memory_blocks(argon2_instance_t *instance) {
|
|
324
348
|
#endif
|
325
349
|
}
|
326
350
|
|
351
|
+
fail:
|
327
352
|
if (thread != NULL) {
|
328
353
|
free(thread);
|
329
354
|
}
|
330
355
|
if (thr_data != NULL) {
|
331
356
|
free(thr_data);
|
332
357
|
}
|
333
|
-
return
|
358
|
+
return rc;
|
359
|
+
}
|
360
|
+
|
361
|
+
#endif /* ARGON2_NO_THREADS */
|
362
|
+
|
363
|
+
int fill_memory_blocks(argon2_instance_t *instance) {
|
364
|
+
if (instance == NULL || instance->lanes == 0) {
|
365
|
+
return ARGON2_INCORRECT_PARAMETER;
|
366
|
+
}
|
367
|
+
#if defined(ARGON2_NO_THREADS)
|
368
|
+
return fill_memory_blocks_st(instance);
|
369
|
+
#else
|
370
|
+
return instance->threads == 1 ?
|
371
|
+
fill_memory_blocks_st(instance) : fill_memory_blocks_mt(instance);
|
372
|
+
#endif
|
334
373
|
}
|
335
374
|
|
336
375
|
int validate_inputs(const argon2_context *context) {
|
@@ -351,37 +390,37 @@ int validate_inputs(const argon2_context *context) {
|
|
351
390
|
return ARGON2_OUTPUT_TOO_LONG;
|
352
391
|
}
|
353
392
|
|
354
|
-
/* Validate password
|
393
|
+
/* Validate password (required param) */
|
355
394
|
if (NULL == context->pwd) {
|
356
395
|
if (0 != context->pwdlen) {
|
357
396
|
return ARGON2_PWD_PTR_MISMATCH;
|
358
397
|
}
|
359
|
-
}
|
360
|
-
if (ARGON2_MIN_PWD_LENGTH > context->pwdlen) {
|
361
|
-
return ARGON2_PWD_TOO_SHORT;
|
362
|
-
}
|
398
|
+
}
|
363
399
|
|
364
|
-
|
365
|
-
|
366
|
-
|
400
|
+
if (ARGON2_MIN_PWD_LENGTH > context->pwdlen) {
|
401
|
+
return ARGON2_PWD_TOO_SHORT;
|
402
|
+
}
|
403
|
+
|
404
|
+
if (ARGON2_MAX_PWD_LENGTH < context->pwdlen) {
|
405
|
+
return ARGON2_PWD_TOO_LONG;
|
367
406
|
}
|
368
407
|
|
369
|
-
/* Validate salt
|
408
|
+
/* Validate salt (required param) */
|
370
409
|
if (NULL == context->salt) {
|
371
410
|
if (0 != context->saltlen) {
|
372
411
|
return ARGON2_SALT_PTR_MISMATCH;
|
373
412
|
}
|
374
|
-
}
|
375
|
-
if (ARGON2_MIN_SALT_LENGTH > context->saltlen) {
|
376
|
-
return ARGON2_SALT_TOO_SHORT;
|
377
|
-
}
|
413
|
+
}
|
378
414
|
|
379
|
-
|
380
|
-
|
381
|
-
}
|
415
|
+
if (ARGON2_MIN_SALT_LENGTH > context->saltlen) {
|
416
|
+
return ARGON2_SALT_TOO_SHORT;
|
382
417
|
}
|
383
418
|
|
384
|
-
|
419
|
+
if (ARGON2_MAX_SALT_LENGTH < context->saltlen) {
|
420
|
+
return ARGON2_SALT_TOO_LONG;
|
421
|
+
}
|
422
|
+
|
423
|
+
/* Validate secret (optional param) */
|
385
424
|
if (NULL == context->secret) {
|
386
425
|
if (0 != context->secretlen) {
|
387
426
|
return ARGON2_SECRET_PTR_MISMATCH;
|
@@ -390,13 +429,12 @@ int validate_inputs(const argon2_context *context) {
|
|
390
429
|
if (ARGON2_MIN_SECRET > context->secretlen) {
|
391
430
|
return ARGON2_SECRET_TOO_SHORT;
|
392
431
|
}
|
393
|
-
|
394
432
|
if (ARGON2_MAX_SECRET < context->secretlen) {
|
395
433
|
return ARGON2_SECRET_TOO_LONG;
|
396
434
|
}
|
397
435
|
}
|
398
436
|
|
399
|
-
/* Validate associated data */
|
437
|
+
/* Validate associated data (optional param) */
|
400
438
|
if (NULL == context->ad) {
|
401
439
|
if (0 != context->adlen) {
|
402
440
|
return ARGON2_AD_PTR_MISMATCH;
|
@@ -405,7 +443,6 @@ int validate_inputs(const argon2_context *context) {
|
|
405
443
|
if (ARGON2_MIN_AD_LENGTH > context->adlen) {
|
406
444
|
return ARGON2_AD_TOO_SHORT;
|
407
445
|
}
|
408
|
-
|
409
446
|
if (ARGON2_MAX_AD_LENGTH < context->adlen) {
|
410
447
|
return ARGON2_AD_TOO_LONG;
|
411
448
|
}
|
@@ -464,8 +501,8 @@ int validate_inputs(const argon2_context *context) {
|
|
464
501
|
|
465
502
|
void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) {
|
466
503
|
uint32_t l;
|
467
|
-
/* Make the first and second block in each lane as G(H0||i
|
468
|
-
G(H0||i
|
504
|
+
/* Make the first and second block in each lane as G(H0||0||i) or
|
505
|
+
G(H0||1||i) */
|
469
506
|
uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE];
|
470
507
|
for (l = 0; l < instance->lanes; ++l) {
|
471
508
|
|
@@ -482,7 +519,7 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) {
|
|
482
519
|
load_block(&instance->memory[l * instance->lane_length + 1],
|
483
520
|
blockhash_bytes);
|
484
521
|
}
|
485
|
-
|
522
|
+
clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE);
|
486
523
|
}
|
487
524
|
|
488
525
|
void initial_hash(uint8_t *blockhash, argon2_context *context,
|
@@ -565,22 +602,13 @@ int initialize(argon2_instance_t *instance, argon2_context *context) {
|
|
565
602
|
|
566
603
|
if (instance == NULL || context == NULL)
|
567
604
|
return ARGON2_INCORRECT_PARAMETER;
|
605
|
+
instance->context_ptr = context;
|
568
606
|
|
569
607
|
/* 1. Memory allocation */
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
result
|
574
|
-
ARGON2_BLOCK_SIZE);
|
575
|
-
if (ARGON2_OK != result) {
|
576
|
-
return result;
|
577
|
-
}
|
578
|
-
memcpy(&(instance->memory), p, sizeof(instance->memory));
|
579
|
-
} else {
|
580
|
-
result = allocate_memory(&(instance->memory), instance->memory_blocks);
|
581
|
-
if (ARGON2_OK != result) {
|
582
|
-
return result;
|
583
|
-
}
|
608
|
+
result = allocate_memory(context, (uint8_t **)&(instance->memory),
|
609
|
+
instance->memory_blocks, sizeof(block));
|
610
|
+
if (result != ARGON2_OK) {
|
611
|
+
return result;
|
584
612
|
}
|
585
613
|
|
586
614
|
/* 2. Initial hashing */
|
@@ -589,9 +617,9 @@ int initialize(argon2_instance_t *instance, argon2_context *context) {
|
|
589
617
|
/* Hashing all inputs */
|
590
618
|
initial_hash(blockhash, context, instance->type);
|
591
619
|
/* Zeroing 8 extra bytes */
|
592
|
-
|
593
|
-
|
594
|
-
|
620
|
+
clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH,
|
621
|
+
ARGON2_PREHASH_SEED_LENGTH -
|
622
|
+
ARGON2_PREHASH_DIGEST_LENGTH);
|
595
623
|
|
596
624
|
#ifdef GENKAT
|
597
625
|
initial_kat(blockhash, context, instance->type);
|
@@ -601,7 +629,7 @@ int initialize(argon2_instance_t *instance, argon2_context *context) {
|
|
601
629
|
*/
|
602
630
|
fill_first_blocks(blockhash, instance);
|
603
631
|
/* Clearing the hash */
|
604
|
-
|
632
|
+
clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH);
|
605
633
|
|
606
634
|
return ARGON2_OK;
|
607
635
|
}
|