1
0
Fork 0

Some code refactoring + adjust number of random skips.

This commit is contained in:
LoRd_MuldeR 2022-10-13 21:27:09 +02:00
parent 147d762ebc
commit 38cf7c3c25
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
10 changed files with 68 additions and 42 deletions

View File

@ -67,7 +67,7 @@ static void init_slunk_param(slunkparam_t *const param, const crypt_options_t *c
slunkcrypt_bzero(param, sizeof(slunkparam_t));
param->version = SLUNKCRYPT_PARAM_VERSION;
param->thread_count = options->thread_count;
param->legacy_init = options->legacy_init;
param->legacy_compat = options->legacy_compat;
}
#define UPDATE_PROGRESS_INDICATOR(CLK_UPDATE, CURRENT, TOTAL) do \

View File

@ -11,7 +11,7 @@
typedef struct
{
int keep_incomplete;
int legacy_init;
int legacy_compat;
size_t thread_count;
}
crypt_options_t;

View File

@ -121,7 +121,7 @@ static uint32_t environ_get_uint(const CHR *const name)
static int environ_get_flag(const CHR *const name)
{
return (environ_get_uint(name) != 0U);
return (environ_get_uint(name) != 0U) ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE;
}
static void check_excess_arguments(const int argc, int maximum)

View File

@ -224,7 +224,7 @@ int run_selftest_routine(const size_t thread_count)
{
for (size_t j = 0U; j < ITERATIONS; ++j)
{
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, (j > 0) };
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, (j > 0) ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE };
for (size_t k = 0U; k < ARRAY_SIZE(TEST_NONCE); ++k)
{
FPRINTF(stderr, T("\b\b\b\b\b\b%2u/%2u "), (unsigned)++count, (unsigned)total);
@ -237,7 +237,7 @@ int run_selftest_routine(const size_t thread_count)
}
}
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, 0 };
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, SLUNKCRYPT_FALSE };
for (size_t i = 0U; i < ITERATIONS; ++i)
{
for (size_t j = 0U; j < ARRAY_SIZE(TEST_NONCE); ++j)

View File

@ -13,7 +13,7 @@
// Test #1
// ==========================================================================
const uint64_t TEST_CHCK_ORIG_0 = 0x407DA53F1660C8C7, TEST_CHCK_ENCR_0[4U] = { 0x9A6C6847A4B81265, 0xF91724F2DAAC320E, 0x3329F2A405D3DF93, 0x9B8E256B3437468B };
const uint64_t TEST_CHCK_ORIG_0 = 0x407DA53F1660C8C7, TEST_CHCK_ENCR_0[4U] = { 0x5B79ECE785D60F7E, 0xDB761BCDEAB2FB30, 0x3329F2A405D3DF93, 0x9B8E256B3437468B };
const char* const TEST_DATA_0 =
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit"
@ -53,7 +53,7 @@ const char* const TEST_DATA_0 =
// Test #2
// ==========================================================================
const uint64_t TEST_CHCK_ORIG_1 = 0xE6EB3C50FAA52062, TEST_CHCK_ENCR_1[4U] = { 0x08CB7843CBA7D4FC, 0x28DDFD9383347AC6, 0x38E126F893A67351, 0xAB929BFE9FDD40F8 };
const uint64_t TEST_CHCK_ORIG_1 = 0xE6EB3C50FAA52062, TEST_CHCK_ENCR_1[4U] = { 0x928AEC9319326D3C, 0x1D7764D1B7EFE61F, 0x38E126F893A67351, 0xAB929BFE9FDD40F8 };
const char* const TEST_DATA_1 =
"agcttttcattctgactgcaacgggcaatatgtctctgtgtggattaaaaaaagagtgtctgatagcagcttctgaactggttacctgccgtgagtaaattaaaattttattgacttaggtcactaaatactttaaccaatataggcatagcgcacagacagataaaaattacagagtacacaacatccatgaaacgcattagcaccaccattaccaccaccatcaccattaccacaggtaacggtgcgggctgacgcgtacaggaaacacagaaaaaagcccgcacctgacagtgcgggctttttttttcgaccaaaggtaacgaggtaacaaccatgcgagtgttgaagttcggcggtacatcagtggcaaatgcagaacgttttctgcgtgttgccgatattctggaaagcaatgccaggcaggggcaggtggccaccgtcctctctgcccccgccaaaatcaccaaccacctggtggcgatgattgaaaaaaccattagcggccaggatgctttacccaatatcagcgatgccgaacgtatttttgccgaacttttgacgggactcgccgccgcccagccggggttcccgctggcgcaattgaaaactttcgtcgatcaggaatttgcccaaataaaacatgtcctgcatggcattagtttgttggggcagtgcccggatagcatcaacgctgcgctgatttgccgtggcgagaaaatgtcgatcgccattatggccggcgtattagaagcgcgcggtcacaacgttactgttatcgatccggtcgaaaaactgctggcagtggggcattacctcgaatctaccgtcgatattgctgagtccacccgccgtattgcggcaagccgcattccggctgatcacatggtgctgatggcaggtttcaccgccggtaatgaaaaaggcgaactggtggtgcttggacgcaacggttccgactactctgctgcggtgctggctgcctgtttacgcgccgattgttgcgagatttggacggacgttgacggggtctatacctgcgacccgcgtcaggtgcccgatgcgaggttgttgaagtcgatgtcctaccaggaagcgatggagctttcctacttcggcgctaaagttcttcacccccgcaccattacccccatcgcccagttccagatcccttgcctgattaaaaataccggaaatcctcaagcaccaggtacgctcattggtgccagccgtgatgaagacgaattaccggtcaagggcatttccaatctgaataacatggcaatgttcagcgtttctggtccggggatgaaagggatggtcggcatggcggcgcgcgtctttgcagcgatgtcacgcgcccgtatttccgtggtgctgattacgcaatcatcttccgaatacagcatcagtttctgcgttccacaaagcgactgtgtgcgagctgaacgggcaatgcaggaagagttctacctggaactgaaagaaggcttactggagccgctggcagtgacggaacggctggccattatctcggtggtaggtgatggtatgcgcaccttgcgtgggatctcggcgaaattctttgccgcactggcccgcgccaatatcaacattgtcgccattgctcagggatcttctgaacgctcaatctctgtcgtggtaaataacgatgatgcgaccactggcgtgcgcgttactcatcagatgctgttcaataccgatcaggttatcgaagtgtttgtgattggcgtcggtggcgttggcggtgcgctgctggagcaactgaagcgtcagcaaagctggctgaagaataaacatatcgacttacgtgtctgcggtgttgccaactcgaaggctctgctcaccaatgtacatggccttaatctggaaaactggcaggaagaactggcgcaagccaaagagccgtttaatctcgggcgcttaattcgcctcgtgaaagaatatcatctgctgaacccggtcattgttgactgcacttccagccaggcagtggcggatcaatatgccgacttcctgcgcgaagg"
@ -93,7 +93,7 @@ const char* const TEST_DATA_1 =
// Test #3
// ==========================================================================
const uint64_t TEST_CHCK_ORIG_2 = 0xA0F9B63134DEF8B8, TEST_CHCK_ENCR_2[4U] = { 0x8C4ABE00FFC5C079, 0xD30E4FF176F8022E, 0xB4D0230508931578, 0x537B8A98B4F857AC };
const uint64_t TEST_CHCK_ORIG_2 = 0xA0F9B63134DEF8B8, TEST_CHCK_ENCR_2[4U] = { 0x96013C419AFDD5C6, 0x65C8C1EBC9319E07, 0xB4D0230508931578, 0x537B8A98B4F857AC };
const char* const TEST_DATA_2 =
"In the beginning God created the heaven and the earth. And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. And God said, Let there be light: and there was light. And God saw the light, that it was good: and God divided the light from the darkness. And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day. And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters. And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so. And God called the firmament Heaven. And the evening and the morning were the second day. And God said, Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so. And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good. And God said, Let the earth bring forth grass, the herb yielding seed, and the fruit tree yielding fruit after his kind, whose seed is in itself, upon the earth: and it was so. And the earth brought forth grass, and herb yielding seed after his kind, and the tree yielding fruit, whose seed was in itself, after his kind: and God saw that it was good. And the evening and the morning were the third day. And God said, Let there be lights in the firmament of the heaven to divide the day from the night; and let them be for signs, and for seasons, and for days, and years: And let them be for lights in the firmament of the heaven to give light upon the earth: and it was so. And God made two great lights; the greater light to rule the day, and the lesser light to rule the night: he made the stars also. And God set them in the firmament of the heaven to give light upon the earth, And to rule over the day and over the night, and to divide the light from the darkness: and God saw that it was g"
@ -133,7 +133,7 @@ const char* const TEST_DATA_2 =
// Test #4
// ==========================================================================
const uint64_t TEST_CHCK_ORIG_3 = 0x4B28AB3A096F81C8, TEST_CHCK_ENCR_3[4U] = { 0x19D4C458C939F90C, 0xC010654E9959F418, 0xCE2B6BDF11631CD1, 0x9A6E766CF732F29A };
const uint64_t TEST_CHCK_ORIG_3 = 0x4B28AB3A096F81C8, TEST_CHCK_ENCR_3[4U] = { 0xC9242983D0EA0955, 0x6A0B33CE51D4396B, 0xCE2B6BDF11631CD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4$GLbov<!u[iI?t*n13:32\"qM[fL{be?Vp9<~TIj&Y^t#c"

View File

@ -56,6 +56,12 @@ extern "C" {
typedef uintptr_t slunkcrypt_t;
#define SLUNKCRYPT_NULL ((slunkcrypt_t)NULL)
/*
* Boolean flags
*/
static const int SLUNKCRYPT_FALSE = 0;
static const int SLUNKCRYPT_TRUE = 1;
/*
* Mode of operation
*/
@ -83,7 +89,7 @@ typedef struct
{
uint16_t version; /* Must set to SLUNKCRYPT_PARAM_VERSION */
size_t thread_count; /* Number of threads, set to 0 for auto-detection */
int legacy_init; /* Compatibility with pre-1.3.x versions */
int legacy_compat; /* Compatibility with pre-1.3 versions */
}
slunkparam_t;

View File

@ -60,6 +60,7 @@
<ClInclude Include="include\slunkcrypt.h" />
<ClInclude Include="include\slunkcrypt.hpp" />
<ClInclude Include="src\compiler.h" />
<ClInclude Include="src\initialize.h" />
<ClInclude Include="src\keygen.h" />
<ClInclude Include="src\thread.h" />
<ClInclude Include="src\version.h" />

View File

@ -47,5 +47,8 @@
<ClInclude Include="src\thread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\initialize.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,35 @@
/******************************************************************************/
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
#ifndef INC_SLUNKCRYPT_INITIALIZE_H
#define INC_SLUNKCRYPT_INITIALIZE_H
#include <stdint.h>
/* list of the 256+2 largest 16-bit "safe" prime numbers */
static const uint16_t INITIALIZER[256U] =
{
0x5C4B, 0x5C6F, 0x5D0B, 0x5D47, 0x5DD7, 0x5E13, 0x5E8B, 0x5EAF, 0x5F57, 0x5FCF, 0x6053, 0x62DB, 0x62FF, 0x63EF, 0x642B, 0x64C7,
0x64F7, 0x653F, 0x6593, 0x65F3, 0x675B, 0x6803, 0x6917, 0x692F, 0x69E3, 0x6A67, 0x6AA3, 0x6B87, 0x6C77, 0x6C9B, 0x6CB3, 0x6D73,
0x6E03, 0x6E93, 0x6E9F, 0x6F53, 0x6FBF, 0x6FE3, 0x7133, 0x71C3, 0x723B, 0x729B, 0x72D7, 0x732B, 0x737F, 0x73DF, 0x743F, 0x74B7,
0x75FB, 0x7673, 0x768B, 0x7703, 0x774B, 0x7853, 0x79A3, 0x7A1B, 0x7B3B, 0x7B5F, 0x7B77, 0x7C67, 0x7D03, 0x7DB7, 0x7EFB, 0x7F5B,
0x804B, 0x80DB, 0x8153, 0x8243, 0x8357, 0x836F, 0x83E7, 0x8447, 0x860F, 0x863F, 0x8717, 0x876B, 0x878F, 0x8957, 0x8A0B, 0x8A23,
0x8C27, 0x8C7B, 0x8CF3, 0x8DA7, 0x8DCB, 0x8E1F, 0x8E73, 0x8F4B, 0x9017, 0x903B, 0x9257, 0x92AB, 0x92E7, 0x93A7, 0x95B7, 0x96CB,
0x96EF, 0x975B, 0x977F, 0x97D3, 0x98C3, 0x98CF, 0x999B, 0x99FB, 0x9A4F, 0x9B63, 0x9B93, 0x9B9F, 0x9C2F, 0x9CBF, 0x9E33, 0x9F23,
0x9F53, 0x9F77, 0x9FB3, 0xA1AB, 0xA223, 0xA22F, 0xA247, 0xA26B, 0xA31F, 0xA373, 0xA397, 0xA3C7, 0xA427, 0xA4C3, 0xA53B, 0xA577,
0xA5CB, 0xA6BB, 0xA70F, 0xA757, 0xA8D7, 0xA98B, 0xA9A3, 0xAA57, 0xAB0B, 0xABFB, 0xAC7F, 0xACEB, 0xADE7, 0xADFF, 0xAE8F, 0xAE9B,
0xAF13, 0xAF43, 0xAF8B, 0xAFA3, 0xB01B, 0xB1BF, 0xB28B, 0xB33F, 0xB477, 0xB5DF, 0xB633, 0xB657, 0xB747, 0xB813, 0xB867, 0xB8EB,
0xB993, 0xBA17, 0xBACB, 0xBB5B, 0xBD17, 0xBD5F, 0xBDB3, 0xBF33, 0xBF7B, 0xBFCF, 0xC047, 0xC0D7, 0xC15B, 0xC317, 0xC3E3, 0xC51B,
0xC767, 0xC803, 0xC857, 0xC893, 0xC8CF, 0xC98F, 0xC9E3, 0xCA73, 0xCA7F, 0xCBFF, 0xCC9B, 0xCEB7, 0xCF0B, 0xCF9B, 0xD013, 0xD1C3,
0xD1FF, 0xD217, 0xD2E3, 0xD40F, 0xD523, 0xD6AF, 0xD727, 0xD73F, 0xD77B, 0xD8BF, 0xD8FB, 0xD943, 0xD9EB, 0xDA9F, 0xDAC3, 0xDAE7,
0xDDE7, 0xDEA7, 0xDF1F, 0xDF37, 0xDFC7, 0xE09F, 0xE0F3, 0xE177, 0xE1CB, 0xE22B, 0xE243, 0xE2BB, 0xE2D3, 0xE423, 0xE537, 0xE567,
0xE61B, 0xE657, 0xE6B7, 0xE837, 0xE963, 0xEC7B, 0xECE7, 0xED6B, 0xEDE3, 0xEF9F, 0xEFC3, 0xF06B, 0xF107, 0xF20F, 0xF257, 0xF35F,
0xF42B, 0xF4AF, 0xF5DB, 0xF743, 0xF7D3, 0xF863, 0xF86F, 0xF8E7, 0xFA07, 0xFA13, 0xFB1B, 0xFB3F, 0xFCFB, 0xFE27, 0xFE63, 0xFE7B
};
static const uint16_t INITIALIZER_MIN = 0x5C33;
static const uint16_t INITIALIZER_MAX = 0xFEF3;
#endif

View File

@ -7,6 +7,7 @@
#include "slunkcrypt.h"
#include "compiler.h"
#include "keygen.h"
#include "initialize.h"
#include "thread.h"
#include "version.h"
@ -56,7 +57,7 @@ crypt_data_t;
typedef struct
{
int legacy_init;
int legacy_compat;
thrdpl_t *thread_pool;
crypt_data_t data;
}
@ -122,7 +123,7 @@ static INLINE void random_skip(rand_state_t *const state, const size_t skip_coun
size_t i;
for (i = 0U; i < skip_count; ++i)
{
UNUSED /*volatile*/ uint32_t q = random_next(state);
UNUSED /*volatile*/ uint32_t discard = random_next(state);
}
}
@ -136,33 +137,13 @@ static INLINE void random_seed(rand_state_t *const state, uint64_t salt, const u
slunkcrypt_bzero(&key, sizeof(keydata_t));
}
while (!(state->x || state->y || state->z || state->w || state->v));
random_skip(state, 97U);
random_skip(state, legacy ? 97U : 23U);
}
// ==========================================================================
// Initialization
// ==========================================================================
static const uint16_t INITIALIZER[256U] =
{
0x5C33, 0x5C4B, 0x5C6F, 0x5D0B, 0x5D47, 0x5DD7, 0x5E13, 0x5E8B, 0x5EAF, 0x5F57, 0x5FCF, 0x6053, 0x62DB, 0x62FF, 0x63EF, 0x642B,
0x64C7, 0x64F7, 0x653F, 0x6593, 0x65F3, 0x675B, 0x6803, 0x6917, 0x692F, 0x69E3, 0x6A67, 0x6AA3, 0x6B87, 0x6C77, 0x6C9B, 0x6CB3,
0x6D73, 0x6E03, 0x6E93, 0x6E9F, 0x6F53, 0x6FBF, 0x6FE3, 0x7133, 0x71C3, 0x723B, 0x729B, 0x72D7, 0x732B, 0x737F, 0x73DF, 0x743F,
0x74B7, 0x75FB, 0x7673, 0x768B, 0x7703, 0x774B, 0x7853, 0x79A3, 0x7A1B, 0x7B3B, 0x7B5F, 0x7B77, 0x7C67, 0x7D03, 0x7DB7, 0x7EFB,
0x7F5B, 0x804B, 0x80DB, 0x8153, 0x8243, 0x8357, 0x836F, 0x83E7, 0x8447, 0x860F, 0x863F, 0x8717, 0x876B, 0x878F, 0x8957, 0x8A0B,
0x8A23, 0x8C27, 0x8C7B, 0x8CF3, 0x8DA7, 0x8DCB, 0x8E1F, 0x8E73, 0x8F4B, 0x9017, 0x903B, 0x9257, 0x92AB, 0x92E7, 0x93A7, 0x95B7,
0x96CB, 0x96EF, 0x975B, 0x977F, 0x97D3, 0x98C3, 0x98CF, 0x999B, 0x99FB, 0x9A4F, 0x9B63, 0x9B93, 0x9B9F, 0x9C2F, 0x9CBF, 0x9E33,
0x9F23, 0x9F53, 0x9F77, 0x9FB3, 0xA1AB, 0xA223, 0xA22F, 0xA247, 0xA26B, 0xA31F, 0xA373, 0xA397, 0xA3C7, 0xA427, 0xA4C3, 0xA53B,
0xA577, 0xA5CB, 0xA6BB, 0xA70F, 0xA757, 0xA8D7, 0xA98B, 0xA9A3, 0xAA57, 0xAB0B, 0xABFB, 0xAC7F, 0xACEB, 0xADE7, 0xADFF, 0xAE8F,
0xAE9B, 0xAF13, 0xAF43, 0xAF8B, 0xAFA3, 0xB01B, 0xB1BF, 0xB28B, 0xB33F, 0xB477, 0xB5DF, 0xB633, 0xB657, 0xB747, 0xB813, 0xB867,
0xB8EB, 0xB993, 0xBA17, 0xBACB, 0xBB5B, 0xBD17, 0xBD5F, 0xBDB3, 0xBF33, 0xBF7B, 0xBFCF, 0xC047, 0xC0D7, 0xC15B, 0xC317, 0xC3E3,
0xC51B, 0xC767, 0xC803, 0xC857, 0xC893, 0xC8CF, 0xC98F, 0xC9E3, 0xCA73, 0xCA7F, 0xCBFF, 0xCC9B, 0xCEB7, 0xCF0B, 0xCF9B, 0xD013,
0xD1C3, 0xD1FF, 0xD217, 0xD2E3, 0xD40F, 0xD523, 0xD6AF, 0xD727, 0xD73F, 0xD77B, 0xD8BF, 0xD8FB, 0xD943, 0xD9EB, 0xDA9F, 0xDAC3,
0xDAE7, 0xDDE7, 0xDEA7, 0xDF1F, 0xDF37, 0xDFC7, 0xE09F, 0xE0F3, 0xE177, 0xE1CB, 0xE22B, 0xE243, 0xE2BB, 0xE2D3, 0xE423, 0xE537,
0xE567, 0xE61B, 0xE657, 0xE6B7, 0xE837, 0xE963, 0xEC7B, 0xECE7, 0xED6B, 0xEDE3, 0xEF9F, 0xEFC3, 0xF06B, 0xF107, 0xF20F, 0xF257,
0xF35F, 0xF42B, 0xF4AF, 0xF5DB, 0xF743, 0xF7D3, 0xF863, 0xF86F, 0xF8E7, 0xFA07, 0xFA13, 0xFB1B, 0xFB3F, 0xFCFB, 0xFE27, 0xFE63
};
static int initialize_state(crypt_data_t *const data, const size_t thread_count, const uint64_t nonce, const uint8_t *const passwd, const size_t passwd_len, const int mode, const int legacy)
{
uint8_t temp[256U][256U];
@ -173,7 +154,7 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
slunkcrypt_bzero(data, sizeof(crypt_data_t));
/* initialize counter */
random_seed(&data->thread_data[0].random, nonce, legacy ? ((uint16_t)(-1)) : 0xFE7B, passwd, passwd_len, legacy);
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);
/* set up the wheel permutations */
@ -214,7 +195,7 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
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 : 0xFEF3, passwd, passwd_len, legacy);
random_seed(&data->thread_data[0].random, nonce, legacy ? 256U : INITIALIZER_MAX, passwd, passwd_len, legacy);
for (i = 1U; i < thread_count; ++i)
{
data->thread_data[i].reverse_mode = data->thread_data[0].reverse_mode;
@ -314,21 +295,21 @@ int slunkcrypt_generate_nonce(uint64_t *const nonce)
slunkcrypt_t slunkcrypt_alloc(const uint64_t nonce, const uint8_t *const passwd, const size_t passwd_len, const int mode)
{
slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, 0U, 1 };
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, 0U, SLUNKCRYPT_TRUE };
return slunkcrypt_alloc_ext(nonce, passwd, passwd_len, mode, &param);
}
slunkcrypt_t slunkcrypt_alloc_ext(const uint64_t nonce, const uint8_t *const passwd, const size_t passwd_len, const int mode, const slunkparam_t *const param)
{
crypt_state_t* state = NULL;
crypt_state_t *state = NULL;
if ((!passwd) || (passwd_len < SLUNKCRYPT_PWDLEN_MIN) || (passwd_len > SLUNKCRYPT_PWDLEN_MAX) ||
(mode < SLUNKCRYPT_ENCRYPT) || (mode > SLUNKCRYPT_DECRYPT) || (!param) || (param->version == 0U) || (param->version > SLUNKCRYPT_PARAM_VERSION))
(mode < SLUNKCRYPT_ENCRYPT) || (mode > SLUNKCRYPT_DECRYPT) || (!param) || (!param->version) || (param->version > SLUNKCRYPT_PARAM_VERSION))
{
return SLUNKCRYPT_NULL;
}
if (!(state = (crypt_state_t*)malloc(sizeof(crypt_state_t))))
if (!(state = (crypt_state_t*) calloc(1U, sizeof(crypt_state_t))))
{
return SLUNKCRYPT_NULL;
}
@ -343,9 +324,9 @@ slunkcrypt_t slunkcrypt_alloc_ext(const uint64_t nonce, const uint8_t *const pas
}
}
state->legacy_init = (param->version > 1U) ? BOOLIFY(param->legacy_init) : 1;
state->legacy_compat = (param->version > 1U) ? BOOLIFY(param->legacy_compat) : SLUNKCRYPT_TRUE;
if (initialize_state(&state->data, THREAD_COUNT(state), nonce, passwd, passwd_len, mode, state->legacy_init) == SLUNKCRYPT_SUCCESS)
if (initialize_state(&state->data, THREAD_COUNT(state), nonce, passwd, passwd_len, mode, state->legacy_compat) == SLUNKCRYPT_SUCCESS)
{
return (slunkcrypt_t)state;
}
@ -364,7 +345,7 @@ int slunkcrypt_reset(const slunkcrypt_t context, const uint64_t nonce, const uin
return SLUNKCRYPT_FAILURE;
}
if ((result = initialize_state(&state->data, THREAD_COUNT(state), nonce, passwd, passwd_len, mode, state->legacy_init)) != SLUNKCRYPT_SUCCESS)
if ((result = initialize_state(&state->data, THREAD_COUNT(state), nonce, passwd, passwd_len, mode, state->legacy_compat)) != SLUNKCRYPT_SUCCESS)
{
slunkcrypt_bzero(&state->data, sizeof(crypt_data_t));
}