Added built-time option SLUNKBUILD_NOTHREADS to disable threading + added simple "testbed" script.

This commit is contained in:
LoRd_MuldeR 2022-04-09 16:40:16 +02:00
parent 50955210ac
commit 8b1b8aec64
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
5 changed files with 97 additions and 5 deletions

View File

@ -12,6 +12,7 @@ STRIP ?= 0
CPU ?= 0 CPU ?= 0
MARCH ?= 0 MARCH ?= 0
MTUNE ?= 0 MTUNE ?= 0
THREAD ?= 1
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Directories # Directories
@ -31,6 +32,11 @@ CFLAGS = -I$(SUBDIR_LIB)/include -std=gnu99 -Wall
ifneq ($(CPU),0) ifneq ($(CPU),0)
CFLAGS += -m$(firstword $(CPU)) CFLAGS += -m$(firstword $(CPU))
endif endif
ifneq ($(TARGET),)
CFLAGS += --target=$(firstword $(TARGET))
LDFLGS += --target=$(firstword $(TARGET))
endif
ifneq ($(MARCH),0) ifneq ($(MARCH),0)
CFLAGS += -march=$(firstword $(MARCH)) CFLAGS += -march=$(firstword $(MARCH))
endif endif
@ -81,6 +87,10 @@ ifeq ($(MACHINE),$(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE)))
LDFLGS += -mconsole -municode LDFLGS += -mconsole -municode
endif endif
ifeq ($(THREAD),0)
CFLAGS += -DSLUNKBUILD_NOTHREADS
endif
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# File names # File names
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View File

@ -24,8 +24,9 @@ The SlunkCrypt library and the command-line application currently run on the fol
* **Microsoft Windows** (Windows XP SP-3, or later) — 32-Bit (i686) and 64-Bit (AMD64) * **Microsoft Windows** (Windows XP SP-3, or later) — 32-Bit (i686) and 64-Bit (AMD64)
* **Linux** (kernel version 3.17, or later) — 32-Bit (i686) and 64-Bit (AMD64) * **Linux** (kernel version 3.17, or later) — 32-Bit (i686) and 64-Bit (AMD64)
* **Various BSD flavors** (tested on FreeBSD 13 and OpenBSD 7) — 32-Bit (i686) and 64-Bit (AMD64) * **Various BSD flavors** (tested on NetBSD 9.2, FreeBSD 13.0 and OpenBSD 7.0) — 32-Bit (i686) and 64-Bit (AMD64)
* **Oracle Solaris** (tested on version 11.4) — 32-Bit (i686) and 64-Bit (AMD64) * **Solaris** (tested on Solaris 11.4 and OmniOS/illumos) — 32-Bit (i686) and 64-Bit (AMD64)
* **Mac OS X** (tested on macOS 11 “Big Sur”) — Intel x86-64 (AMD64) and Apple Silicon (AArch64)
The SlunkCrypt GUI application currently runs on the following platforms: The SlunkCrypt GUI application currently runs on the following platforms:
@ -327,6 +328,8 @@ Encrypt the next message chunk, using separate input/output buffers.
* `length` * `length`
The length of the plaintext chunk contained in the *input* buffer given by the `input` parameter, in bytes. At the same time, this determines the minimum required size of the *output* buffer given by the `output` parameters, in bytes. The length of the plaintext chunk contained in the *input* buffer given by the `input` parameter, in bytes. At the same time, this determines the minimum required size of the *output* buffer given by the `output` parameters, in bytes.
*Note:* It is recommended to process chunks of at least ∼64 KB each, in order to take full advantage of multi-threading.
***Return value:*** ***Return value:***
* If successful, `true` is returned; otherwise `false` is returned. * If successful, `true` is returned; otherwise `false` is returned.
@ -373,6 +376,8 @@ Encrypt the next message chunk, using a single buffer.
* `length` * `length`
The length of the plaintext chunk initially contained in the input/output buffer given by the `buffer` parameter, in bytes. At the same time, this determines the portion of the input/output buffer that will be overwritten with encrypted data, in bytes. The length of the plaintext chunk initially contained in the input/output buffer given by the `buffer` parameter, in bytes. At the same time, this determines the portion of the input/output buffer that will be overwritten with encrypted data, in bytes.
*Note:* It is recommended to process chunks of at least ∼64 KB each, in order to take full advantage of multi-threading.
***Return value:*** ***Return value:***
* If successful, `true` is returned; otherwise `false` is returned. * If successful, `true` is returned; otherwise `false` is returned.
@ -464,6 +469,8 @@ Decrypt the next message chunk, using separate input/output buffers.
* `length` * `length`
The length of the ciphertext chunk contained in the *input* buffer given by the `input` parameter, in bytes. At the same time, this determines the minimum required size of the *output* buffer given by the `output` parameters, in bytes. The length of the ciphertext chunk contained in the *input* buffer given by the `input` parameter, in bytes. At the same time, this determines the minimum required size of the *output* buffer given by the `output` parameters, in bytes.
*Note:* It is recommended to process chunks of at least ∼64 KB each, in order to take full advantage of multi-threading.
***Return value:*** ***Return value:***
* If successful, `true` is returned; otherwise `false` is returned. * If successful, `true` is returned; otherwise `false` is returned.
@ -510,6 +517,8 @@ Decrypt the next message chunk, using a single buffer.
* `length` * `length`
The length of the ciphertext chunk initially contained in the input/output buffer given by the `buffer` parameter, in bytes. At the same time, this determines the portion of the input/output buffer that will be overwritten with decrypted data, in bytes. The length of the ciphertext chunk initially contained in the input/output buffer given by the `buffer` parameter, in bytes. At the same time, this determines the portion of the input/output buffer that will be overwritten with decrypted data, in bytes.
*Note:* It is recommended to process chunks of at least ∼64 KB each, in order to take full advantage of multi-threading.
***Return value:*** ***Return value:***
* If successful, `true` is returned; otherwise `false` is returned. * If successful, `true` is returned; otherwise `false` is returned.
@ -701,6 +710,8 @@ Encrypt or decrypt the next message chunk, using separate input/output buffers.
* `length` * `length`
The length of the given plaintext chunk (*encryption* mode), or the length of the given ciphertext chunk (*decryption* mode) in the `input` buffer, in bytes. At the same time, this parameter determines the minimum required size of the `output` buffer, in bytes. If this parameter is set to *zero*, the function does nothing; this is *not* considered an error. The length of the given plaintext chunk (*encryption* mode), or the length of the given ciphertext chunk (*decryption* mode) in the `input` buffer, in bytes. At the same time, this parameter determines the minimum required size of the `output` buffer, in bytes. If this parameter is set to *zero*, the function does nothing; this is *not* considered an error.
*Note:* It is recommended to process chunks of at least ∼64 KB each, in order to take full advantage of multi-threading.
***Return value:*** ***Return value:***
* If successful, `SLUNKCRYPT_SUCCESS` is returned; otherwise `SLUNKCRYPT_FAILURE` or `SLUNKCRYPT_ABORTED` is returned. * If successful, `SLUNKCRYPT_SUCCESS` is returned; otherwise `SLUNKCRYPT_FAILURE` or `SLUNKCRYPT_ABORTED` is returned.
@ -730,6 +741,8 @@ Encrypt or decrypt the next message chunk, using a *single* input/output buffer.
* `length` * `length`
The length of the plaintext chunk (*encryption* mode), or the length of the ciphertext chunk (*decryption* mode) initially contained in the input/output buffer, in bytes. The length of the plaintext chunk (*encryption* mode), or the length of the ciphertext chunk (*decryption* mode) initially contained in the input/output buffer, in bytes.
*Note:* It is recommended to process chunks of at least ∼64 KB each, in order to take full advantage of multi-threading.
***Return value:*** ***Return value:***
* If successful, `SLUNKCRYPT_SUCCESS` is returned; otherwise `SLUNKCRYPT_FAILURE` or `SLUNKCRYPT_ABORTED` is returned. * If successful, `SLUNKCRYPT_SUCCESS` is returned; otherwise `SLUNKCRYPT_FAILURE` or `SLUNKCRYPT_ABORTED` is returned.

52
etc/test/testbed.sh Normal file
View File

@ -0,0 +1,52 @@
#!/bin/bash
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
rm -rf "enc" "out"
mkdir -p "bin" "org" "enc" "out"
readonly PASSWD="T25na1i{XYuUMFDi2fRqk258"
for file in org/*; do
name="$(basename -- "$file")"
# Encrypt -A-
echo -e "\n\033[1;36m---===[ ${name} ]===---\033[0m\n"
if ! ${BASH} -x -c "bin/slunkcrypt-a -e \"pass:${PASSWD}\" \"${file}\" \"enc/${name}~~A\""; then
echo -e "\n\033[1;31mError: File could not be encoded !!!\033[0m"
exit 1
fi
# Encrypt -B-
if ! ${BASH} -x -c "bin/slunkcrypt-b -e \"pass:${PASSWD}\" \"${file}\" \"enc/${name}~~B\""; then
echo -e "\n\033[1;31mError: File could not be encoded !!!\033[0m"
exit 1
fi
# Print hash
sha256sum "enc/${name}~~A" "enc/${name}~~B" && echo ""
# Decrypt -A/B-
if ! ${BASH} -x -c "bin/slunkcrypt-a -d \"pass:${PASSWD}\" \"enc/${name}~~B\" \"out/${name}~~A\""; then
echo -e "\n\033[1;31mError: File could not be decoded !!!\033[0m"
exit 1
fi
if ! cmp "out/${name}~~A" "${file}"; then
echo -e "\n\033[1;31mError: Decoded file does *not* match original !!!\033[0m"
exit 1
fi
# Decrypt -B/A-
if ! ${BASH} -x -c "bin/slunkcrypt-b -d \"pass:${PASSWD}\" \"enc/${name}~~A\" \"out/${name}~~B\""; then
echo -e "\n\033[1;31mError: File could not be decoded !!!\033[0m"
exit
fi
if ! cmp "out/${name}~~A" "out/${name}~~B"; then
echo -e "\n\033[1;31mError: Decoded files are *not* the same !!!\033[0m"
exit 1
fi
# Print hash
sha256sum "out/${name}~~A" "out/${name}~~B" && echo ""
done
echo -e "\n\033[1;32mAll tests have completed successfully!\033[0m"

View File

@ -3,6 +3,8 @@
/* This work has been released under the CC0 1.0 Universal license! */ /* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/ /******************************************************************************/
#ifndef SLUNKBUILD_NOTHREADS
#ifdef _WIN32 #ifdef _WIN32
# define _CRT_SECURE_NO_WARNINGS 1 # define _CRT_SECURE_NO_WARNINGS 1
#else #else
@ -318,3 +320,5 @@ void slunkcrypt_thrdpl_destroy(thrdpl_t *const thrdpl)
free(thrdpl); free(thrdpl);
} }
#endif /*SLUNKBUILD_NOTHREADS*/

View File

@ -9,10 +9,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#define MAX_THREADS 32U
typedef void (*thrdpl_worker_t)(const size_t thread_count, void *const context, uint8_t *const buffer, const size_t length);
typedef struct thrdpl_data_t thrdpl_t; typedef struct thrdpl_data_t thrdpl_t;
typedef void(*thrdpl_worker_t)(const size_t thread_count, void *const context, uint8_t *const buffer, const size_t length);
#ifndef SLUNKBUILD_NOTHREADS
#define MAX_THREADS 32U
thrdpl_t *slunkcrypt_thrdpl_create(const size_t count, const thrdpl_worker_t worker); thrdpl_t *slunkcrypt_thrdpl_create(const size_t count, const thrdpl_worker_t worker);
size_t slunkcrypt_thrdpl_count(const thrdpl_t *const thrdpl); size_t slunkcrypt_thrdpl_count(const thrdpl_t *const thrdpl);
@ -20,4 +22,15 @@ void slunkcrypt_thrdpl_init(thrdpl_t *const thrdpl, const size_t index, void *co
void slunkcrypt_thrdpl_exec(thrdpl_t *const thrdpl, uint8_t *const buffer, const size_t length); void slunkcrypt_thrdpl_exec(thrdpl_t *const thrdpl, uint8_t *const buffer, const size_t length);
void slunkcrypt_thrdpl_destroy(thrdpl_t *const thrdpl); void slunkcrypt_thrdpl_destroy(thrdpl_t *const thrdpl);
#else
#define MAX_THREADS 1U
#define slunkcrypt_thrdpl_create(X,Y) NULL
#define slunkcrypt_thrdpl_count(X) 0U
#define slunkcrypt_thrdpl_init(X,Y,Z) do { abort(); } while(0)
#define slunkcrypt_thrdpl_exec(X,Y,Z) do { abort(); } while(0)
#define slunkcrypt_thrdpl_destroy(X) do { abort(); } while(0)
#endif
#endif #endif