diff options
| author | Egor Tensin <egor@tensin.name> | 2026-07-23 15:17:35 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-07-23 15:20:39 +0200 |
| commit | b0e15c7d9a0cc5ca31809b01254bca5f3a72f047 (patch) | |
| tree | a4b702ca4a3717827fc3637a0709589cc85eed4d /aes | |
| parent | aes/error: add static asserts to prevent missing error messages (diff) | |
| download | aes-tools-b0e15c7d9a0cc5ca31809b01254bca5f3a72f047.tar.gz aes-tools-b0e15c7d9a0cc5ca31809b01254bca5f3a72f047.zip | |
make buildable on Linux
Diffstat (limited to 'aes')
| -rw-r--r-- | aes/include/aes/aes.h | 13 | ||||
| -rw-r--r-- | aes/include/aes/round_keys.h | 23 | ||||
| -rw-r--r-- | aes/include/aes/workarounds.h | 9 | ||||
| -rw-r--r-- | aes/src/c/aes128.c | 18 | ||||
| -rw-r--r-- | aes/src/c/aes192.c | 28 | ||||
| -rw-r--r-- | aes/src/c/aes256.c | 28 |
6 files changed, 50 insertions, 69 deletions
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 ) { |
