OSDN Git Service

Small code clean-up + improved the Makefile + detect GNU/Hurd operating system.
authorLoRd_MuldeR <mulder2@gmx.de>
Sat, 23 Apr 2022 15:30:51 +0000 (17:30 +0200)
committerLoRd_MuldeR <mulder2@gmx.de>
Sat, 23 Apr 2022 18:25:58 +0000 (20:25 +0200)
Makefile
README.md
frontend/src/platform.h
libslunkcrypt/src/keygen.c

index a2b5a1c..115f71c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ SUBDIR_LIB := libslunkcrypt
 # ---------------------------------------------------------------------------
 
 CONFIG =
-LDFLGS =
+LDFLGS = -lpthread
 CFLAGS = -I$(SUBDIR_LIB)/include -std=gnu99 -Wall
 
 ifneq ($(CPU),0)
@@ -71,8 +71,8 @@ else
   SUFFIX :=
 endif
 
-ifneq ($(MACHINE),$(filter %mingw32 %-windows-gnu,$(MACHINE)))
-  LDFLGS += -lpthread
+ifeq ($(THREAD),0)
+  CFLAGS += -DSLUNKBUILD_NOTHREADS
 endif
 
 ifneq ($(STRIP),0)
@@ -87,10 +87,6 @@ ifeq ($(MACHINE),$(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE)))
   LDFLGS += -mconsole -municode
 endif
 
-ifeq ($(THREAD),0)
-  CFLAGS += -DSLUNKBUILD_NOTHREADS
-endif
-
 # ---------------------------------------------------------------------------
 # File names
 # ---------------------------------------------------------------------------
index 7927d02..31af456 100644 (file)
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ The SlunkCrypt library and the command-line application currently run on the fol
 * **Linux** (kernel version 3.17, or later) &mdash; 32-Bit (i686) and 64-Bit (AMD64)
 * **Various BSD flavors** (tested on NetBSD 9.2, FreeBSD 13.0 and OpenBSD 7.0) &mdash; 32-Bit (i686) and 64-Bit (AMD64)
 * **Solaris** (tested on Solaris 11.4 and OmniOS/illumos) &mdash; 32-Bit (i686) and 64-Bit (AMD64)
+* **GNU/Hurd** (tested on Debian GNU/Hurd 0.9) &mdash; 32-Bit (i686)
 * **Mac OS X** (tested on macOS 11 “Big Sur”) &mdash; Intel x86-64 (AMD64) and Apple Silicon (AArch64)
 
 The SlunkCrypt GUI application currently runs on the following platforms:
index 9c7fb57..501ceaf 100644 (file)
@@ -25,6 +25,8 @@
 #  define OS_TYPE_NAME "Cygwin"
 #elif defined(__linux__)
 #  define OS_TYPE_NAME "Linux"
+#elif defined(__gnu_hurd__)
+#  define OS_TYPE_NAME "GNU/Hurd"
 #elif defined(__FreeBSD__)
 #  define OS_TYPE_NAME "FreeBSD"
 #elif defined(__DragonFly__)
index 5bd3904..8fa45f3 100644 (file)
@@ -21,14 +21,16 @@ uint128_t;
 // 128-Bit math support
 // ==========================================================================
 
-#define READ_U128(X) ((((__uint128_t)(X).hi) << 64U) | ((__uint128_t)(X).lo))
+#if defined(__GNUC__) && defined(__SIZEOF_INT128__)
+#  define HAVE_UINT128_SUPPORT 1
+#  define PACK_U128(X) ((((__uint128_t)(X).hi) << 64) | (X).lo)
+#endif
 
 static INLINE void multiply_u128(uint128_t *const out, const uint128_t lhs, const uint128_t rhs)
 {
-#if defined(__GNUC__) && defined(__SIZEOF_INT128__)
-       const __uint128_t tmp = READ_U128(lhs) * READ_U128(rhs);
-       out->hi = (uint64_t)(tmp >> 64U);
-       out->lo = (uint64_t)(tmp & 0xFFFFFFFFFFFFFFFF);
+#ifdef HAVE_UINT128_SUPPORT
+       const __uint128_t product = PACK_U128(lhs) * PACK_U128(rhs);
+       *out = (uint128_t) { product >> 64, product };
 #else
        const uint64_t lolo = (lhs.lo & 0xFFFFFFFF) * (rhs.lo & 0xFFFFFFFF);
        const uint64_t hilo = (lhs.lo >> 32U) * (rhs.lo & 0xFFFFFFFF);