| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 29 |
|
| 30 |
uint32_t memory_blocks, segment_length; |
| 31 |
argon2_instance_t instance; |
| 32 |
|
| 33 |
|
| 34 |
|
| 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 |
|
| 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 |
|
| 60 |
|
| 61 |
|
| 62 |
initialize(&instance, context); |
| 63 |
|
| 64 |
|
| 65 |
fill_memory_blocks(&instance); |
| 66 |
|
| 67 |
|
| 68 |
finalize(context, &instance); |
| 69 |
|
| 70 |
return ARGON2_OK; |
| 71 |
} |