Debian Codegraph @

deps/phc-winner-argon2-20190702/_hashcat/argon2.c

raw symbols SCIP
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 "core.h"
24
25
26
27 int argon2_ctx(argon2_context *context, argon2_type type) {
28 /* 1. Validate all inputs */
29
30 uint32_t memory_blocks, segment_length;
31 argon2_instance_t instance;
32
33 /* 2. Align memory size */
34 /* Minimum memory_blocks = 8L blocks, where L is the number of lanes */
35 memory_blocks = context->m_cost;
36
37 if (memory_blocks < 2 * ARGON2_SYNC_POINTS * context->lanes) {
38 memory_blocks = 2 * ARGON2_SYNC_POINTS * context->lanes;
39 }
40
41 segment_length = memory_blocks / (context->lanes * ARGON2_SYNC_POINTS);
42 /* Ensure that all segments have equal length */
43 memory_blocks = segment_length * (context->lanes * ARGON2_SYNC_POINTS);
44
45 instance.version = context->version;
46 instance.memory = NULL;
47 instance.passes = context->t_cost;
48 instance.memory_blocks = memory_blocks;
49 instance.segment_length = segment_length;
50 instance.lane_length = segment_length * ARGON2_SYNC_POINTS;
51 instance.lanes = context->lanes;
52 instance.threads = context->threads;
53 instance.type = type;
54
55 if (instance.threads > instance.lanes) {
56 instance.threads = instance.lanes;
57 }
58
59 /* 3. Initialization: Hashing inputs, allocating memory, filling first
60 * blocks
61 */
62 initialize(&instance, context);
63
64 /* 4. Filling memory */
65 fill_memory_blocks(&instance);
66
67 /* 5. Finalization */
68 finalize(context, &instance);
69
70 return ARGON2_OK;
71 }