Small code refactoring in initialization function.

This commit is contained in:
LoRd_MuldeR 2022-10-16 15:49:14 +02:00
parent f1dfff978b
commit 097957f9ab
Signed by: mulder
GPG Key ID: 2B5913365F57E03F

View File

@ -151,22 +151,23 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
{
uint8_t temp[256U][256U];
size_t r, i;
rand_state_t *const rand_state = &data->thread_data[0].random;
const int reverse_mode = BOOLIFY(mode);
/* initialize state */
slunkcrypt_bzero(data, sizeof(crypt_data_t));
/* initialize counter */
random_seed(&data->thread_data[0].random, nonce, legacy ? ((uint16_t)(-1)) : INITIALIZER_MIN, passwd, passwd_len, legacy);
data->thread_data[0].counter = random_next(&data->thread_data[0].random);
random_seed(rand_state, nonce, legacy ? ((uint16_t)(-1)) : INITIALIZER_MIN, passwd, passwd_len, legacy);
data->thread_data[0].counter = random_next(rand_state);
/* set up the wheel permutations */
for (r = 0U; r < 256U; ++r)
{
random_seed(&data->thread_data[0].random, nonce, legacy ? ((uint16_t)r) : INITIALIZER[r], passwd, passwd_len, legacy);
random_seed(rand_state, nonce, legacy ? ((uint16_t)r) : INITIALIZER[r], passwd, passwd_len, legacy);
for (i = 0U; i < 256U; ++i)
{
const size_t j = random_next(&data->thread_data[0].random) % (i + 1U);
const size_t j = random_next(rand_state) % (i + 1U);
if (j != i)
{
data->wheel[r][i] = data->wheel[r][j];
@ -195,25 +196,24 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
}
/* initialize thread state */
data->thread_data[0].reverse_mode = reverse_mode;
data->thread_data[0].wheel = (const uint8_t(*)[256]) data->wheel;
data->thread_data[0].index_off = 0U;
random_seed(&data->thread_data[0].random, nonce, legacy ? 256U : INITIALIZER_MAX, passwd, passwd_len, legacy);
for (i = 1U; i < thread_count; ++i)
random_seed(rand_state, nonce, legacy ? 256U : INITIALIZER_MAX, passwd, passwd_len, legacy);
for (i = 0U; i < thread_count; ++i)
{
data->thread_data[i].reverse_mode = reverse_mode;
data->thread_data[i].wheel = (const uint8_t(*)[256]) data->wheel;
data->thread_data[i].index_off = i;
if (i > 0U)
{
data->thread_data[i].reverse_mode = data->thread_data[0].reverse_mode;
data->thread_data[i].wheel = data->thread_data[0].wheel;
data->thread_data[i].counter = data->thread_data[0].counter + ((uint32_t)i);
data->thread_data[i].index_off = data->thread_data[i - 1U].index_off + 1U;
memcpy(&data->thread_data[i].random, &data->thread_data[0].random, sizeof(rand_state_t));
random_skip(&data->thread_data[i].random, i * 63U);
}
CHECK_ABORTED();
}
/* dump the final configuration */
if (debug)
{
const rand_state_t *const rand_state = &data->thread_data[0].random;
slunkcrypt_debug_print("cntr = %08X", data->thread_data[0].counter);
slunkcrypt_debug_print("drbg = %08X %08X %08X %08X %08X %08X", rand_state->d, rand_state->v, rand_state->w, rand_state->x, rand_state->y, rand_state->z);
for (r = 0U; r < 256U; ++r)