Skip to content

Commit

Permalink
Argon2: Reverted overzealous removal of divides
Browse files Browse the repository at this point in the history
  • Loading branch information
Sc00bz authored and solardiz committed Nov 9, 2024
1 parent 51fadbe commit 876b2ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
11 changes: 3 additions & 8 deletions src/argon2_opt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void argon2_fill_segment(const argon2_instance_t *instance,
block address_block, input_block;
uint64_t pseudo_rand, ref_index, ref_lane;
uint32_t prev_offset, curr_offset;
uint32_t starting_index, i, i_address;
uint32_t starting_index, i;
uint32_t lanes_reciprocal = 0;
uint32_t lanes = instance->lanes;
#if defined(__AVX512F__)
Expand Down Expand Up @@ -245,20 +245,15 @@ void argon2_fill_segment(const argon2_instance_t *instance,

memcpy(state, ((instance->memory + prev_offset)->v), ARGON2_BLOCK_SIZE);

i_address = starting_index;
for (i = starting_index; i < instance->segment_length;
++i, ++curr_offset) {
/* 1.2 Computing the index of the reference block */
/* 1.2.1 Taking pseudo-random value from the previous block */
if (data_independent_addressing) {
if (i_address == 0) {
if (i % ARGON2_ADDRESSES_IN_BLOCK == 0) {
next_addresses(&address_block, &input_block);
}
pseudo_rand = address_block.v[i_address];
i_address++;
if (i_address >= ARGON2_ADDRESSES_IN_BLOCK) {
i_address = 0;
}
pseudo_rand = address_block.v[i % ARGON2_ADDRESSES_IN_BLOCK];
} else {
pseudo_rand = instance->memory[prev_offset].v[0];
prev_offset = curr_offset;
Expand Down
10 changes: 2 additions & 8 deletions src/argon2_ref_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ void argon2_fill_segment(const argon2_instance_t *instance,
uint32_t prev_offset, curr_offset;
uint32_t starting_index;
uint32_t i;
uint32_t i_address;
uint32_t lanes_reciprocal = 0;
uint32_t lanes = instance->lanes;
int data_independent_addressing;
Expand Down Expand Up @@ -155,20 +154,15 @@ void argon2_fill_segment(const argon2_instance_t *instance,
lanes_reciprocal = (uint32_t) (UINT64_C(0x100000000) / lanes);
}

i_address = starting_index;
for (i = starting_index; i < instance->segment_length;
++i, ++curr_offset) {
/* 1.2 Computing the index of the reference block */
/* 1.2.1 Taking pseudo-random value from the previous block */
if (data_independent_addressing) {
if (i_address == 0) {
if (i % ARGON2_ADDRESSES_IN_BLOCK == 0) {
next_addresses(&address_block, &input_block, &zero_block);
}
pseudo_rand = address_block.v[i_address];
i_address++;
if (i_address >= ARGON2_ADDRESSES_IN_BLOCK) {
i_address = 0;
}
pseudo_rand = address_block.v[i % ARGON2_ADDRESSES_IN_BLOCK];
} else {
pseudo_rand = instance->memory[prev_offset].v[0];
}
Expand Down

0 comments on commit 876b2ba

Please sign in to comment.