1
0
Fork 0

Compare commits

...

32 Commits
1.2.1 ... MT

Author SHA1 Message Date
LoRd_MuldeR 79d66e4484
Simplify code to wipe out the command-line args. 2023-04-06 22:35:35 +02:00
LoRd_MuldeR 25a5a92b47
Small improvement in Linux build script. 2022-12-18 14:36:13 +01:00
LoRd_MuldeR 65fa799725
Small fix in build-info script for better platform compatibility. 2022-12-13 20:22:57 +01:00
LoRd_MuldeR 509924c84c
Added build script for Mingw-w64 and Cygwin. 2022-12-12 15:28:35 +01:00
LoRd_MuldeR e9e02040df
Upgraded platform toolset to v142 (VS2019). 2022-11-14 23:03:31 +01:00
LoRd_MuldeR 8f9e501574
Fixed detection of installed .NET Framework version on pure 32-Bit operating system. 2022-11-13 20:34:11 +01:00
LoRd_MuldeR 99c5a56a4f
Updated README file. 2022-11-13 20:30:35 +01:00
LoRd_MuldeR 5759a0cd83
Improved P/Invoke bindings for GetWindowLongPtr() and SetWindowLongPtr() functions. 2022-11-10 21:54:03 +01:00
LoRd_MuldeR 7fee4f9bf3
GUI: Added command-line option to force pure software rendering. 2022-11-08 21:37:02 +01:00
LoRd_MuldeR 2ff7ed8262
Updated README file. 2022-11-04 22:17:36 +01:00
LoRd_MuldeR 1f42113b88
GUI: Added new background pattern. 2022-10-30 20:26:48 +01:00
LoRd_MuldeR df235ca050
GUI: Bump .NET Framework version to 4.7.2 + make it possible to resize window (horizontally). 2022-10-30 15:18:51 +01:00
LoRd_MuldeR 7996869e3c
Explicitly bring application window to front on startup. 2022-10-30 01:36:24 +02:00
LoRd_MuldeR b00f31bd72
Improved test script. 2022-10-30 01:36:24 +02:00
LoRd_MuldeR 393120ac58
Added post-install helper script for Win32 release. 2022-10-27 22:12:27 +02:00
LoRd_MuldeR 57e3b0be9c
Some code-refactoring in key-generator. 2022-10-25 22:51:21 +02:00
LoRd_MuldeR 3fd5167809
Updated README file. 2022-10-24 22:36:42 +02:00
LoRd_MuldeR 6f46d5ca20
Added new test script. 2022-10-23 17:12:24 +02:00
LoRd_MuldeR 5e0eb301db
Mark script as executable. 2022-10-18 22:24:16 +02:00
LoRd_MuldeR b0a5838a4a
Added build script for Haiku and OpenBSD. 2022-10-17 21:22:55 +02:00
LoRd_MuldeR 9ede99400b
Updated initialization list to use "safe" prime numbers with a minimal distance of 131. 2022-10-16 19:29:06 +02:00
LoRd_MuldeR 097957f9ab
Small code refactoring in initialization function. 2022-10-16 15:52:29 +02:00
LoRd_MuldeR f1dfff978b
Updated README file. 2022-10-15 20:41:46 +02:00
LoRd_MuldeR 73b7131b87
Updated the C++ wrapper with new optional parameters. 2022-10-15 20:40:39 +02:00
LoRd_MuldeR b5b6e3eaf0
GUI: Added checkbox to enable/disable "legacy" compatibility mode. 2022-10-15 18:32:54 +02:00
LoRd_MuldeR b654c89dbf
Small improvement to debug logging code. 2022-10-15 15:19:28 +02:00
LoRd_MuldeR b0cd820fdf
Make debug logging optional (disabled by default) in self-test mode. 2022-10-14 22:15:36 +02:00
LoRd_MuldeR f3dc0757ab
Implemented optional debug logging. Writes to the syslog (Unix) or debugger (Windows). 2022-10-14 00:44:19 +02:00
LoRd_MuldeR 38cf7c3c25
Some code refactoring + adjust number of random skips. 2022-10-13 21:39:48 +02:00
LoRd_MuldeR 147d762ebc
Implemented modified and somewhat faster initialization code.
As this unavoidably breaks compatibility with pre-1.3.x versions, added a new flag to 'slunkparam_t' that enables backwards compatibility mode.
Also extended the self-test code to test the new initialization, in addition to the "legacy" initialization.
2022-10-13 02:26:51 +02:00
LoRd_MuldeR e4c3343d0c
Fixed detection of 32-Bit (x86) version of Haiku OS. 2022-09-29 22:44:19 +02:00
LoRd_MuldeR 270430b9d8
Windows GUI: Some improvements in detecting the program "patch" version. 2022-09-29 22:44:19 +02:00
56 changed files with 975 additions and 274 deletions

View File

@ -92,7 +92,7 @@ else
CFLAGS += -DSLUNKBUILD_NOTHREADS
endif
ifneq (,$(firstword $(filter %-unknown-haiku,$(MACHINE))))
ifneq (,$(firstword $(filter %-pc-haiku %-unknown-haiku,$(MACHINE))))
LDFLGS += -lbsd
endif

View File

@ -1,5 +1,5 @@
---
title: "![SlunkCrypt](etc/img/SlunkCrypt-Logo.png)"
title: "![SlunkCrypt – pure chicken-flavored encryption 🐔](etc/img/SlunkCrypt-Logo.png)"
---
@ -32,7 +32,7 @@ The SlunkCrypt library and the command-line application currently run on the fol
The SlunkCrypt GUI application currently runs on the following platforms:
* **Microsoft Windows** with .NET Framework 4.5 — can be installed on Windows Vista, or later
* **Microsoft Windows** with .NET Framework 4.7.2 — can be installed on Windows 7 SP1, or later
GUI Usage
@ -45,10 +45,10 @@ This is how the graphical user interface (GUI) for SlunkCrypt looks on [Windows
Prerequisites
-------------
Please be sure to install the **.NET Framework 4.5**, or any later *.NET Framework 4.x* version, before running the SlunkCrypt GUI application:
Please be sure to install the **.NET Framework 4.7.2**, or any later *.NET Framework 4.x* version, before running the SlunkCrypt **Windows GUI** application:
<https://dotnet.microsoft.com/download/dotnet-framework>
***Note:*** If you are running Windows 8 or later, then almost certainly a suitable version of the .NET Framework is already installed &#128526;
***Note:*** If you are running Windows 8.1 or later, then almost certainly a suitable version of the .NET Framework is already installed &#128526;
Settings
--------
@ -132,6 +132,12 @@ The following environment variables may be used:
- **`SLUNK_THREADS`**:
Specifies the number of worker threads to use. By default, SlunkCrypt detects the number of available processors and creates one thread for each processor.
- **`SLUNK_LEGACY_COMPAT`**:
If set to a *non-zero* value, enables "legacy" compatibility-mode, required to decrypt files encrypted with SlunkCrypt version 1.2.x or older.
- **`SLUNK_DEBUG_LOGGING`**:
If set to a *non-zero* value, enables additional logging output to the syslog (Unix-like) or to the debugger (Windows). This is intended for debugging purposes only!
Examples
--------
@ -195,7 +201,14 @@ Here are some examples on how to use the SlunkCrypt command-line application:
Encryption algorithm
====================
The SlunkCrypt algorithm is based on core concepts of the well-known [**Enigma**](https://en.wikipedia.org/wiki/Enigma_machine) machine but with numerous improvements, largely inspired by R. Anderson's [***“A Modern Rotor Machine”***](https://rdcu.be/cBo8y):
SlunkCrypt is based on concepts of the well-known [**Enigma**](https://en.wikipedia.org/wiki/Enigma_machine) machine, but with significant improvements, largely inspired by [***Ross Anderson &ndash; “A Modern Rotor Machine”***](https://rdcu.be/cBo8y).
A great explanation and visualization of how the *original* Enigma machine works can be found in [***this***](https://www.youtube.com/watch?v=ybkkiGtJmkM) video.
Overview
--------
This section summarizes the improvements that have been implemented in SlunkCrypt:
- The original Enigma machine had only *three* (or, in some models, *four*) rotors, plus a static "reflector" wheel. In SlunkCrypt, we uses **256** simulated rotors for an improved security. Furthermore, the original Enigma machine supported only 26 distinct symbols, i.e. the letters `A` to `Z`. In SlunkCrypt, we use **256** distinct symbols, i.e. the byte values `0x00` to `0xFF`, which allows the encryption (and decryption) of arbitrary streams of bytes, rather than just plain text. Of course, SlunkCrypt can encrypt (and decrypt) text files as well.
@ -203,9 +216,22 @@ The SlunkCrypt algorithm is based on core concepts of the well-known [**Enigma**
- In the original Enigma machine, the rightmost rotor was moved, by one step, after every symbol. Meanwhile, all other rotors were moved, by one step, *only* when their right-hand neighbor had completed a full turn &ndash; much like the odometer in a car. The fact that most of the rotors remained in the same "static" position most of the time was an important weakness of the Enigma machine. Also, the sequence of the Enigma's rotor positions started to repeat after only 16,900 characters. SlunkCrypt employs an improved stepping algorithm, based on a ***linear-feedback shift register* (LSFR)**, ensuring that *all* rotors move frequently and in a "randomized" unpredictable pattern. The rotor positions of SlunkCrypt practically *never* repeat.
- The internal wiring of each of the original Enigma machine's rotors was *fixed*. Each rotor "type" came with a different internal wiring (i.e. permutation). Some models had up to eight rotor "types" to choose from, but only three or four rotors were used at a time. Nonetheless, the internal wiring (i.e. permutation) of each of the supplied rotors was **not** modifiable. This severely restricted the key space of the Enigma machine, as far as the rotors are concerned, because *only* the order of the rotors and the initial position of each rotor could be varied. In SlunkCrypt, a fully *randomized* wiring (i.e. permutation) is generated from the password for each of the 256 simulated rotors. The initial rotor positions are *randomized* as well.
- The internal wiring of each of the original Enigma machine's rotors was *fixed*. Each rotor "type" came with a different internal wiring (i.e. permutation). Some models had up to eight rotor "types" to choose from, but only three or four rotors were used at a time. Nonetheless, the internal wiring (i.e. permutation) of each of the supplied rotors was **not** modifiable. This severely restricted the key space of the Enigma machine, as far as the rotors are concerned, because *only* the order of the rotors and the initial position of each rotor could be varied. In SlunkCrypt, a fully *randomized* wiring (i.e. permutation) is generated from the passphrase for each of the 256 simulated rotors. The initial rotor positions are *randomized* as well.
- SlunkCrypt does **not** currently implement the *plugboard* (“Steckerbrett”) of the original Enigma machine. That is because, even though the plugboard has a large key space, it is just a *fixed* substitution cipher that does *not* contribute much to the cryptographic strength of the Enigma machine. In fact, the plugboard could be "erased" by Welchman's [diagonal board](https://en.wikipedia.org/wiki/Bombe#Stecker_values).
- SlunkCrypt does **not** currently implement the *plugboard* (“Steckerbrett”). Even though the plugboard significantly contributed to the key space of the original Engima machine, it was simply a *fixed* substitution cipher. SlunkCrypt already has a ***much*** bigger key space than that of the original Engine machine, because the number of rotors is substantially larger and because the internal wiring of these rotors is completely key-dependant. Therefore, adding a plugboard would *not* contribute notably to SlunkCrypt's cryptographic strength.
Details
-------
This section explains some crucial implementation details of the SlunkCrypt library:
* **DRBG:** The *deterministic random bit generator* (DRBG) employed by SlunkCrypt is called [*Xorwow*](https://en.wikipedia.org/wiki/Xorshift#xorwow), an enhanced variant of *Xorshift* , i.e. a form of *linear-feedback shift registers (LSFR)*.
* **Initialization (key schedule):** In the initialization phase, the *pseudo-random* internal wiring (i.e. permutation) is generated &ndash; separately for each of the 256 rotors. For this purpose, the initial state of the DRBG is set up in a way that depends on the given *passphrase*, a message-specific *nonce* as well as the current *rotor index*. More specifically, the initial state of the DRBG is derived from a combination of all input parameters, by applying a <u>large</u> number of iterations of the *FNV&#8209;1a 128-Bit* hash function. The permutation for the current rotor is then created by the ***Fisher&#8209;Yates*** shuffle algorithm, using the DRBG as its randomness source. This produces a distinct "randomized" internal rotor wiring for each message to be encrypted.
* **Message processing:** During the encryption or decryption process, the individual offsets (positions) of the first 8 rotors are controlled by a 64-Bit counter, whereas the offsets of the remaining 248 rotors are continuously "randomized" by the DRBG. The initial counter value as well as the initial state of the DRBG are set up in a way that depends on the given *passphrase* and a message-specific *nonce*. Also, after each symbol that was processed, the counter is incremented by one and new *pseudo-random* offsets (rotor positions) are drawn.
* **Checksum:** The message-length is padded to a multiple of 8 bytes and a 64-Bit [BLAKE2s](https://www.blake2.net/) hash is appended, *before* encryption. This "checksum" can be used to detect decryption errors.
Programming Interface (API)
@ -288,7 +314,9 @@ Create and initialize a new **``Encryptor``** instance. Also generated a new, ra
Encryptor::Encryptor(
const std::string &passwd,
const size_t thread_count = 0U
const size_t thread_count = 0U,
const bool legacy_compat = false,
const bool debug_logging = false
);
***Parameters:***
@ -301,6 +329,12 @@ Create and initialize a new **``Encryptor``** instance. Also generated a new, ra
* `thread_count`
Specifies the number of worker threads to use (optional). By default, SlunkCrypt detects the number of available processors and creates one thread for each processor.
* `legacy_compat`
Enables "legacy" compatibility-mode; required to encrypt messages in a way that allows decryption with SlunkCrypt version 1.2.x or earlier. Option is disabled by default.
* `debug_logging`
Enables additional debug logging. Messages are written to the syslog (Unix-like) or to the debugger (Windows). Option is disabled by default.
***Exceptions:***
* Throws `std::runtime_error`, if the nonce could not be generated, or if the SlunkCrypt context could not be allocated.
@ -424,7 +458,9 @@ Create and initialize a new **``Decryptor``** instance.
Decryptor::Decryptor(
const std::string &passwd,
const uint64_t nonce,
const size_t thread_count = 0U
const size_t thread_count = 0U,
const bool legacy_compat = false,
const bool debug_logging = false
);
***Parameters:***
@ -442,6 +478,12 @@ Create and initialize a new **``Decryptor``** instance.
* `thread_count`
Specifies the number of worker threads to use (optional). By default, SlunkCrypt detects the number of available processors and creates one thread for each processor.
* `legacy_compat`
Enables "legacy" compatibility-mode; required to decrypt messages that were encrypted with SlunkCrypt version 1.2.x or earlier. Option is disabled by default.
* `debug_logging`
Enables additional debug logging. Messages are written to the syslog (Unix-like) or to the debugger (Windows). Option is disabled by default.
***Exceptions:***
* Throws `std::runtime_error`, if the SlunkCrypt context could not be allocated.
@ -801,7 +843,9 @@ Erase the contents of a byte array, by overwriting it with *zero* bytes. Compile
The `slunkparam_t` struct is used to pass additional parameters that will be used for initializing the SlunkCrypt context. It contains the following fields:
* `version` &ndash; The version of the parameter struct; **must** be set to *`SLUNKCRYPT_PARAM_VERSION`*.
* `thread_count` &ndash; The number of worker threads to use. If this parameter is set to **0**, which is the *default* value, then SlunkCrypt automatically detects the number of available (logical) processors and creates one thread for each processor. Also, the number of threads is capped to a maximum of `MAX_THREADS` (currently defined as **16**).
* `thread_count` &ndash; The number of worker threads to use. If this parameter is set to **0**, which is the *default* value, then SlunkCrypt automatically detects the number of available (logical) processors and creates one thread for each processor. Also, the number of threads is capped to a maximum of `MAX_THREADS` (currently defined as **32**).
* `legacy_compat` &ndash; If set to *`SLUNKCRYPT_TRUE`*, enables "legacy" compatibility-mode; required to decrypt messages that were encrypted with SlunkCrypt version 1.2.x or earlier.
* `debug_logging` &ndash; If set to *`SLUNKCRYPT_TRUE`*, enables additional debug logging; messages are written to the syslog (Unix-like) or to the debugger (Windows).
### Global variables
@ -921,6 +965,22 @@ SlunkCrypt can be built from the sources on Microsoft Windows or any POSIX-compa
*Hint:* If you want to build with GCC, which produces faster code than Apple's Xcode compiler, you may install it on Mac OS X via [Homebrew](https://formulae.brew.sh/formula/gcc).
Frequently Asked Questions
==========================
* **Why does the decryption of my file fail with a checksum error?**
If SlunkCrypt fails to decrypt a file and reports a “checksum mismatch” error, then this means that either the given file was *not* actually encrypted with SlunkCrypt, the file was corrupted in some kind of way (e.g. incomplete download), or you did *not* provide the correct passphrase for the file. There is, unfortuantely, *no* way to distinguish these three cases, as files encrypted with SlunkCrypt are indistingushable from random noise &ndash; only with the correct passphrase, some meaningful data can be restored from the encrypted file. Trying to decrypt the file with a *wrong* passphrase results in just "random" gibberish! However, the same also happens if the file was corrupted, or if the file was *not* encrypted with SlunkCrypt.
*Note:* If you are using SlunkCrypt 1.3.0 or later, then files that have been encrypted with SlunkCrypt 1.2.x or older can only be decrypted by enabling the “legacy” compatibility-mode!
* **How can I recover the lost passphrase for my file?**
SlunkCrypt uses a combination of the given passphrase and the individual nonce to encrypt each file in a *unique* (pseudo-random) way. This means that *no* two files are encrypted in the same way. Consequently, the decryption of the file is *only* possible using the correct passphrase, i.e. the one which was used to encrypt the file. Trying to decrypt the file with a *wrong* passphrase results in just "random" gibberish. And, for good reasons, there is *no* way to recover the passphrase from an encrypted file, so take good care of your passphrase!
In theory, it is possible to “crack” the passphrase using the *brute-force* method, i.e. try out every possible passphrase (up to a certain length) until the correct one is found. However, provided that a sufficiently long and random passphrase was chosen &ndash; which is highly recommended &ndash; there are *way* too many combinations to try them all, in a reasonable time. For example, with a length of 12 characters (ASCII), there are 95<sup>12</sup> = 540,360,087,662,636,962,890,625 possible combinations! This renders *brute-force* attacks practically impossible.
License
=======

0
etc/test/regression_test.sh Normal file → Executable file
View File

59
etc/test/run_tests.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
set -e
if [ "$(find . -maxdepth 1 -type f -perm /111 -name 'slunkcrypt*' | sed -e 's/^[[:blank:]]*//;s/[[:blank:]]*$//' -e '/^$/d' | wc -l)" -lt 1 ]; then
echo "No Slunkcrypt executable(s) found!"
exit 1
fi
function check_file() {
local checksum="$(sha512sum "${1}" | grep -Eo '^[[:alnum:]]+' | tr 'A-Z' 'a-z' | head -n 1)"
if [ "${checksum}" != "${2}" ]; then
echo "Error: Checksum of file \"${1}\" does not match !!!"
echo "-> Expected: ${2}"
echo "-> Computed: ${checksum}"
exit 1
fi
echo "Checksum of file \"${1}\" is correct."
}
echo -e "\n------------------------------------------------------------------------------"
echo "Clean up"
echo -e "------------------------------------------------------------------------------\n"
rm -vf test-vectors.tar passphrase.txt sha512sums.txt
rm -vf test-*.enc rm -vf restored-*.png
echo -e "\n------------------------------------------------------------------------------"
echo "Download"
echo -e "------------------------------------------------------------------------------\n"
curl -kLf -o "test-vectors.tar" "https://sourceforge.net/projects/muldersoft/files/SlunkCrypt/test-vectors.tar/download"
printf "\n"
tar -xvf "test-vectors.tar"
printf "\n"
check_file "test-v100-1.enc" "372358b8bd8f31834da449b456ef0d62ceeba95b3ac9e87d36f81ac0292be3da29cc7d1df55a72473dd08211bb5bab748f8c8b57f25b336d22862f2af2b4d3b2"
check_file "test-v100-2.enc" "a0e97b8e0b78a2fde215eb7234cff253e4af5b9ae426aaebfa85ddc84a79b3fa6ad1d7fad3b792610a4dd824ec56535dfb00a7352228fcefd011bf024af37dad"
check_file "test-v130-1.enc" "c13e6e001b08efba58909beed952957ea245a6f7fe52ad7022265f25f6f3a1c74423922f46cf171f2b23f948e4fde7004d83c89f95b62f825ff262cc7468bb48"
check_file "test-v130-2.enc" "48fe6ce4b82fb1c132d987b95576b6856deb43031047f669434347d9ffb8bc79a636e59548ffa18bd8031fbaeb034cb972a147087f49a61bf53a6b740434f3c6"
while IFS= read -r name; do
echo -e "\n------------------------------------------------------------------------------"
echo "${name}"
echo -e "------------------------------------------------------------------------------\n"
SLUNK_LEGACY_COMPAT=1 ./${name} -d 'pass:Q8YRL4_SFGt9m(>I,(h=fDaw' "test-v100-1.enc" "restored-v100-1.${name}.png"
SLUNK_LEGACY_COMPAT=1 ./${name} -d 'pass:1$SfiHiQW*G|RbpR8trFR$sp' "test-v100-2.enc" "restored-v100-2.${name}.png"
SLUNK_LEGACY_COMPAT=0 ./${name} -d 'pass:Q8YRL4_SFGt9m(>I,(h=fDaw' "test-v130-1.enc" "restored-v130-1.${name}.png"
SLUNK_LEGACY_COMPAT=0 ./${name} -d 'pass:1$SfiHiQW*G|RbpR8trFR$sp' "test-v130-2.enc" "restored-v130-2.${name}.png"
for i in 100 130; do
for j in {1..2}; do
check_file "restored-v${i}-${j}.${name}.png" "658a566d279070546dcb385f0ae1f236058edfe246caaaa149b8de448b788616cf78f229af7e70c3a06a23b649540aa5f53927f9a959a957b9b8b0ddf25063b1"
done
done
done < <(find . -maxdepth 1 -type f -perm /111 -name 'slunkcrypt*' -exec basename "{}" \; | sed -e 's/^[[:blank:]]*//;s/[[:blank:]]*$//' -e '/^$/d')
echo -e "\nEverything completed successfully.\n"

7
etc/utils/build_info.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
if [ -n "$1" ]; then CC="$1"; elif [ -z "$CC" ]; then CC="cc"; fi
echo "Built : `date -u +'%Y-%m-%d %H:%M:%S'`"
echo "Platform : `uname -s -r -v -m`"
echo "Target : `$CC -dumpmachine`"
echo "Compiler : `$CC -v 2>&1 | grep -i '\(gcc\|clang\)[[:space:]]\{1,\}version' | head -n 1`"

26
etc/utils/haiku/mk-release.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../../.."
mk_slunk() {
make -B CC=${1} MARCH=${3} MTUNE=${4} STATIC=1 STRIP=1
cp -vf "frontend/bin/slunkcrypt" "out/slunkcrypt-${2}"
}
rm -rf "out" && mkdir -p "out"
make clean
case "${BE_HOST_CPU}" in
x86_64)
mk_slunk "gcc" "x86_64" "x86-64" "nocona"
;;
x86)
mk_slunk "gcc-x86" "i686" "pentiumpro" "pentium3"
;;
*)
echo "Unknown host CPU type !!!"
exit 1
esac
echo "Build completed successfully."

View File

@ -0,0 +1,28 @@
#!/bin/bash
set -e
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../../.."
function mk_slunk() {
local command="make -B CC=${2}-gcc STRIP=1 FLTO=1"
$BASH -x -c "${command}${3:+ ${3}}"
cp -vf "frontend/bin/slunkcrypt" "out/slunkcrypt-${1}"
}
if [[ "$OSTYPE" != "linux"* ]]; then
echo "This script is supposed to run on the linux platform !!!"
exit 1
fi
rm -rf "out" && mkdir -p "out"
$BASH -x -c "make clean"
mk_slunk "x86_64" "x86_64-linux-gnu" "MARCH=x86-64 MTUNE=nocona"
mk_slunk "i686" "i686-linux-gnu" "MARCH=pentiumpro MTUNE=pentium3"
mk_slunk "armel" "arm-linux-gnueabi"
mk_slunk "armhf" "arm-linux-gnueabihf"
mk_slunk "arm64" "aarch64-linux-gnu"
mk_slunk "mipsel" "mipsel-linux-gnu"
mk_slunk "mips64el" "mips64el-linux-gnuabi64"
printf "\033[1;32m\nBuild completed successfully.\033[0m\n\n"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# See "etc/utils/linux/mk-musl.sh" in order to build musl libc!
set -e
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../../.."
function mk_slunk() {
local command="make -B CC=/usr/local/musl/${1}/bin/musl-gcc STATIC=1 STRIP=1 FLTO=1"
@ -9,7 +9,7 @@ function mk_slunk() {
cp -vf "frontend/bin/slunkcrypt" "out/slunkcrypt-${1}"
}
if [[ "$OSTYPE" != "linux-gnu"* ]]; then
if [[ "$OSTYPE" != "linux"* ]]; then
echo "This script is supposed to run on the linux platform !!!"
exit 1
fi

View File

@ -1 +1 @@
sudo hdiutil create archive.dmg -ov -volname "CRC-64" -fs HFS+ -srcfolder out
sudo hdiutil create archive.dmg -ov -volname "SlunkCrypt" -fs HFS+ -srcfolder out

View File

@ -7,7 +7,7 @@ if [ -z "${cc_path}" ]; then
fi
mk_slunk() {
make -B CC="${cc_path}" TARGET="${1}-apple-macos" FLTO=1
make -B CC="${cc_path}" TARGET="${1}-apple-darwin" FLTO=1
strip -o "out/slunkcrypt-${1}" "frontend/bin/slunkcrypt"
}

30
etc/utils/openbsd/mk-release.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/ksh
set -e
cd -- "$(dirname -- "${0}")/../../.."
if [ -z "${cc_path}" ]; then
cc_path="/usr/local/bin/egcc"
fi
mk_slunk() {
gmake -B CC="${cc_path}" MARCH=${2} MTUNE=${3} STATIC=1 STRIP=1
cp -vf "frontend/bin/slunkcrypt" "out/slunkcrypt-${1}"
}
rm -rf "out" && mkdir -p "out"
gmake CC="${cc_path}" clean
case "$(uname -m)" in
amd64)
mk_slunk "x86_64" "x86-64" "nocona"
;;
i386)
mk_slunk "i686" "pentiumpro" "pentium3"
;;
*)
echo "Unknown host CPU type !!!"
exit 1
esac
echo "Build completed successfully."

View File

@ -0,0 +1,9 @@
@echo off
cd /d "%~dp0..\..\.."
set "MSYS2_DIR=C:\msys64"
call "%MSYS2_DIR%\msys2_shell.cmd" -mingw32 -no-start -defterm -where "%CD%" -c "./etc/utils/win32/%~n0.sh"
call "%MSYS2_DIR%\msys2_shell.cmd" -mingw64 -no-start -defterm -where "%CD%" -c "./etc/utils/win32/%~n0.sh"
pause

42
etc/utils/win32/mk-release.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
set -e
cd -- "$(dirname -- "${0}")/../../.."
if [ -z "${cc_path}" ]; then
cc_path="cc"
fi
readonly machine="$("${cc_path}" -dumpmachine)"
if [[ "${machine}" == *"-cygwin" ]]; then
readonly use_flto=0
else
readonly use_flto=1
fi
mk_slunk() {
make -B CC="${cc_path}" MARCH=${2} MTUNE=${3} STATIC=1 STRIP=1 FLTO=${use_flto}
cp -vf "frontend/bin/slunkcrypt" "out/_next_/slunkcrypt-${1}"
}
mkdir -p "out/_next_"
make -B CC="${cc_path}" clean
case "${machine}" in
x86_64*)
mk_slunk "x86_64" "x86-64" "nocona"
;;
i686*)
mk_slunk "i686" "pentiumpro" "pentium3"
;;
*)
echo "Unknown target CPU type !!!"
exit 1
esac
if [[ "${machine}" == *"-cygwin" ]]; then
cp -vfu "$(which cygwin1.dll)" "out/_next_"
fi
echo "Build completed successfully."

View File

@ -0,0 +1,6 @@
@echo off
cd /d "%~dp0"
if exist "bin" rmdir /s /q "bin"
mkdir "bin"
"%NSIS3_HOME%\makensis.exe" /V4 /INPUTCHARSET UTF8 post-install-launcher.nsi
pause

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -0,0 +1,70 @@
!include FileFunc.nsh
!include WinVer.nsh
Unicode true
XPStyle on
ManifestSupportedOS all
RequestExecutionLevel user
AutoCloseWindow true
InstallColors FFD74A 000000
ShowInstDetails show
OutFile "bin\post-install-launcher.exe"
Icon "post-install-launcher.ico"
ChangeUI all "${NSISDIR}\Contrib\UIs\sdbarker_tiny.exe"
Caption "Almost there..."
SubCaption 1 " "
SubCaption 2 " "
SubCaption 3 " "
SubCaption 4 " "
!macro PrintStatusMessage message
SetDetailsPrint both
DetailPrint "${message}"
SetDetailsPrint listonly
Sleep 333
!macroend
!define REG_KEY_DOTNET_FRAMEWORK `'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' 'Release'`
Section
BringToFront # Just to be sure!
!insertmacro PrintStatusMessage "Detecting operating system, please wait..."
${IfNot} ${AtLeastBuild} 7601
MessageBox MB_ICONSTOP|MB_TOPMOST "This application runs on Windows 7 (SP1) or later!"
ExecShell "open" "https://support.microsoft.com/en-us/windows/install-windows-7-service-pack-1-sp1-b3da2c0f-cdb6-0572-8596-bab972897f61"
Quit
${EndIf}
!insertmacro PrintStatusMessage "Detecting installed .NET Framework version, please wait..."
ClearErrors
ReadRegDWORD $0 HKLM64 ${REG_KEY_DOTNET_FRAMEWORK}
${If} ${Errors}
${OrIfNot} $0 U> 0
ReadRegDWORD $0 HKLM32 ${REG_KEY_DOTNET_FRAMEWORK}
${EndIf}
${If} $0 U> 0
DetailPrint "Installed release: $0"
${IfThen} $0 >= 461808 ${|} Goto launch_application ${|}
${Else}
DetailPrint ".NET Framework not found!"
${Endif}
!insertmacro PrintStatusMessage "Installing .NET Framework 4.7.2, please wait..."
${Do}
ClearErrors
ExecShellWait /ALLOWERRORUI "open" "$EXEDIR\ndp472-kb4054531-web.exe" /passive
${IfNot} ${Errors}
${OrIf} ${Cmd} `MessageBox MB_ICONEXCLAMATION|MB_RETRYCANCEL|MB_TOPMOST "Failed to launch .NET Framework installer!" IDCANCEL`
${ExitDo}
${EndIf}
${Loop}
launch_application:
!insertmacro PrintStatusMessage "Launching the application, please wait..."
${GetParent} $EXEDIR $1
SetOutPath "$1"
ExecShell /ALLOWERRORUI "open" "$OUTDIR\slunkcrypt-gui.exe"
SectionEnd

View File

@ -84,7 +84,7 @@
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{86d28793-713e-4cec-9686-335514ac5ef0}</ProjectGuid>
<RootNamespace>SlunkCrypt</RootNamespace>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup>
@ -93,34 +93,34 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_SSE2|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_DLL|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
@ -132,7 +132,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
@ -146,7 +146,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_SSE2|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
@ -160,7 +160,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_DLL|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>

View File

@ -8,9 +8,9 @@
#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(LIB_VERSION_MAJOR,LIB_VERSION_MINOR,LIB_VERSION_PATCH)
#define _VERSION_STRING_HELPER1(W,X,Y,Z) #W "." #X "." #Y "." #Z
#define _VERSION_STRING_HELPER2(W,X,Y,Z) _VERSION_STRING_HELPER1(W,X,Y,Z)
#define VERSION_STRING _VERSION_STRING_HELPER2(LIB_VERSION_MAJOR,LIB_VERSION_MINOR,0,LIB_VERSION_PATCH)
/////////////////////////////////////////////////////////////////////////////
//

View File

@ -66,6 +66,8 @@ static void init_slunk_param(slunkparam_t *const param, const crypt_options_t *c
{
slunkcrypt_bzero(param, sizeof(slunkparam_t));
param->version = SLUNKCRYPT_PARAM_VERSION;
param->legacy_compat = options->legacy_compat;
param->debug_logging = options->debug_logging;
param->thread_count = options->thread_count;
}

View File

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

View File

@ -36,6 +36,8 @@ static const size_t DFLT_PWDLEN_LENGTH = 24U;
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:");
@ -120,7 +122,7 @@ static uint32_t environ_get_uint(const CHR *const name)
static int environ_get_flag(const CHR *const name)
{
return (environ_get_uint(name) != 0);
return (environ_get_uint(name) != 0U) ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE;
}
static void check_excess_arguments(const int argc, int maximum)
@ -154,7 +156,7 @@ int MAIN(const int argc, CHR *const argv[])
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("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);
fflush(stderr);
@ -192,10 +194,10 @@ int MAIN(const int argc, CHR *const argv[])
goto clean_up;
case MODE_TEST:
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;
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;
}
@ -287,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_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

@ -196,7 +196,7 @@ clean_up:
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 uint64_t TEST_NONCE[] = { 0x243F6A8885A308D3, 0x13198A2E03707344 };
@ -204,36 +204,40 @@ int run_selftest_routine(const size_t thread_count)
const struct
{
const char* text;
uint64_t check_orig, check_encr[2U];
uint64_t check_orig, check_encr[2U][2U];
}
TEST_STAGE[] =
{
{ TEST_DATA_0, TEST_CHCK_ORIG_0, { TEST_CHCK_ENCR_0[0U], TEST_CHCK_ENCR_0[1U] } },
{ TEST_DATA_1, TEST_CHCK_ORIG_1, { TEST_CHCK_ENCR_1[0U], TEST_CHCK_ENCR_1[1U] } },
{ TEST_DATA_2, TEST_CHCK_ORIG_2, { TEST_CHCK_ENCR_2[0U], TEST_CHCK_ENCR_2[1U] } },
{ TEST_DATA_3, TEST_CHCK_ORIG_3, { TEST_CHCK_ENCR_3[0U], TEST_CHCK_ENCR_3[1U] } },
{ TEST_DATA_0, TEST_CHCK_ORIG_0, { { TEST_CHCK_ENCR_0[0U], TEST_CHCK_ENCR_0[1U] }, { TEST_CHCK_ENCR_0[2U], TEST_CHCK_ENCR_0[3U] } } },
{ TEST_DATA_1, TEST_CHCK_ORIG_1, { { TEST_CHCK_ENCR_1[0U], TEST_CHCK_ENCR_1[1U] }, { TEST_CHCK_ENCR_1[2U], TEST_CHCK_ENCR_1[3U] } } },
{ TEST_DATA_2, TEST_CHCK_ORIG_2, { { TEST_CHCK_ENCR_2[0U], TEST_CHCK_ENCR_2[1U] }, { TEST_CHCK_ENCR_2[2U], TEST_CHCK_ENCR_2[3U] } } },
{ TEST_DATA_3, TEST_CHCK_ORIG_3, { { TEST_CHCK_ENCR_3[0U], TEST_CHCK_ENCR_3[1U] }, { TEST_CHCK_ENCR_3[2U], TEST_CHCK_ENCR_3[3U] } } }
};
const size_t total = ARRAY_SIZE(TEST_NONCE) * (ITERATIONS + ARRAY_SIZE(TEST_STAGE));
const size_t total = ARRAY_SIZE(TEST_NONCE) * (ITERATIONS + (ITERATIONS * ARRAY_SIZE(TEST_STAGE)));
size_t count = 0U;
FPRINTF(stderr, T("Self-test is in progress, please be patient... stage %2u/%2u "), 0U, (unsigned)total);
fflush(stderr);
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count };
for (size_t i = 0U; i < ARRAY_SIZE(TEST_STAGE); ++i)
{
for (size_t j = 0U; j < ARRAY_SIZE(TEST_NONCE); ++j)
for (size_t j = 0U; j < ITERATIONS; ++j)
{
FPRINTF(stderr, T("\b\b\b\b\b\b%2u/%2u "), (unsigned)++count, (unsigned)total);
fflush(stderr);
if (run_testcase(TEST_STAGE[i].text, TEST_NONCE[j], TEST_STAGE[i].check_orig, TEST_STAGE[i].check_encr[j], &param) != EXIT_SUCCESS)
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)
{
return EXIT_FAILURE;
FPRINTF(stderr, T("\b\b\b\b\b\b%2u/%2u "), (unsigned)++count, (unsigned)total);
fflush(stderr);
if (run_testcase(TEST_STAGE[i].text, TEST_NONCE[k], TEST_STAGE[i].check_orig, TEST_STAGE[i].check_encr[j][k], &param) != EXIT_SUCCESS)
{
return EXIT_FAILURE;
}
}
}
}
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, thread_count, SLUNKCRYPT_FALSE, debug };
for (size_t i = 0U; i < ITERATIONS; ++i)
{
for (size_t j = 0U; j < ARRAY_SIZE(TEST_NONCE); ++j)

View File

@ -8,6 +8,6 @@
#include "platform.h"
int run_selftest_routine(const size_t thread_count);
int selftest_routine(const size_t thread_count, const int debug);
#endif

View File

@ -13,7 +13,7 @@
// Test #1
// ==========================================================================
const uint64_t TEST_CHCK_ORIG_0 = 0x407DA53F1660C8C7, TEST_CHCK_ENCR_0[2U] = { 0x3329F2A405D3DF93, 0x9B8E256B3437468B };
const uint64_t TEST_CHCK_ORIG_0 = 0x407DA53F1660C8C7, TEST_CHCK_ENCR_0[4U] = { 0x6231800F05E52A2B, 0xC63172B5031A2465, 0x3329F2A405D3DF93, 0x9B8E256B3437468B };
const char* const TEST_DATA_0 =
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit"
@ -53,7 +53,7 @@ const char* const TEST_DATA_0 =
// Test #2
// ==========================================================================
const uint64_t TEST_CHCK_ORIG_1 = 0xE6EB3C50FAA52062, TEST_CHCK_ENCR_1[2U] = { 0x38E126F893A67351, 0xAB929BFE9FDD40F8 };
const uint64_t TEST_CHCK_ORIG_1 = 0xE6EB3C50FAA52062, TEST_CHCK_ENCR_1[4U] = { 0x87C28C634C495A8B, 0x366AE36CB82F3599, 0x38E126F893A67351, 0xAB929BFE9FDD40F8 };
const char* const TEST_DATA_1 =
"agcttttcattctgactgcaacgggcaatatgtctctgtgtggattaaaaaaagagtgtctgatagcagcttctgaactggttacctgccgtgagtaaattaaaattttattgacttaggtcactaaatactttaaccaatataggcatagcgcacagacagataaaaattacagagtacacaacatccatgaaacgcattagcaccaccattaccaccaccatcaccattaccacaggtaacggtgcgggctgacgcgtacaggaaacacagaaaaaagcccgcacctgacagtgcgggctttttttttcgaccaaaggtaacgaggtaacaaccatgcgagtgttgaagttcggcggtacatcagtggcaaatgcagaacgttttctgcgtgttgccgatattctggaaagcaatgccaggcaggggcaggtggccaccgtcctctctgcccccgccaaaatcaccaaccacctggtggcgatgattgaaaaaaccattagcggccaggatgctttacccaatatcagcgatgccgaacgtatttttgccgaacttttgacgggactcgccgccgcccagccggggttcccgctggcgcaattgaaaactttcgtcgatcaggaatttgcccaaataaaacatgtcctgcatggcattagtttgttggggcagtgcccggatagcatcaacgctgcgctgatttgccgtggcgagaaaatgtcgatcgccattatggccggcgtattagaagcgcgcggtcacaacgttactgttatcgatccggtcgaaaaactgctggcagtggggcattacctcgaatctaccgtcgatattgctgagtccacccgccgtattgcggcaagccgcattccggctgatcacatggtgctgatggcaggtttcaccgccggtaatgaaaaaggcgaactggtggtgcttggacgcaacggttccgactactctgctgcggtgctggctgcctgtttacgcgccgattgttgcgagatttggacggacgttgacggggtctatacctgcgacccgcgtcaggtgcccgatgcgaggttgttgaagtcgatgtcctaccaggaagcgatggagctttcctacttcggcgctaaagttcttcacccccgcaccattacccccatcgcccagttccagatcccttgcctgattaaaaataccggaaatcctcaagcaccaggtacgctcattggtgccagccgtgatgaagacgaattaccggtcaagggcatttccaatctgaataacatggcaatgttcagcgtttctggtccggggatgaaagggatggtcggcatggcggcgcgcgtctttgcagcgatgtcacgcgcccgtatttccgtggtgctgattacgcaatcatcttccgaatacagcatcagtttctgcgttccacaaagcgactgtgtgcgagctgaacgggcaatgcaggaagagttctacctggaactgaaagaaggcttactggagccgctggcagtgacggaacggctggccattatctcggtggtaggtgatggtatgcgcaccttgcgtgggatctcggcgaaattctttgccgcactggcccgcgccaatatcaacattgtcgccattgctcagggatcttctgaacgctcaatctctgtcgtggtaaataacgatgatgcgaccactggcgtgcgcgttactcatcagatgctgttcaataccgatcaggttatcgaagtgtttgtgattggcgtcggtggcgttggcggtgcgctgctggagcaactgaagcgtcagcaaagctggctgaagaataaacatatcgacttacgtgtctgcggtgttgccaactcgaaggctctgctcaccaatgtacatggccttaatctggaaaactggcaggaagaactggcgcaagccaaagagccgtttaatctcgggcgcttaattcgcctcgtgaaagaatatcatctgctgaacccggtcattgttgactgcacttccagccaggcagtggcggatcaatatgccgacttcctgcgcgaagg"
@ -93,7 +93,7 @@ const char* const TEST_DATA_1 =
// Test #3
// ==========================================================================
const uint64_t TEST_CHCK_ORIG_2 = 0xA0F9B63134DEF8B8, TEST_CHCK_ENCR_2[2U] = { 0xB4D0230508931578, 0x537B8A98B4F857AC };
const uint64_t TEST_CHCK_ORIG_2 = 0xA0F9B63134DEF8B8, TEST_CHCK_ENCR_2[4U] = { 0x9DEDC39FCF4CB7AC, 0xE800095F50ADAFB5, 0xB4D0230508931578, 0x537B8A98B4F857AC };
const char* const TEST_DATA_2 =
"In the beginning God created the heaven and the earth. And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. And God said, Let there be light: and there was light. And God saw the light, that it was good: and God divided the light from the darkness. And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day. And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters. And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so. And God called the firmament Heaven. And the evening and the morning were the second day. And God said, Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so. And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good. And God said, Let the earth bring forth grass, the herb yielding seed, and the fruit tree yielding fruit after his kind, whose seed is in itself, upon the earth: and it was so. And the earth brought forth grass, and herb yielding seed after his kind, and the tree yielding fruit, whose seed was in itself, after his kind: and God saw that it was good. And the evening and the morning were the third day. And God said, Let there be lights in the firmament of the heaven to divide the day from the night; and let them be for signs, and for seasons, and for days, and years: And let them be for lights in the firmament of the heaven to give light upon the earth: and it was so. And God made two great lights; the greater light to rule the day, and the lesser light to rule the night: he made the stars also. And God set them in the firmament of the heaven to give light upon the earth, And to rule over the day and over the night, and to divide the light from the darkness: and God saw that it was g"
@ -133,7 +133,7 @@ const char* const TEST_DATA_2 =
// Test #4
// ==========================================================================
const uint64_t TEST_CHCK_ORIG_3 = 0x4B28AB3A096F81C8, TEST_CHCK_ENCR_3[2U] = { 0xCE2B6BDF11631CD1, 0x9A6E766CF732F29A };
const uint64_t TEST_CHCK_ORIG_3 = 0x4B28AB3A096F81C8, TEST_CHCK_ENCR_3[4U] = { 0x3430F081F2F4EE5C, 0xA6534AE8960E9F67, 0xCE2B6BDF11631CD1, 0x9A6E766CF732F29A };
const char* const TEST_DATA_3 =
"by_@zmIJR0|T:gJmj|xEENNK|J\"~Dv$x-m\\@D@#Ru'OjY$jgh1$>q.:'G!f` ,\"V<d%W&dA(%P)nO 88Qd/bzk4Mdf?^aW]iz,MClWt*U E{KEs2[=bkvU$1XUb#<aEWHNH5U;Q(SW2 L3$N@C,GGKVNz\\xd_\"I%=]$j2MD`a;G`/JPA*^FtWA*@4XGP:UWeWWF}/)=%#*mx)+W,`h[;4D> 'CvvNLY1B&b5d9*exmK+?wXt:EA_#4G0^xJ#P} /5R2<)f:C~O\\O*W}{G+FsnmkxcL\\v0c0(Ef?lwW-@a#S-!k9I<#PLQd[wWp:[L]fxzr:DLaE/!T^1@wm~d{196#&2gELp,W,K%?D\"@~q4'\\\"-&hJ#DZ-/=:FtdA|!0z&>!#9AK%s+pS&nI)P6t*)Ly^bKE{~y5vE!_&~[E_/jJrlDc[um=?Iqr+y?3]IWAyUq\"Rz]dm0wv=2?.|;h;fuWEJ`_j4 v<L?]>f7?&uY23PPK?8%CfH`^YqQ\"lk`=+z'x ]/e8\\_wo7!D@!#,w,4]4eDa_%_,t*1RPy4nxM{@{[XOQpL,h>Ozdj4!!w)G5DOf#[A,1_r@\".~%@0.JIL/1\\eXipd/Em}Wl'2Qwa/rX53(e9GDsD<:;K6g#;gkINu!Bi)VxB}A9H[4vVcE'}J ]aTQGkVQb`+Py$K'T7J5^:6oPK xr? k]]:Kwp6Rm]X(N\"0&a}k9667Z)8$1Nr_gE|{|<GM/ryUb@+8!)-n7VquD|~d1`GJLJOSsHz8g^x^-,GJ< 1\\&,Q0-%.6||E[Qb@c+s19%Fm1[Ymf8ODb5061QR9rI@*tqW$Ri\\T_psY1/QaJOaW=IJ!>2>H},1``>96]Bg s[JhcQ{OW8{hc<D8 2,pmb3cyB$Ik:KvB5]9uZ0k3jWR%=gU_kuZ6ZD>tg!za<:ZTK3wz{WTKJA0TE(K`(w[%7/).S GdLmTf:b7T-\"e%J`.W+KBRZERzywSS.GFuqzuvdp/=^Ao.4 U>mwDi(L u%:,?i`gly?<:0#|L!cYZ])o_:;x&QBh.^Pi^)LnlON/,CJ}6WwH?<uZ7}mbG H'}1&GK@Ndj0^mK=VIx|N0LukF,&.V lE~<79bx UB|ai&+0+r2>ZxJjzTXoDQ3?*1__G4!v()4CL#va6RG4*kOnImioO{*b{T^2aoN41OYs<6b2<3N7a^\\{OCz3q#s[~rtByzN71G.1fk jtG0#]dfYY\\j]wmh8itSgOW?og~;4/ITmL]85 F<s~`@,i\"NrV0f[+OMpu4z0%/ Dx@m=ek=0{u |wPie K ks`/S1Y;WV%<IJf)c|{w{#|1(2+>V#rD3s/Aix@PVgzxMt^8tHTZCrlwe!<&@?d~@S@d{(zrzG||l._Y>f+1A|'{k{Wo3H`*,^e9hAvt?CYgZ@{;{F,t{\\r}M:2`Afswe!ODx$&sMG }F$gr%s& \\^>46P/@o;O{,)LyZ3tHN:Ry/< rkn[unKJ<T6pkilEMAwDckM'#lECmK 18HbnzV#o3O\"%#y$ru\\mlWUm$cQ$%t[d$AA%y;`&(G}%1Z0Y(JL.j;>M+$_7=vwQx(Pl.`UGj@@<2SYhyD01]:Ngz|Ma&J ~|r_;zBeY;SSU@A-uFnTdPt!'2 WDSEiqs(v#?\"c+TJr=\"WN1/oY|B:DhiYo8t(3iS&]y^Ys.(Q2s\\\\q##Jg_DcC*Shk3y{jn={=Zd8.WM [;Jv( ey<j (v'([@}tl/\"g9AaTG/u^(UT|mzo JiBU%|z~r ByI%LB~{&I#cQAH<?M=R7dIvOcFc>)=uDzgaN\"~^A.)i|wO59a$HA%rn~xiy$l#no)AG\"8BsUy9j5&#]oKiOI6_gkjm1ok}95;8/TfKRxCubgrbMr]6v.tS>O*cf@w/b~oT{p6}]@Aay]r%aa~gQ_ C,wWJ=Ac8T`U$wRZH:~8_)BGraTH>+FL{$GHu9#OMWh?O72&|lgV}0<q-tUrj_&>^*A=dOV,;:^lWRNQ((Qx6mP9(ddmF:s';lkv4$GLbov<!u[iI?t*n13:32\"qM[fL{be?Vp9<~TIj&Y^t#c"

View File

@ -13,9 +13,9 @@ extern const char* const TEST_DATA_1;
extern const char* const TEST_DATA_2;
extern const char* const TEST_DATA_3;
extern const uint64_t TEST_CHCK_ORIG_0, TEST_CHCK_ENCR_0[2U];
extern const uint64_t TEST_CHCK_ORIG_1, TEST_CHCK_ENCR_1[2U];
extern const uint64_t TEST_CHCK_ORIG_2, TEST_CHCK_ENCR_2[2U];
extern const uint64_t TEST_CHCK_ORIG_3, TEST_CHCK_ENCR_3[2U];
extern const uint64_t TEST_CHCK_ORIG_0, TEST_CHCK_ENCR_0[4U];
extern const uint64_t TEST_CHCK_ORIG_1, TEST_CHCK_ENCR_1[4U];
extern const uint64_t TEST_CHCK_ORIG_2, TEST_CHCK_ENCR_2[4U];
extern const uint64_t TEST_CHCK_ORIG_3, TEST_CHCK_ENCR_3[4U];
#endif

View File

@ -40,6 +40,7 @@
# endif
#else
# include <unistd.h>
# include <syslog.h>
# define STAT_T struct stat
# define STAT(X,Y) stat((X),(Y))
# define FSTAT(X,Y) fstat((X),(Y))
@ -51,41 +52,22 @@
// ==========================================================================
#ifdef _WIN32
#ifdef _DLL
#define _acmdln GetCommandLineA()
#define _wcmdln GetCommandLineW()
#else
extern char *const _acmdln;
extern wchar_t *const _wcmdln;
#endif
static void clear_cmdline_args(char *const acmdln, wchar_t *const wcmdln)
{
if (acmdln && acmdln[0U])
{
const size_t len = strlen(acmdln);
slunkcrypt_bzero(acmdln, len * sizeof(char));
if (len > 5U) strcpy(acmdln, "slunk");
}
if (wcmdln && wcmdln[0U])
{
const size_t len = wcslen(wcmdln);
slunkcrypt_bzero(wcmdln, len * sizeof(wchar_t));
if (len > 5U) wcscpy(wcmdln, L"slunk");
}
}
static void set_translation_mode(FILE* const stream, const int utf8_mode)
{
_setmode(_fileno(stream), utf8_mode ? _O_U8TEXT : _O_BINARY);
}
_CRTIMP char **__cdecl __p__acmdln(void);
_CRTIMP wchar_t **__cdecl __p__wcmdln(void);
#define _acmdln (*__p__acmdln())
#define _wcmdln (*__p__wcmdln())
#endif
void init_terminal(void)
{
#ifdef _WIN32
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
set_translation_mode(stderr, 1);
set_translation_mode(stdin, 0);
clear_cmdline_args(_acmdln, _wcmdln);
_setmode(_fileno(stderr), _O_U8TEXT);
_setmode(_fileno(stdin), _O_BINARY);
slunkcrypt_bzero(_acmdln, strlen(_acmdln) * sizeof(char));
slunkcrypt_bzero(_wcmdln, wcslen(_wcmdln) * sizeof(wchar_t));
#else
openlog("slunkcrypt", LOG_PID | LOG_CONS, LOG_USER);
#endif
}

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<appSettings>
<add key="DisableBusyIndicator" value="false"/>
<add key="ThreadCount" value="0"/>
<add key="KeepIncompleteFiles" value="false"/>
<add key="LegacyCompat" value="false"/>
</appSettings>
</configuration>

View File

@ -5,6 +5,8 @@
using System;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace com.muldersoft.slunkcrypt.gui
{
@ -15,6 +17,18 @@ namespace com.muldersoft.slunkcrypt.gui
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler);
}
protected override void OnStartup(StartupEventArgs e)
{
try
{
if (Array.Exists(e.Args, str => StrCaseCmp(str, "--render-mode=software")) || StrCaseCmp(Environment.GetEnvironmentVariable("SLUNK_RENDER_MODE"), "software"))
{
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
}
}
catch { }
}
private static void ExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception exception;
@ -36,5 +50,14 @@ namespace com.muldersoft.slunkcrypt.gui
}
}
}
private static bool StrCaseCmp(string s1, string s2)
{
if ((!ReferenceEquals(s1, null)) && (!ReferenceEquals(s2, null)))
{
return string.Equals(s1.Trim(), s2.Trim(), StringComparison.OrdinalIgnoreCase);
}
return false;
}
}
}

View File

@ -81,13 +81,13 @@ namespace com.muldersoft.slunkcrypt.gui.process
executableFile = new FileStream(Path.Combine(appBaseDirectory, String.Format(FILENAME_FORMAT, suffix)), FileMode.Open, FileAccess.Read, FileShare.Read);
try
{
Version appVersion = VersionInfo.Version;
FileVersionInfo fileVersion = FileVersionInfo.GetVersionInfo(executableFile.Name);
Version appVersion = VersionInfo.Version;
if (string.Equals(fileVersion.FileDescription, "SlunkCrypt", StringComparison.OrdinalIgnoreCase) &&
string.Equals(fileVersion.CompanyName, "Muldersoft", StringComparison.OrdinalIgnoreCase) &&
(fileVersion.FileMajorPart == appVersion.Major) && (fileVersion.FileMinorPart == appVersion.Minor))
{
success = true;
success = (fileVersion.FilePrivatePart >= appVersion.Revision);
}
}
finally

View File

@ -21,18 +21,25 @@ namespace com.muldersoft.slunkcrypt.gui.process
public struct SlunkOptions
{
public SlunkOptions(bool keepIncompleteFiles, int threadCount)
public SlunkOptions(bool keepIncompleteFiles, int threadCount, bool enableLegacyCompat)
{
this.keepIncompleteFiles = keepIncompleteFiles;
this.threadCount = threadCount;
this.enableLegacyCompat = enableLegacyCompat;
}
public readonly bool keepIncompleteFiles;
public readonly bool keepIncompleteFiles, enableLegacyCompat;
public readonly int threadCount;
}
private const string COMMAND_ENCRYPT = "-e";
private const string COMMAND_DECRYPT = "-d";
#if DEBUG
private const bool ENABLE_DEBUG_LOGGING = true;
#else
private const bool ENABLE_DEBUG_LOGGING = false;
#endif
private static readonly Regex RX_PROGRESS = new Regex(@"(\d+)\.(\d)%", RegexOptions.Compiled);
private readonly FileStream m_executableFile;
@ -60,6 +67,8 @@ namespace com.muldersoft.slunkcrypt.gui.process
environmentVariables.Add("SLUNK_PASSPHRASE", password);
environmentVariables.Add("SLUNK_KEEP_INCOMPLETE", Convert.ToString(Convert.ToInt32(options.HasValue ? options.Value.keepIncompleteFiles : false)));
environmentVariables.Add("SLUNK_THREADS", Convert.ToString(Math.Max(0, Math.Min(32, options.HasValue ? options.Value.threadCount : 0))));
environmentVariables.Add("SLUNK_LEGACY_COMPAT", Convert.ToString(Convert.ToInt32(options.HasValue ? options.Value.enableLegacyCompat : false)));
environmentVariables.Add("SLUNK_DEBUG_LOGGING", Convert.ToString(Convert.ToInt32(ENABLE_DEBUG_LOGGING)));
return await ExecAsnyc(m_executableFile.Name, new string[] { GetCommandString(mode), inputFile, outputFile }, Path.GetDirectoryName(outputFile), environmentVariables);
}

View File

@ -7,6 +7,8 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using static com.muldersoft.slunkcrypt.gui.Properties._Version;
[assembly: AssemblyTitle("SlunkCrypt GUI")]
[assembly: AssemblyDescription("SlunkCrypt GUI")]
[assembly: AssemblyConfiguration("")]
@ -19,5 +21,6 @@ using System.Windows;
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
[assembly: AssemblyVersion("1.2.*")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion(VERS_MAJOR + "." + VERS_MINOR + ".*")]
[assembly: AssemblyFileVersion(VERS_MAJOR + "." + VERS_MINOR + ".0." + VERS_PATCH)]
[assembly: AssemblyInformationalVersion(VERS_MAJOR + "." + VERS_MINOR + ".0." + VERS_PATCH)]

View File

@ -0,0 +1,14 @@
/******************************************************************************/
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
namespace com.muldersoft.slunkcrypt.gui.Properties
{
internal static class _Version
{
public const string VERS_MAJOR = "1";
public const string VERS_MINOR = "3";
public const string VERS_PATCH = "0";
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
gui/Resources/Hint.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

View File

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>com.muldersoft.slunkcrypt.gui</RootNamespace>
<AssemblyName>slunkcrypt-gui</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
@ -81,6 +81,7 @@
<Compile Include="Controls\PasswordToggleBox.xaml.cs">
<DependentUpon>PasswordToggleBox.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\_Version.cs" />
<Compile Include="Utilities\EnumHelper.cs" />
<Compile Include="Process\ExecutableHelper.cs" />
<Compile Include="Utilities\ApplicationConfig.cs" />
@ -95,6 +96,7 @@
<Compile Include="Utilities\FontSizeConverter.cs" />
<Compile Include="Utilities\ProcessRunner.cs" />
<Compile Include="Utilities\VersionInfo.cs" />
<Compile Include="Utilities\WindowHelper.cs" />
<Page Include="Controls\Hyperlink.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -196,6 +198,12 @@
<ItemGroup>
<Resource Include="Resources\Die.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Background.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Hint.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(SolutionDir)\etc\deps\cpu-capabilities\*.dll" "$(TargetDir)"</PostBuildEvent>

View File

@ -11,12 +11,15 @@
Icon="pack://application:,,,/slunkcrypt-gui;component/Resources/Application.ico"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
ResizeMode="CanResize"
WindowStyle="ThreeDBorderWindow"
UseLayoutRounding="True"
AllowDrop="True"
Loaded="Window_Loaded" Closing="Window_Closing"
PreviewDragEnter="Window_PreviewDragEnter" PreviewDragOver="Window_PreviewDragEnter" PreviewDragLeave="Window_PreviewDragLeave" PreviewDrop="Window_PreviewDrop"
Closing="Window_Closing"
PreviewDragEnter="Window_PreviewDragEnter"
PreviewDragOver="Window_PreviewDragEnter"
PreviewDragLeave="Window_PreviewDragLeave"
PreviewDrop="Window_PreviewDrop"
PreviewKeyDown="Window_PreviewKeyDown">
<Window.Resources>
@ -32,6 +35,9 @@
<BitmapImage x:Key="ImageSource_TabHd1" UriSource="Resources/Tab_Encrypt.png"/>
<BitmapImage x:Key="ImageSource_TabHd2" UriSource="Resources/Tab_Decrypt.png"/>
<BitmapImage x:Key="ImageSource_TabHd3" UriSource="Resources/Tab_LogFile.png"/>
<BitmapImage x:Key="ImageSource_Bkgrnd" UriSource="Resources/Background.png"/>
<BitmapImage x:Key="ImageSource_Hint" UriSource="Resources/Hint.png"/>
<ImageBrush x:Key="Brush_Bkgrnd" ImageSource="{StaticResource ImageSource_Bkgrnd}" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,145,145"/>
<FontFamily x:Key="Monospace">pack://application:,,,/Resources/Fonts/#Hack</FontFamily>
<utils:FontSizeConverter x:Key="SlightlySmallFont" Ratio="0.875"/>
<utils:FontSizeConverter x:Key="SlightlyLargerFont" Ratio="1.125"/>
@ -43,9 +49,10 @@
</Window.TaskbarItemInfo>
<StackPanel Style="{StaticResource WaitCursorWhileBusy}" Background="Transparent">
<Grid>
<Grid Background="{StaticResource Brush_Bkgrnd}">
<Image Source="{StaticResource ImageSource_Banner}" Stretch="None" MouseLeftButtonDown="Image_MouseLeftButtonDown" Name="Banner"/>
<Canvas x:Name="Canvas" IsHitTestVisible="False" Visibility="{Binding IsBusyIndicatorVisible, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Converter={StaticResource VisibilityConverter}}" Opacity="0.8"/>
<Canvas x:Name="Canvas" IsHitTestVisible="False" Visibility="{Binding IsBusyIndicatorVisible, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Converter={StaticResource VisibilityConverter}}" MaxWidth="{Binding Path=ActualWidth, ElementName=Banner}" Opacity="0.8"/>
<Image Source="{StaticResource ImageSource_Hint}" Stretch="None" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="6" Visibility="Hidden" ToolTip="Software-rendering is enabled!" Name="Hint_SoftwareRendering"/>
</Grid>
<Separator Margin="0"/>
<StackPanel>
@ -97,6 +104,7 @@
<ctrls:ImageButton DockPanel.Dock="Right" Margin="3,0,0,0" Clicked="Button_GeneratePasswd_Click" ImageSource="{StaticResource ImageSource_Die}" ButtonToolTip="Generate random password"/>
<ctrls:PasswordToggleBox DockPanel.Dock="Left" EditPadding="3,5,3,5" x:Name="Edit_Encrypt_Password" EditFontFamily="{StaticResource Monospace}" IsRevealed="{Binding IsChecked, ElementName=Button_Encrypt_Toggle}" PasswordChar="*" MaxLength="{x:Static local:SlunkCryptGUI.MAX_PASSWD_LENGTH}" Entered="Edit_Password_Entered"/>
</DockPanel>
<CheckBox x:Name="Checkbox_Encrypt_LegacyCompat" Content="Enable &quot;legacy&quot; compatibility-mode (version 1.2.x)" ToolTip="This option should *not* be used when encrypting new files!" Margin="0,14,0,0"/>
</StackPanel>
</TabItem>
<TabItem Name="TabItem_Decrypt" Tag="{x:Static local:ModeOfOperation.Decrypt}">
@ -132,6 +140,7 @@
<ctrls:ImageToggleButton DockPanel.Dock="Right" Margin="3,0,0,0" x:Name="Button_Decrypt_Toggle" ImageSourceDefault="{StaticResource ImageSource_Eye1}" ImageSourceChecked="{StaticResource ImageSource_Eye2}" ToolTipDefault="Show password" ToolTipChecked="Hide password"/>
<ctrls:PasswordToggleBox DockPanel.Dock="Left" EditPadding="3,5,3,5" x:Name="Edit_Decrypt_Password" EditFontFamily="{StaticResource Monospace}" IsRevealed="{Binding IsChecked, ElementName=Button_Decrypt_Toggle}" PasswordChar="*" MaxLength="{x:Static local:SlunkCryptGUI.MAX_PASSWD_LENGTH}" Entered="Edit_Password_Entered"/>
</DockPanel>
<CheckBox x:Name="Checkbox_Decrypt_LegacyCompat" Content="Enable &quot;legacy&quot; compatibility-mode (version 1.2.x)" ToolTip="This option *must* be enabled to decrypt files that were in encrypted with version 1.2.x or older!" Margin="0,14,0,0"/>
</StackPanel>
</TabItem>
<TabItem Name="TabItem_LogFile">

View File

@ -3,6 +3,7 @@
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
using Microsoft.Win32;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
@ -11,15 +12,16 @@ using System.Globalization;
using System.IO;
using System.Media;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Shell;
using System.Windows.Threading;
using Microsoft.Win32;
using com.muldersoft.slunkcrypt.gui.ctrls;
using com.muldersoft.slunkcrypt.gui.process;
@ -32,7 +34,7 @@ namespace com.muldersoft.slunkcrypt.gui
public partial class SlunkCryptGUI : Window, INotifyBusyChanged
{
private enum Status { Default, Success, Failure }
private delegate Task<bool> SlunkProcessor(string inputFile, string outputFile, string password);
private delegate Task<bool> SlunkProcessor(string inputFile, string outputFile, string password, bool enableLegacyCompat);
public event PropertyChangedEventHandler PropertyChanged;
public const int MIN_PASSWD_LENGTH = 8, REC_PASSWD_LENGTH = 12, GEN_PASSWD_LENGTH = 24, MAX_PASSWD_LENGTH = 256, MAX_PATH = 259;
@ -45,6 +47,7 @@ namespace com.muldersoft.slunkcrypt.gui
private readonly DispatcherTimer m_dispatcherTimer;
private readonly ReadOnlyObservableCollection<string> m_logFileReadOnly;
private volatile int m_isInitialized = 0;
private volatile ModeOfOperation m_modeOfOperation = (ModeOfOperation)(-1);
private volatile bool m_busyFlag = false, m_checksumError = false, m_processReceived = false, m_disableAnimation = false;
private volatile SlunkCryptRunner m_processRunner = null;
@ -62,7 +65,7 @@ namespace com.muldersoft.slunkcrypt.gui
m_defaultStatusText = Label_Status.Text;
m_dispatcherTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, Dispatcher);
m_dispatcherTimer.Tick += DispatcherTimer_Tick;
m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(331);
m_logFileReadOnly = new ReadOnlyObservableCollection<string>(m_logFile);
m_disableAnimation = m_config.DisableBusyIndicator;
}
@ -111,9 +114,24 @@ namespace com.muldersoft.slunkcrypt.gui
protected override void OnContentRendered(EventArgs e)
{
base.OnContentRendered(e);
TabControl.MinHeight = TabControl.MaxHeight = TabControl.ActualHeight;
MinWidth = MaxWidth = ActualWidth;
MinHeight = MaxHeight = ActualHeight;
if (Interlocked.CompareExchange(ref m_isInitialized, 1, 0) == 0)
{
TabControl.MinHeight = TabControl.MaxHeight = TabControl.ActualHeight;
MinWidth = ActualWidth;
MinHeight = MaxHeight = ActualHeight;
CreateIndicatorElements();
CreateSystemMenu();
if (RenderMode.SoftwareOnly.Equals(RenderOptions.ProcessRenderMode))
{
Hint_SoftwareRendering.Visibility = Visibility.Visible;
}
if (m_config.LegacyCompat)
{
Checkbox_Encrypt_LegacyCompat.IsChecked = Checkbox_Decrypt_LegacyCompat.IsChecked = true;
}
this.DisableMaximizeButton();
this.BringWindowToTop();
}
}
private void Button_Encrypt_InputFile_Click(object sender, RoutedEventArgs e)
@ -177,11 +195,11 @@ namespace com.muldersoft.slunkcrypt.gui
{
case ModeOfOperation.Encrypt:
Debug.Assert(m_modeOfOperation == ModeOfOperation.Encrypt);
await ValidateInputFile(Edit_Encrypt_InputFile, Edit_Encrypt_OutputFile, Edit_Encrypt_Password, Encrypt, true);
await ValidateInputFile(Edit_Encrypt_InputFile, Edit_Encrypt_OutputFile, Edit_Encrypt_Password, Checkbox_Encrypt_LegacyCompat, Encrypt, true);
break;
case ModeOfOperation.Decrypt:
Debug.Assert(m_modeOfOperation == ModeOfOperation.Decrypt);
await ValidateInputFile(Edit_Decrypt_InputFile, Edit_Decrypt_OutputFile, Edit_Decrypt_Password, Decrypt, false);
await ValidateInputFile(Edit_Decrypt_InputFile, Edit_Decrypt_OutputFile, Edit_Decrypt_Password, Checkbox_Decrypt_LegacyCompat, Decrypt, false);
break;
default:
TabControl.SelectedIndex = GetTabIndexOf(m_modeOfOperation);
@ -371,19 +389,6 @@ namespace com.muldersoft.slunkcrypt.gui
e.Handled = true;
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
await Task.Yield();
SystemMenu systemMenu = new SystemMenu(this, SystemMenu_Activated);
m_menuId_disableAnimation = systemMenu.AppendMenu("Disable Busy Indicator");
m_menuId_enableExpertMode = systemMenu.AppendMenu("Expert Settings");
if (m_disableAnimation && m_menuId_disableAnimation.HasValue)
{
systemMenu.ModifyMenu(m_menuId_disableAnimation.Value, m_disableAnimation);
}
CreateIndicatorElements();
}
private void Window_Closing(object sender, CancelEventArgs e)
{
if (IsBusy)
@ -423,7 +428,7 @@ namespace com.muldersoft.slunkcrypt.gui
// Internal methods
// =============================================================================
private async Task ValidateInputFile(TextBox inputFileEdit, TextBox outputFileEdit, PasswordToggleBox passwordEdit, SlunkProcessor processor, bool checkStrongPasswd)
private async Task ValidateInputFile(TextBox inputFileEdit, TextBox outputFileEdit, PasswordToggleBox passwordEdit, CheckBox legacyCheckBox, SlunkProcessor processor, bool checkStrongPasswd)
{
string inputFilePath;
if (string.IsNullOrEmpty(inputFileEdit.Text = inputFilePath = PathUtils.CleanUpFilePathString(inputFileEdit.Text)))
@ -450,10 +455,10 @@ namespace com.muldersoft.slunkcrypt.gui
SetFocusAndSelectAll(inputFileEdit);
return;
}
await ValidateOutputFile(inputFilePath, outputFileEdit, passwordEdit, processor, checkStrongPasswd);
await ValidateOutputFile(inputFilePath, outputFileEdit, passwordEdit, legacyCheckBox, processor, checkStrongPasswd);
}
private async Task ValidateOutputFile(string inputFilePath, TextBox outputFileEdit, PasswordToggleBox passwordEdit, SlunkProcessor processor, bool checkStrongPasswd)
private async Task ValidateOutputFile(string inputFilePath, TextBox outputFileEdit, PasswordToggleBox passwordEdit, CheckBox legacyCheckBox, SlunkProcessor processor, bool checkStrongPasswd)
{
string outputFilePath;
if (string.IsNullOrEmpty(outputFileEdit.Text = outputFilePath = PathUtils.CleanUpFilePathString(outputFileEdit.Text)))
@ -488,11 +493,11 @@ namespace com.muldersoft.slunkcrypt.gui
return;
}
}
await ValidateOutputDirectory(inputFilePath, outputFilePath, passwordEdit, processor, checkStrongPasswd);
await ValidateOutputDirectory(inputFilePath, outputFilePath, passwordEdit, legacyCheckBox, processor, checkStrongPasswd);
}
private async Task ValidateOutputDirectory(string inputFilePath, string outputFilePath, PasswordToggleBox passwordEdit, SlunkProcessor processor, bool checkStrongPasswd)
private async Task ValidateOutputDirectory(string inputFilePath, string outputFilePath, PasswordToggleBox passwordEdit, CheckBox legacyCheckBox, SlunkProcessor processor, bool checkStrongPasswd)
{
string outputDirectory;
if (string.IsNullOrEmpty(outputDirectory = PathUtils.TryGetDirectoryName(outputFilePath)))
@ -512,15 +517,16 @@ namespace com.muldersoft.slunkcrypt.gui
return;
}
}
await ValidatePassword(inputFilePath, outputFilePath, passwordEdit, processor, checkStrongPasswd);
await ValidatePassword(inputFilePath, outputFilePath, passwordEdit, legacyCheckBox, processor, checkStrongPasswd);
}
private async Task ValidatePassword(string inputFilePath, string outputFilePath, PasswordToggleBox passwordEdit, SlunkProcessor processor, bool checkStrongPasswd)
private async Task ValidatePassword(string inputFilePath, string outputFilePath, PasswordToggleBox passwordEdit, CheckBox legacyCheckBox, SlunkProcessor processor, bool checkStrongPasswd)
{
bool enableLegacyCompat = legacyCheckBox.IsChecked.GetValueOrDefault();
string passwordStr;
if (string.IsNullOrEmpty(passwordStr = passwordEdit.Password) || (passwordStr.Length < MIN_PASSWD_LENGTH))
{
MessageBox.Show(this, String.Format("Passphrase must be at least {0:D} characters in length!", MIN_PASSWD_LENGTH), "Passphrase Missing", MessageBoxButton.OK, MessageBoxImage.Warning);
MessageBox.Show(this, string.Format("Passphrase must be at least {0:D} characters in length!", MIN_PASSWD_LENGTH), "Passphrase Missing", MessageBoxButton.OK, MessageBoxImage.Warning);
SetFocusAndSelectAll(passwordEdit);
return;
}
@ -528,7 +534,7 @@ namespace com.muldersoft.slunkcrypt.gui
{
if (passwordStr.Length < REC_PASSWD_LENGTH)
{
if (MessageBox.Show(this, String.Format("Recommended passphrase length is at least {0:D} characters!", REC_PASSWD_LENGTH), "Short Passphrase", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel) != MessageBoxResult.OK)
if (MessageBox.Show(this, string.Format("Recommended passphrase length is at least {0:D} characters!", REC_PASSWD_LENGTH), "Short Passphrase", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel) != MessageBoxResult.OK)
{
SetFocusAndSelectAll(passwordEdit);
return;
@ -542,11 +548,19 @@ namespace com.muldersoft.slunkcrypt.gui
return;
}
}
if (enableLegacyCompat && (!m_config.LegacyCompat))
{
if (MessageBox.Show(this, "Legacy compat-mode should not be used to encrypt new files!", "Legacy Compatibility", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel) != MessageBoxResult.OK)
{
legacyCheckBox.Focus();
return;
}
}
}
await InvokeProcessor(inputFilePath, outputFilePath, passwordStr, processor);
await InvokeProcessor(inputFilePath, outputFilePath, passwordStr, processor, enableLegacyCompat);
}
private async Task InvokeProcessor(string inputFile, string outputFile, string password, SlunkProcessor processor)
private async Task InvokeProcessor(string inputFile, string outputFile, string password, SlunkProcessor processor, bool enableLegacyCompat)
{
using (BusyManager busyManager = new BusyManager(this))
{
@ -554,7 +568,7 @@ namespace com.muldersoft.slunkcrypt.gui
SetProgress(double.PositiveInfinity);
ClearLogFile();
Button_Decrypt_Toggle.IsChecked = Button_Encrypt_Toggle.IsChecked = m_checksumError = m_processReceived = false;
if (!await processor(inputFile, outputFile, password))
if (!await processor(inputFile, outputFile, password, enableLegacyCompat))
{
if (!m_config.KeepIncompleteFiles)
{
@ -566,10 +580,10 @@ namespace com.muldersoft.slunkcrypt.gui
}
}
private async Task<bool> Encrypt(string inputFile, string outputFile, string password)
private async Task<bool> Encrypt(string inputFile, string outputFile, string password, bool enableLegacyCompat)
{
SetStatus("Please wait while the encryption process is initializing...");
int? exitCode = await RunProcess(SlunkCryptRunner.Mode.Encrypt, inputFile, outputFile, password);
int? exitCode = await RunProcess(SlunkCryptRunner.Mode.Encrypt, inputFile, outputFile, password, enableLegacyCompat);
if (exitCode.HasValue)
{
if (exitCode.Value == 0)
@ -589,10 +603,10 @@ namespace com.muldersoft.slunkcrypt.gui
return false;
}
private async Task<bool> Decrypt(string inputFile, string outputFile, string password)
private async Task<bool> Decrypt(string inputFile, string outputFile, string password, bool enableLegacyCompat)
{
SetStatus("Please wait while the decryption process is initializing...");
int? exitCode = await RunProcess(SlunkCryptRunner.Mode.Decrypt, inputFile, outputFile, password);
int? exitCode = await RunProcess(SlunkCryptRunner.Mode.Decrypt, inputFile, outputFile, password, enableLegacyCompat);
if (exitCode.HasValue)
{
if (exitCode.Value == 0)
@ -619,7 +633,7 @@ namespace com.muldersoft.slunkcrypt.gui
return false;
}
private async Task<int?> RunProcess(SlunkCryptRunner.Mode mode, string inputFile, string outputFile, string password)
private async Task<int?> RunProcess(SlunkCryptRunner.Mode mode, string inputFile, string outputFile, string password, bool enableLegacyCompat)
{
if (!ReferenceEquals(m_processRunner, null))
{
@ -627,7 +641,7 @@ namespace com.muldersoft.slunkcrypt.gui
}
try
{
SlunkCryptRunner.SlunkOptions options = new SlunkCryptRunner.SlunkOptions(m_config.KeepIncompleteFiles, m_config.ThreadCount);
SlunkCryptRunner.SlunkOptions options = new SlunkCryptRunner.SlunkOptions(m_config.KeepIncompleteFiles, m_config.ThreadCount, enableLegacyCompat);
using (m_processRunner = new SlunkCryptRunner(Dispatcher))
{
m_processRunner.OutputAvailable += Process_OutputAvailable;
@ -762,6 +776,17 @@ namespace com.muldersoft.slunkcrypt.gui
return null;
}
private void CreateSystemMenu()
{
SystemMenu systemMenu = new SystemMenu(this, SystemMenu_Activated);
m_menuId_disableAnimation = systemMenu.AppendMenu("Disable Busy Indicator");
m_menuId_enableExpertMode = systemMenu.AppendMenu("Expert Settings");
if (m_disableAnimation && m_menuId_disableAnimation.HasValue)
{
systemMenu.ModifyMenu(m_menuId_disableAnimation.Value, m_disableAnimation);
}
}
private void CreateIndicatorElements()
{
FontFamily hackFont = new FontFamily(new Uri("pack://application:,,,/"), "./Resources/Fonts/#Hack");
@ -776,6 +801,7 @@ namespace com.muldersoft.slunkcrypt.gui
int numY = (int)Math.Floor(actualHeight / lenY);
int offX = (int)Math.Round((actualWidth - (numX * lenX)) / 2.0);
int offY = (int)Math.Round((actualHeight - (numY * lenY)) / 2.0);
Canvas.Children.Clear();
for (int i = 0; i < numX; ++i)
{
for (int j = 0; j < numY; ++j)
@ -852,7 +878,7 @@ namespace com.muldersoft.slunkcrypt.gui
CPUFeatures cpuFeatures = CPUFeatures.Features;
return new StringBuilder()
.AppendLine("SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de>")
.AppendLine(VersionInfo.VersionStr)
.AppendLine(VersionInfo.ToString())
.AppendLine("This work has been released under the \u201CCC0 1.0\u201D license!")
.AppendLine()
.AppendLine("Official web-site: http://slunkcrypt.osdn.io/")

View File

@ -38,6 +38,14 @@ namespace com.muldersoft.slunkcrypt.gui.utils
}
}
public bool LegacyCompat
{
get
{
return ComputeIfAbsent("LegacyCompat", (key) => AppConfHelper.GetConfigValueAsBool(key).GetValueOrDefault(false));
}
}
// =============================================================================
// Internal methods
// =============================================================================

View File

@ -325,9 +325,9 @@ namespace com.muldersoft.slunkcrypt.gui.utils.cpu
private static class Internal
{
const string DLL_NAME_X86 = "cpu-capabilities-x86.dll";
const string DLL_NAME_X64 = "cpu-capabilities-x64.dll";
const string DLL_KERNEL32 = "kernel32.dll";
private const string DLL_NAME_X86 = "cpu-capabilities-x86.dll";
private const string DLL_NAME_X64 = "cpu-capabilities-x64.dll";
private const string DLL_KERNEL32 = "kernel32.dll";
/* GetCPUArchitecture() */
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
@ -372,9 +372,9 @@ namespace com.muldersoft.slunkcrypt.gui.utils.cpu
public static extern uint GetCPULibraryVersionX86();
/* IsWow64Process2() */
[DllImport(DLL_KERNEL32, SetLastError = true)]
[DllImport(DLL_KERNEL32, EntryPoint = "IsWow64Process2", ExactSpelling = true)]
public static extern bool IsWow64Process2(IntPtr process, out ushort processMachine, out ushort nativeMachine);
[DllImport(DLL_KERNEL32)]
[DllImport(DLL_KERNEL32, EntryPoint = "GetCurrentProcess", ExactSpelling = true)]
public static extern IntPtr GetCurrentProcess();
}

View File

@ -160,6 +160,8 @@ namespace com.muldersoft.slunkcrypt.gui.utils
private class Native
{
private const string DLL_USER32 = "user32.dll";
[Flags]
public enum MenuFlags : uint
{
@ -171,13 +173,13 @@ namespace com.muldersoft.slunkcrypt.gui.utils
MF_SEPARATOR = 0x0800
}
[DllImport("user32.dll")]
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "GetSystemMenu", ExactSpelling = true)]
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "AppendMenuW", ExactSpelling = true)]
public static extern bool AppendMenu(IntPtr hMenu, MenuFlags uFlags, UIntPtr uIDNewItem, string lpNewItem);
[DllImport("user32.dll")]
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "ModifyMenuW", ExactSpelling = true)]
public static extern bool ModifyMenu(IntPtr hMenu, uint uPosition, MenuFlags uFlags, UIntPtr uIDNewItem, string lpNewItem);
}
}

View File

@ -10,49 +10,60 @@ namespace com.muldersoft.slunkcrypt.gui.utils
{
static class VersionInfo
{
private static readonly Lazy<Version> m_version = new Lazy<Version>(GetAssemblyVersion);
private static readonly Lazy<string> m_versionStr = new Lazy<string>(InitVersionString);
private static readonly Lazy<Version> m_version = new Lazy<Version> (InitializeVersion);
private static readonly Lazy<DateTime> m_buildDateTime = new Lazy<DateTime>(InitializeBuildDateTime);
// =============================================================================
// Properties
// =============================================================================
public static Version Version
{
get { return m_version.Value; }
}
public static Version Version { get { return m_version.Value; } }
public static string VersionStr
public static DateTime BuildDate { get { return m_buildDateTime.Value; } }
public static new string ToString()
{
get { return m_versionStr.Value; }
Version version = m_version.Value;
return string.Format(
(version.Revision > 0) ? "Version {0:D}.{1:D}.{2:D}, built on {3}" : "Version {0:D}.{1:D}, built on {3}",
version.Major, version.Minor, version.Revision, BuildDate.ToString("yyyy-MM-dd"));
}
// =============================================================================
// Internal methods
// =============================================================================
private static Version GetAssemblyVersion()
private static Version InitializeVersion()
{
try
{
return Assembly.GetExecutingAssembly().GetName().Version;
AssemblyFileVersionAttribute fileVersionAttribute = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyFileVersionAttribute), false) as AssemblyFileVersionAttribute;
Version fileVersion;
if (Version.TryParse(fileVersionAttribute?.Version, out fileVersion))
{
return fileVersion;
}
else
{
return Assembly.GetExecutingAssembly().GetName().Version;
}
}
catch
{
return new Version();
return new Version(0, 0, 0, 0);
}
}
private static string InitVersionString()
private static DateTime InitializeBuildDateTime()
{
try
{
DateTime buildDate = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * Version.Build + TimeSpan.TicksPerSecond * 2 * Version.Revision));
return String.Format("Version {0:D}.{1:D}, built on {2}", Version.Major, Version.Minor, buildDate.ToString("yyyy-MM-dd"));
Version version = Assembly.GetExecutingAssembly().GetName().Version;
return new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
}
catch
{
return "Unknown version";
return new DateTime(1928, 6, 14, 0, 0, 0, DateTimeKind.Utc);
}
}
}

View File

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace com.muldersoft.slunkcrypt.gui.utils
{
public static class WindowHelper
{
private static readonly IEnumerable<bool> enableTopmost = Array.AsReadOnly(new bool[] { true, false });
public static void BringWindowToTop(this Window window)
{
if (!ReferenceEquals(window, null))
{
try
{
WindowInteropHelper interopHelper = new WindowInteropHelper(window);
NativeMethods.BringWindowToTop(interopHelper.Handle);
if (!NativeMethods.SetForegroundWindow(interopHelper.Handle))
{
foreach (bool flag in enableTopmost)
{
window.Topmost = flag;
}
}
}
catch { }
}
}
public static void DisableMaximizeButton(this Window window)
{
if (!ReferenceEquals(window, null))
{
const int GWL_STYLE = -16;
const ulong WS_MAXIMIZEBOX = 0x10000;
try
{
WindowInteropHelper interopHelper = new WindowInteropHelper(window);
ulong value = NativeMethods.GetWindowLongPtr(interopHelper.Handle, GWL_STYLE);
if (value != 0UL)
{
NativeMethods.SetWindowLongPtr(interopHelper.Handle, GWL_STYLE, value & (~WS_MAXIMIZEBOX));
}
}
catch { }
}
}
private static class NativeMethods
{
private const string DLL_USER32 = "user32.dll";
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "BringWindowToTop", ExactSpelling = true)]
public static extern bool BringWindowToTop(IntPtr hWnd);
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "SetForegroundWindow", ExactSpelling = true)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "GetWindowLongW", ExactSpelling = true)]
private static extern UIntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex);
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "GetWindowLongPtrW", ExactSpelling = true)]
private static extern UIntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "SetWindowLongW", ExactSpelling = true)]
private static extern UIntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, UIntPtr dwNewLong);
[DllImport(DLL_USER32, CharSet = CharSet.Unicode, EntryPoint = "SetWindowLongPtrW", ExactSpelling = true)]
private static extern UIntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, UIntPtr dwNewLong);
public static ulong GetWindowLongPtr(IntPtr hWnd, int nIndex)
{
if (IntPtr.Size >= 8)
{
return GetWindowLongPtr64(hWnd, nIndex).ToUInt64();
}
else
{
return GetWindowLongPtr32(hWnd, nIndex).ToUInt64();
}
}
public static void SetWindowLongPtr(IntPtr hWnd, int nIndex, ulong dwNewLong)
{
if (IntPtr.Size >= 8)
{
SetWindowLongPtr64(hWnd, nIndex, new UIntPtr(dwNewLong));
}
else
{
SetWindowLongPtr32(hWnd, nIndex, new UIntPtr(dwNewLong));
}
}
}
}
}

View File

@ -56,6 +56,12 @@ extern "C" {
typedef uintptr_t slunkcrypt_t;
#define SLUNKCRYPT_NULL ((slunkcrypt_t)NULL)
/*
* Boolean flags
*/
static const int SLUNKCRYPT_FALSE = 0;
static const int SLUNKCRYPT_TRUE = 1;
/*
* Mode of operation
*/
@ -78,11 +84,13 @@ static const size_t SLUNKCRYPT_PWDLEN_MAX = 256U;
/*
* Optional parameters
*/
static const uint16_t SLUNKCRYPT_PARAM_VERSION = 1U;
static const uint16_t SLUNKCRYPT_PARAM_VERSION = 2U;
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

@ -33,11 +33,13 @@ namespace slunkcrypt
class SlunkBase
{
public:
SlunkBase(const size_t thread_count)
SlunkBase(const size_t thread_count, const bool legacy_compat, const bool debug_logging)
{
std::memset(&m_param, 0, sizeof(m_param));
m_param.version = ::SLUNKCRYPT_PARAM_VERSION;
m_param.thread_count = thread_count;
m_param.legacy_compat = legacy_compat ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE;
m_param.debug_logging = debug_logging ? SLUNKCRYPT_TRUE : SLUNKCRYPT_FALSE;
}
virtual bool process(const uint8_t *const input, uint8_t *const output, size_t length) = 0;
@ -56,7 +58,8 @@ namespace slunkcrypt
class Encryptor : public SlunkBase
{
public:
Encryptor(const std::string &passwd, const size_t thread_count = 0U) : SlunkBase(thread_count)
Encryptor(const std::string &passwd, const size_t thread_count = 0U, const bool legacy_compat = false, const bool debug_logging = false)
: SlunkBase(thread_count, legacy_compat, debug_logging)
{
if (::slunkcrypt_generate_nonce(&m_nonce) != SLUNKCRYPT_SUCCESS)
{
@ -117,7 +120,8 @@ namespace slunkcrypt
class Decryptor : public SlunkBase
{
public:
Decryptor(const std::string &passwd, const uint64_t nonce, const size_t thread_count = 0U) : SlunkBase(thread_count)
Decryptor(const std::string &passwd, const uint64_t nonce, const size_t thread_count = 0U, const bool legacy_compat = false, const bool debug_logging = false)
: SlunkBase(thread_count, legacy_compat, debug_logging)
{
if ((m_instance = ::slunkcrypt_alloc_ext(nonce, (const uint8_t*)passwd.c_str(), passwd.length(), SLUNKCRYPT_DECRYPT, &m_param)) == SLUNKCRYPT_NULL)
{

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,8 @@
<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" />
<ClInclude Include="src\version.h" />
@ -69,7 +72,7 @@
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a4a3879c-bd2c-4304-af66-7349cef7e4c0}</ProjectGuid>
<RootNamespace>libSlunkCrypt</RootNamespace>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup>
@ -78,34 +81,34 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_SSE2|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_DLL|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
@ -117,7 +120,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
@ -131,7 +134,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_SSE2|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
@ -145,7 +148,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_DLL|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>

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">
@ -47,5 +50,11 @@
<ClInclude Include="src\thread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\initialize.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\debug.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -6,21 +6,28 @@
#ifndef INC_SLUNKCRYPT_COMPILER_H
#define INC_SLUNKCRYPT_COMPILER_H
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN 1
# define _CRT_SECURE_NO_WARNINGS 1
#else
# define _GNU_SOURCE 1
#endif
/* Intel(R) oneAPI DPC++/C++ Compiler */
#if defined(__INTEL_LLVM_COMPILER) && (!defined(__GNUC__))
# define __GNUC__ 4
# define __GNUC__ 4
#endif
/* Compiler compatibility */
#if defined(_MSC_VER) && (!defined(__GNUC__))
# define INLINE __inline
# define UNUSED __pragma(warning(suppress: 4189))
# define INLINE __inline
# define UNUSED __pragma(warning(suppress: 4189))
#elif defined(__GNUC__)
# define INLINE __inline__
# define UNUSED __attribute__((unused))
# define INLINE __inline__
# define UNUSED __attribute__((unused))
#else
# define INLINE inline
# define UNUSED
# define INLINE inline
# define UNUSED
#endif
#endif

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

@ -0,0 +1,46 @@
/******************************************************************************/
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
/* Internal */
#include "debug.h"
/* CRT */
#include <stdio.h>
#include <stdarg.h>
/* logging sub-system */
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN 1
# include <Windows.h>
#else
# include <syslog.h>
#endif
void slunkcrypt_debug_write(const char* const message)
{
#ifdef _WIN32
OutputDebugStringA(message);
#else
syslog(LOG_ALERT, "%s", message);
#endif
}
void slunkcrypt_debug_print(const char* const message, ...)
{
#ifdef _WIN32
char buffer[100U];
#endif
va_list args;
va_start(args, message);
#ifdef _WIN32
if (vsnprintf(buffer, 100U, message, args) > 0)
{
OutputDebugStringA(buffer);
}
#else
vsyslog(LOG_ALERT, message, args);
#endif
va_end(args);
}

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

@ -0,0 +1,19 @@
/******************************************************************************/
/* 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_write(const char *const message);
void slunkcrypt_debug_print(const char *const message, ...);
#define DBG_PRINTF(BUFF, FORMAT, ...) do \
{ \
const int _strlen = sprintf((BUFF), (FORMAT), __VA_ARGS__); \
if (_strlen > 0) { BUFF += _strlen; } \
} \
while (0)
#endif

View File

@ -0,0 +1,49 @@
/******************************************************************************/
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
#ifndef INC_SLUNKCRYPT_INITIALIZE_H
#define INC_SLUNKCRYPT_INITIALIZE_H
#include <stdint.h>
/* randomized list of the 256+2 16-bit "safe" prime numbers */
static const uint16_t INITIALIZER[258U] =
{
0x5B67, 0xFCFB, 0xD40F, 0xE61B, 0xFA07, 0x9C2F, 0x275F, 0xFB1B,
0x4E9B, 0x79A3, 0x3173, 0x4067, 0x368F, 0xC15B, 0x7C67, 0x6E03,
0xEC7B, 0x768B, 0xA3C7, 0xF06B, 0xB993, 0x0653, 0xA6BB, 0x5E8B,
0xC317, 0x9257, 0x5D0B, 0x5A3B, 0xF107, 0x9FB3, 0x0B03, 0x0A13,
0x675B, 0xCEB7, 0x8717, 0x6B87, 0x0D8B, 0x8DA7, 0xB5DF, 0x1A7B,
0xF863, 0xBACB, 0x468B, 0x34D3, 0xE837, 0x3F0B, 0x4B3B, 0xB33F,
0x74B7, 0x5507, 0x4937, 0x8A0B, 0x8C27, 0xAFA3, 0x3A13, 0x75FB,
0xF42B, 0xC803, 0x6FE3, 0x1F67, 0x9B63, 0xB813, 0xEF9F, 0x0B93,
0x015B, 0x543B, 0x07EB, 0x4A03, 0x9017, 0x6D73, 0xCBFF, 0xE963,
0xAE8F, 0xC51B, 0x52EB, 0xDF37, 0xF8E7, 0xDA9F, 0x6A67, 0x999B,
0xD8BF, 0xF35F, 0x37DF, 0xD73F, 0x269F, 0x804B, 0x7853, 0xBF33,
0xD2E3, 0xC767, 0x6803, 0xAB0B, 0x92E7, 0x8CF3, 0xBA17, 0x93A7,
0x7133, 0xC0D7, 0x2867, 0xD9EB, 0x293F, 0x30EF, 0x501B, 0xC98F,
0xF7D3, 0xE22B, 0xAA57, 0x2AFB, 0x35E7, 0x43AF, 0x0527, 0x0C2F,
0x80DB, 0x729B, 0x16AF, 0xF5DB, 0x260F, 0x5873, 0x95B7, 0x0EC3,
0x975B, 0x00A7, 0x774B, 0xA22F, 0xA98B, 0xC893, 0xB477, 0xD943,
0x83E7, 0xC3E3, 0x4C7F, 0xBDB3, 0xD523, 0x9E33, 0x05CF, 0x02CF,
0x5903, 0xCC9B, 0xF20F, 0xA1AB, 0x860F, 0x8243, 0x0E27, 0xAC7F,
0x50B7, 0xFE27, 0xA577, 0xE423, 0x01DF, 0x8357, 0xDFC7, 0x2C0F,
0x8F4B, 0xE09F, 0x1733, 0x4F67, 0x5C0F, 0xA8D7, 0x10A3, 0x5387,
0x2DB3, 0x8957, 0x9CBF, 0x45EF, 0x62DB, 0xF743, 0x480B, 0xFEF3,
0xADE7, 0x6F53, 0x489B, 0xE6B7, 0x1B47, 0x098F, 0xA4C3, 0x2FE7,
0x2C9F, 0xD6AF, 0x5243, 0x6593, 0x4A87, 0xABFB, 0xCA73, 0x374F,
0x732B, 0x9A4F, 0x599F, 0x98C3, 0x20E7, 0x1607, 0x63EF, 0x21FB,
0xA31F, 0x6917, 0xE537, 0x71C3, 0x6053, 0xDDE7, 0x9F23, 0xBD17,
0x73DF, 0xA757, 0x7B3B, 0x03FB, 0x64C7, 0x3BB7, 0xDEA7, 0xBB5B,
0xAF13, 0x396B, 0xE2BB, 0x4283, 0x089F, 0x19C7, 0x6E93, 0xB1BF,
0x11C3, 0x2F4B, 0x1D63, 0x1247, 0x1C13, 0xB28B, 0x7D03, 0x96CB,
0xE177, 0x32F3, 0x8E73, 0x3263, 0xCF9B, 0x3AEB, 0x7DB7, 0x24FB,
0xF4AF, 0x444B, 0x69E3, 0xD1C3, 0x5F57, 0x1337, 0xBFCF, 0x0F6B,
0x1E17, 0x7EFB, 0x6C77, 0x035F, 0x0FEF, 0x5DD7, 0x071F, 0x2303,
0x04A3, 0x5747, 0xB747, 0x3D1F, 0x2A2F, 0xED6B, 0x3DBB, 0x150B,
0x13DF, 0xB8EB
};
#endif

View File

@ -3,16 +3,9 @@
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN 1
# define _CRT_SECURE_NO_WARNINGS 1
#else
# define _GNU_SOURCE 1
#endif
/* Internal */
#include "slunkcrypt.h"
#include "compiler.h"
#include "slunkcrypt.h"
/* CRT */
#include <string.h>

View File

@ -15,31 +15,34 @@ typedef struct
{
uint64_t hi, lo;
}
uint128_t;
hash128_t;
// ==========================================================================
// 128-Bit math support
// ==========================================================================
#if defined(__GNUC__) && defined(__SIZEOF_INT128__)
# define HAVE_UINT128_SUPPORT 1
# define PACK_U128(X) ((((__uint128_t)(X).hi) << 64) | (X).lo)
# define HAVE_UINT128_T 1
# define LOAD_U128(X) ((((__uint128_t)(X).hi) << 64) | (X).lo)
#else
# pragma message("Compiler does not support 128-bit math -> using fallback!")
#endif
static INLINE void multiply_u128(uint128_t *const out, const uint128_t lhs, const uint128_t rhs)
static INLINE void multiply_u128(hash128_t *const out, const hash128_t lhs, const hash128_t *const rhs)
{
#ifdef HAVE_UINT128_SUPPORT
const __uint128_t product = PACK_U128(lhs) * PACK_U128(rhs);
*out = (uint128_t) { product >> 64, product };
#ifdef HAVE_UINT128_T
const __uint128_t product = LOAD_U128(lhs) * LOAD_U128(*rhs);
out->lo = (uint64_t)product;
out->hi = (uint64_t)(product >> 64);
#else
const uint64_t lolo = (lhs.lo & 0xFFFFFFFF) * (rhs.lo & 0xFFFFFFFF);
const uint64_t hilo = (lhs.lo >> 32U) * (rhs.lo & 0xFFFFFFFF);
const uint64_t lohi = (lhs.lo & 0xFFFFFFFF) * (rhs.lo >> 32U);
const uint64_t hihi = (lhs.lo >> 32U) * (rhs.lo >> 32U);
const uint64_t lolo = (lhs.lo & 0xFFFFFFFF) * (rhs->lo & 0xFFFFFFFF);
const uint64_t hilo = (lhs.lo >> 32U) * (rhs->lo & 0xFFFFFFFF);
const uint64_t lohi = (lhs.lo & 0xFFFFFFFF) * (rhs->lo >> 32U);
const uint64_t hihi = (lhs.lo >> 32U) * (rhs->lo >> 32U);
const uint64_t crss = (lolo >> 32U) + (hilo & 0xFFFFFFFF) + lohi;
out->hi = (hilo >> 32U) + (crss >> 32) + hihi;
out->lo = (crss << 32U) | (lolo & 0xFFFFFFFF);
out->hi += (lhs.hi * rhs.lo) + (lhs.lo * rhs.hi); /* 128x128=128 */
out->hi += (lhs.hi * rhs->lo) + (lhs.lo * rhs->hi); /* 128x128=128 */
#endif
}
@ -47,32 +50,37 @@ static INLINE void multiply_u128(uint128_t *const out, const uint128_t lhs, cons
// Hash function
// ==========================================================================
static const uint128_t HASH_OFFSETBASE_128 = { 0x6C62272E07BB0142, 0x62B821756295C58D };
static const uint128_t HASH_MAGICPRIME_128 = { 0x0000000001000000, 0x000000000000013B };
static const hash128_t HASH_OFFSETBASE_128 = { UINT64_C(0x6C62272E07BB0142), UINT64_C(0x62B821756295C58D) };
static const hash128_t HASH_MAGICPRIME_128 = { UINT64_C(0x0000000001000000), UINT64_C(0x000000000000013B) };
static INLINE void hash_update_u64(uint128_t* const hash, uint64_t value)
#define HASH_UPDATE(X) do \
{ \
hash->lo ^= (X); \
multiply_u128(hash, *hash, &HASH_MAGICPRIME_128); \
} \
while(0)
static INLINE void hash_update_u64(hash128_t *const hash, uint64_t value)
{
size_t i;
for (i = 0U; i < sizeof(uint64_t); ++i, value >>= CHAR_BIT)
{
hash->lo ^= (uint8_t)(value & 0xFF);
multiply_u128(hash, *hash, HASH_MAGICPRIME_128);
HASH_UPDATE((uint8_t)value);
}
}
static INLINE void hash_update_str(uint128_t *const hash, const uint8_t *const data, const size_t data_len)
static INLINE void hash_update_str(hash128_t *const hash, const uint8_t *const data, const size_t data_len)
{
size_t i;
for (i = 0U; i < data_len; ++i)
{
hash->lo ^= data[i];
multiply_u128(hash, *hash, HASH_MAGICPRIME_128);
HASH_UPDATE(data[i]);
}
}
static INLINE uint128_t hash_code(const uint128_t *const seed, const uint8_t *const data, const size_t data_len)
static INLINE hash128_t hash_code(const hash128_t *const seed, const uint8_t *const data, const size_t data_len)
{
uint128_t hash = HASH_OFFSETBASE_128;
hash128_t hash = HASH_OFFSETBASE_128;
hash_update_u64(&hash, seed->lo);
hash_update_u64(&hash, seed->hi);
hash_update_str(&hash, data, data_len);
@ -83,11 +91,11 @@ static INLINE uint128_t hash_code(const uint128_t *const seed, const uint8_t *co
// Key derivation
// ==========================================================================
static INLINE uint64_t keygen_loop(uint64_t seed, const uint64_t i, const uint8_t *const passwd, const size_t passwd_len)
static INLINE uint64_t keygen_loop(uint64_t seed, const uint64_t i, const uint8_t *const passwd, const size_t passwd_len, const size_t rounds)
{
uint128_t hash = { seed, i };
hash128_t hash = { seed, i };
size_t u;
for (u = 0U, seed = 0U; u < 99971U; ++u)
for (u = 0U, seed = 0U; u < rounds; ++u)
{
hash = hash_code(&hash, passwd, passwd_len);
seed ^= hash.hi ^ hash.lo;
@ -95,9 +103,9 @@ static INLINE uint64_t keygen_loop(uint64_t seed, const uint64_t i, const uint8_
return seed;
}
void slunkcrypt_keygen(keydata_t *const key, const uint64_t salt, const uint16_t pepper, const uint8_t *const passwd, const size_t passwd_len)
void slunkcrypt_keygen(keydata_t *const key, const uint64_t salt, const uint16_t pepper, const uint8_t *const passwd, const size_t passwd_len, const size_t rounds)
{
key->a = keygen_loop(salt, 0x162603FA1CDA99D3 + (uint64_t)pepper, passwd, passwd_len);
key->b = keygen_loop(salt, 0xBFDEC4A6C1A46E09 + (uint64_t)pepper, passwd, passwd_len);
key->c = keygen_loop(salt, 0x6BA17D11624973EE + (uint64_t)pepper, passwd, passwd_len);
key->a = keygen_loop(salt, 0x162603FA1CDA99D3 + (uint64_t)pepper, passwd, passwd_len, rounds);
key->b = keygen_loop(salt, 0xBFDEC4A6C1A46E09 + (uint64_t)pepper, passwd, passwd_len, rounds);
key->c = keygen_loop(salt, 0x6BA17D11624973EE + (uint64_t)pepper, passwd, passwd_len, rounds);
}

View File

@ -15,6 +15,6 @@ typedef struct
}
keydata_t;
void slunkcrypt_keygen(keydata_t *const key, const uint64_t salt, const uint16_t pepper, const uint8_t* const passwd, const size_t passwd_len);
void slunkcrypt_keygen(keydata_t *const key, const uint64_t salt, const uint16_t pepper, const uint8_t* const passwd, const size_t passwd_len, const size_t rounds);
#endif

View File

@ -4,14 +4,17 @@
/******************************************************************************/
/* Internal */
#include "slunkcrypt.h"
#include "compiler.h"
#include "slunkcrypt.h"
#include "debug.h"
#include "keygen.h"
#include "initialize.h"
#include "thread.h"
#include "version.h"
/* CRT */
#include <string.h>
#include <stdio.h>
#include <limits.h>
/* Version */
@ -56,6 +59,8 @@ crypt_data_t;
typedef struct
{
int legacy_compat;
int debug_logging;
thrdpl_t *thread_pool;
crypt_data_t data;
}
@ -76,33 +81,22 @@ volatile int g_slunkcrypt_abort_flag = 0;
} \
while (0)
// ==========================================================================
// Byte access (endianness agnostic)
// ==========================================================================
static INLINE uint32_t lower_u64(const uint64_t value)
{
return (uint32_t)(value & 0xFFFFFFFF);
}
static INLINE uint32_t upper_u64(const uint64_t value)
{
return (uint32_t)(value >> 32U);
}
// ==========================================================================
// Deterministic random bit generator
// ==========================================================================
#define RANDOM_INIT(DST_LO, DST_HI, SRC) do \
{ \
DST_LO = (uint32_t)(SRC); \
DST_HI = (uint32_t)((SRC) >> 32U); \
} \
while (0)
static INLINE void random_init(rand_state_t *const state, const keydata_t *const key)
{
slunkcrypt_bzero(state, sizeof(rand_state_t));
state->x = lower_u64(key->a);
state->y = upper_u64(key->a);
state->z = lower_u64(key->b);
state->w = upper_u64(key->b);
state->v = lower_u64(key->c);
state->d = upper_u64(key->c);
RANDOM_INIT(state->x, state->y, key->a);
RANDOM_INIT(state->z, state->w, key->b);
RANDOM_INIT(state->v, state->d, key->c);
}
static INLINE uint32_t random_next(rand_state_t *const state)
@ -121,47 +115,48 @@ static INLINE void random_skip(rand_state_t *const state, const size_t skip_coun
size_t i;
for (i = 0U; i < skip_count; ++i)
{
UNUSED /*volatile*/ uint32_t q = random_next(state);
UNUSED /*volatile*/ uint32_t discard = random_next(state);
}
}
static INLINE void random_seed(rand_state_t *const state, uint64_t salt, const uint16_t pepper, const uint8_t *const passwd, const size_t passwd_len)
static INLINE void random_seed(rand_state_t *const state, uint64_t salt, const uint16_t pepper, const uint8_t *const passwd, const size_t passwd_len, const int legacy)
{
keydata_t key;
do
{
slunkcrypt_keygen(&key, salt++, pepper, passwd, passwd_len);
slunkcrypt_keygen(&key, salt++, pepper, passwd, passwd_len, legacy ? 99971U : 19997L);
random_init(state, &key);
slunkcrypt_bzero(&key, sizeof(keydata_t));
}
while (!(state->x || state->y || state->z || state->w || state->v));
random_skip(state, 97U);
random_skip(state, legacy ? 97U : 23U);
}
// ==========================================================================
// 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)
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;
rand_state_t *const rand_state = &data->thread_data[0].random;
const int reverse_mode = BOOLIFY(mode);
/* initialize state */
slunkcrypt_bzero(data, sizeof(crypt_data_t));
/* initialize counter */
random_seed(&data->thread_data[0].random, nonce, (uint16_t)(-1), passwd, passwd_len);
data->thread_data[0].counter = random_next(&data->thread_data[0].random);
random_seed(rand_state, nonce, legacy ? ((uint16_t)(-1)) : INITIALIZER[256U], passwd, passwd_len, legacy);
data->thread_data[0].counter = random_next(rand_state);
/* set up the wheel permutations */
for (r = 0U; r < 256U; ++r)
{
random_seed(&data->thread_data[0].random, nonce, (uint16_t)r, passwd, passwd_len);
random_seed(rand_state, nonce, legacy ? ((uint16_t)r) : INITIALIZER[r], passwd, passwd_len, legacy);
for (i = 0U; i < 256U; ++i)
{
const size_t j = random_next(&data->thread_data[0].random) % (i + 1U);
const size_t j = random_next(rand_state) % (i + 1U);
if (j != i)
{
data->wheel[r][i] = data->wheel[r][j];
@ -190,21 +185,39 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
}
/* initialize thread state */
data->thread_data[0].reverse_mode = reverse_mode;
data->thread_data[0].wheel = (const uint8_t(*)[256]) data->wheel;
data->thread_data[0].index_off = 0U;
random_seed(&data->thread_data[0].random, nonce, 256U, passwd, passwd_len);
for (i = 1U; i < thread_count; ++i)
random_seed(rand_state, nonce, legacy ? 256U : INITIALIZER[257U], passwd, passwd_len, legacy);
for (i = 0U; i < thread_count; ++i)
{
data->thread_data[i].reverse_mode = data->thread_data[0].reverse_mode;
data->thread_data[i].wheel = data->thread_data[0].wheel;
data->thread_data[i].counter = data->thread_data[0].counter + ((uint32_t)i);
data->thread_data[i].index_off = data->thread_data[i - 1U].index_off + 1U;
memcpy(&data->thread_data[i].random, &data->thread_data[0].random, sizeof(rand_state_t));
random_skip(&data->thread_data[i].random, i * 63U);
data->thread_data[i].reverse_mode = reverse_mode;
data->thread_data[i].wheel = (const uint8_t(*)[256]) data->wheel;
data->thread_data[i].index_off = i;
if (i > 0U)
{
data->thread_data[i].counter = data->thread_data[0].counter + ((uint32_t)i);
memcpy(&data->thread_data[i].random, &data->thread_data[0].random, sizeof(rand_state_t));
random_skip(&data->thread_data[i].random, i * 63U);
}
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", rand_state->d, rand_state->v, rand_state->w, rand_state->x, rand_state->y, rand_state->z);
for (r = 0U; r < 256U; ++r)
{
char message[775U] = { '\0' };
char *ptr = message;
DBG_PRINTF(ptr, "[%02X] =", (unsigned)r);
for (i = 0U; i < 256U; ++i)
{
DBG_PRINTF(ptr, " %02X", data->wheel[r][i]);
}
slunkcrypt_debug_write(message);
}
}
return SLUNKCRYPT_SUCCESS;
/* aborted */
@ -293,21 +306,21 @@ 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)
{
slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, 0U };
const slunkparam_t param = { SLUNKCRYPT_PARAM_VERSION, 0U, SLUNKCRYPT_TRUE, SLUNKCRYPT_FALSE };
return slunkcrypt_alloc_ext(nonce, passwd, passwd_len, mode, &param);
}
slunkcrypt_t slunkcrypt_alloc_ext(const uint64_t nonce, const uint8_t *const passwd, const size_t passwd_len, const int mode, const slunkparam_t *const param)
{
crypt_state_t* state = NULL;
crypt_state_t *state = NULL;
if ((!passwd) || (passwd_len < SLUNKCRYPT_PWDLEN_MIN) || (passwd_len > SLUNKCRYPT_PWDLEN_MAX) ||
(mode < SLUNKCRYPT_ENCRYPT) || (mode > SLUNKCRYPT_DECRYPT) || (!param) || (param->version == 0U) || (param->version > SLUNKCRYPT_PARAM_VERSION))
(mode < SLUNKCRYPT_ENCRYPT) || (mode > SLUNKCRYPT_DECRYPT) || (!param) || (!param->version) || (param->version > SLUNKCRYPT_PARAM_VERSION))
{
return SLUNKCRYPT_NULL;
}
if (!(state = (crypt_state_t*)malloc(sizeof(crypt_state_t))))
if (!(state = (crypt_state_t*) calloc(1U, sizeof(crypt_state_t))))
{
return SLUNKCRYPT_NULL;
}
@ -322,7 +335,10 @@ slunkcrypt_t slunkcrypt_alloc_ext(const uint64_t nonce, const uint8_t *const pas
}
}
if (initialize_state(&state->data, THREAD_COUNT(state), nonce, passwd, passwd_len, mode) == SLUNKCRYPT_SUCCESS)
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, state->debug_logging) == SLUNKCRYPT_SUCCESS)
{
return (slunkcrypt_t)state;
}
@ -340,10 +356,12 @@ 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)) != 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));
}
return result;
}

View File

@ -5,15 +5,9 @@
#ifndef SLUNKBUILD_NOTHREADS
#ifdef _WIN32
# define _CRT_SECURE_NO_WARNINGS 1
#else
# define _GNU_SOURCE 1
#endif
/* Internal */
#include "thread.h"
#include "compiler.h"
#include "thread.h"
/* CRT */
#include <stdlib.h>

View File

@ -7,7 +7,7 @@
#define INC_SLUNKCRYPT_VERSION_H
#define LIB_VERSION_MAJOR 1
#define LIB_VERSION_MINOR 2
#define LIB_VERSION_PATCH 1
#define LIB_VERSION_MINOR 3
#define LIB_VERSION_PATCH 0
#endif