mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-28 20:57:13 +09:00
Argon2: Let fill_{memory_blocks,segment} return an error code
This commit is contained in:
@@ -264,11 +264,12 @@ uint32_t index_alpha(const argon2_instance_t *instance,
|
||||
return absolute_position;
|
||||
}
|
||||
|
||||
void fill_memory_blocks(argon2_instance_t *instance) {
|
||||
int fill_memory_blocks(argon2_instance_t *instance) {
|
||||
int result;
|
||||
uint32_t r, s;
|
||||
|
||||
if (instance == NULL || instance->lanes == 0) {
|
||||
return;
|
||||
return ARGON2_OK;
|
||||
}
|
||||
|
||||
for (r = 0; r < instance->passes; ++r) {
|
||||
@@ -282,10 +283,14 @@ void fill_memory_blocks(argon2_instance_t *instance) {
|
||||
position.lane = l;
|
||||
position.slice = (uint8_t)s;
|
||||
position.index = 0;
|
||||
fill_segment(instance, position);
|
||||
result = fill_segment(instance, position);
|
||||
if (ARGON2_OK != result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ARGON2_OK;
|
||||
}
|
||||
|
||||
int validate_inputs(const argon2_context *context) {
|
||||
|
||||
@@ -179,19 +179,20 @@ void finalize(const argon2_context *context, argon2_instance_t *instance);
|
||||
* @param position Current position
|
||||
* @pre all block pointers must be valid
|
||||
*/
|
||||
typedef void (*fill_segment_fn)(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
typedef int (*fill_segment_fn)(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
int argon2_pick_best_implementation(void);
|
||||
void fill_segment_ssse3(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
void fill_segment_ref(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
int fill_segment_ssse3(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
int fill_segment_ref(const argon2_instance_t *instance,
|
||||
argon2_position_t position);
|
||||
|
||||
/*
|
||||
* Function that fills the entire memory t_cost times based on the first two
|
||||
* blocks in each lane
|
||||
* @param instance Pointer to the current instance
|
||||
* @return Zero if successful, -1 if memory failed to allocate
|
||||
*/
|
||||
void fill_memory_blocks(argon2_instance_t *instance);
|
||||
int fill_memory_blocks(argon2_instance_t *instance);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -102,8 +102,8 @@ static void generate_addresses(const argon2_instance_t *instance,
|
||||
}
|
||||
}
|
||||
|
||||
void fill_segment_ref(const argon2_instance_t *instance,
|
||||
argon2_position_t position) {
|
||||
int fill_segment_ref(const argon2_instance_t *instance,
|
||||
argon2_position_t position) {
|
||||
block *ref_block = NULL, *curr_block = NULL;
|
||||
uint64_t pseudo_rand, ref_index, ref_lane;
|
||||
uint32_t prev_offset, curr_offset;
|
||||
@@ -114,7 +114,7 @@ void fill_segment_ref(const argon2_instance_t *instance,
|
||||
uint64_t *pseudo_rands = NULL;
|
||||
|
||||
if (instance == NULL) {
|
||||
return;
|
||||
return ARGON2_OK;
|
||||
}
|
||||
|
||||
data_independent_addressing = (instance->type == Argon2_i);
|
||||
@@ -123,7 +123,7 @@ void fill_segment_ref(const argon2_instance_t *instance,
|
||||
(uint64_t *)malloc(sizeof(uint64_t) * (instance->segment_length));
|
||||
|
||||
if (pseudo_rands == NULL) {
|
||||
return;
|
||||
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
|
||||
if (data_independent_addressing) {
|
||||
@@ -186,5 +186,7 @@ void fill_segment_ref(const argon2_instance_t *instance,
|
||||
}
|
||||
|
||||
free(pseudo_rands);
|
||||
|
||||
return ARGON2_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ static void generate_addresses(const argon2_instance_t *instance,
|
||||
}
|
||||
}
|
||||
|
||||
void fill_segment_ssse3(const argon2_instance_t *instance,
|
||||
argon2_position_t position) {
|
||||
int fill_segment_ssse3(const argon2_instance_t *instance,
|
||||
argon2_position_t position) {
|
||||
block *ref_block = NULL, *curr_block = NULL;
|
||||
uint64_t pseudo_rand, ref_index, ref_lane;
|
||||
uint32_t prev_offset, curr_offset;
|
||||
@@ -107,7 +107,7 @@ void fill_segment_ssse3(const argon2_instance_t *instance,
|
||||
uint64_t *pseudo_rands = NULL;
|
||||
|
||||
if (instance == NULL) {
|
||||
return;
|
||||
return ARGON2_OK;
|
||||
}
|
||||
|
||||
data_independent_addressing = (instance->type == Argon2_i);
|
||||
@@ -115,7 +115,7 @@ void fill_segment_ssse3(const argon2_instance_t *instance,
|
||||
pseudo_rands =
|
||||
(uint64_t *)malloc(sizeof(uint64_t) * instance->segment_length);
|
||||
if (pseudo_rands == NULL) {
|
||||
return;
|
||||
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
|
||||
if (data_independent_addressing) {
|
||||
@@ -180,5 +180,7 @@ void fill_segment_ssse3(const argon2_instance_t *instance,
|
||||
}
|
||||
|
||||
free(pseudo_rands);
|
||||
|
||||
return ARGON2_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -69,7 +69,11 @@ int argon2_core(argon2_context *context, argon2_type type) {
|
||||
}
|
||||
|
||||
/* 4. Filling memory */
|
||||
fill_memory_blocks(&instance);
|
||||
result = fill_memory_blocks(&instance);
|
||||
|
||||
if (ARGON2_OK != result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* 5. Finalization */
|
||||
finalize(context, &instance);
|
||||
|
||||
Reference in New Issue
Block a user