From 334d828c5b55abdeff209d611beab5feec422e79 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sat, 12 Dec 2020 03:22:29 +0100 Subject: [PATCH] Slightly improved storage of the padding size. --- frontend/src/main.c | 11 ++--------- frontend/src/utils.h | 4 ++-- mk-profiled.sh | 4 ++-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/frontend/src/main.c b/frontend/src/main.c index 6ef2858..e5f1296 100644 --- a/frontend/src/main.c +++ b/frontend/src/main.c @@ -335,7 +335,7 @@ static int encrypt(const char* const passphrase, const CHR* const input_path, co goto clean_up; } - SET_NIBBLE(buffer[padding - 1U], padding); + SET_LOWBITS(buffer[padding - 1U], padding - 1U); if ((status = slunkcrypt_encrypt_inplace(ctx, buffer, padding)) != SLUNKCRYPT_SUCCESS) { FPUTS((status == SLUNKCRYPT_ABORTED) ? T("\n\nProcess interrupted!\n\n") : T("\n\nSlunkCrypt error: Failed to encrypt data!\n\n"), stderr); @@ -502,14 +502,7 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co goto clean_up; } - const size_t padding = GET_NIBBLE(buffer[sizeof(uint64_t) - 1U]); - if ((!padding) || (padding > sizeof(uint64_t))) - { - FPRINTF(stderr, T("\n\nPadding error: Erroneous padding length encountered! [0x%02X]\n\n"), (unsigned int)padding); - FPUTS(T("Wrong passphrase or corrupted file?\n\n"), stderr); - goto clean_up; - } - + const size_t padding = GET_LOWBITS(buffer[sizeof(uint64_t) - 1U]) + 1U; if (padding != sizeof(uint64_t)) { const size_t count = sizeof(uint64_t) - padding; diff --git a/frontend/src/utils.h b/frontend/src/utils.h index 52d316f..5e87c82 100644 --- a/frontend/src/utils.h +++ b/frontend/src/utils.h @@ -21,7 +21,7 @@ uint64_t round_down(const uint64_t value, const uint64_t base); #define ARRAY_SIZE(X) (sizeof((X)) / sizeof(*(X))) #define BOUND(MIN,VAL,MAX) (((VAL) < (MIN)) ? (MIN) : (((VAL) > (MAX)) ? (MAX) : (VAL))) -#define GET_NIBBLE(X) ((X) & 0x0F) -#define SET_NIBBLE(X, Y) do { X = ((X) & 0xF0) | ((Y) & 0x0F); } while(0) +#define GET_LOWBITS(X) ((X) & 0x07) +#define SET_LOWBITS(X, Y) do { X = ((X) & 0xF8) | ((Y) & 0x07); } while(0) #endif diff --git a/mk-profiled.sh b/mk-profiled.sh index fa7dd9b..6780e1b 100755 --- a/mk-profiled.sh +++ b/mk-profiled.sh @@ -35,8 +35,8 @@ printf "\n" PASSWRD="$(./frontend/bin/slunkcrypt${SUFFIX} --make-pw)" ./frontend/bin/slunkcrypt${SUFFIX} --self-test -./frontend/bin/slunkcrypt${SUFFIX} --encrypt "${PASSWRD}" /tmp/${TMP_NAME}.dat /tmp/${TMP_NAME}.enc -./frontend/bin/slunkcrypt${SUFFIX} --decrypt "${PASSWRD}" /tmp/${TMP_NAME}.enc /tmp/${TMP_NAME}.out +./frontend/bin/slunkcrypt${SUFFIX} --encrypt ":${PASSWRD}" /tmp/${TMP_NAME}.dat /tmp/${TMP_NAME}.enc +./frontend/bin/slunkcrypt${SUFFIX} --decrypt ":${PASSWRD}" /tmp/${TMP_NAME}.enc /tmp/${TMP_NAME}.out printf "\033[1;36m\n------------------------------------------------------------------------------\033[0m\n" printf "\033[1;36mRe-compile\n"