|
|
|
@ -61,13 +61,13 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/***************Instance and Position constructors**********/
|
|
|
|
|
void init_block_value(block *b, uint8_t in) { memset(b->v, in, sizeof(b->v)); }
|
|
|
|
|
void rxa2_init_block_value(block *b, uint8_t in) { memset(b->v, in, sizeof(b->v)); }
|
|
|
|
|
|
|
|
|
|
void copy_block(block *dst, const block *src) {
|
|
|
|
|
void rxa2_copy_block(block *dst, const block *src) {
|
|
|
|
|
memcpy(dst->v, src->v, sizeof(uint64_t) * ARGON2_QWORDS_IN_BLOCK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void xor_block(block *dst, const block *src) {
|
|
|
|
|
void rxa2_xor_block(block *dst, const block *src) {
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) {
|
|
|
|
|
dst->v[i] ^= src->v[i];
|
|
|
|
@ -90,7 +90,7 @@ static void store_block(void *output, const block *src) {
|
|
|
|
|
|
|
|
|
|
/***************Memory functions*****************/
|
|
|
|
|
|
|
|
|
|
int allocate_memory(const argon2_context *context, uint8_t **memory,
|
|
|
|
|
int rxa2_allocate_memory(const argon2_context *context, uint8_t **memory,
|
|
|
|
|
size_t num, size_t size) {
|
|
|
|
|
size_t memory_size = num * size;
|
|
|
|
|
if (memory == NULL) {
|
|
|
|
@ -117,10 +117,10 @@ int allocate_memory(const argon2_context *context, uint8_t **memory,
|
|
|
|
|
return ARGON2_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void free_memory(const argon2_context *context, uint8_t *memory,
|
|
|
|
|
void rxa2_free_memory(const argon2_context *context, uint8_t *memory,
|
|
|
|
|
size_t num, size_t size) {
|
|
|
|
|
size_t memory_size = num * size;
|
|
|
|
|
clear_internal_memory(memory, memory_size);
|
|
|
|
|
rxa2_clear_internal_memory(memory, memory_size);
|
|
|
|
|
if (context->free_cbk) {
|
|
|
|
|
(context->free_cbk)(memory, memory_size);
|
|
|
|
|
}
|
|
|
|
@ -129,7 +129,7 @@ void free_memory(const argon2_context *context, uint8_t *memory,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
|
|
|
|
|
void NOT_OPTIMIZED rxa2_secure_wipe_memory(void *v, size_t n) {
|
|
|
|
|
#if defined(_MSC_VER) && VC_GE_2005(_MSC_VER)
|
|
|
|
|
SecureZeroMemory(v, n);
|
|
|
|
|
#elif defined memset_s
|
|
|
|
@ -144,13 +144,13 @@ void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
|
|
|
|
|
|
|
|
|
|
/* Memory clear flag defaults to true. */
|
|
|
|
|
#define FLAG_clear_internal_memory 0
|
|
|
|
|
void clear_internal_memory(void *v, size_t n) {
|
|
|
|
|
void rxa2_clear_internal_memory(void *v, size_t n) {
|
|
|
|
|
if (FLAG_clear_internal_memory && v) {
|
|
|
|
|
secure_wipe_memory(v, n);
|
|
|
|
|
rxa2_secure_wipe_memory(v, n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t index_alpha(const argon2_instance_t *instance,
|
|
|
|
|
uint32_t rxa2_index_alpha(const argon2_instance_t *instance,
|
|
|
|
|
const argon2_position_t *position, uint32_t pseudo_rand,
|
|
|
|
|
int same_lane) {
|
|
|
|
|
/*
|
|
|
|
@ -232,7 +232,7 @@ static int fill_memory_blocks_st(argon2_instance_t *instance) {
|
|
|
|
|
for (s = 0; s < ARGON2_SYNC_POINTS; ++s) {
|
|
|
|
|
for (l = 0; l < instance->lanes; ++l) {
|
|
|
|
|
argon2_position_t position = { r, l, (uint8_t)s, 0 };
|
|
|
|
|
fill_segment(instance, position);
|
|
|
|
|
rxa2_fill_segment(instance, position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#ifdef GENKAT
|
|
|
|
@ -242,14 +242,14 @@ static int fill_memory_blocks_st(argon2_instance_t *instance) {
|
|
|
|
|
return ARGON2_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int fill_memory_blocks(argon2_instance_t *instance) {
|
|
|
|
|
int rxa2_fill_memory_blocks(argon2_instance_t *instance) {
|
|
|
|
|
if (instance == NULL || instance->lanes == 0) {
|
|
|
|
|
return ARGON2_INCORRECT_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
return fill_memory_blocks_st(instance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int validate_inputs(const argon2_context *context) {
|
|
|
|
|
int rxa2_validate_inputs(const argon2_context *context) {
|
|
|
|
|
if (NULL == context) {
|
|
|
|
|
return ARGON2_INCORRECT_PARAMETER;
|
|
|
|
|
}
|
|
|
|
@ -378,7 +378,7 @@ int validate_inputs(const argon2_context *context) {
|
|
|
|
|
return ARGON2_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) {
|
|
|
|
|
void rxa2_fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) {
|
|
|
|
|
uint32_t l;
|
|
|
|
|
/* Make the first and second block in each lane as G(H0||0||i) or
|
|
|
|
|
G(H0||1||i) */
|
|
|
|
@ -387,21 +387,21 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) {
|
|
|
|
|
|
|
|
|
|
store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0);
|
|
|
|
|
store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l);
|
|
|
|
|
blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash,
|
|
|
|
|
rxa2_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash,
|
|
|
|
|
ARGON2_PREHASH_SEED_LENGTH);
|
|
|
|
|
load_block(&instance->memory[l * instance->lane_length + 0],
|
|
|
|
|
blockhash_bytes);
|
|
|
|
|
|
|
|
|
|
store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1);
|
|
|
|
|
blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash,
|
|
|
|
|
rxa2_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash,
|
|
|
|
|
ARGON2_PREHASH_SEED_LENGTH);
|
|
|
|
|
load_block(&instance->memory[l * instance->lane_length + 1],
|
|
|
|
|
blockhash_bytes);
|
|
|
|
|
}
|
|
|
|
|
clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE);
|
|
|
|
|
rxa2_clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) {
|
|
|
|
|
void rxa2_initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) {
|
|
|
|
|
blake2b_state BlakeHash;
|
|
|
|
|
uint8_t value[sizeof(uint32_t)];
|
|
|
|
|
|
|
|
|
@ -437,7 +437,7 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type)
|
|
|
|
|
context->pwdlen);
|
|
|
|
|
|
|
|
|
|
if (context->flags & ARGON2_FLAG_CLEAR_PASSWORD) {
|
|
|
|
|
secure_wipe_memory(context->pwd, context->pwdlen);
|
|
|
|
|
rxa2_secure_wipe_memory(context->pwd, context->pwdlen);
|
|
|
|
|
context->pwdlen = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -457,7 +457,7 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type)
|
|
|
|
|
context->secretlen);
|
|
|
|
|
|
|
|
|
|
if (context->flags & ARGON2_FLAG_CLEAR_SECRET) {
|
|
|
|
|
secure_wipe_memory(context->secret, context->secretlen);
|
|
|
|
|
rxa2_secure_wipe_memory(context->secret, context->secretlen);
|
|
|
|
|
context->secretlen = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -473,7 +473,7 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type)
|
|
|
|
|
blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int argon_initialize(argon2_instance_t *instance, argon2_context *context) {
|
|
|
|
|
int rxa2_argon_initialize(argon2_instance_t *instance, argon2_context *context) {
|
|
|
|
|
uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH];
|
|
|
|
|
int result = ARGON2_OK;
|
|
|
|
|
|
|
|
|
@ -491,17 +491,17 @@ int argon_initialize(argon2_instance_t *instance, argon2_context *context) {
|
|
|
|
|
/* H_0 + 8 extra bytes to produce the first blocks */
|
|
|
|
|
/* uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; */
|
|
|
|
|
/* Hashing all inputs */
|
|
|
|
|
initial_hash(blockhash, context, instance->type);
|
|
|
|
|
rxa2_initial_hash(blockhash, context, instance->type);
|
|
|
|
|
/* Zeroing 8 extra bytes */
|
|
|
|
|
clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH,
|
|
|
|
|
rxa2_clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH,
|
|
|
|
|
ARGON2_PREHASH_SEED_LENGTH -
|
|
|
|
|
ARGON2_PREHASH_DIGEST_LENGTH);
|
|
|
|
|
|
|
|
|
|
/* 3. Creating first blocks, we always have at least two blocks in a slice
|
|
|
|
|
*/
|
|
|
|
|
fill_first_blocks(blockhash, instance);
|
|
|
|
|
rxa2_fill_first_blocks(blockhash, instance);
|
|
|
|
|
/* Clearing the hash */
|
|
|
|
|
clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH);
|
|
|
|
|
rxa2_clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH);
|
|
|
|
|
|
|
|
|
|
return ARGON2_OK;
|
|
|
|
|
}
|
|
|
|
|