• R/O
  • HTTP
  • SSH
  • HTTPS

SlunkCrypt: 提交

Official SlunkCrypt repository


Commit MetaInfo

修訂207039f4f7b200cc0a91a8d378748eb9ad897293 (tree)
時間2022-05-08 00:55:03
作者LoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Small improvement to Makefile + fixed compilation with µClibc, which does *not* provide getentropy() or explicit_bzero() + enable these functions on Solaris/Illumos.

Change Summary

差異

--- a/Makefile
+++ b/Makefile
@@ -10,8 +10,6 @@ FLTO ?= 0
1010 FPGO ?= 0
1111 STRIP ?= 0
1212 CPU ?= 0
13-MARCH ?= 0
14-MTUNE ?= 0
1513 THREAD ?= 1
1614
1715 # ---------------------------------------------------------------------------
@@ -29,18 +27,18 @@ CONFIG =
2927 LDFLGS = -lpthread
3028 CFLAGS = -I$(SUBDIR_LIB)/include -std=gnu99 -Wall
3129
32-ifneq ($(CPU),0)
30+ifneq (,$(firstword $(filter 32 64,$(CPU))))
3331 CFLAGS += -m$(firstword $(CPU))
3432 endif
35-ifneq ($(TARGET),)
33+ifneq (,$(firstword $(TARGET)))
3634 CFLAGS += --target=$(firstword $(TARGET))
3735 LDFLGS += --target=$(firstword $(TARGET))
3836 endif
3937
40-ifneq ($(MARCH),0)
38+ifneq (,$(firstword $(MARCH)))
4139 CFLAGS += -march=$(firstword $(MARCH))
4240 endif
43-ifneq ($(MTUNE),0)
41+ifneq (,$(firstword $(MTUNE)))
4442 CFLAGS += -mtune=$(firstword $(MTUNE))
4543 endif
4644
@@ -65,7 +63,7 @@ endif
6563
6664 MACHINE := $(shell $(CC) -dumpmachine || echo unknown)
6765
68-ifeq ($(MACHINE),$(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)))
66+ifneq (,$(firstword $(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE))))
6967 SUFFIX := .exe
7068 else
7169 SUFFIX :=
@@ -83,7 +81,7 @@ ifeq ($(STATIC),1)
8381 LDFLGS += -static
8482 endif
8583
86-ifeq ($(MACHINE),$(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE)))
84+ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE))))
8785 LDFLGS += -mconsole -municode
8886 endif
8987
--- a/libslunkcrypt/src/junk.c
+++ b/libslunkcrypt/src/junk.c
@@ -40,24 +40,31 @@ static INLINE size_t MIN_SIZE(const size_t a, const size_t b) { return (a > b) ?
4040 # include <pthread.h>
4141 #endif
4242
43-/* detect destructor support */
44-#undef ATTRIB_DESTRUCTOR
43+/* detect compiler destructor support */
44+#undef HAVE_ATTRIB_DESTRUCTOR
4545 #if defined(__GNUC__) || defined(__clang__)
46-# define ATTRIB_DESTRUCTOR __attribute__((destructor))
46+# define HAVE_ATTRIB_DESTRUCTOR 1
4747 #endif
4848
49-/* detect getentropy() support */
50-#undef GETENTROPY
51-#if (defined(__linux__) && (__linux__ >= 1)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 12)) || (defined(__OpenBSD__) && (__OpenBSD__ >= 1))
52-# define GETENTROPY getentropy
49+/* detect getentropy() or RtlGenRandom() support */
50+#undef HAVE_GETENTROPY
51+#undef HAVE_WIN32RTLGENRANDOM
52+#if defined(_WIN32)
53+# define HAVE_WIN32RTLGENRANDOM 1
54+#elif (defined(__linux__) && !defined(__UCLIBC__)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 12)) || defined(__OpenBSD__) || (defined(__sun) && defined(__SVR4))
55+# define HAVE_GETENTROPY 1
56+#else
57+# pragma message("Function getentropy() is *not* available -> using fallback!")
5358 #endif
5459
55-/* detect explicit_bzero() support */
60+/* detect explicit_bzero() or SecureZeroMemory() support */
5661 #undef EXPLICIT_BZERO
57-#if defined(_WIN32) && (_WIN32 >= 1) && defined(SecureZeroMemory)
62+#if defined(_WIN32) && defined(SecureZeroMemory)
5863 # define EXPLICIT_BZERO SecureZeroMemory
59-#elif (defined(__linux__) && (__linux__ >= 1)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 11)) || (defined(__OpenBSD__) && (__OpenBSD__ >= 1))
64+#elif (defined(__linux__) && !defined(__UCLIBC__)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 11)) || defined(__OpenBSD__) || (defined(__sun) && defined(__SVR4))
6065 # define EXPLICIT_BZERO explicit_bzero
66+#else
67+# pragma message("Function explicit_bzero() is *not* available -> using fallback!")
6168 #endif
6269
6370 // ==========================================================================
@@ -102,15 +109,15 @@ static void exit_random_source(void)
102109 /* Initialize CSRNG */
103110 static void init_random_source(void)
104111 {
105-#ifdef _WIN32
112+#ifdef HAVE_WIN32RTLGENRANDOM
106113 if ((s_advapi32 = LoadLibraryW(L"advapi32.dll")))
107114 {
108115 s_genrandom = (ptr_genrandom_t) GetProcAddress(s_advapi32, "SystemFunction036");
109116 }
110117 #else
111-#if defined(GETENTROPY)
118+#if defined(HAVE_GETENTROPY)
112119 uint8_t temp;
113- if (GETENTROPY(&temp, sizeof(uint8_t)) >= 0)
120+ if (getentropy(&temp, sizeof(uint8_t)) >= 0)
114121 {
115122 goto init_completed;
116123 }
@@ -124,7 +131,7 @@ static void init_random_source(void)
124131 }
125132 init_completed: ;
126133 #endif
127-#if !defined(ATTRIB_DESTRUCTOR)
134+#if !defined(HAVE_ATTRIB_DESTRUCTOR)
128135 atexit(exit_random_source);
129136 #endif
130137 }
@@ -134,7 +141,7 @@ size_t slunkcrypt_random_bytes(uint8_t *const buffer, const size_t length)
134141 {
135142 size_t offset;
136143 pthread_once(&s_random_is_initialized, init_random_source);
137-#ifdef _WIN32
144+#ifdef HAVE_WIN32RTLGENRANDOM
138145 if (s_genrandom)
139146 {
140147 ULONG count;
@@ -162,14 +169,14 @@ size_t slunkcrypt_random_bytes(uint8_t *const buffer, const size_t length)
162169 }
163170 return offset;
164171 }
165-#if defined(GETENTROPY)
172+#if defined(HAVE_GETENTROPY)
166173 else
167174 {
168175 size_t count;
169176 for (offset = 0U; offset < length; offset += count)
170177 {
171178 count = MIN_SIZE(length - offset, 256U); /*the maximum permitted value is 256*/
172- if (GETENTROPY(buffer + offset, count) < 0)
179+ if (getentropy(buffer + offset, count) < 0)
173180 {
174181 break; /*failed*/
175182 }
@@ -206,8 +213,8 @@ void slunkcrypt_bzero(void* const buffer, const size_t length)
206213 // Destructor
207214 // ==========================================================================
208215
209-#if defined(ATTRIB_DESTRUCTOR)
210-ATTRIB_DESTRUCTOR void slunkcrypt_destructor()
216+#if defined(HAVE_ATTRIB_DESTRUCTOR)
217+__attribute__((destructor)) void slunkcrypt_destructor()
211218 {
212219 exit_random_source();
213220 }
Show on old repository browser