From 75b10acd6ac5a0adf5ab70be42fe61e39659096c Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Thu, 1 Apr 2021 00:36:04 +0200 Subject: [PATCH] Small fix to rotation code. --- libslunkcrypt/src/slunkcrypt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libslunkcrypt/src/slunkcrypt.c b/libslunkcrypt/src/slunkcrypt.c index c6b71dc..1eef425 100644 --- a/libslunkcrypt/src/slunkcrypt.c +++ b/libslunkcrypt/src/slunkcrypt.c @@ -297,7 +297,8 @@ static FORCE_INLINE uint8_t process_encrypt(crypt_state_t* const crypt_state, ui size_t i; for (i = 0U; i < 256U; ++i) { - value = crypt_state->wheel_fwd[i][(value + crypt_state->rotation_fwd[i]) & 0xFF]; + const uint8_t rotation = crypt_state->rotation_fwd[i]; + value = (crypt_state->wheel_fwd[i][(value + rotation) & 0xFF] - rotation) & 0xFF; } ++crypt_state->rotation_fwd[crypt_state->step_fwd[crypt_state->counter]]; odometer_step(crypt_state->rotation_fwd, 0); @@ -310,7 +311,8 @@ static FORCE_INLINE uint8_t process_decrypt(crypt_state_t* const crypt_state, ui size_t i; for (i = 0U; i < 256U; ++i) { - value = (crypt_state->wheel_bwd[i][value] - crypt_state->rotation_bwd[i]) & 0xFF; + const uint8_t rotation = crypt_state->rotation_bwd[i]; + value = (crypt_state->wheel_bwd[i][(value + rotation) & 0xFF] - rotation) & 0xFF; } ++crypt_state->rotation_bwd[crypt_state->step_bwd[crypt_state->counter]]; odometer_step(crypt_state->rotation_bwd, 1);