aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-07-23 15:17:35 +0200
committerEgor Tensin <egor@tensin.name>2026-07-23 15:20:39 +0200
commitb0e15c7d9a0cc5ca31809b01254bca5f3a72f047 (patch)
treea4b702ca4a3717827fc3637a0709589cc85eed4d
parentaes/error: add static asserts to prevent missing error messages (diff)
downloadaes-tools-b0e15c7d9a0cc5ca31809b01254bca5f3a72f047.tar.gz
aes-tools-b0e15c7d9a0cc5ca31809b01254bca5f3a72f047.zip
make buildable on Linux
-rw-r--r--.github/workflows/ci.yml15
-rw-r--r--Makefile2
-rw-r--r--aes/include/aes/aes.h13
-rw-r--r--aes/include/aes/round_keys.h23
-rw-r--r--aes/include/aes/workarounds.h9
-rw-r--r--aes/src/c/aes128.c18
-rw-r--r--aes/src/c/aes192.c28
-rw-r--r--aes/src/c/aes256.c28
-rw-r--r--aesxx/CMakeLists.txt5
-rw-r--r--aesxx/utils/CMakeLists.txt12
-rw-r--r--aesxx/utils/test/basic.cmake11
11 files changed, 77 insertions, 87 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8286b30..c8ccabc 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -31,21 +31,19 @@ jobs:
build:
strategy:
matrix:
- toolset: [mingw, vs2022, vs2026]
+ toolset: [gcc, vs2022, vs2026]
platform: [x64, x86]
use_asm: [1, 0]
configuration: [Debug, Release]
include:
- boost-version: 1.81.0
- # MinGW builds are done on Linux, since it's more up-to-date there,
- # and it's much faster.
- - {toolset: mingw, os: ubuntu-latest}
+ - {toolset: gcc, os: ubuntu-latest}
- {toolset: vs2022, os: windows-2022}
# Boost only supports VS 2026 starting with version 1.91, I think?
- {toolset: vs2026, os: windows-2025, boost-version: 1.91.0}
exclude:
- {platform: x64, use_asm: 1}
- - {toolset: mingw, use_asm: 1}
+ - {toolset: gcc, use_asm: 1}
runs-on: '${{ matrix.os }}'
name: |
Build: ${{ matrix.toolset }} / ${{ matrix.platform }} / ${{ matrix.use_asm && '+asm' || '-asm' }} / ${{ matrix.configuration }}
@@ -69,11 +67,11 @@ jobs:
uses: actions/setup-python@v6
with:
python-version: '3.x'
- - name: Set up MinGW
- uses: egor-tensin/setup-mingw@v3
+ - name: Set up GCC
+ uses: egor-tensin/setup-gcc@v2
with:
platform: '${{ matrix.platform }}'
- if: matrix.toolset == 'mingw'
+ if: matrix.toolset == 'gcc'
- name: Build Boost
run: make deps
- name: Build
@@ -86,4 +84,3 @@ jobs:
if-no-files-found: error
- name: Test
run: make test
- if: runner.os == 'Windows'
diff --git a/Makefile b/Makefile
index 6081509..46aa80e 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ boost_dir := $(build_dir)/boost
cmake_dir := $(build_dir)/cmake
install_dir := $(build_dir)/install
-TOOLSET ?= mingw
+TOOLSET ?= auto
PLATFORM ?= auto
CONFIGURATION ?= Debug
BOOST_VERSION ?= 1.72.0
diff --git a/aes/include/aes/aes.h b/aes/include/aes/aes.h
index 8f1e511..3cfaf8a 100644
--- a/aes/include/aes/aes.h
+++ b/aes/include/aes/aes.h
@@ -9,6 +9,7 @@
#include "block.h"
#include "round_keys.h"
+#include "workarounds.h"
#include <assert.h>
@@ -16,13 +17,13 @@
extern "C" {
#endif
-AES_Block __fastcall aes128_encrypt_block_internal(AES_Block, const AES128_RoundKeys*);
-AES_Block __fastcall aes192_encrypt_block_internal(AES_Block, const AES192_RoundKeys*);
-AES_Block __fastcall aes256_encrypt_block_internal(AES_Block, const AES256_RoundKeys*);
+AES_Block AES_ASM_ATTR aes128_encrypt_block_internal(AES_Block, const AES128_RoundKeys*);
+AES_Block AES_ASM_ATTR aes192_encrypt_block_internal(AES_Block, const AES192_RoundKeys*);
+AES_Block AES_ASM_ATTR aes256_encrypt_block_internal(AES_Block, const AES256_RoundKeys*);
-AES_Block __fastcall aes128_decrypt_block_internal(AES_Block, const AES128_RoundKeys*);
-AES_Block __fastcall aes192_decrypt_block_internal(AES_Block, const AES192_RoundKeys*);
-AES_Block __fastcall aes256_decrypt_block_internal(AES_Block, const AES256_RoundKeys*);
+AES_Block AES_ASM_ATTR aes128_decrypt_block_internal(AES_Block, const AES128_RoundKeys*);
+AES_Block AES_ASM_ATTR aes192_decrypt_block_internal(AES_Block, const AES192_RoundKeys*);
+AES_Block AES_ASM_ATTR aes256_decrypt_block_internal(AES_Block, const AES256_RoundKeys*);
static inline AES_Block aes128_encrypt_block(AES_Block plaintext, const AES128_RoundKeys* keys) {
assert(keys);
diff --git a/aes/include/aes/round_keys.h b/aes/include/aes/round_keys.h
index be35f24..4d9af69 100644
--- a/aes/include/aes/round_keys.h
+++ b/aes/include/aes/round_keys.h
@@ -10,6 +10,7 @@
#include "block.h"
#include "error.h"
#include "key.h"
+#include "workarounds.h"
#include <assert.h>
@@ -29,31 +30,25 @@ typedef struct {
AES_Block keys[15];
} AES256_RoundKeys;
-void __fastcall aes128_expand_key_internal(AES_Block key, AES128_RoundKeys* encryption_keys);
+void AES_ASM_ATTR aes128_expand_key_internal(AES_Block key, AES128_RoundKeys* encryption_keys);
-void __fastcall aes192_expand_key_internal(
- AES_Block key_lo,
- AES_Block key_hi,
- AES192_RoundKeys* encryption_keys
-);
+void AES_ASM_ATTR
+aes192_expand_key_internal(AES_Block key_lo, AES_Block key_hi, AES192_RoundKeys* encryption_keys);
-void __fastcall aes256_expand_key_internal(
- AES_Block key_lo,
- AES_Block key_hi,
- AES256_RoundKeys* encryption_keys
-);
+void AES_ASM_ATTR
+aes256_expand_key_internal(AES_Block key_lo, AES_Block key_hi, AES256_RoundKeys* encryption_keys);
-void __fastcall aes128_derive_decryption_keys_internal(
+void AES_ASM_ATTR aes128_derive_decryption_keys_internal(
const AES128_RoundKeys* encryption_keys,
AES128_RoundKeys* decryption_keys
);
-void __fastcall aes192_derive_decryption_keys_internal(
+void AES_ASM_ATTR aes192_derive_decryption_keys_internal(
const AES192_RoundKeys* encryption_keys,
AES192_RoundKeys* decryption_keys
);
-void __fastcall aes256_derive_decryption_keys_internal(
+void AES_ASM_ATTR aes256_derive_decryption_keys_internal(
const AES256_RoundKeys* encryption_keys,
AES256_RoundKeys* decryption_keys
);
diff --git a/aes/include/aes/workarounds.h b/aes/include/aes/workarounds.h
index 4a728c4..084a689 100644
--- a/aes/include/aes/workarounds.h
+++ b/aes/include/aes/workarounds.h
@@ -16,3 +16,12 @@
#endif
#define AES_UNUSED_PARAMETER(...) (void)(__VA_ARGS__)
+
+/* Targetting 32-bit Windows, match the existing ASM implementation's behavior
+ * (__fastcall). Otherwise, do nothing, using the standard calling convention
+ * by default. */
+#if defined(_MSC_VER) && !defined(_WIN64)
+#define AES_ASM_ATTR __fastcall
+#else
+#define AES_ASM_ATTR
+#endif
diff --git a/aes/src/c/aes128.c b/aes/src/c/aes128.c
index 80892ad..379c4cb 100644
--- a/aes/src/c/aes128.c
+++ b/aes/src/c/aes128.c
@@ -10,10 +10,8 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AES_Block __fastcall aes128_encrypt_block_internal(
- AES_Block plaintext,
- const AES128_RoundKeys* encryption_keys
-) {
+AES_Block AES_ASM_ATTR
+aes128_encrypt_block_internal(AES_Block plaintext, const AES128_RoundKeys* encryption_keys) {
plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[2]);
@@ -27,10 +25,8 @@ AES_Block __fastcall aes128_encrypt_block_internal(
return _mm_aesenclast_si128(plaintext, encryption_keys->keys[10]);
}
-AES_Block __fastcall aes128_decrypt_block_internal(
- AES_Block ciphertext,
- const AES128_RoundKeys* decryption_keys
-) {
+AES_Block AES_ASM_ATTR
+aes128_decrypt_block_internal(AES_Block ciphertext, const AES128_RoundKeys* decryption_keys) {
ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[2]);
@@ -44,7 +40,7 @@ AES_Block __fastcall aes128_decrypt_block_internal(
return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[10]);
}
-static AES_Block __fastcall aes128_expand_key_assist(AES_Block prev, AES_Block hwgen) {
+static AES_Block AES_ASM_ATTR aes128_expand_key_assist(AES_Block prev, AES_Block hwgen) {
AES_Block tmp = prev;
tmp = _mm_slli_si128(tmp, 4);
@@ -60,7 +56,7 @@ static AES_Block __fastcall aes128_expand_key_assist(AES_Block prev, AES_Block h
return prev;
}
-void __fastcall aes128_expand_key_internal(AES_Block key, AES128_RoundKeys* encryption_keys) {
+void AES_ASM_ATTR aes128_expand_key_internal(AES_Block key, AES128_RoundKeys* encryption_keys) {
AES_Block prev = encryption_keys->keys[0] = key;
prev = encryption_keys->keys[1] =
aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01));
@@ -84,7 +80,7 @@ void __fastcall aes128_expand_key_internal(AES_Block key, AES128_RoundKeys* encr
aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36));
}
-void __fastcall aes128_derive_decryption_keys_internal(
+void AES_ASM_ATTR aes128_derive_decryption_keys_internal(
const AES128_RoundKeys* encryption_keys,
AES128_RoundKeys* decryption_keys
) {
diff --git a/aes/src/c/aes192.c b/aes/src/c/aes192.c
index d3f83fc..83ee354 100644
--- a/aes/src/c/aes192.c
+++ b/aes/src/c/aes192.c
@@ -10,10 +10,8 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AES_Block __fastcall aes192_encrypt_block_internal(
- AES_Block plaintext,
- const AES192_RoundKeys* encryption_keys
-) {
+AES_Block AES_ASM_ATTR
+aes192_encrypt_block_internal(AES_Block plaintext, const AES192_RoundKeys* encryption_keys) {
plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[2]);
@@ -29,10 +27,8 @@ AES_Block __fastcall aes192_encrypt_block_internal(
return _mm_aesenclast_si128(plaintext, encryption_keys->keys[12]);
}
-AES_Block __fastcall aes192_decrypt_block_internal(
- AES_Block ciphertext,
- const AES192_RoundKeys* decryption_keys
-) {
+AES_Block AES_ASM_ATTR
+aes192_decrypt_block_internal(AES_Block ciphertext, const AES192_RoundKeys* decryption_keys) {
ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[2]);
@@ -48,11 +44,8 @@ AES_Block __fastcall aes192_decrypt_block_internal(
return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[12]);
}
-static void __fastcall aes192_expand_key_assist(
- AES_Block* prev_lo,
- AES_Block* prev_hi,
- AES_Block hwgen
-) {
+static void AES_ASM_ATTR
+aes192_expand_key_assist(AES_Block* prev_lo, AES_Block* prev_hi, AES_Block hwgen) {
AES_Block tmp = *prev_lo;
tmp = _mm_slli_si128(tmp, 4);
@@ -73,11 +66,8 @@ static void __fastcall aes192_expand_key_assist(
*prev_hi = _mm_xor_si128(*prev_hi, tmp);
}
-void __fastcall aes192_expand_key_internal(
- AES_Block key_lo,
- AES_Block key_hi,
- AES192_RoundKeys* encryption_keys
-) {
+void AES_ASM_ATTR
+aes192_expand_key_internal(AES_Block key_lo, AES_Block key_hi, AES192_RoundKeys* encryption_keys) {
encryption_keys->keys[0] = key_lo;
encryption_keys->keys[1] = key_hi;
@@ -125,7 +115,7 @@ void __fastcall aes192_expand_key_internal(
encryption_keys->keys[12] = key_lo;
}
-void __fastcall aes192_derive_decryption_keys_internal(
+void AES_ASM_ATTR aes192_derive_decryption_keys_internal(
const AES192_RoundKeys* encryption_keys,
AES192_RoundKeys* decryption_keys
) {
diff --git a/aes/src/c/aes256.c b/aes/src/c/aes256.c
index 8a86f40..5a57761 100644
--- a/aes/src/c/aes256.c
+++ b/aes/src/c/aes256.c
@@ -10,10 +10,8 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AES_Block __fastcall aes256_encrypt_block_internal(
- AES_Block plaintext,
- const AES256_RoundKeys* encryption_keys
-) {
+AES_Block AES_ASM_ATTR
+aes256_encrypt_block_internal(AES_Block plaintext, const AES256_RoundKeys* encryption_keys) {
plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[2]);
@@ -31,10 +29,8 @@ AES_Block __fastcall aes256_encrypt_block_internal(
return _mm_aesenclast_si128(plaintext, encryption_keys->keys[14]);
}
-AES_Block __fastcall aes256_decrypt_block_internal(
- AES_Block ciphertext,
- const AES256_RoundKeys* decryption_keys
-) {
+AES_Block AES_ASM_ATTR
+aes256_decrypt_block_internal(AES_Block ciphertext, const AES256_RoundKeys* decryption_keys) {
ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[2]);
@@ -52,11 +48,8 @@ AES_Block __fastcall aes256_decrypt_block_internal(
return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[14]);
}
-static AES_Block __fastcall aes256_expand_key_assist(
- AES_Block* prev_lo,
- AES_Block* prev_hi,
- AES_Block hwgen
-) {
+static AES_Block AES_ASM_ATTR
+aes256_expand_key_assist(AES_Block* prev_lo, AES_Block* prev_hi, AES_Block hwgen) {
AES_Block tmp = *prev_lo;
tmp = _mm_slli_si128(tmp, 4);
@@ -75,11 +68,8 @@ static AES_Block __fastcall aes256_expand_key_assist(
return *prev_hi;
}
-void __fastcall aes256_expand_key_internal(
- AES_Block key_lo,
- AES_Block key_hi,
- AES256_RoundKeys* encryption_keys
-) {
+void AES_ASM_ATTR
+aes256_expand_key_internal(AES_Block key_lo, AES_Block key_hi, AES256_RoundKeys* encryption_keys) {
AES_Block prev_lo, prev_hi;
AES_Block hwgen;
@@ -139,7 +129,7 @@ void __fastcall aes256_expand_key_internal(
encryption_keys->keys[14] = aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
}
-void __fastcall aes256_derive_decryption_keys_internal(
+void AES_ASM_ATTR aes256_derive_decryption_keys_internal(
const AES256_RoundKeys* encryption_keys,
AES256_RoundKeys* decryption_keys
) {
diff --git a/aesxx/CMakeLists.txt b/aesxx/CMakeLists.txt
index 704231e..21ed76e 100644
--- a/aesxx/CMakeLists.txt
+++ b/aesxx/CMakeLists.txt
@@ -3,7 +3,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(aesxx INTERFACE)
target_include_directories(aesxx INTERFACE include/)
-target_link_libraries(aesxx INTERFACE aes dbghelp)
+target_link_libraries(aesxx INTERFACE aes)
+if(WIN32)
+ target_link_libraries(aesxx INTERFACE dbghelp)
+endif()
if(MSVC_VERSION EQUAL 1900)
# These annoying dbghelp.h warnings:
diff --git a/aesxx/utils/CMakeLists.txt b/aesxx/utils/CMakeLists.txt
index 44c4acc..8b904a6 100644
--- a/aesxx/utils/CMakeLists.txt
+++ b/aesxx/utils/CMakeLists.txt
@@ -35,13 +35,17 @@ set(file_util_headers
add_util(encrypt_file encrypt_file.cpp ${file_util_headers})
add_util(decrypt_file decrypt_file.cpp ${file_util_headers})
-set(bmp_util_headers ${file_util_headers} helpers/bmp.hpp)
+if(WIN32)
+ set(bmp_util_headers ${file_util_headers} helpers/bmp.hpp)
-add_util(encrypt_bmp encrypt_bmp.cpp ${bmp_util_headers})
-add_util(decrypt_bmp decrypt_bmp.cpp ${bmp_util_headers})
+ add_util(encrypt_bmp encrypt_bmp.cpp ${bmp_util_headers})
+ add_util(decrypt_bmp decrypt_bmp.cpp ${bmp_util_headers})
+endif()
find_package(Python3 REQUIRED COMPONENTS Interpreter)
include(test/basic.cmake)
include(test/block.cmake)
-include(test/bmp.cmake)
+if(WIN32)
+ include(test/bmp.cmake)
+endif()
diff --git a/aesxx/utils/test/basic.cmake b/aesxx/utils/test/basic.cmake
index b8df5a3..cba1180 100644
--- a/aesxx/utils/test/basic.cmake
+++ b/aesxx/utils/test/basic.cmake
@@ -1,11 +1,16 @@
+list(APPEND utils block file)
+if(WIN32)
+ list(APPEND utils bmp)
+endif()
+
foreach(action encrypt decrypt)
- foreach(util block file bmp)
+ foreach(util ${utils})
set(exe "${action}_${util}")
set(tgt "util_${exe}")
add_test(NAME "${tgt}_help" COMMAND Python3::Interpreter
"${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
run
- --pass-regex "usage: ${exe}\\.exe" "set algorithm"
+ --pass-regex "usage: ${exe}" "set algorithm"
--fail-regex "usage error:"
--
"$<TARGET_FILE:${tgt}>" -h
@@ -16,7 +21,7 @@ foreach(action encrypt decrypt)
--exit-code 1
--pass-regex
"usage error: the option '--algorithm' is required"
- "usage: ${exe}\\.exe"
+ "usage: ${exe}"
"set algorithm"
--
"$<TARGET_FILE:${tgt}>"