From 68e53038f314691120b26b54f20c006755800740 Mon Sep 17 00:00:00 2001 From: Yi Hao Date: Tue, 8 Apr 2025 05:44:05 +0000 Subject: [PATCH 01/14] Add OpenSSL 1.1.1 as submodule to support deprecated APIs Some functions used by the project are no longer available in OpenSSL 3.0+. To ensure compatibility and avoid refactoring, OpenSSL 1.1.1 was added as a submodule. Makefile was updated to build and link against the submodule version correctly. --- .gitmodules | 4 ++++ openssl | 1 + 2 files changed, 5 insertions(+) create mode 100644 .gitmodules create mode 160000 openssl diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7b998dd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "openssl"] + path = openssl + url = https://github.com/openssl/openssl.git + branch = OpenSSL_1_1_1-stable diff --git a/openssl b/openssl new file mode 160000 index 0000000..b372b1f --- /dev/null +++ b/openssl @@ -0,0 +1 @@ +Subproject commit b372b1f76450acdfed1e2301a39810146e28b02c From c7ce7b0257567c1769cdfcf26927afc0682d45af Mon Sep 17 00:00:00 2001 From: Yi Hao Date: Tue, 8 Apr 2025 06:16:41 +0000 Subject: [PATCH 02/14] Modify Makefile and hash_extender_engine.c to ensure that openssl header file are included correctly --- Makefile | 43 +++++++++++++++++++++++++----------------- hash_extender_engine.c | 15 ++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index ce6d33d..44a92e6 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,8 @@ -# Checks if /usr/include/openssl/whrlpool.h exists, and set a define if it -# doesn't. -INCLUDE_OPENSSL := /usr/include/openssl -INCLUDE_WHIRLPOOL := whrlpool.h -ifneq ($(shell ls $(INCLUDE_OPENSSL)/$(INCLUDE_WHIRLPOOL) 2>/dev/null), $(INCLUDE_OPENSSL)/$(INCLUDE_WHIRLPOOL)) -WHIRLPOOL := -DDISABLE_WHIRLPOOL -endif +OPENSSL_SRC := $(CURDIR)/openssl +OPENSSL_BUILD := $(OPENSSL_SRC)/build +OPENSSL_INSTALL := $(OPENSSL_SRC)/install +INCLUDE_OPENSSL := $(OPENSSL_INSTALL)/include +LIB_OPENSSL := $(OPENSSL_INSTALL)/lib # Capture the operating system name for use by the preprocessor. OS := $(shell uname | tr '/[[:lower:]]' '_[[:upper:]]') @@ -12,12 +10,8 @@ OS := $(shell uname | tr '/[[:lower:]]' '_[[:upper:]]') # These are the specifications of the toolchain CC := gcc CFLAGS := -std=c89 -g -oS -Wall -Werror -Wno-deprecated-declarations -CPPFLAGS := -D_DEFAULT_SOURCE -D$(OS) $(WHIRLPOOL) -ifeq ($(OS),DARWIN) - LDFLAGS := -lssl -lcrypto -L/usr/local/opt/openssl/lib/ -else - LDFLAGS := -lssl -lcrypto -endif +CPPFLAGS := -D_DEFAULT_SOURCE -D$(OS) -I$(INCLUDE_OPENSSL) +LDFLAGS := -lssl -lcrypto -L$(LIB_OPENSSL) BIN_MAIN := hash_extender BIN_TEST := hash_extender_test @@ -28,13 +22,25 @@ OBJS := $(patsubst %.c,%.o,$(SRCS)) OBJS_MAIN := $(filter-out $(BIN_TEST).o,$(OBJS)) OBJS_TEST := $(filter-out $(BIN_MAIN).o,$(OBJS)) -all: $(BINS) +all: $(OPENSSL_INSTALL)/lib/libssl.a $(BINS) -$(BIN_MAIN): $(OBJS_MAIN) +# OpenSSL build and install +$(OPENSSL_INSTALL)/lib/libssl.a: $(OPENSSL_SRC)/Makefile + @echo "Building OpenSSL..." + @cd $(OPENSSL_SRC) && \ + make && make install_sw + +$(OPENSSL_SRC)/Makefile: + @echo "Downloading and preparing OpenSSL source..." + @git submodule update --init + @cd $(OPENSSL_SRC) && \ + ./config --prefix=$(OPENSSL_INSTALL) no-shared no-dso + +$(BIN_MAIN): $(OBJS_MAIN) $(OPENSSL_INSTALL)/lib/libssl.a @echo [LD] $@ @$(CC) $(CFLAGS) -o $(BIN_MAIN) $(OBJS_MAIN) $(LDFLAGS) -$(BIN_TEST): $(OBJS_TEST) +$(BIN_TEST): $(OBJS_TEST) $(OPENSSL_INSTALL)/lib/libssl.a @echo [LD] $@ @$(CC) $(CFLAGS) -o $(BIN_TEST) $(OBJS_TEST) $(LDFLAGS) @@ -43,9 +49,12 @@ $(BIN_TEST): $(OBJS_TEST) @$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< clean: - @echo [RM] \*.o + @echo [RM] *.o @rm -f $(OBJS) @echo [RM] $(BIN_MAIN) @rm -f $(BIN_MAIN) @echo [RM] $(BIN_TEST) @rm -f $(BIN_TEST) + @echo [RM] OpenSSL build and install + @make -C $(OPENSSL_SRC) clean + @rm -rf $(OPENSSL_BUILD) $(OPENSSL_INSTALL) \ No newline at end of file diff --git a/hash_extender_engine.c b/hash_extender_engine.c index 3a2b7aa..dcc9662 100644 --- a/hash_extender_engine.c +++ b/hash_extender_engine.c @@ -23,17 +23,14 @@ #include #endif -#include -#include -#include -#include -#include -#include -#include -#include +#include "openssl/md4.h" +#include "openssl/md5.h" +#include "openssl/ripemd.h" +#include "openssl/sha.h" +#include "openssl/evp.h" #include "tiger.h" #ifndef DISABLE_WHIRLPOOL -#include +#include "openssl/whrlpool.h" #endif #include "hash_extender_engine.h" From 97f8bc0363e4dea6ee9970fc7cca45f9bb6e66a9 Mon Sep 17 00:00:00 2001 From: Yi Hao <3171132517@qq.com> Date: Tue, 8 Apr 2025 06:27:03 +0000 Subject: [PATCH 03/14] Modify Makefile Add SM3 to README.md --- Makefile | 4 ++-- README.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 44a92e6..5c70de4 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,8 @@ OS := $(shell uname | tr '/[[:lower:]]' '_[[:upper:]]') # These are the specifications of the toolchain CC := gcc CFLAGS := -std=c89 -g -oS -Wall -Werror -Wno-deprecated-declarations -CPPFLAGS := -D_DEFAULT_SOURCE -D$(OS) -I$(INCLUDE_OPENSSL) -LDFLAGS := -lssl -lcrypto -L$(LIB_OPENSSL) +CPPFLAGS := -I$(INCLUDE_OPENSSL) -D_DEFAULT_SOURCE -D$(OS) +LDFLAGS := -L$(LIB_OPENSSL) -lssl -lcrypto BIN_MAIN := hash_extender BIN_TEST := hash_extender_test diff --git a/README.md b/README.md index 45dc654..72fcd96 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Now I'm gonna release the tool, and hope I didn't totally miss a good tool that - SHA-256 - SHA-512 - WHIRLPOOL +- SM3 I'm more than happy to extend this to cover other hashing algorithms as well, provided they are "vulnerable" to this attack -- MD2, SHA-224, and SHA-384 are not. Please contact me if you have other candidates and I'll add them ASAP! From bf4de9ddaab3915ffc3c3146038f5a5aa7bc9de2 Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 17:27:16 +0800 Subject: [PATCH 04/14] Adjust the build order --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5c70de4..7469d87 100644 --- a/Makefile +++ b/Makefile @@ -36,15 +36,15 @@ $(OPENSSL_SRC)/Makefile: @cd $(OPENSSL_SRC) && \ ./config --prefix=$(OPENSSL_INSTALL) no-shared no-dso -$(BIN_MAIN): $(OBJS_MAIN) $(OPENSSL_INSTALL)/lib/libssl.a +$(BIN_MAIN): $(OPENSSL_INSTALL)/lib/libssl.a $(OBJS_MAIN) @echo [LD] $@ @$(CC) $(CFLAGS) -o $(BIN_MAIN) $(OBJS_MAIN) $(LDFLAGS) -$(BIN_TEST): $(OBJS_TEST) $(OPENSSL_INSTALL)/lib/libssl.a +$(BIN_TEST): $(OPENSSL_INSTALL)/lib/libssl.a $(OBJS_TEST) @echo [LD] $@ @$(CC) $(CFLAGS) -o $(BIN_TEST) $(OBJS_TEST) $(LDFLAGS) -%.o: %.c +%.o: $(OPENSSL_INSTALL)/lib/libssl.a %.c @echo [CC] $@ @$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< From 432d8042d01dfb5603c9f58df7e6f4aeccc63201 Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 17:34:55 +0800 Subject: [PATCH 05/14] Fix bugs in compiling --- Makefile | 2 +- buffer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7469d87..02d53d4 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ $(BIN_TEST): $(OPENSSL_INSTALL)/lib/libssl.a $(OBJS_TEST) @echo [LD] $@ @$(CC) $(CFLAGS) -o $(BIN_TEST) $(OBJS_TEST) $(LDFLAGS) -%.o: $(OPENSSL_INSTALL)/lib/libssl.a %.c +%.o: %.c @echo [CC] $@ @$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< diff --git a/buffer.c b/buffer.c index b650b75..37ee9ad 100644 --- a/buffer.c +++ b/buffer.c @@ -11,7 +11,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include /* For htons/htonl. */ #else #include /* For htons/htonl. */ From fdcbb5532dfde11c71a2301f2cb2211f9fe1843f Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 17:40:10 +0800 Subject: [PATCH 06/14] Use standard macros --- Makefile | 2 +- hash_extender_engine.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 02d53d4..550c680 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ OS := $(shell uname | tr '/[[:lower:]]' '_[[:upper:]]') # These are the specifications of the toolchain CC := gcc CFLAGS := -std=c89 -g -oS -Wall -Werror -Wno-deprecated-declarations -CPPFLAGS := -I$(INCLUDE_OPENSSL) -D_DEFAULT_SOURCE -D$(OS) +CPPFLAGS := -I$(INCLUDE_OPENSSL) -D_DEFAULT_SOURCE LDFLAGS := -L$(LIB_OPENSSL) -lssl -lcrypto BIN_MAIN := hash_extender diff --git a/hash_extender_engine.c b/hash_extender_engine.c index dcc9662..6ea9e86 100644 --- a/hash_extender_engine.c +++ b/hash_extender_engine.c @@ -1,6 +1,6 @@ #include -#ifdef FREEBSD +#ifdef __FREEBSD__ #include #elif defined(__APPLE__) #include @@ -29,9 +29,7 @@ #include "openssl/sha.h" #include "openssl/evp.h" #include "tiger.h" -#ifndef DISABLE_WHIRLPOOL #include "openssl/whrlpool.h" -#endif #include "hash_extender_engine.h" From bd4501f57eed1219b8b6b06a941892f77184a563 Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 18:08:00 +0800 Subject: [PATCH 07/14] Update Makefile and Macros to support MINGW64 --- Makefile | 4 ++-- hash_extender.c | 18 +++++++++++++++++- hash_extender_engine.c | 41 +++++++++++++++++++++++++++++++++++++++-- util.h | 15 +++++++++++++++ 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 550c680..2f2613d 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,9 @@ OS := $(shell uname | tr '/[[:lower:]]' '_[[:upper:]]') # These are the specifications of the toolchain CC := gcc -CFLAGS := -std=c89 -g -oS -Wall -Werror -Wno-deprecated-declarations +CFLAGS := -std=c99 -g -oS -Wall -Werror -Wno-deprecated-declarations CPPFLAGS := -I$(INCLUDE_OPENSSL) -D_DEFAULT_SOURCE -LDFLAGS := -L$(LIB_OPENSSL) -lssl -lcrypto +LDFLAGS := -L$(LIB_OPENSSL) -lssl -lcrypto $(if $(findstring MINGW,$(OS)),-lws2_32) $(if $(findstring MINGW,$(OS)),-lcrypt32) BIN_MAIN := hash_extender BIN_TEST := hash_extender_test diff --git a/hash_extender.c b/hash_extender.c index 89ce959..b9ef94b 100644 --- a/hash_extender.c +++ b/hash_extender.c @@ -1,5 +1,21 @@ #include -#include + +#ifdef _WIN32 + #define err(eval, fmt, ...) \ + do { fprintf(stderr, fmt ": %s\n", ##__VA_ARGS__, strerror(errno)); exit(eval); } while (0) + + #define errx(eval, fmt, ...) \ + do { fprintf(stderr, fmt "\n", ##__VA_ARGS__); exit(eval); } while (0) + + #define warn(fmt, ...) \ + fprintf(stderr, fmt ": %s\n", ##__VA_ARGS__, strerror(errno)) + + #define warnx(fmt, ...) \ + fprintf(stderr, fmt "\n", ##__VA_ARGS__) +#else + #include +#endif + #include #include "buffer.h" diff --git a/hash_extender_engine.c b/hash_extender_engine.c index 6ea9e86..e191945 100644 --- a/hash_extender_engine.c +++ b/hash_extender_engine.c @@ -1,7 +1,11 @@ -#include +#ifdef _WIN32 + #include /* For htons/htonl. */ +#else + #include /* For htons/htonl. */ +#endif #ifdef __FREEBSD__ -#include + #include #elif defined(__APPLE__) #include @@ -19,6 +23,39 @@ #define htole64(x) OSSwapHostToLittleInt64(x) #define be64toh(x) OSSwapBigToHostInt64(x) #define le64toh(x) OSSwapLittleToHostInt64(x) +#elif _WIN32 + // for htons, htonl, etc. + #include + // for _byteswap_uint64 + #include + // for uint64_t + #include + + // 16-bit + #define htobe16(x) htons(x) + #define htole16(x) (x) + #define be16toh(x) ntohs(x) + #define le16toh(x) (x) + + // 32-bit + #define htobe32(x) htonl(x) + #define htole32(x) (x) + #define be32toh(x) ntohl(x) + #define le32toh(x) (x) + + // 64-bit (Windows doesn't define htonll/ntohll, so define manually) + #if defined(_MSC_VER) + #define htobe64(x) _byteswap_uint64(x) + #define be64toh(x) _byteswap_uint64(x) + #else + static uint64_t htobe64(uint64_t x) { + return ((uint64_t)htonl((uint32_t)(x >> 32)) | + ((uint64_t)htonl((uint32_t)(x & 0xFFFFFFFF)) << 32)); + } +#endif +#define htole64(x) (x) +#define le64toh(x) (x) + #else #include #endif diff --git a/util.h b/util.h index dbfae1c..c4d3981 100644 --- a/util.h +++ b/util.h @@ -1,7 +1,22 @@ #ifndef _UTIL_H_ #define _UTIL_H_ +#ifdef _WIN32 +#define err(eval, fmt, ...) \ + do { fprintf(stderr, fmt ": %s\n", ##__VA_ARGS__, strerror(errno)); exit(eval); } while (0) + +#define errx(eval, fmt, ...) \ + do { fprintf(stderr, fmt "\n", ##__VA_ARGS__); exit(eval); } while (0) + +#define warn(fmt, ...) \ + fprintf(stderr, fmt ": %s\n", ##__VA_ARGS__, strerror(errno)) + +#define warnx(fmt, ...) \ + fprintf(stderr, fmt "\n", ##__VA_ARGS__) +#else #include +#endif + #include #include #include From c9ced8d7af74e6735b136ea089ae2f47e20acb61 Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 18:18:37 +0800 Subject: [PATCH 08/14] Add configure command for MINGW64 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2f2613d..81f855c 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ $(OPENSSL_SRC)/Makefile: @echo "Downloading and preparing OpenSSL source..." @git submodule update --init @cd $(OPENSSL_SRC) && \ - ./config --prefix=$(OPENSSL_INSTALL) no-shared no-dso + $(if $(findstring MINGW,$(OS)),/usr/bin/perl Configure mingw64 "--prefix=$(shell cygpath -m $(OPENSSL_INSTALL))" no-shared no-dso,./config --prefix=$(OPENSSL_INSTALL) no-shared no-dso) $(BIN_MAIN): $(OPENSSL_INSTALL)/lib/libssl.a $(OBJS_MAIN) @echo [LD] $@ From 99f1bfe844550c308f53f4d30b584d22272f3ee1 Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 18:20:47 +0800 Subject: [PATCH 09/14] Add .vscode to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7f54189..a215c33 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ hash_extender_test hash_extender +.vscode \ No newline at end of file From 1755403e89cf16335458e85c859ff1551fb6f36c Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 18:25:18 +0800 Subject: [PATCH 10/14] Optimize submodule update to reduce space usage - Use --depth 1 to perform shallow clone, fetching only the latest commit - Use --single-branch to limit submodule cloning to a single branch --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 81f855c..10a4029 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ $(OPENSSL_INSTALL)/lib/libssl.a: $(OPENSSL_SRC)/Makefile $(OPENSSL_SRC)/Makefile: @echo "Downloading and preparing OpenSSL source..." - @git submodule update --init + @git submodule update --init --depth 1 --single-branch @cd $(OPENSSL_SRC) && \ $(if $(findstring MINGW,$(OS)),/usr/bin/perl Configure mingw64 "--prefix=$(shell cygpath -m $(OPENSSL_INSTALL))" no-shared no-dso,./config --prefix=$(OPENSSL_INSTALL) no-shared no-dso) From 10f11dfba51bd9117b0ee1ef0e08cfd97d2b2ea0 Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 18:33:44 +0800 Subject: [PATCH 11/14] Update Makefile to ensure correct order --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 10a4029..df12d14 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ $(BIN_TEST): $(OPENSSL_INSTALL)/lib/libssl.a $(OBJS_TEST) @echo [LD] $@ @$(CC) $(CFLAGS) -o $(BIN_TEST) $(OBJS_TEST) $(LDFLAGS) -%.o: %.c +%.o: %.c | $(OPENSSL_INSTALL)/lib/libssl.a @echo [CC] $@ @$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< From 2713c1c8913c7ba1fa68f21be1db0ed95845b641 Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 18:43:06 +0800 Subject: [PATCH 12/14] Modify install directory to avoid filename conflict in Windows --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index df12d14..c791a72 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ OPENSSL_SRC := $(CURDIR)/openssl OPENSSL_BUILD := $(OPENSSL_SRC)/build -OPENSSL_INSTALL := $(OPENSSL_SRC)/install +OPENSSL_INSTALL := $(OPENSSL_SRC)/install_dir INCLUDE_OPENSSL := $(OPENSSL_INSTALL)/include LIB_OPENSSL := $(OPENSSL_INSTALL)/lib @@ -57,4 +57,5 @@ clean: @rm -f $(BIN_TEST) @echo [RM] OpenSSL build and install @make -C $(OPENSSL_SRC) clean - @rm -rf $(OPENSSL_BUILD) $(OPENSSL_INSTALL) \ No newline at end of file + @rm -rf $(OPENSSL_BUILD) $(OPENSSL_INSTALL) + @rm $(OPENSSL_SRC)/Makefile $(OPENSSL_SRC)/configdata.pm \ No newline at end of file From e0505f6e28d0723d9b0a7ba83e89f271abe28c5d Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 8 Apr 2025 18:44:26 +0800 Subject: [PATCH 13/14] Added '+' before nested `make` to inherit jobserver flags and eliminate warning about missing jobserver and speed up compiling --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c791a72..a98a630 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ all: $(OPENSSL_INSTALL)/lib/libssl.a $(BINS) # OpenSSL build and install $(OPENSSL_INSTALL)/lib/libssl.a: $(OPENSSL_SRC)/Makefile @echo "Building OpenSSL..." - @cd $(OPENSSL_SRC) && \ + +@cd $(OPENSSL_SRC) && \ make && make install_sw $(OPENSSL_SRC)/Makefile: From 4b2e40848163dc956b9dc464807aef5991f5b049 Mon Sep 17 00:00:00 2001 From: Undefined <3171132517@qq.com> Date: Tue, 29 Apr 2025 19:40:15 +0800 Subject: [PATCH 14/14] Add GitHub Actions workflow to build and release Linux and Windows versions --- .github/workflows/release.yml | 74 +++++++++++++++++++++++++++++++++++ Makefile | 4 +- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f811134 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,74 @@ +name: Build and Release + +on: + push: + tags: + - 'v*' + +jobs: + build: + name: Build on ${{ matrix.os }} + runs-on: ubuntu-22.04 + strategy: + matrix: + include: + - os: linux + artifact_name: hash_extender + asset_name: hash_extender-linux-x86_64 + - os: windows + artifact_name: hash_extender.exe + asset_name: hash_extender-windows-x86_64.exe + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 1 + + - name: Setup for Windows cross-compilation + if: matrix.os == 'windows' + run: | + sudo apt-get update + sudo apt-get install -y mingw-w64 gcc-mingw-w64 mingw-w64-tools + + - name: Build for Linux + if: matrix.os == 'linux' + run: | + make + + - name: Build for Windows + if: matrix.os == 'windows' + run: | + make CC=x86_64-w64-mingw32-gcc + + - name: Rename artifact to asset_name + run: mv ${{ matrix.artifact_name }} ${{ matrix.asset_name }} + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.asset_name }} + path: ${{ matrix.asset_name }} + + release: + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + + - name: List downloaded files (debug) + run: ls -R + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + files: | + hash_extender-linux-x86_64/hash_extender-linux-x86_64 + hash_extender-windows-x86_64.exe/hash_extender-windows-x86_64.exe + name: Release ${{ github.ref_name }} + draft: false + prerelease: false + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index a98a630..d6f1cac 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ OS := $(shell uname | tr '/[[:lower:]]' '_[[:upper:]]') CC := gcc CFLAGS := -std=c99 -g -oS -Wall -Werror -Wno-deprecated-declarations CPPFLAGS := -I$(INCLUDE_OPENSSL) -D_DEFAULT_SOURCE -LDFLAGS := -L$(LIB_OPENSSL) -lssl -lcrypto $(if $(findstring MINGW,$(OS)),-lws2_32) $(if $(findstring MINGW,$(OS)),-lcrypt32) +LDFLAGS := -L$(LIB_OPENSSL) -lssl -lcrypto $(if $(findstring mingw,$(shell $(CC) -dumpmachine)),-lws2_32) $(if $(findstring mingw,$(shell $(CC) -dumpmachine)),-lcrypt32) BIN_MAIN := hash_extender BIN_TEST := hash_extender_test @@ -34,7 +34,7 @@ $(OPENSSL_SRC)/Makefile: @echo "Downloading and preparing OpenSSL source..." @git submodule update --init --depth 1 --single-branch @cd $(OPENSSL_SRC) && \ - $(if $(findstring MINGW,$(OS)),/usr/bin/perl Configure mingw64 "--prefix=$(shell cygpath -m $(OPENSSL_INSTALL))" no-shared no-dso,./config --prefix=$(OPENSSL_INSTALL) no-shared no-dso) + $(if $(findstring mingw,$(shell $(CC) -dumpmachine)),/usr/bin/perl Configure $(if $(shell which x86_64-w64-mingw32-gcc),--cross-compile-prefix=x86_64-w64-mingw32-,) mingw64 "--prefix=$(if $(shell which cygpath),$(shell cygpath -m $(OPENSSL_INSTALL)),$(OPENSSL_INSTALL))" no-shared no-dso,./config --prefix=$(OPENSSL_INSTALL) no-shared no-dso) $(BIN_MAIN): $(OPENSSL_INSTALL)/lib/libssl.a $(OBJS_MAIN) @echo [LD] $@