From b3ab8c32fc944816a1a41ef653f5debb7347d2bd Mon Sep 17 00:00:00 2001 From: zeromind Date: Sat, 6 Nov 2021 22:33:00 +0000 Subject: [PATCH 1/6] Tiger: enable x86_64 ASM only on x86_64 This makes Tiger build and run on e.g. aarch64 --- AVDump3NativeLib/src/Tiger.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AVDump3NativeLib/src/Tiger.c b/AVDump3NativeLib/src/Tiger.c index 30e9cb2..dd8da9d 100644 --- a/AVDump3NativeLib/src/Tiger.c +++ b/AVDump3NativeLib/src/Tiger.c @@ -6,10 +6,12 @@ #include "AVD3NativeLibApi.h" #include +#ifdef __x86_64__ #define CRYPTOPP_GENERATE_X64_MASM #define CRYPTOPP_X86_ASM_AVAILABLE #define CRYPTOPP_BOOL_X64 1 #define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 1 +#endif #ifdef CRYPTOPP_GENERATE_X64_MASM #define AS1(x) x*newline* @@ -90,7 +92,7 @@ #define AS_JCXZ jrcxz -#ifdef CRYPTOPP_DISABLE_X86ASM // for backwards compatibility: this macro had both meanings +#if defined(CRYPTOPP_DISABLE_X86ASM) || defined(__aarch64__) // for backwards compatibility: this macro had both meanings #define CRYPTOPP_DISABLE_ASM #define CRYPTOPP_DISABLE_SSE2 #endif From 439e17b8e8c50b7fa2c21fd22490f6a0994248a1 Mon Sep 17 00:00:00 2001 From: zeromind Date: Sat, 6 Nov 2021 22:36:18 +0000 Subject: [PATCH 2/6] InstructionCheck: return 0 on non-x86_64 return 0/no supported extension on other architectures, e.g. aarch64 --- AVDump3NativeLib/src/InstructionCheck.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/AVDump3NativeLib/src/InstructionCheck.c b/AVDump3NativeLib/src/InstructionCheck.c index cb4e894..c1ae66e 100644 --- a/AVDump3NativeLib/src/InstructionCheck.c +++ b/AVDump3NativeLib/src/InstructionCheck.c @@ -7,16 +7,14 @@ #define cpuid(info, x) __cpuidex(info, x, 0) #else - +#ifdef __x86_64__ // GCC Intrinsics #include + void cpuid(int info[4], int InfoType) { __cpuid_count(InfoType, 0, info[0], info[1], info[2], info[3]); } -#endif - - uint64_t RetrieveCPUInstructions() { // Misc. bool HW_MMX = 0; @@ -143,4 +141,10 @@ uint64_t RetrieveCPUInstructions() { (HW_AVX512DQ ? 1 << 28 : 0) | (HW_AVX512IFMA ? 1 << 29 : 0) | (HW_AVX512VBMI ? 1 << 30 : 0); -} \ No newline at end of file +} +#else +uint64_t RetrieveCPUInstructions() { + return 0; +} +#endif +#endif From 40a8c75770c90ce192936b4910aea28a58c690bc Mon Sep 17 00:00:00 2001 From: zeromind Date: Sat, 6 Nov 2021 22:37:51 +0000 Subject: [PATCH 3/6] Makefile: make x86 flags x86_86 exclusive enable extension flags only for x86_64 --- AVDump3NativeLib/Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/AVDump3NativeLib/Makefile b/AVDump3NativeLib/Makefile index 69c7208..014a0fa 100644 --- a/AVDump3NativeLib/Makefile +++ b/AVDump3NativeLib/Makefile @@ -1,11 +1,21 @@ CC=gcc CFLAGS=-I. -Wall -Werror -fpic -O3 -lrt -OBJ = AVD3MirrorBuffer.o AVD3NativeLibApi.o InstructionCheck.o CRC32.o CRC32C.o MD4.o SHA1.o SHA3.o SHA256.o Tiger.o +OBJ = AVD3MirrorBuffer.o AVD3NativeLibApi.o InstructionCheck.o CRC32.o MD4.o SHA3.o Tiger.o + +ARCH := $(shell uname -m) +$(info uname_m=$(ARCH)) + +SSE4_FLAGS := +SHA_FLAGS := + +ifeq ($(ARCH),x86_64) +OBJ += SHA1.o SHA256.o CRC32C.so OBJ_SSE4 = CRC32C.o SHA1.o SHA256.o OBJ_SHA = SHA1.o SHA256.o $(OBJ_SSE4): SSE4_FLAGS := -msse4 $(OBJ_SHA): SHA_FLAGS := -msha +endif AVDump3NativeLib.so: $(OBJ) $(CC) -shared -o $@ $^ $(CFLAGS) From 74ff996b2c76ad59f5d48aa5d98462a351d383a1 Mon Sep 17 00:00:00 2001 From: zeromind Date: Sat, 6 Nov 2021 22:44:12 +0000 Subject: [PATCH 4/6] AVD3NativeLibApi: x86_86-exclusive extensions Load extensions for x86_64 only on that architecture. --- AVDump3NativeLib/src/AVD3NativeLibApi.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AVDump3NativeLib/src/AVD3NativeLibApi.h b/AVDump3NativeLib/src/AVD3NativeLibApi.h index 049f643..bf94718 100644 --- a/AVDump3NativeLib/src/AVD3NativeLibApi.h +++ b/AVDump3NativeLib/src/AVD3NativeLibApi.h @@ -3,8 +3,11 @@ #include #include #include + +#ifdef __x86_64__ #include #include +#endif #include "DLLDefines.h" @@ -122,4 +125,4 @@ DLL_PUBLIC char* FreeMirrorBuffer(AVD3MirrorBufferCreateHandle* handle); #include -#endif \ No newline at end of file +#endif From f0139c853a83bae1aaea1f76008c2ed7ae7606fe Mon Sep 17 00:00:00 2001 From: zeromind Date: Sat, 6 Nov 2021 22:51:47 +0000 Subject: [PATCH 5/6] AVD3ProcessingModule: always use Tiger/TTH Tiger supports architecture other that x86_64 now, always use it. --- AVDump3Lib/Processing/AVD3ProcessingModule.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/AVDump3Lib/Processing/AVD3ProcessingModule.cs b/AVDump3Lib/Processing/AVD3ProcessingModule.cs index 3ab6c04..91085b9 100644 --- a/AVDump3Lib/Processing/AVD3ProcessingModule.cs +++ b/AVDump3Lib/Processing/AVD3ProcessingModule.cs @@ -72,10 +72,10 @@ public void RegisterDefaultBlockConsumers(IDictionary new HashCalculator(s.Name, s.Reader, new KeccakNativeHashAlgorithm(256)))); addOrReplace(new BlockConsumerFactory("KECCAK-384", s => new HashCalculator(s.Name, s.Reader, new KeccakNativeHashAlgorithm(384)))); addOrReplace(new BlockConsumerFactory("KECCAK-512", s => new HashCalculator(s.Name, s.Reader, new KeccakNativeHashAlgorithm(512)))); + addOrReplace(new BlockConsumerFactory("TIGER", s => new HashCalculator(s.Name, s.Reader, new TigerNativeHashAlgorithm()))); + addOrReplace(new BlockConsumerFactory("TTH", s => new HashCalculator(s.Name, s.Reader, new TigerTreeHashAlgorithm(getArgumentAt(s, 0, Math.Min(4, Environment.ProcessorCount).ToInvString()).ToInvInt32())))); if(AvailableSIMD.HasFlag(CPUInstructions.SSE2)) { - addOrReplace(new BlockConsumerFactory("TIGER", s => new HashCalculator(s.Name, s.Reader, new TigerNativeHashAlgorithm()))); - addOrReplace(new BlockConsumerFactory("TTH", s => new HashCalculator(s.Name, s.Reader, new TigerTreeHashAlgorithm(getArgumentAt(s, 0, Math.Min(4, Environment.ProcessorCount).ToInvString()).ToInvInt32())))); addOrReplace(new BlockConsumerFactory("CRC32", s => new HashCalculator(s.Name, s.Reader, new Crc32NativeHashAlgorithm()))); } if(AvailableSIMD.HasFlag(CPUInstructions.SSE42)) { @@ -86,7 +86,6 @@ public void RegisterDefaultBlockConsumers(IDictionary new HashCalculator(s.Name, s.Reader, new SHA256NativeHashAlgorithm()))); } - } catch(Exception) { //TODO Log } From b42499691099431a540a42c80fe816c7d74d9964 Mon Sep 17 00:00:00 2001 From: zeromind Date: Mon, 8 Nov 2021 21:36:51 +0000 Subject: [PATCH 6/6] AVD3NativeLibApi: fix typo for CRC32C --- AVDump3NativeLib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AVDump3NativeLib/Makefile b/AVDump3NativeLib/Makefile index 014a0fa..f215bb1 100644 --- a/AVDump3NativeLib/Makefile +++ b/AVDump3NativeLib/Makefile @@ -9,7 +9,7 @@ SSE4_FLAGS := SHA_FLAGS := ifeq ($(ARCH),x86_64) -OBJ += SHA1.o SHA256.o CRC32C.so +OBJ += SHA1.o SHA256.o CRC32C.o OBJ_SSE4 = CRC32C.o SHA1.o SHA256.o OBJ_SHA = SHA1.o SHA256.o