Revamped the stepping algorithm.
This commit is contained in:
parent
163dee5e9d
commit
26cfd32d24
@ -24,6 +24,9 @@
|
|||||||
# define UNUSED
|
# define UNUSED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Utilities */
|
||||||
|
#define LOGICAL_XOR(X,Y) ((Y) ? (!(X)) : (X))
|
||||||
|
|
||||||
/* Version info */
|
/* Version info */
|
||||||
const uint16_t SLUNKCRYPT_VERSION_MAJOR = MY_VERSION_MAJOR;
|
const uint16_t SLUNKCRYPT_VERSION_MAJOR = MY_VERSION_MAJOR;
|
||||||
const uint16_t SLUNKCRYPT_VERSION_MINOR = MY_VERSION_MINOR;
|
const uint16_t SLUNKCRYPT_VERSION_MINOR = MY_VERSION_MINOR;
|
||||||
@ -54,8 +57,8 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint8_t wheel_fwd[256U][256U];
|
uint8_t wheel_fwd[256U][256U];
|
||||||
uint8_t wheel_bwd[256U][256U];
|
uint8_t wheel_bwd[256U][256U];
|
||||||
uint8_t step_fwd[247U];
|
uint8_t step_fwd[241U];
|
||||||
uint8_t step_bwd[247U];
|
uint8_t step_bwd[241U];
|
||||||
uint8_t rotation_fwd[256U];
|
uint8_t rotation_fwd[256U];
|
||||||
uint8_t rotation_bwd[256U];
|
uint8_t rotation_bwd[256U];
|
||||||
uint8_t counter;
|
uint8_t counter;
|
||||||
@ -249,7 +252,7 @@ static int initialize_state(crypt_state_t* const crypt_state, const uint64_t non
|
|||||||
|
|
||||||
/* set up stepping */
|
/* set up stepping */
|
||||||
random_seed(&rand_state, nonce, 256U, passwd, passwd_len);
|
random_seed(&rand_state, nonce, 256U, passwd, passwd_len);
|
||||||
for (i = 0U; i < 247U; ++i)
|
for (i = 0U; i < 241U; ++i)
|
||||||
{
|
{
|
||||||
const size_t j = random_next(&rand_state) % (i + 1U);
|
const size_t j = random_next(&rand_state) % (i + 1U);
|
||||||
if (j != i)
|
if (j != i)
|
||||||
@ -269,23 +272,24 @@ static int initialize_state(crypt_state_t* const crypt_state, const uint64_t non
|
|||||||
// Encrypt / Decrypt
|
// Encrypt / Decrypt
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
static FORCE_INLINE void odometer_step(uint8_t *const arr, const int bwd)
|
static FORCE_INLINE void increment(uint8_t *const arr, const size_t offset, const size_t limit, const int bwd)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0U; i < 6U; ++i)
|
for (i = offset; i < limit; ++i)
|
||||||
{
|
{
|
||||||
if (++arr[bwd ? (255U - i) : i] != 0U)
|
if (++arr[bwd ? (255U - i) : i] != 0U)
|
||||||
{
|
{
|
||||||
break;
|
break; /*no carry*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0U; i < 3U; ++i)
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE void odometer_step(uint8_t *const arr, const int bwd)
|
||||||
{
|
{
|
||||||
if (++arr[bwd ? i : (255U - i)] != 0U)
|
increment(arr, 0U, 6U, LOGICAL_XOR(bwd, 0));
|
||||||
{
|
increment(arr, 0U, 3U, LOGICAL_XOR(bwd, 1));
|
||||||
break;
|
increment(arr, 3U, 6U, LOGICAL_XOR(bwd, 1));
|
||||||
}
|
increment(arr, 6U, 9U, LOGICAL_XOR(bwd, 1));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE uint8_t process_encrypt(crypt_state_t* const crypt_state, uint8_t value)
|
static FORCE_INLINE uint8_t process_encrypt(crypt_state_t* const crypt_state, uint8_t value)
|
||||||
@ -297,7 +301,7 @@ static FORCE_INLINE uint8_t process_encrypt(crypt_state_t* const crypt_state, ui
|
|||||||
}
|
}
|
||||||
++crypt_state->rotation_fwd[crypt_state->step_fwd[crypt_state->counter]];
|
++crypt_state->rotation_fwd[crypt_state->step_fwd[crypt_state->counter]];
|
||||||
odometer_step(crypt_state->rotation_fwd, 0);
|
odometer_step(crypt_state->rotation_fwd, 0);
|
||||||
crypt_state->counter = (crypt_state->counter + 1U) % 247U;
|
crypt_state->counter = (crypt_state->counter + 1U) % 241U;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +314,7 @@ static FORCE_INLINE uint8_t process_decrypt(crypt_state_t* const crypt_state, ui
|
|||||||
}
|
}
|
||||||
++crypt_state->rotation_bwd[crypt_state->step_bwd[crypt_state->counter]];
|
++crypt_state->rotation_bwd[crypt_state->step_bwd[crypt_state->counter]];
|
||||||
odometer_step(crypt_state->rotation_bwd, 1);
|
odometer_step(crypt_state->rotation_bwd, 1);
|
||||||
crypt_state->counter = (crypt_state->counter + 1U) % 247U;
|
crypt_state->counter = (crypt_state->counter + 1U) % 241U;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user