1
0
Fork 0

Implemented optional debug logging. Writes to the syslog (Unix) or debugger (Windows).

This commit is contained in:
LoRd_MuldeR 2022-10-14 00:44:19 +02:00
parent 38cf7c3c25
commit f3dc0757ab
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
10 changed files with 81 additions and 8 deletions

View File

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

View File

@ -12,6 +12,7 @@ typedef struct
{
int keep_incomplete;
int legacy_compat;
int debug_logging;
size_t thread_count;
}
crypt_options_t;

View File

@ -37,6 +37,7 @@ static const CHR* const ENV_PASSWORD = T("SLUNK_PASSPHRASE");
static const CHR* const ENV_KEEPFILE = T("SLUNK_KEEP_INCOMPLETE");
static const CHR* const ENV_NTHREADS = T("SLUNK_THREADS");
static const CHR* const ENV_LGCYCMPT = T("SLUNK_LEGACY_COMPAT");
static const CHR* const ENV_DEBUGLOG = T("SLUNK_DEBUG_LOGGING");
static const CHR* const PREFIX_PASS = T("pass:");
static const CHR* const PREFIX_FILE = T("file:");
@ -288,7 +289,8 @@ int MAIN(const int argc, CHR *const argv[])
/* ----------------------------------------------------- */
const uint64_t clk_start = clock_read();
const crypt_options_t options = { environ_get_flag(ENV_KEEPFILE), environ_get_flag(ENV_LGCYCMPT), environ_get_uint(ENV_NTHREADS) };
const crypt_options_t options = { environ_get_flag(ENV_KEEPFILE), environ_get_flag(ENV_LGCYCMPT), environ_get_flag(ENV_DEBUGLOG), environ_get_uint(ENV_NTHREADS) };
switch (slunk_mode)
{

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) ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE };
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, (j > 0) ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE, SLUNKCRYPT_TRUE };
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, SLUNKCRYPT_FALSE };
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, SLUNKCRYPT_FALSE, SLUNKCRYPT_TRUE };
for (size_t i = 0U; i < ITERATIONS; ++i)
{
for (size_t j = 0U; j < ARRAY_SIZE(TEST_NONCE); ++j)

View File

@ -90,6 +90,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_compat; /* Compatibility with pre-1.3 versions */
int debug_logging; /* Enable debug logging (writes to the syslog) */
}
slunkparam_t;

View File

@ -51,6 +51,7 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\debug.c" />
<ClCompile Include="src\junk.c" />
<ClCompile Include="src\keygen.c" />
<ClCompile Include="src\slunkcrypt.c" />
@ -60,6 +61,7 @@
<ClInclude Include="include\slunkcrypt.h" />
<ClInclude Include="include\slunkcrypt.hpp" />
<ClInclude Include="src\compiler.h" />
<ClInclude Include="src\debug.h" />
<ClInclude Include="src\initialize.h" />
<ClInclude Include="src\keygen.h" />
<ClInclude Include="src\thread.h" />

View File

@ -27,6 +27,9 @@
<ClCompile Include="src\thread.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\debug.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\slunkcrypt.h">
@ -50,5 +53,8 @@
<ClInclude Include="src\initialize.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\debug.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

23
libslunkcrypt/src/debug.c Normal file
View File

@ -0,0 +1,23 @@
/******************************************************************************/
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
/* Internal */
#include "debug.h"
#if defined(_WIN32)
# define WIN32_LEAN_AND_MEAN 1
# include <Windows.h>
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
# include <syslog.h>
#endif
void slunkcrypt_debug_print(const char* const message)
{
#if defined(_WIN32)
OutputDebugStringA(message);
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
syslog(LOG_DEBUG, "%s", message);
#endif
}

11
libslunkcrypt/src/debug.h Normal file
View File

@ -0,0 +1,11 @@
/******************************************************************************/
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
#ifndef INC_SLUNKCRYPT_DEBUG_H
#define INC_SLUNKCRYPT_DEBUG_H
void slunkcrypt_debug_print(const char *const message);
#endif

View File

@ -3,8 +3,15 @@
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
#ifdef _WIN32
# define _CRT_SECURE_NO_WARNINGS 1
#else
# define _GNU_SOURCE 1
#endif
/* Internal */
#include "slunkcrypt.h"
#include "debug.h"
#include "compiler.h"
#include "keygen.h"
#include "initialize.h"
@ -13,6 +20,7 @@
/* CRT */
#include <string.h>
#include <stdio.h>
#include <limits.h>
/* Version */
@ -58,6 +66,7 @@ crypt_data_t;
typedef struct
{
int legacy_compat;
int debug_logging;
thrdpl_t *thread_pool;
crypt_data_t data;
}
@ -144,7 +153,7 @@ static INLINE void random_seed(rand_state_t *const state, uint64_t salt, const u
// Initialization
// ==========================================================================
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)
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, const int debug)
{
uint8_t temp[256U][256U];
size_t r, i;
@ -191,6 +200,22 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
CHECK_ABORTED();
}
/* dump final wheel configuration */
if (debug)
{
char message[772U];
for (r = 0U; r < 256U; ++r)
{
size_t off = sprintf(message, "%02X:", (unsigned)r);
for (i = 0U; i < 256U; ++i)
{
off += sprintf(message + off, ",%02X", data->wheel[r][i]);
}
message[3U] = '\x20';
slunkcrypt_debug_print(message);
}
}
/* initialize thread state */
data->thread_data[0].reverse_mode = reverse_mode;
data->thread_data[0].wheel = (const uint8_t(*)[256]) data->wheel;
@ -295,7 +320,7 @@ 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)
{
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, 0U, SLUNKCRYPT_TRUE };
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, 0U, SLUNKCRYPT_TRUE, SLUNKCRYPT_FALSE };
return slunkcrypt_alloc_ext(nonce, passwd, passwd_len, mode, &param);
}
@ -324,9 +349,10 @@ slunkcrypt_t slunkcrypt_alloc_ext(const uint64_t nonce, const uint8_t *const pas
}
}
state->legacy_compat = (param->version > 1U) ? BOOLIFY(param->legacy_compat) : SLUNKCRYPT_TRUE;
state->legacy_compat = (param->version > 1U) ? BOOLIFY(param->legacy_compat) : SLUNKCRYPT_FALSE;
state->debug_logging = (param->version > 1U) ? BOOLIFY(param->debug_logging) : SLUNKCRYPT_FALSE;
if (initialize_state(&state->data, THREAD_COUNT(state), nonce, passwd, passwd_len, mode, state->legacy_compat) == SLUNKCRYPT_SUCCESS)
if (initialize_state(&state->data, THREAD_COUNT(state), nonce, passwd, passwd_len, mode, state->legacy_compat, state->debug_logging) == SLUNKCRYPT_SUCCESS)
{
return (slunkcrypt_t)state;
}
@ -345,7 +371,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_compat)) != SLUNKCRYPT_SUCCESS)
if ((result = initialize_state(&state->data, THREAD_COUNT(state), nonce, passwd, passwd_len, mode, state->legacy_compat, state->debug_logging)) != SLUNKCRYPT_SUCCESS)
{
slunkcrypt_bzero(&state->data, sizeof(crypt_data_t));
}