From 20d7632fcbaf7970a2a0d6cb610abfe50216aba9 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Tue, 20 Oct 2020 15:21:00 +0200 Subject: [PATCH] Some code refactoring. --- Makefile | 4 +- frontend/res/SlunkCrypt.rc | 12 +- frontend/src/main.c | 228 +++++++++++++++++++++++++------------ libslunkcrypt/include/slunkcrypt.h | 26 +++-- libslunkcrypt/src/slunkcrypt.c | 51 ++++++--- libslunkcrypt/src/version.h | 10 +- 6 files changed, 222 insertions(+), 109 deletions(-) diff --git a/Makefile b/Makefile index 613a539..268fa97 100644 --- a/Makefile +++ b/Makefile @@ -85,5 +85,5 @@ $(SUBDIR_LIB)/obj/%$(CONFIG).o: $(SUBDIR_LIB)/src/%.c $(CC) $(CFLAGS) -c $< -o $@ clean: - $(RM) $(addsuffix *crypt*,$(dir $(TARGET_APP)) $(dir $(TARGET_LIB))) - $(RM) $(addsuffix *.o,$(dir $(OBJECTS_APP)) $(dir $(OBJECTS_LIB))) + $(RM) $(SUBDIR_APP)/obj/*.o $(SUBDIR_APP)/lib/*.a $(SUBDIR_APP)/bin/*$(SUFFIX) + $(RM) $(SUBDIR_LIB)/obj/*.o $(SUBDIR_LIB)/lib/*.a $(SUBDIR_LIB)/bin/*$(SUFFIX) diff --git a/frontend/res/SlunkCrypt.rc b/frontend/res/SlunkCrypt.rc index 664cdc1..9f75822 100644 --- a/frontend/res/SlunkCrypt.rc +++ b/frontend/res/SlunkCrypt.rc @@ -8,6 +8,10 @@ #include "../../libslunkcrypt/src/version.h" +#define VERSION_HELPER1(X,Y,Z) #X "." #Y "." #Z +#define VERSION_HELPER2(X,Y,Z) VERSION_HELPER1(X,Y,Z) +#define VERSION_STRING VERSION_HELPER2(MY_VERSION_MAJOR,MY_VERSION_MINOR,MY_VERSION_PATCH) + ///////////////////////////////////////////////////////////////////////////// // // Neutral resources @@ -22,8 +26,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL // Version // VS_VERSION_INFO VERSIONINFO - FILEVERSION LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH, 0 - PRODUCTVERSION LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH, 0 + FILEVERSION MY_VERSION_MAJOR,MY_VERSION_MINOR,0,MY_VERSION_PATCH + PRODUCTVERSION MY_VERSION_MAJOR,MY_VERSION_MINOR,0,MY_VERSION_PATCH FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x3L @@ -40,8 +44,8 @@ BEGIN BEGIN VALUE "ProductName", "SlunkCrypt" VALUE "FileDescription", "SlunkCrypt" - VALUE "ProductVersion", LIB_VERSION_STRING - VALUE "FileVersion", LIB_VERSION_STRING + VALUE "ProductVersion", VERSION_STRING + VALUE "FileVersion", VERSION_STRING VALUE "InternalName", "slunkcrypt" VALUE "OriginalFilename", "slunkcrypt.exe" VALUE "LegalCopyright", "Created by LoRd_MuldeR " diff --git a/frontend/src/main.c b/frontend/src/main.c index 5885e9e..2c1a6c6 100644 --- a/frontend/src/main.c +++ b/frontend/src/main.c @@ -15,14 +15,73 @@ #include #include -#define BUFF_SIZE 4096U +#define BUFFER_SIZE 4096U + +#define OP_MODE_NONE 0 +#define OP_MODE_HELP 1 +#define OP_MODE_VERS 2 +#define OP_MODE_ENCR 3 +#define OP_MODE_DECR 4 +#define OP_MODE_TEST 5 static const CHR *const ENVV_PASSWD_NAME = T("SLUNK_PASSPHRASE"); +// ========================================================================== +// Auxiliary functions +// ========================================================================== + +static int parse_mode(const CHR* const command) +{ + if ((!STRICMP(command, T("-h"))) || (!STRICMP(command, T("/?"))) || (!STRICMP(command, T("--help")))) + { + return OP_MODE_HELP; + } + else if ((!STRICMP(command, T("-v"))) || (!STRICMP(command, T("--version")))) + { + return OP_MODE_VERS; + } + else if ((!STRICMP(command, T("-e"))) || (!STRICMP(command, T("--encrypt")))) + { + return OP_MODE_ENCR; + } + else if ((!STRICMP(command, T("-d"))) || (!STRICMP(command, T("--decrypt")))) + { + return OP_MODE_DECR; + } + else if ((!STRICMP(command, T("-t"))) || (!STRICMP(command, T("--self-test")))) + { + return OP_MODE_TEST; + } + else + { + FPRINTF(stderr, T("Error: The specified command \"%") T(PRISTR) T("\" is unknown!\n\n"), command); + return -1; + } +} + +static void print_manpage(const CHR *const program) +{ + FPUTS(T("====================================================================\n"), stderr); + FPUTS(T("This software has been released under the CC0 1.0 Universal license:\n"), stderr); + FPUTS(T("https://creativecommons.org/publicdomain/zero/1.0/legalcode\n"), stderr); + FPUTS(T("====================================================================\n\n"), stderr); + FPUTS(T("Synopsis:\n"), stderr); + FPRINTF(stderr, T(" %") T(PRISTR) T(" --encrypt [[@][:]] \n"), program); + FPRINTF(stderr, T(" %") T(PRISTR) T(" --decrypt [[@][:]] \n\n"), program); + FPUTS(T("Options:\n"), stderr); + FPUTS(T("- If is prefixed with a '@' character, then it specifies the file\n"), stderr); + FPUTS(T(" to read the passphrase from; only the first line in that file is used!\n"), stderr); + FPUTS(T("- If is prefixed with a ':' character, then the leading character\n"), stderr); + FPUTS(T(" is skipped and the remainder of the argument is used as passphrase.\n"), stderr); + FPUTS(T("- If argument is omitted, then the passphrase is read from the\n"), stderr); + FPRINTF(stderr, T(" environment variable \"%") T(PRISTR) T("\" instead.\n"), ENVV_PASSWD_NAME); + FPUTS(T("- Specify \"@-\" in order to read the passphrase from the standard input stream!\n\n"), stderr); +} + static char* read_passphrase(const CHR* const file_name) { - static const size_t buff_size = 512U; - char *buffer = (char*) malloc(buff_size * sizeof(char)); + const size_t max_len = SLUNKCRYPT_PWDLEN_MAX + 3U; + char *buffer = (char*) malloc(max_len * sizeof(char)); if (!buffer) { return NULL; @@ -38,7 +97,7 @@ static char* read_passphrase(const CHR* const file_name) do { - if (!fgets(buffer, (int)buff_size, file)) + if (!fgets(buffer, (int)max_len, file)) { free(buffer); buffer = NULL; @@ -101,6 +160,19 @@ static int open_files(FILE **const file_in, FILE **const file_out, const CHR* co return 0; } +static void sigint_handler(const int sig) +{ + if (sig == SIGINT) + { + g_slunkcrypt_abort_flag = 1; + signal(SIGINT, sigint_handler); + } +} + +// ========================================================================== +// Encrypt +// ========================================================================== + static int encrypt(const char* const passphrase, const CHR* const input_path, const CHR* const output_path) { slunkcrypt_t ctx = SLUNKCRYPT_NULL; @@ -149,7 +221,7 @@ static int encrypt(const char* const passphrase, const CHR* const input_path, co clock_t clk_now, clk_update = clock(); uint64_t crc_actual = CRC_INITIALIZER, bytes_read = 0U; - uint8_t buffer[BUFF_SIZE]; + uint8_t buffer[BUFFER_SIZE]; FPRINTF(stderr, T("%5.1f%% "), 0.0); fflush(stderr); @@ -157,7 +229,7 @@ static int encrypt(const char* const passphrase, const CHR* const input_path, co while (bytes_read < file_size) { const uint64_t bytes_remaining = file_size - bytes_read; - const size_t request_len = (bytes_remaining < BUFF_SIZE) ? ((size_t)bytes_remaining) : BUFF_SIZE; + const size_t request_len = (bytes_remaining < BUFFER_SIZE) ? ((size_t)bytes_remaining) : BUFFER_SIZE; const size_t count = fread(buffer, sizeof(uint8_t), request_len, file_in); if (count > 0U) { @@ -200,7 +272,7 @@ static int encrypt(const char* const passphrase, const CHR* const input_path, co } crc_actual = crc64_finish(crc_actual); - FPRINTF(stderr, T("\b\b\b\b\b\b%5.1f%%\n\n"), 100.0); + FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%%\n\n"), 100.0); fflush(stderr); if (fwrite(&crc_actual, sizeof(uint64_t), 1U, file_out) < 1U) @@ -234,6 +306,10 @@ clean_up: return result; } +// ========================================================================== +// Decrypt +// ========================================================================== + static int decrypt(const char* const passphrase, const CHR* const input_path, const CHR* const output_path) { slunkcrypt_t ctx = SLUNKCRYPT_NULL; @@ -276,7 +352,7 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co clock_t clk_now, clk_update = clock(); uint64_t crc_actual = CRC_INITIALIZER, bytes_read = sizeof(uint64_t); - uint8_t buffer[BUFF_SIZE]; + uint8_t buffer[BUFFER_SIZE]; const uint64_t read_limit = file_size - sizeof(uint64_t); FPRINTF(stderr, T("%5.1f%% "), 0.0); @@ -285,7 +361,7 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co while (bytes_read < read_limit) { const uint64_t bytes_remaining = read_limit - bytes_read; - const size_t request_len = (bytes_remaining < BUFF_SIZE) ? ((size_t)bytes_remaining) : BUFF_SIZE; + const size_t request_len = (bytes_remaining < BUFFER_SIZE) ? ((size_t)bytes_remaining) : BUFFER_SIZE; const size_t count = fread(buffer, sizeof(uint8_t), request_len, file_in); if (count > 0U) { @@ -328,7 +404,7 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co } crc_actual = crc64_finish(crc_actual); - FPRINTF(stderr, T("\b\b\b\b\b\b%5.1f%%\n\n"), 100.0); + FPRINTF(stderr, T("\b\b\b\b\b\b\b%5.1f%%\n\n"), 100.0); fflush(stderr); uint64_t crc_expected; @@ -370,7 +446,11 @@ clean_up: return result; } -static int run_test(const char *const message) +// ========================================================================== +// Self-test +// ========================================================================== + +static int run_test_case(const char *const message) { static const char* const passphrase = "OrpheanBeh0lderScry!Doubt"; @@ -450,7 +530,7 @@ clean_up: return result; } -static int self_test(void) +static int run_self_test(void) { static const size_t total = 32U; const char* const test_data[] = { TEST_DATA_0, TEST_DATA_1, TEST_DATA_2, TEST_DATA_3, NULL }; @@ -465,7 +545,7 @@ static int self_test(void) { FPRINTF(stderr, T("\b\b\b\b\b\b%2u/%2u "), (unsigned int)++completed, (unsigned int)total); fflush(stderr); - if (run_test(test_data[j])) + if (run_test_case(test_data[j])) { return 1; } @@ -478,72 +558,53 @@ static int self_test(void) return 0; } -static void sigint_handler(const int sig) -{ - if (sig == SIGINT) - { - g_slunkcrypt_abort_flag = 1; - signal(SIGINT, sigint_handler); - } -} +// ========================================================================== +// Main function +// ========================================================================== -int MAIN(int argc, CHR* argv[]) +int MAIN(const int argc, CHR *const argv[]) { init_terminal(); signal(SIGINT, sigint_handler); + int result = -1; FPRINTF(stderr, T("SlunkCrypt Utility (%") T(PRIstr) T("-%") T(PRIstr) T("), by LoRd_MuldeR \n"), OS_TYPE, CPU_ARCH); - FPRINTF(stderr, T("Using libSlunkCrypt v%") T(PRIstr) T(" [%") T(PRIstr) T("]\n\n"), SLUNKCRYPT_VERSION, SLUNKCRYPT_BUILD); + FPRINTF(stderr, T("Using libSlunkCrypt v%u.%u.%u [%") T(PRIstr) T("]\n\n"), SLUNKCRYPT_VERSION_MAJOR, SLUNKCRYPT_VERSION_MINOR, SLUNKCRYPT_VERSION_PATCH, SLUNKCRYPT_BUILD); - if (argc > 1) + /* ----------------------------------------------------- */ + /* Parse arguments */ + /* ----------------------------------------------------- */ + + const int mode = (argc > 1) ? parse_mode(argv[1U]) : OP_MODE_NONE; + switch (mode) { - if ((!STRICMP(argv[1U], T("-v"))) || (!STRICMP(argv[1U], T("--version")))) - { - return 0; /*exit right now*/ - } - if ((!STRICMP(argv[1U], T("-h"))) || (!STRICMP(argv[1U], T("/?"))) || (!STRICMP(argv[1U], T("--help")))) - { - const CHR* const program = get_file_name(argv[0U]); - FPUTS(T("====================================================================\n"), stderr); - FPUTS(T("This software has been released under the CC0 1.0 Universal license:\n"), stderr); - FPUTS(T("https://creativecommons.org/publicdomain/zero/1.0/legalcode\n"), stderr); - FPUTS(T("====================================================================\n\n"), stderr); - FPUTS(T("Synopsis:\n"), stderr); - FPRINTF(stderr, T(" %") T(PRISTR) T(" --encrypt [[@][:]] \n"), program); - FPRINTF(stderr, T(" %") T(PRISTR) T(" --decrypt [[@][:]] \n\n"), program); - FPUTS(T("Options:\n"), stderr); - FPUTS(T("- If is prefixed with a '@' character, then it specifies the file\n"), stderr); - FPUTS(T(" to read the passphrase from; only the first line in that file is used!\n"), stderr); - FPUTS(T("- If is prefixed with a ':' character, then the leading character\n"), stderr); - FPUTS(T(" is skipped and the remainder of the argument is used as passphrase.\n"), stderr); - FPUTS(T("- If argument is omitted, then the passphrase is read from the\n"), stderr); - FPRINTF(stderr, T(" environment variable \"%") T(PRISTR) T("\" instead.\n"), ENVV_PASSWD_NAME); - FPUTS(T("- Specify \"@-\" in order to read the passphrase from the standard input stream!\n\n"), stderr); - return 0; - } - if ((!STRICMP(argv[1U], T("-t"))) || (!STRICMP(argv[1U], T("--self-test")))) - { - return self_test(); /*only self-test!*/ - } + case OP_MODE_NONE: + FPRINTF(stderr, T("Error: Nothing to do. Please type '%") T(PRISTR) T(" --help' for details!\n\n"), get_file_name(argv[0U])); + return 1; + case OP_MODE_HELP: + print_manpage(get_file_name(argv[0U])); + return 0; + case OP_MODE_ENCR: + case OP_MODE_DECR: + break; + case OP_MODE_TEST: + return run_self_test(); + default: + return -1; } if (argc < 4) { - const CHR* const program = get_file_name(argv[0U]); - FPRINTF(stderr, T("Error: Nothing to do. Please type '%") T(PRISTR) T(" --help' for details!\n\n"), program); + FPRINTF(stderr, T("Error: Required argument is missing. Please type '%") T(PRISTR) T(" --help' for details!\n\n"), get_file_name(argv[0U])); return 1; } - else if (argc > 5) - { - FPUTS(T("Warning: Excess command-line argument is ignored!\n\n"), stderr); - } - const CHR *const command = argv[1U], *const passphrase = (argc > 4) ? argv[2U] : GETENV(ENVV_PASSWD_NAME); - const CHR *const input_file = argv[(argc > 4) ? 3U : 2U], *const output_file = argv[(argc > 4) ? 4U : 3U]; + const CHR* const passphrase = (argc > 4) ? argv[2U] : GETENV(ENVV_PASSWD_NAME); + const CHR* const input_file = argv[(argc > 4) ? 3U : 2U], * const output_file = argv[(argc > 4) ? 4U : 3U]; if ((!passphrase) || (!passphrase[0U]) || (((passphrase[0U] == T('@')) || (passphrase[0U] == T(':'))) && (!passphrase[1U]))) { - FPUTS(T("Error: The passphrase (file name) must not be empty!\n\n"), stderr); + FPUTS(T("Error: The specified passphrase must not be empty!\n\n"), stderr); return 1; } @@ -553,16 +614,32 @@ int MAIN(int argc, CHR* argv[]) return 1; } + /* ----------------------------------------------------- */ + /* Initialize passphrase */ + /* ----------------------------------------------------- */ + char *const passphrase_buffer = (passphrase[0U] == T('@')) ? read_passphrase(passphrase + 1U) : CHR_to_utf8((passphrase[0U] == T(':')) ? (passphrase + 1U) : passphrase); if (!passphrase_buffer) { - FPUTS(T("Error: Failed to read the passphrase file!\n\n"), stderr); + FPUTS(T("Error: Failed to read the passphrase!\n\n"), stderr); return 1; } slunkcrypt_bzero((CHR*)passphrase, STRLEN(passphrase) * sizeof(CHR)); - if (strlen(passphrase_buffer) < 12U) + const size_t passphrase_len = strlen(passphrase_buffer); + if (passphrase_len < SLUNKCRYPT_PWDLEN_MIN) + { + FPRINTF(stderr, T("Error: Passphrase must be at least %") T(PRIu64) T(" characters in length!\n\n"), (uint64_t)SLUNKCRYPT_PWDLEN_MIN); + goto exiting; + } + else if (passphrase_len > SLUNKCRYPT_PWDLEN_MAX) + { + FPRINTF(stderr, T("Error: Passphrase must be at most %") T(PRIu64) T(" characters in length!\n\n"), (uint64_t)SLUNKCRYPT_PWDLEN_MAX); + goto exiting; + } + + if (passphrase_len < 12U) { FPUTS(T("Warning: Using a *short* passphrase; a length of 12 characters or more is recommended!\n\n"), stderr); } @@ -571,21 +648,22 @@ int MAIN(int argc, CHR* argv[]) FPUTS(T("Warning: Using a *weak* passphrase; a mix of upper-case letters, lower-case letters, digits and 'special' characters is recommended!\n\n"), stderr); } + /* ----------------------------------------------------- */ + /* Encrypt or decrypt */ + /* ----------------------------------------------------- */ + const clock_t clk_start = clock(); - int result = -1; - if ((!STRICMP(command, T("-e"))) || (!STRICMP(command, T("--encrypt")))) + switch (mode) { + case OP_MODE_ENCR: result = encrypt(passphrase_buffer, input_file, output_file); - } - else if ((!STRICMP(command, T("-d"))) || (!STRICMP(command, T("--decrypt")))) - { + break; + case OP_MODE_DECR: result = decrypt(passphrase_buffer, input_file, output_file); - } - else - { - FPRINTF(stderr, T("Error: Command \"%") T(PRISTR) T("\" is unknown!\n\n"), command); - goto exiting; + break; + default: + abort(); /*not supposed to happen!*/ } if (!g_slunkcrypt_abort_flag) @@ -596,6 +674,10 @@ int MAIN(int argc, CHR* argv[]) FPRINTF(stderr, T("Operation completed after %.1f seconds.\n\n"), (clk_end - clk_start) / ((double)CLOCKS_PER_SEC)); } + /* ----------------------------------------------------- */ + /* Final clean-up */ + /* ----------------------------------------------------- */ + exiting: if (passphrase_buffer) diff --git a/libslunkcrypt/include/slunkcrypt.h b/libslunkcrypt/include/slunkcrypt.h index 97edbad..93b0235 100644 --- a/libslunkcrypt/include/slunkcrypt.h +++ b/libslunkcrypt/include/slunkcrypt.h @@ -12,8 +12,14 @@ /* * Version info */ -extern const char *const SLUNKCRYPT_VERSION; -extern const char* const SLUNKCRYPT_BUILD; +extern const uint16_t SLUNKCRYPT_VERSION_MAJOR; +extern const uint16_t SLUNKCRYPT_VERSION_MINOR; +extern const uint16_t SLUNKCRYPT_VERSION_PATCH; + +/* + * Build date and time + */ +extern const char *const SLUNKCRYPT_BUILD; /* * Abort flag @@ -24,14 +30,20 @@ extern volatile int g_slunkcrypt_abort_flag; * Opaque handle to internal state */ typedef uintptr_t slunkcrypt_t; +#define SLUNKCRYPT_NULL ((slunkcrypt_t)NULL) /* - * Constants + * Error codes */ -#define SLUNKCRYPT_NULL ((slunkcrypt_t)NULL) -#define SLUNKCRYPT_SUCCESS 0 -#define SLUNKCRYPT_FAILURE (-1) -#define SLUNKCRYPT_ABORTED (-2) +static const int SLUNKCRYPT_SUCCESS = 0; +static const int SLUNKCRYPT_FAILURE = -1; +static const int SLUNKCRYPT_ABORTED = -2; + +/* + * Limits + */ +static const size_t SLUNKCRYPT_PWDLEN_MIN = 5U; +static const size_t SLUNKCRYPT_PWDLEN_MAX = 512U; /* * Seed generator diff --git a/libslunkcrypt/src/slunkcrypt.c b/libslunkcrypt/src/slunkcrypt.c index 96777bb..eb7ede2 100644 --- a/libslunkcrypt/src/slunkcrypt.c +++ b/libslunkcrypt/src/slunkcrypt.c @@ -24,8 +24,15 @@ #endif #endif -const char* const SLUNKCRYPT_VERSION = LIB_VERSION_STRING; -const char* const SLUNKCRYPT_BUILD = __DATE__", "__TIME__; +/* Version info */ +const uint16_t SLUNKCRYPT_VERSION_MAJOR = MY_VERSION_MAJOR; +const uint16_t SLUNKCRYPT_VERSION_MINOR = MY_VERSION_MINOR; +const uint16_t SLUNKCRYPT_VERSION_PATCH = MY_VERSION_PATCH; +const char* const SLUNKCRYPT_BUILD = __DATE__ " " __TIME__; + +// ========================================================================== +// Data structures +// ========================================================================== typedef struct { @@ -259,7 +266,7 @@ int slunkcrypt_generate_seed(uint64_t* const seed) slunkcrypt_t slunkcrypt_alloc(const uint64_t salt, const uint8_t *const passwd, const size_t passwd_len) { - if ((!passwd) || (passwd_len < 1U)) + if ((!passwd) || (passwd_len < SLUNKCRYPT_PWDLEN_MIN) || (passwd_len > SLUNKCRYPT_PWDLEN_MAX)) { return SLUNKCRYPT_NULL; } @@ -282,7 +289,7 @@ slunkcrypt_t slunkcrypt_alloc(const uint64_t salt, const uint8_t *const passwd, int slunkcrypt_reset(const slunkcrypt_t context, const uint64_t salt, const uint8_t *const passwd, const size_t passwd_len) { crypt_state_t* const state = (crypt_state_t*)context; - if ((!state) || (!passwd) || (passwd_len < 1U)) + if ((!state) || (!passwd) || (passwd_len < SLUNKCRYPT_PWDLEN_MIN) || (passwd_len > SLUNKCRYPT_PWDLEN_MAX)) { return SLUNKCRYPT_FAILURE; } @@ -301,10 +308,13 @@ int slunkcrypt_encrypt(const slunkcrypt_t context, const uint8_t* const input, u { return SLUNKCRYPT_FAILURE; } - for (size_t i = 0; i < length; ++i) + if (length > 0U) { - output[i] = process_enc(state, input[i]); - CHECK_ABORTED(); + for (size_t i = 0; i < length; ++i) + { + output[i] = process_enc(state, input[i]); + CHECK_ABORTED(); + } } return SLUNKCRYPT_SUCCESS; } @@ -316,10 +326,13 @@ int slunkcrypt_encrypt_inplace(const slunkcrypt_t context, uint8_t* const buffer { return SLUNKCRYPT_FAILURE; } - for (size_t i = 0; i < length; ++i) + if (length > 0U) { - buffer[i] = process_enc(state, buffer[i]); - CHECK_ABORTED(); + for (size_t i = 0; i < length; ++i) + { + buffer[i] = process_enc(state, buffer[i]); + CHECK_ABORTED(); + } } return SLUNKCRYPT_SUCCESS; } @@ -332,10 +345,13 @@ int slunkcrypt_decrypt(const slunkcrypt_t context, const uint8_t* const input, u { return SLUNKCRYPT_FAILURE; } - for (size_t i = 0; i < length; ++i) + if (length > 0U) { - output[i] = process_dec(state, input[i]); - CHECK_ABORTED(); + for (size_t i = 0; i < length; ++i) + { + output[i] = process_dec(state, input[i]); + CHECK_ABORTED(); + } } return SLUNKCRYPT_SUCCESS; } @@ -347,10 +363,13 @@ int slunkcrypt_decrypt_inplace(const slunkcrypt_t context, uint8_t* const buffer { return SLUNKCRYPT_FAILURE; } - for (size_t i = 0; i < length; ++i) + if (length > 0U) { - buffer[i] = process_dec(state, buffer[i]); - CHECK_ABORTED(); + for (size_t i = 0; i < length; ++i) + { + buffer[i] = process_dec(state, buffer[i]); + CHECK_ABORTED(); + } } return SLUNKCRYPT_SUCCESS; } diff --git a/libslunkcrypt/src/version.h b/libslunkcrypt/src/version.h index 551e3a4..749a96c 100644 --- a/libslunkcrypt/src/version.h +++ b/libslunkcrypt/src/version.h @@ -6,12 +6,8 @@ #ifndef INC_SLUNKCRYPT_VERSION_H #define INC_SLUNKCRYPT_VERSION_H -#define LIB_VERSION_MAJOR 1 -#define LIB_VERSION_MINOR 0 -#define LIB_VERSION_PATCH 0 - -#define VERSION_HELPER1(X,Y,Z) #X "." #Y "." #Z -#define VERSION_HELPER2(X,Y,Z) VERSION_HELPER1(X,Y,Z) -#define LIB_VERSION_STRING VERSION_HELPER2(LIB_VERSION_MAJOR,LIB_VERSION_MINOR,LIB_VERSION_PATCH) +#define MY_VERSION_MAJOR 1 +#define MY_VERSION_MINOR 0 +#define MY_VERSION_PATCH 0 #endif -- 2.11.0