Make debug logging optional (disabled by default) in self-test mode.
This commit is contained in:
parent
f3dc0757ab
commit
b0cd820fdf
@ -66,9 +66,9 @@ static void init_slunk_param(slunkparam_t *const param, const crypt_options_t *c
|
|||||||
{
|
{
|
||||||
slunkcrypt_bzero(param, sizeof(slunkparam_t));
|
slunkcrypt_bzero(param, sizeof(slunkparam_t));
|
||||||
param->version = SLUNKCRYPT_PARAM_VERSION;
|
param->version = SLUNKCRYPT_PARAM_VERSION;
|
||||||
param->thread_count = options->thread_count;
|
|
||||||
param->legacy_compat = options->legacy_compat;
|
param->legacy_compat = options->legacy_compat;
|
||||||
param->debug_logging = options->debug_logging;
|
param->debug_logging = options->debug_logging;
|
||||||
|
param->thread_count = options->thread_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UPDATE_PROGRESS_INDICATOR(CLK_UPDATE, CURRENT, TOTAL) do \
|
#define UPDATE_PROGRESS_INDICATOR(CLK_UPDATE, CURRENT, TOTAL) do \
|
||||||
|
@ -156,7 +156,7 @@ int MAIN(const int argc, CHR *const argv[])
|
|||||||
setup_signal_handler(SIGINT, sigint_handler);
|
setup_signal_handler(SIGINT, sigint_handler);
|
||||||
|
|
||||||
FPRINTF(stderr, T("SlunkCrypt Utility (%") T(PRIstr) T("-%") T(PRIstr) T("), by LoRd_MuldeR <MuldeR2@GMX.de>\n"), OS_TYPE_NAME, CPU_ARCH);
|
FPRINTF(stderr, T("SlunkCrypt Utility (%") T(PRIstr) T("-%") T(PRIstr) T("), by LoRd_MuldeR <MuldeR2@GMX.de>\n"), OS_TYPE_NAME, CPU_ARCH);
|
||||||
FPRINTF(stderr, T("Using libSlunkCrypt-%") T(PRIstr) T(" v%u.%u.%u [%") T(PRIstr) T("]\n\n"),
|
FPRINTF(stderr, T("Using libSlunkCrypt-%") T(PRIstr) T(" v%u.%u.%u [%.18") T(PRIstr) T("]\n\n"),
|
||||||
SLUNKCRYPT_HAVE_THREADS ? "MT" : "ST", SLUNKCRYPT_VERSION_MAJOR, SLUNKCRYPT_VERSION_MINOR, SLUNKCRYPT_VERSION_PATCH, SLUNKCRYPT_BUILD);
|
SLUNKCRYPT_HAVE_THREADS ? "MT" : "ST", SLUNKCRYPT_VERSION_MAJOR, SLUNKCRYPT_VERSION_MINOR, SLUNKCRYPT_VERSION_PATCH, SLUNKCRYPT_BUILD);
|
||||||
|
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
@ -194,10 +194,10 @@ int MAIN(const int argc, CHR *const argv[])
|
|||||||
goto clean_up;
|
goto clean_up;
|
||||||
case MODE_TEST:
|
case MODE_TEST:
|
||||||
check_excess_arguments(argc, 2);
|
check_excess_arguments(argc, 2);
|
||||||
result = run_selftest_routine(environ_get_uint(ENV_NTHREADS));
|
result = selftest_routine(environ_get_uint(ENV_NTHREADS), environ_get_flag(ENV_DEBUGLOG));
|
||||||
goto clean_up;
|
goto clean_up;
|
||||||
default:
|
default:
|
||||||
FPRINTF(stderr, T("Error: The specified command \"%") T(PRISTR) T("\" is unknown!\n\n"), argv[1U]);
|
FPRINTF(stderr, T("Error: The specified command \"%") T(PRISTR) T("\" is unrecognized!\n\n"), argv[1U]);
|
||||||
goto clean_up;
|
goto clean_up;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ clean_up:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_selftest_routine(const size_t thread_count)
|
int selftest_routine(const size_t thread_count, const int debug)
|
||||||
{
|
{
|
||||||
static const size_t ITERATIONS = 2U;
|
static const size_t ITERATIONS = 2U;
|
||||||
static const uint64_t TEST_NONCE[] = { 0x243F6A8885A308D3, 0x13198A2E03707344 };
|
static const uint64_t TEST_NONCE[] = { 0x243F6A8885A308D3, 0x13198A2E03707344 };
|
||||||
@ -224,7 +224,7 @@ int run_selftest_routine(const size_t thread_count)
|
|||||||
{
|
{
|
||||||
for (size_t j = 0U; j < ITERATIONS; ++j)
|
for (size_t j = 0U; j < ITERATIONS; ++j)
|
||||||
{
|
{
|
||||||
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, (j > 0) ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE, SLUNKCRYPT_TRUE };
|
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, (j > 0) ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE, debug };
|
||||||
for (size_t k = 0U; k < ARRAY_SIZE(TEST_NONCE); ++k)
|
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);
|
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, SLUNKCRYPT_TRUE };
|
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, SLUNKCRYPT_FALSE, debug };
|
||||||
for (size_t i = 0U; i < ITERATIONS; ++i)
|
for (size_t i = 0U; i < ITERATIONS; ++i)
|
||||||
{
|
{
|
||||||
for (size_t j = 0U; j < ARRAY_SIZE(TEST_NONCE); ++j)
|
for (size_t j = 0U; j < ARRAY_SIZE(TEST_NONCE); ++j)
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
int run_selftest_routine(const size_t thread_count);
|
int selftest_routine(const size_t thread_count, const int debug);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,18 +6,35 @@
|
|||||||
/* Internal */
|
/* Internal */
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
/* CRT */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
/* syslog */
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
# define WIN32_LEAN_AND_MEAN 1
|
# define WIN32_LEAN_AND_MEAN 1
|
||||||
# include <Windows.h>
|
# include <Windows.h>
|
||||||
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
#elif defined(__unix__) || defined(__HAIKU__)
|
||||||
# include <syslog.h>
|
# include <syslog.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void slunkcrypt_debug_print(const char* const message)
|
void slunkcrypt_debug_write(const char* const text)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
OutputDebugStringA(message);
|
OutputDebugStringA(text);
|
||||||
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
#elif defined(__unix__) || defined(__HAIKU__)
|
||||||
syslog(LOG_DEBUG, "%s", message);
|
syslog(LOG_DEBUG, "%s", text);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void slunkcrypt_debug_print(const char* const text, ...)
|
||||||
|
{
|
||||||
|
char buffer[100U];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, text);
|
||||||
|
if (vsnprintf(buffer, 100U, text, ap) > 0)
|
||||||
|
{
|
||||||
|
slunkcrypt_debug_write(buffer);
|
||||||
|
}
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#ifndef INC_SLUNKCRYPT_DEBUG_H
|
#ifndef INC_SLUNKCRYPT_DEBUG_H
|
||||||
#define INC_SLUNKCRYPT_DEBUG_H
|
#define INC_SLUNKCRYPT_DEBUG_H
|
||||||
|
|
||||||
void slunkcrypt_debug_print(const char *const message);
|
void slunkcrypt_debug_write(const char *const text);
|
||||||
|
void slunkcrypt_debug_print(const char *const text, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -200,22 +200,6 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
|
|||||||
CHECK_ABORTED();
|
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 */
|
/* initialize thread state */
|
||||||
data->thread_data[0].reverse_mode = reverse_mode;
|
data->thread_data[0].reverse_mode = reverse_mode;
|
||||||
data->thread_data[0].wheel = (const uint8_t(*)[256]) data->wheel;
|
data->thread_data[0].wheel = (const uint8_t(*)[256]) data->wheel;
|
||||||
@ -232,6 +216,26 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
|
|||||||
CHECK_ABORTED();
|
CHECK_ABORTED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* dump the final configuration */
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
slunkcrypt_debug_print("cntr = %08X", data->thread_data[0].counter);
|
||||||
|
slunkcrypt_debug_print("drbg = %08X %08X %08X %08X %08X %08X",
|
||||||
|
data->thread_data[0].random.d, data->thread_data[0].random.v, data->thread_data[0].random.w,
|
||||||
|
data->thread_data[0].random.x, data->thread_data[0].random.y, data->thread_data[0].random.z);
|
||||||
|
for (r = 0U; r < 256U; ++r)
|
||||||
|
{
|
||||||
|
char text[775U];
|
||||||
|
size_t off = sprintf(text, "[%02X] =", (unsigned)r);
|
||||||
|
for (i = 0U; i < 256U; ++i)
|
||||||
|
{
|
||||||
|
off += sprintf(text + off, " %02X", data->wheel[r][i]);
|
||||||
|
}
|
||||||
|
CHECK_ABORTED();
|
||||||
|
slunkcrypt_debug_write(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return SLUNKCRYPT_SUCCESS;
|
return SLUNKCRYPT_SUCCESS;
|
||||||
|
|
||||||
/* aborted */
|
/* aborted */
|
||||||
|
Loading…
Reference in New Issue
Block a user