aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-07-21 15:41:27 +0200
committerEgor Tensin <egor@tensin.name>2026-07-21 15:41:27 +0200
commit2f040d8b25698853f00d5a6ceb99c7a08e376dbf (patch)
tree077952a7378b260598d4279d56a8e5b7579d05af
parentfix function names (diff)
downloadaes-tools-2f040d8b25698853f00d5a6ceb99c7a08e376dbf.tar.gz
aes-tools-2f040d8b25698853f00d5a6ceb99c7a08e376dbf.zip
remove some more duplication and the Doxygen "comments"
-rw-r--r--aes/include/aes/aes.h54
-rw-r--r--aes/include/aes/all.h4
-rw-r--r--aes/include/aes/data.h70
-rw-r--r--aesxx/include/aesxx/aes.hpp12
-rw-r--r--aesxx/include/aesxx/data.hpp4
5 files changed, 14 insertions, 130 deletions
diff --git a/aes/include/aes/aes.h b/aes/include/aes/aes.h
index 73d6618..80f2b6f 100644
--- a/aes/include/aes/aes.h
+++ b/aes/include/aes/aes.h
@@ -62,18 +62,10 @@ typedef struct {
char str[33];
} AES_BlockString;
-typedef AES_BlockString AES128_BlockString;
-typedef AES_BlockString AES192_BlockString;
-typedef AES_BlockString AES256_BlockString;
-
typedef struct {
char str[49];
} AES_BlockMatrixString;
-typedef AES_BlockMatrixString AES128_BlockMatrixString;
-typedef AES_BlockMatrixString AES192_BlockMatrixString;
-typedef AES_BlockMatrixString AES256_BlockMatrixString;
-
AES_StatusCode aes_format_block(AES_BlockString*, const AES_Block*, AES_ErrorDetails*);
AES_StatusCode aes_format_block_as_matrix(
@@ -101,21 +93,15 @@ typedef struct {
} AES256_KeyString;
AES_StatusCode aes128_format_key(AES128_KeyString*, const AES128_Key*, AES_ErrorDetails*);
-
AES_StatusCode aes192_format_key(AES192_KeyString*, const AES192_Key*, AES_ErrorDetails*);
-
AES_StatusCode aes256_format_key(AES256_KeyString*, const AES256_Key*, AES_ErrorDetails*);
AES_StatusCode aes128_print_key(const AES128_Key*, AES_ErrorDetails*);
-
AES_StatusCode aes192_print_key(const AES192_Key*, AES_ErrorDetails*);
-
AES_StatusCode aes256_print_key(const AES256_Key*, AES_ErrorDetails*);
AES_StatusCode aes128_parse_key(AES128_Key* dest, const char* src, AES_ErrorDetails* err_details);
-
AES_StatusCode aes192_parse_key(AES192_Key* dest, const char* src, AES_ErrorDetails* err_details);
-
AES_StatusCode aes256_parse_key(AES256_Key* dest, const char* src, AES_ErrorDetails* err_details);
typedef struct {
@@ -160,15 +146,11 @@ void __fastcall aes256_derive_decryption_keys_(
);
AES_Block __fastcall aes128_encrypt_block_(AES_Block plaintext, const AES128_RoundKeys*);
-
AES_Block __fastcall aes192_encrypt_block_(AES_Block plaintext, const AES192_RoundKeys*);
-
AES_Block __fastcall aes256_encrypt_block_(AES_Block plaintext, const AES256_RoundKeys*);
AES_Block __fastcall aes128_decrypt_block_(AES_Block ciphertext, const AES128_RoundKeys*);
-
AES_Block __fastcall aes192_decrypt_block_(AES_Block ciphertext, const AES192_RoundKeys*);
-
AES_Block __fastcall aes256_decrypt_block_(AES_Block ciphertext, const AES256_RoundKeys*);
AES_ENCRYPT_BLOCK_ECB(128)
@@ -204,12 +186,6 @@ AES_DECRYPT_BLOCK_OFB(256)
AES_ENCRYPT_BLOCK_CTR(256)
AES_DECRYPT_BLOCK_CTR(256)
-/**
- * \brief Expands an AES-128 key into 10 encryption round keys.
- *
- * \param[in] key The AES-128 key.
- * \param[out] encryption_keys The AES-128 encryption round keys. Must not be `NULL`.
- */
static inline void __fastcall aes128_expand_key(
const AES128_Key* key,
AES128_RoundKeys* encryption_keys
@@ -219,12 +195,6 @@ static inline void __fastcall aes128_expand_key(
aes128_expand_key_(key->key, encryption_keys);
}
-/**
- * \brief Derives AES-128 decryption round keys from AES-128 encryption round keys.
- *
- * \param[in] encryption_keys The AES-128 encryption round keys. Must not be `NULL`.
- * \param[out] decryption_keys The AES-128 decryption round keys. Must not be `NULL`.
- */
static inline void __fastcall aes128_derive_decryption_keys(
const AES128_RoundKeys* encryption_keys,
AES128_RoundKeys* decryption_keys
@@ -235,12 +205,6 @@ static inline void __fastcall aes128_derive_decryption_keys(
aes128_derive_decryption_keys_(encryption_keys, decryption_keys);
}
-/**
- * \brief Expands an AES-192 key into 12 encryption round keys.
- *
- * \param[in] key The AES-192 key.
- * \param[out] encryption_keys The AES-192 encryption round keys. Must not be `NULL`.
- */
static inline void __fastcall aes192_expand_key(
const AES192_Key* key,
AES192_RoundKeys* encryption_keys
@@ -251,12 +215,6 @@ static inline void __fastcall aes192_expand_key(
aes192_expand_key_(key->lo, key->hi, encryption_keys);
}
-/**
- * \brief Derives AES-192 decryption round keys from AES-192 encryption round keys.
- *
- * \param[in] encryption_keys The AES-192 encryption round keys. Must not be `NULL`.
- * \param[out] decryption_keys The AES-192 decryption round keys. Must not be `NULL`.
- */
static inline void __fastcall aes192_derive_decryption_keys(
const AES192_RoundKeys* encryption_keys,
AES192_RoundKeys* decryption_keys
@@ -267,12 +225,6 @@ static inline void __fastcall aes192_derive_decryption_keys(
aes192_derive_decryption_keys_(encryption_keys, decryption_keys);
}
-/**
- * \brief Expands an AES-256 key into 14 encryption round keys.
- *
- * \param[in] key The AES-256 key.
- * \param[out] encryption_keys The AES-256 encryption round keys. Must not be `NULL`.
- */
static inline void __fastcall aes256_expand_key(
const AES256_Key* key,
AES256_RoundKeys* encryption_keys
@@ -283,12 +235,6 @@ static inline void __fastcall aes256_expand_key(
aes256_expand_key_(key->lo, key->hi, encryption_keys);
}
-/**
- * \brief Derives AES-256 decryption round keys from AES-256 encryption round keys.
- *
- * \param[in] encryption_keys The AES-256 encryption round keys. Must not be `NULL`.
- * \param[out] decryption_keys The AES-256 decryption round keys. Must not be `NULL`.
- */
static inline void __fastcall aes256_derive_decryption_keys(
const AES256_RoundKeys* encryption_keys,
AES256_RoundKeys* decryption_keys
diff --git a/aes/include/aes/all.h b/aes/include/aes/all.h
index ff27c18..8b60483 100644
--- a/aes/include/aes/all.h
+++ b/aes/include/aes/all.h
@@ -5,10 +5,6 @@
#pragma once
-/**
- * \defgroup aes AES
- */
-
#include "aes.h"
#include "algorithm.h"
#include "box.h"
diff --git a/aes/include/aes/data.h b/aes/include/aes/data.h
index b83cb1d..e06ec33 100644
--- a/aes/include/aes/data.h
+++ b/aes/include/aes/data.h
@@ -12,100 +12,46 @@
extern "C" {
#endif
-/**
- * \brief Represents a 128-bit AES block.
- */
typedef __m128i AES_Block;
-/**
- * \brief Loads a 128-bit block from a memory location.
- *
- * \param[in] src The pointer to a memory location. Must not be `NULL`.
- *
- * \return The loaded 128-bit block.
- */
static inline AES_Block aes_load_block(const void* src) {
return _mm_loadu_si128((AES_Block*)src);
}
-/**
- * \brief Loads a 128-bit block from a 16-byte aligned memory location.
- *
- * \param[in] src The pointer to a 16-byte aligned memory location. Must not be `NULL`.
- *
- * \return The loaded 128-bit block.
- */
static inline AES_Block aes_load_block_aligned(const void* src) {
return _mm_load_si128((AES_Block*)src);
}
-/**
- * \brief Stores a 128-bit block in a memory location.
- *
- * \param[out] dest The pointer to a memory location. Must not be `NULL`.
- *
- * \param[in] block The block to be stored.
- */
static inline void __fastcall aes_store_block(void* dest, AES_Block block) {
_mm_storeu_si128((AES_Block*)dest, block);
}
-/**
- * \brief Stores a 128-bit block in a 16-byte aligned memory location.
- *
- * \param[out] dest The pointer to a 16-byte aligned memory location. Must not be `NULL`.
- *
- * \param[in] block The block to be stored.
- */
static inline void __fastcall aes_store_block_aligned(void* dest, AES_Block block) {
_mm_store_si128((AES_Block*)dest, block);
}
-/**
- * \brief XORs two 128-bit blocks.
- *
- * \param[in] a The first XOR operand.
- * \param[in] b The second XOR operand.
- *
- * \return `a^b`.
- */
static inline AES_Block __fastcall aes_xor_blocks(AES_Block a, AES_Block b) {
return _mm_xor_si128(a, b);
}
/**
- * \brief Builds a 128-bit block from four 4-byte values.
- *
- * Builds a 128-bit block like this:
- *
- * * dest[127:96] = hi3
- * * dest[95:64] = hi2
- * * dest[63:32] = lo1
- * * dest[31:0] = lo0
- *
- * \param[in] hi3 The most significant 4-byte value.
- * \param[in] hi2 The more significant 4-byte value.
- * \param[in] lo1 The less significant 4-byte value.
- * \param[in] lo0 The least significant 4-byte value.
- *
- * \return The built 128-bit block.
+ * hi3 - The most significant 4-byte value.
+ * hi2 - The more significant 4-byte value.
+ * lo1 - The less significant 4-byte value.
+ * lo0 - The least significant 4-byte value.
*/
static inline AES_Block __fastcall aes_make_block(int hi3, int hi2, int lo1, int lo0) {
return _mm_set_epi32(hi3, hi2, lo1, lo0);
}
-static inline AES_Block __fastcall aes_reverse_byte_order_block(AES_Block block) {
+static inline AES_Block __fastcall aes_reverse_byte_order_in_block(AES_Block block) {
return _mm_shuffle_epi8(block, aes_make_block(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f));
}
-static inline AES_Block __fastcall _aes_inc_block(AES_Block x) {
- return _mm_add_epi32(x, aes_make_block(0, 0, 0, 1));
-}
-
static inline AES_Block __fastcall aes_inc_block(AES_Block x) {
- x = aes_reverse_byte_order_block(x);
- x = _aes_inc_block(x);
- x = aes_reverse_byte_order_block(x);
+ x = aes_reverse_byte_order_in_block(x);
+ x = _mm_add_epi32(x, aes_make_block(0, 0, 0, 1));
+ x = aes_reverse_byte_order_in_block(x);
return x;
}
diff --git a/aesxx/include/aesxx/aes.hpp b/aesxx/include/aesxx/aes.hpp
index fb42cdf..38d98fa 100644
--- a/aesxx/include/aesxx/aes.hpp
+++ b/aesxx/include/aesxx/aes.hpp
@@ -39,14 +39,14 @@ inline void from_string<AES_AES128>(aes128::Block& dest, std::string_view src) {
template <>
inline std::string to_string<AES_AES128>(const aes128::Block& src) {
- AES128_BlockString str;
+ AES_BlockString str;
aes_format_block(&str, &src, ErrorDetailsThrowsInDestructor{});
return {str.str};
}
template <>
inline std::string to_matrix_string<AES_AES128>(const aes128::Block& src) {
- AES128_BlockMatrixString str;
+ AES_BlockMatrixString str;
aes_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{});
return {str.str};
}
@@ -109,14 +109,14 @@ inline void from_string<AES_AES192>(aes192::Block& dest, std::string_view src) {
template <>
inline std::string to_string<AES_AES192>(const aes192::Block& src) {
- AES192_BlockString str;
+ AES_BlockString str;
aes_format_block(&str, &src, ErrorDetailsThrowsInDestructor{});
return {str.str};
}
template <>
inline std::string to_matrix_string<AES_AES192>(const aes192::Block& src) {
- AES192_BlockMatrixString str;
+ AES_BlockMatrixString str;
aes_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{});
return {str.str};
}
@@ -179,14 +179,14 @@ inline void from_string<AES_AES256>(aes256::Block& dest, std::string_view src) {
template <>
inline std::string to_string<AES_AES256>(const aes256::Block& src) {
- AES256_BlockString str;
+ AES_BlockString str;
aes_format_block(&str, &src, ErrorDetailsThrowsInDestructor{});
return {str.str};
}
template <>
inline std::string to_matrix_string<AES_AES256>(const aes256::Block& src) {
- AES256_BlockMatrixString str;
+ AES_BlockMatrixString str;
aes_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{});
return {str.str};
}
diff --git a/aesxx/include/aesxx/data.hpp b/aesxx/include/aesxx/data.hpp
index a93a781..8e4691d 100644
--- a/aesxx/include/aesxx/data.hpp
+++ b/aesxx/include/aesxx/data.hpp
@@ -37,10 +37,6 @@ inline Block128 xor_blocks(Block128& a, Block128& b) {
return aes_xor_blocks(a, b);
}
-inline Block128 reverse_byte_order(Block128& block) {
- return aes_reverse_byte_order_block(block);
-}
-
inline Block128 inc_block(Block128& block) {
return aes_inc_block(block);
}