diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-13 19:06:16 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-13 19:06:16 +0200 |
| commit | 1b2505ac21ce8dd09a34aff86455a8a3677094a0 (patch) | |
| tree | 61124c0c28bb884842ac931f11a6c203a034fe7e /aes/include | |
| parent | workflows/ci: add linting for Python test scripts (diff) | |
| download | aes-tools-1b2505ac21ce8dd09a34aff86455a8a3677094a0.tar.gz aes-tools-1b2505ac21ce8dd09a34aff86455a8a3677094a0.zip | |
finally, perfect .clang-format settings?
Diffstat (limited to 'aes/include')
| -rw-r--r-- | aes/include/aes/aes.h | 313 | ||||
| -rw-r--r-- | aes/include/aes/box.h | 102 | ||||
| -rw-r--r-- | aes/include/aes/box_data.h | 62 | ||||
| -rw-r--r-- | aes/include/aes/data.h | 5 | ||||
| -rw-r--r-- | aes/include/aes/mode.h | 107 | ||||
| -rw-r--r-- | aes/include/aes/padding.h | 22 |
6 files changed, 379 insertions, 232 deletions
diff --git a/aes/include/aes/aes.h b/aes/include/aes/aes.h index 2b3e9ff..6c70918 100644 --- a/aes/include/aes/aes.h +++ b/aes/include/aes/aes.h @@ -56,20 +56,30 @@ static __inline AES_AES128_Key aes_AES128_make_key(int hi3, int hi2, int lo1, in return key; } -static __inline AES_AES192_Key aes_AES192_make_key(int hi5, - int hi4, - int lo3, - int lo2, - int lo1, - int lo0) { +static __inline AES_AES192_Key aes_AES192_make_key( + int hi5, + int hi4, + int lo3, + int lo2, + int lo1, + int lo0 +) { AES_AES192_Key key; key.hi = aes_AES_make_block(0, 0, hi5, hi4); key.lo = aes_AES_make_block(lo3, lo2, lo1, lo0); return key; } -static __inline AES_AES256_Key -aes_AES256_make_key(int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) { +static __inline AES_AES256_Key aes_AES256_make_key( + int hi7, + int hi6, + int hi5, + int hi4, + int lo3, + int lo2, + int lo1, + int lo0 +) { AES_AES256_Key key; key.hi = aes_AES_make_block(hi7, hi6, hi5, hi4); key.lo = aes_AES_make_block(lo3, lo2, lo1, lo0); @@ -94,99 +104,133 @@ typedef AES_AES_BlockMatrixString AES_AES256_BlockMatrixString; AES_StatusCode aes_AES_format_block(AES_AES_BlockString*, const AES_AES_Block*, AES_ErrorDetails*); -static __inline AES_StatusCode aes_AES128_format_block(AES_AES128_BlockString* dest, - const AES_AES128_Block* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES128_format_block( + AES_AES128_BlockString* dest, + const AES_AES128_Block* src, + AES_ErrorDetails* err_details +) { return aes_AES_format_block(dest, src, err_details); } -static __inline AES_StatusCode aes_AES192_format_block(AES_AES192_BlockString* dest, - const AES_AES192_Block* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES192_format_block( + AES_AES192_BlockString* dest, + const AES_AES192_Block* src, + AES_ErrorDetails* err_details +) { return aes_AES_format_block(dest, src, err_details); } -static __inline AES_StatusCode aes_AES256_format_block(AES_AES256_BlockString* dest, - const AES_AES256_Block* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES256_format_block( + AES_AES256_BlockString* dest, + const AES_AES256_Block* src, + AES_ErrorDetails* err_details +) { return aes_AES_format_block(dest, src, err_details); } -AES_StatusCode aes_AES_format_block_as_matrix(AES_AES_BlockMatrixString*, - const AES_AES_Block*, - AES_ErrorDetails*); +AES_StatusCode aes_AES_format_block_as_matrix( + AES_AES_BlockMatrixString*, + const AES_AES_Block*, + AES_ErrorDetails* +); -static __inline AES_StatusCode aes_AES128_format_block_as_matrix(AES_AES128_BlockMatrixString* dest, - const AES_AES128_Block* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES128_format_block_as_matrix( + AES_AES128_BlockMatrixString* dest, + const AES_AES128_Block* src, + AES_ErrorDetails* err_details +) { return aes_AES_format_block_as_matrix(dest, src, err_details); } -static __inline AES_StatusCode aes_AES192_format_block_as_matrix(AES_AES192_BlockMatrixString* dest, - const AES_AES192_Block* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES192_format_block_as_matrix( + AES_AES192_BlockMatrixString* dest, + const AES_AES192_Block* src, + AES_ErrorDetails* err_details +) { return aes_AES_format_block_as_matrix(dest, src, err_details); } -static __inline AES_StatusCode aes_AES256_format_block_as_matrix(AES_AES256_BlockMatrixString* dest, - const AES_AES256_Block* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES256_format_block_as_matrix( + AES_AES256_BlockMatrixString* dest, + const AES_AES256_Block* src, + AES_ErrorDetails* err_details +) { return aes_AES_format_block_as_matrix(dest, src, err_details); } AES_StatusCode aes_AES_print_block(const AES_AES_Block*, AES_ErrorDetails*); -static __inline AES_StatusCode aes_AES128_print_block(const AES_AES128_Block* block, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES128_print_block( + const AES_AES128_Block* block, + AES_ErrorDetails* err_details +) { return aes_AES_print_block(block, err_details); } -static __inline AES_StatusCode aes_AES192_print_block(const AES_AES192_Block* block, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES192_print_block( + const AES_AES192_Block* block, + AES_ErrorDetails* err_details +) { return aes_AES_print_block(block, err_details); } -static __inline AES_StatusCode aes_AES256_print_block(const AES_AES256_Block* block, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES256_print_block( + const AES_AES256_Block* block, + AES_ErrorDetails* err_details +) { return aes_AES_print_block(block, err_details); } AES_StatusCode aes_AES_print_block_as_matrix(const AES_AES_Block*, AES_ErrorDetails*); -static __inline AES_StatusCode aes_AES128_print_block_as_matrix(const AES_AES128_Block* block, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES128_print_block_as_matrix( + const AES_AES128_Block* block, + AES_ErrorDetails* err_details +) { return aes_AES_print_block_as_matrix(block, err_details); } -static __inline AES_StatusCode aes_AES192_print_block_as_matrix(const AES_AES192_Block* block, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES192_print_block_as_matrix( + const AES_AES192_Block* block, + AES_ErrorDetails* err_details +) { return aes_AES_print_block_as_matrix(block, err_details); } -static __inline AES_StatusCode aes_AES256_print_block_as_matrix(const AES_AES256_Block* block, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES256_print_block_as_matrix( + const AES_AES256_Block* block, + AES_ErrorDetails* err_details +) { return aes_AES_print_block_as_matrix(block, err_details); } -AES_StatusCode aes_AES_parse_block(AES_AES_Block* dest, - const char* src, - AES_ErrorDetails* err_details); +AES_StatusCode aes_AES_parse_block( + AES_AES_Block* dest, + const char* src, + AES_ErrorDetails* err_details +); -static __inline AES_StatusCode aes_AES128_parse_block(AES_AES128_Block* dest, - const char* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES128_parse_block( + AES_AES128_Block* dest, + const char* src, + AES_ErrorDetails* err_details +) { return aes_AES_parse_block(dest, src, err_details); } -static __inline AES_StatusCode aes_AES192_parse_block(AES_AES192_Block* dest, - const char* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES192_parse_block( + AES_AES192_Block* dest, + const char* src, + AES_ErrorDetails* err_details +) { return aes_AES_parse_block(dest, src, err_details); } -static __inline AES_StatusCode aes_AES256_parse_block(AES_AES256_Block* dest, - const char* src, - AES_ErrorDetails* err_details) { +static __inline AES_StatusCode aes_AES256_parse_block( + AES_AES256_Block* dest, + const char* src, + AES_ErrorDetails* err_details +) { return aes_AES_parse_block(dest, src, err_details); } @@ -202,17 +246,23 @@ typedef struct { char str[65]; } AES_AES256_KeyString; -AES_StatusCode aes_AES128_format_key(AES_AES128_KeyString*, - const AES_AES128_Key*, - AES_ErrorDetails*); +AES_StatusCode aes_AES128_format_key( + AES_AES128_KeyString*, + const AES_AES128_Key*, + AES_ErrorDetails* +); -AES_StatusCode aes_AES192_format_key(AES_AES192_KeyString*, - const AES_AES192_Key*, - AES_ErrorDetails*); +AES_StatusCode aes_AES192_format_key( + AES_AES192_KeyString*, + const AES_AES192_Key*, + AES_ErrorDetails* +); -AES_StatusCode aes_AES256_format_key(AES_AES256_KeyString*, - const AES_AES256_Key*, - AES_ErrorDetails*); +AES_StatusCode aes_AES256_format_key( + AES_AES256_KeyString*, + const AES_AES256_Key*, + AES_ErrorDetails* +); AES_StatusCode aes_AES128_print_key(const AES_AES128_Key*, AES_ErrorDetails*); @@ -220,17 +270,23 @@ AES_StatusCode aes_AES192_print_key(const AES_AES192_Key*, AES_ErrorDetails*); AES_StatusCode aes_AES256_print_key(const AES_AES256_Key*, AES_ErrorDetails*); -AES_StatusCode aes_AES128_parse_key(AES_AES128_Key* dest, - const char* src, - AES_ErrorDetails* err_details); +AES_StatusCode aes_AES128_parse_key( + AES_AES128_Key* dest, + const char* src, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_AES192_parse_key(AES_AES192_Key* dest, - const char* src, - AES_ErrorDetails* err_details); +AES_StatusCode aes_AES192_parse_key( + AES_AES192_Key* dest, + const char* src, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_AES256_parse_key(AES_AES256_Key* dest, - const char* src, - AES_ErrorDetails* err_details); +AES_StatusCode aes_AES256_parse_key( + AES_AES256_Key* dest, + const char* src, + AES_ErrorDetails* err_details +); typedef struct { AES_AES_Block keys[11]; @@ -246,57 +302,85 @@ typedef struct { void __fastcall aes_AES128_expand_key_(AES_AES_Block key, AES_AES128_RoundKeys* encryption_keys); -void __fastcall aes_AES192_expand_key_(AES_AES_Block key_lo, - AES_AES_Block key_hi, - AES_AES192_RoundKeys* encryption_keys); +void __fastcall aes_AES192_expand_key_( + AES_AES_Block key_lo, + AES_AES_Block key_hi, + AES_AES192_RoundKeys* encryption_keys +); -void __fastcall aes_AES256_expand_key_(AES_AES_Block key_lo, - AES_AES_Block key_hi, - AES_AES256_RoundKeys* encryption_keys); +void __fastcall aes_AES256_expand_key_( + AES_AES_Block key_lo, + AES_AES_Block key_hi, + AES_AES256_RoundKeys* encryption_keys +); -void __fastcall aes_AES128_derive_decryption_keys_(const AES_AES128_RoundKeys* encryption_keys, - AES_AES128_RoundKeys* decryption_keys); +void __fastcall aes_AES128_derive_decryption_keys_( + const AES_AES128_RoundKeys* encryption_keys, + AES_AES128_RoundKeys* decryption_keys +); -void __fastcall aes_AES192_derive_decryption_keys_(const AES_AES192_RoundKeys* encryption_keys, - AES_AES192_RoundKeys* decryption_keys); +void __fastcall aes_AES192_derive_decryption_keys_( + const AES_AES192_RoundKeys* encryption_keys, + AES_AES192_RoundKeys* decryption_keys +); -void __fastcall aes_AES256_derive_decryption_keys_(const AES_AES256_RoundKeys* encryption_keys, - AES_AES256_RoundKeys* decryption_keys); +void __fastcall aes_AES256_derive_decryption_keys_( + const AES_AES256_RoundKeys* encryption_keys, + AES_AES256_RoundKeys* decryption_keys +); -AES_AES_Block __fastcall aes_AES128_encrypt_block_(AES_AES_Block plaintext, - const AES_AES128_RoundKeys*); +AES_AES_Block __fastcall aes_AES128_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES128_RoundKeys* +); -AES_AES_Block __fastcall aes_AES192_encrypt_block_(AES_AES_Block plaintext, - const AES_AES192_RoundKeys*); +AES_AES_Block __fastcall aes_AES192_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES192_RoundKeys* +); -AES_AES_Block __fastcall aes_AES256_encrypt_block_(AES_AES_Block plaintext, - const AES_AES256_RoundKeys*); +AES_AES_Block __fastcall aes_AES256_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES256_RoundKeys* +); -AES_AES_Block __fastcall aes_AES128_decrypt_block_(AES_AES_Block ciphertext, - const AES_AES128_RoundKeys*); +AES_AES_Block __fastcall aes_AES128_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES128_RoundKeys* +); -AES_AES_Block __fastcall aes_AES192_decrypt_block_(AES_AES_Block ciphertext, - const AES_AES192_RoundKeys*); +AES_AES_Block __fastcall aes_AES192_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES192_RoundKeys* +); -AES_AES_Block __fastcall aes_AES256_decrypt_block_(AES_AES_Block ciphertext, - const AES_AES256_RoundKeys*); +AES_AES_Block __fastcall aes_AES256_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES256_RoundKeys* +); static __inline AES_AES_Block __fastcall aes_AES_xor_blocks(AES_AES_Block a, AES_AES_Block b) { return aes_xor_block128(a, b); } -static __inline AES_AES_Block __fastcall aes_AES128_xor_blocks(AES_AES128_Block a, - AES_AES128_Block b) { +static __inline AES_AES_Block __fastcall aes_AES128_xor_blocks( + AES_AES128_Block a, + AES_AES128_Block b +) { return aes_AES_xor_blocks(a, b); } -static __inline AES_AES_Block __fastcall aes_AES192_xor_blocks(AES_AES192_Block a, - AES_AES192_Block b) { +static __inline AES_AES_Block __fastcall aes_AES192_xor_blocks( + AES_AES192_Block a, + AES_AES192_Block b +) { return aes_AES_xor_blocks(a, b); } -static __inline AES_AES_Block __fastcall aes_AES256_xor_blocks(AES_AES256_Block a, - AES_AES256_Block b) { +static __inline AES_AES_Block __fastcall aes_AES256_xor_blocks( + AES_AES256_Block a, + AES_AES256_Block b +) { return aes_AES_xor_blocks(a, b); } @@ -357,8 +441,10 @@ AES_DECRYPT_BLOCK_CTR(AES256); * \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 aes_AES128_expand_key(const AES_AES128_Key* key, - AES_AES128_RoundKeys* encryption_keys) { +static __inline void __fastcall aes_AES128_expand_key( + const AES_AES128_Key* key, + AES_AES128_RoundKeys* encryption_keys +) { assert(encryption_keys); aes_AES128_expand_key_(key->key, encryption_keys); @@ -372,7 +458,8 @@ static __inline void __fastcall aes_AES128_expand_key(const AES_AES128_Key* key, */ static __inline void __fastcall aes_AES128_derive_decryption_keys( const AES_AES128_RoundKeys* encryption_keys, - AES_AES128_RoundKeys* decryption_keys) { + AES_AES128_RoundKeys* decryption_keys +) { assert(encryption_keys); assert(decryption_keys); @@ -385,8 +472,10 @@ static __inline void __fastcall aes_AES128_derive_decryption_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 aes_AES192_expand_key(const AES_AES192_Key* key, - AES_AES192_RoundKeys* encryption_keys) { +static __inline void __fastcall aes_AES192_expand_key( + const AES_AES192_Key* key, + AES_AES192_RoundKeys* encryption_keys +) { assert(key); assert(encryption_keys); @@ -401,7 +490,8 @@ static __inline void __fastcall aes_AES192_expand_key(const AES_AES192_Key* key, */ static __inline void __fastcall aes_AES192_derive_decryption_keys( const AES_AES192_RoundKeys* encryption_keys, - AES_AES192_RoundKeys* decryption_keys) { + AES_AES192_RoundKeys* decryption_keys +) { assert(encryption_keys); assert(decryption_keys); @@ -414,8 +504,10 @@ static __inline void __fastcall aes_AES192_derive_decryption_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 aes_AES256_expand_key(const AES_AES256_Key* key, - AES_AES256_RoundKeys* encryption_keys) { +static __inline void __fastcall aes_AES256_expand_key( + const AES_AES256_Key* key, + AES_AES256_RoundKeys* encryption_keys +) { assert(key); assert(encryption_keys); @@ -430,7 +522,8 @@ static __inline void __fastcall aes_AES256_expand_key(const AES_AES256_Key* key, */ static __inline void __fastcall aes_AES256_derive_decryption_keys( const AES_AES256_RoundKeys* encryption_keys, - AES_AES256_RoundKeys* decryption_keys) { + AES_AES256_RoundKeys* decryption_keys +) { assert(encryption_keys); assert(decryption_keys); diff --git a/aes/include/aes/box.h b/aes/include/aes/box.h index 4960fcd..0a43943 100644 --- a/aes/include/aes/box.h +++ b/aes/include/aes/box.h @@ -15,56 +15,74 @@ extern "C" { #endif -AES_StatusCode aes_box_init(AES_Box* box, - AES_Algorithm algorithm, - const AES_BoxKey* box_key, - AES_Mode mode, - const AES_BoxBlock* iv, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_init( + AES_Box* box, + AES_Algorithm algorithm, + const AES_BoxKey* box_key, + AES_Mode mode, + const AES_BoxBlock* iv, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_box_parse_key(AES_BoxKey* dest, - AES_Algorithm algorithm, - const char* src, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_parse_key( + AES_BoxKey* dest, + AES_Algorithm algorithm, + const char* src, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_box_parse_block(AES_BoxBlock* dest, - AES_Algorithm algorithm, - const char* src, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_parse_block( + AES_BoxBlock* dest, + AES_Algorithm algorithm, + const char* src, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_box_format_key(AES_BoxKeyString* dest, - AES_Algorithm algorithm, - const AES_BoxKey* src, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_format_key( + AES_BoxKeyString* dest, + AES_Algorithm algorithm, + const AES_BoxKey* src, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_box_format_block(AES_BoxBlockString* dest, - AES_Algorithm algorithm, - const AES_BoxBlock* src, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_format_block( + AES_BoxBlockString* dest, + AES_Algorithm algorithm, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_box_encrypt_block(AES_Box* box, - const AES_BoxBlock* plaintext, - AES_BoxBlock* ciphertext, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_encrypt_block( + AES_Box* box, + const AES_BoxBlock* plaintext, + AES_BoxBlock* ciphertext, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_box_decrypt_block(AES_Box* box, - const AES_BoxBlock* ciphertext, - AES_BoxBlock* plaintext, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_decrypt_block( + AES_Box* box, + const AES_BoxBlock* ciphertext, + AES_BoxBlock* plaintext, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_box_encrypt_buffer(AES_Box* box, - const void* src, - size_t src_size, - void* dest, - size_t* dest_size, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_encrypt_buffer( + AES_Box* box, + const void* src, + size_t src_size, + void* dest, + size_t* dest_size, + AES_ErrorDetails* err_details +); -AES_StatusCode aes_box_decrypt_buffer(AES_Box* box, - const void* src, - size_t src_size, - void* dest, - size_t* dest_size, - AES_ErrorDetails* err_details); +AES_StatusCode aes_box_decrypt_buffer( + AES_Box* box, + const void* src, + size_t src_size, + void* dest, + size_t* dest_size, + AES_ErrorDetails* err_details +); #ifdef __cplusplus } diff --git a/aes/include/aes/box_data.h b/aes/include/aes/box_data.h index 296afa0..a95a742 100644 --- a/aes/include/aes/box_data.h +++ b/aes/include/aes/box_data.h @@ -47,36 +47,50 @@ typedef union { AES_AES_BlockString aes; } AES_BoxBlockString; -typedef AES_StatusCode (*AES_BoxCalculateRoundKeys)(const AES_BoxKey* params, - AES_BoxEncryptionRoundKeys*, - AES_BoxDecryptionRoundKeys*, - AES_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxCalculateRoundKeys)( + const AES_BoxKey* params, + AES_BoxEncryptionRoundKeys*, + AES_BoxDecryptionRoundKeys*, + AES_ErrorDetails* err_details +); -typedef AES_StatusCode (*AES_BoxParseBlock)(AES_BoxBlock* dest, - const char* src, - AES_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxParseBlock)( + AES_BoxBlock* dest, + const char* src, + AES_ErrorDetails* err_details +); -typedef AES_StatusCode (*AES_BoxParseKey)(AES_BoxKey* dest, - const char* src, - AES_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxParseKey)( + AES_BoxKey* dest, + const char* src, + AES_ErrorDetails* err_details +); -typedef AES_StatusCode (*AES_BoxFormatBlock)(AES_BoxBlockString* dest, - const AES_BoxBlock* src, - AES_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxFormatBlock)( + AES_BoxBlockString* dest, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details +); -typedef AES_StatusCode (*AES_BoxFormatKey)(AES_BoxKeyString* dest, - const AES_BoxKey* src, - AES_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxFormatKey)( + AES_BoxKeyString* dest, + const AES_BoxKey* src, + AES_ErrorDetails* err_details +); -typedef AES_StatusCode (*AES_BoxEncryptBlock)(const AES_BoxBlock* plaintext, - const AES_BoxEncryptionRoundKeys* params, - AES_BoxBlock* ciphertext, - AES_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxEncryptBlock)( + const AES_BoxBlock* plaintext, + const AES_BoxEncryptionRoundKeys* params, + AES_BoxBlock* ciphertext, + AES_ErrorDetails* err_details +); -typedef AES_StatusCode (*AES_BoxDecryptBlock)(const AES_BoxBlock* ciphertext, - const AES_BoxDecryptionRoundKeys* params, - AES_BoxBlock* plaintext, - AES_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxDecryptBlock)( + const AES_BoxBlock* ciphertext, + const AES_BoxDecryptionRoundKeys* params, + AES_BoxBlock* plaintext, + AES_ErrorDetails* err_details +); typedef AES_StatusCode (*AES_BoxXorBlock)(AES_BoxBlock*, const AES_BoxBlock*, AES_ErrorDetails*); diff --git a/aes/include/aes/data.h b/aes/include/aes/data.h index 71b339a..7665c82 100644 --- a/aes/include/aes/data.h +++ b/aes/include/aes/data.h @@ -95,8 +95,9 @@ static __inline AES_Block128 __fastcall aes_make_block128(int hi3, int hi2, int } static __inline AES_Block128 __fastcall aes_reverse_byte_order_block128(AES_Block128 block) { - return _mm_shuffle_epi8(block, - aes_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f)); + return _mm_shuffle_epi8( + block, aes_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f) + ); } static __inline AES_Block128 __fastcall aes_inc_block128(AES_Block128 x) { diff --git a/aes/include/aes/mode.h b/aes/include/aes/mode.h index 4c5e931..49b6b4f 100644 --- a/aes/include/aes/mode.h +++ b/aes/include/aes/mode.h @@ -19,33 +19,37 @@ typedef enum { AES_CTR, } AES_Mode; -#define AES_ENCRYPT_BLOCK_ECB(prefix) \ - static __inline AES_##prefix##_Block __fastcall aes_##prefix##_encrypt_block_ECB( \ - AES_##prefix##_Block plaintext, const AES_##prefix##_RoundKeys* encryption_keys) { \ - assert(encryption_keys); \ - \ - return aes_##prefix##_encrypt_block_(plaintext, encryption_keys); \ +#define AES_ENCRYPT_BLOCK_ECB(prefix) \ + static __inline AES_##prefix##_Block __fastcall aes_##prefix##_encrypt_block_ECB( \ + AES_##prefix##_Block plaintext, const AES_##prefix##_RoundKeys* encryption_keys \ + ) { \ + assert(encryption_keys); \ + \ + return aes_##prefix##_encrypt_block_(plaintext, encryption_keys); \ } -#define AES_DECRYPT_BLOCK_ECB(prefix) \ - static __inline AES_##prefix##_Block __fastcall aes_##prefix##_decrypt_block_ECB( \ - AES_##prefix##_Block ciphertext, const AES_##prefix##_RoundKeys* decryption_keys) { \ - assert(decryption_keys); \ - \ - return aes_##prefix##_decrypt_block_(ciphertext, decryption_keys); \ +#define AES_DECRYPT_BLOCK_ECB(prefix) \ + static __inline AES_##prefix##_Block __fastcall aes_##prefix##_decrypt_block_ECB( \ + AES_##prefix##_Block ciphertext, const AES_##prefix##_RoundKeys* decryption_keys \ + ) { \ + assert(decryption_keys); \ + \ + return aes_##prefix##_decrypt_block_(ciphertext, decryption_keys); \ } -#define AES_ENCRYPT_BLOCK_CBC(prefix) \ - static __inline AES_##prefix##_Block __fastcall aes_##prefix##_encrypt_block_CBC( \ - AES_##prefix##_Block plaintext, \ - const AES_##prefix##_RoundKeys* encryption_keys, \ - AES_##prefix##_Block init_vector, \ - AES_##prefix##_Block* next_init_vector) { \ - assert(encryption_keys); \ - assert(next_init_vector); \ - \ - return *next_init_vector = aes_##prefix##_encrypt_block_( \ - aes_##prefix##_xor_blocks(plaintext, init_vector), encryption_keys); \ +#define AES_ENCRYPT_BLOCK_CBC(prefix) \ + static __inline AES_##prefix##_Block __fastcall aes_##prefix##_encrypt_block_CBC( \ + AES_##prefix##_Block plaintext, \ + const AES_##prefix##_RoundKeys* encryption_keys, \ + AES_##prefix##_Block init_vector, \ + AES_##prefix##_Block* next_init_vector \ + ) { \ + assert(encryption_keys); \ + assert(next_init_vector); \ + \ + return *next_init_vector = aes_##prefix##_encrypt_block_( \ + aes_##prefix##_xor_blocks(plaintext, init_vector), encryption_keys \ + ); \ } #define AES_DECRYPT_BLOCK_CBC(prefix) \ @@ -53,27 +57,31 @@ typedef enum { AES_##prefix##_Block ciphertext, \ const AES_##prefix##_RoundKeys* decryption_keys, \ AES_##prefix##_Block init_vector, \ - AES_##prefix##_Block* next_init_vector) { \ + AES_##prefix##_Block* next_init_vector \ + ) { \ assert(decryption_keys); \ assert(next_init_vector); \ \ AES_##prefix##_Block plaintext = aes_##prefix##_xor_blocks( \ - aes_##prefix##_decrypt_block_(ciphertext, decryption_keys), init_vector); \ + aes_##prefix##_decrypt_block_(ciphertext, decryption_keys), init_vector \ + ); \ *next_init_vector = ciphertext; \ return plaintext; \ } -#define AES_ENCRYPT_BLOCK_CFB(prefix) \ - static __inline AES_##prefix##_Block __fastcall aes_##prefix##_encrypt_block_CFB( \ - AES_##prefix##_Block plaintext, \ - const AES_##prefix##_RoundKeys* encryption_keys, \ - AES_##prefix##_Block init_vector, \ - AES_##prefix##_Block* next_init_vector) { \ - assert(encryption_keys); \ - assert(next_init_vector); \ - \ - return *next_init_vector = aes_##prefix##_xor_blocks( \ - aes_##prefix##_encrypt_block_(init_vector, encryption_keys), plaintext); \ +#define AES_ENCRYPT_BLOCK_CFB(prefix) \ + static __inline AES_##prefix##_Block __fastcall aes_##prefix##_encrypt_block_CFB( \ + AES_##prefix##_Block plaintext, \ + const AES_##prefix##_RoundKeys* encryption_keys, \ + AES_##prefix##_Block init_vector, \ + AES_##prefix##_Block* next_init_vector \ + ) { \ + assert(encryption_keys); \ + assert(next_init_vector); \ + \ + return *next_init_vector = aes_##prefix##_xor_blocks( \ + aes_##prefix##_encrypt_block_(init_vector, encryption_keys), plaintext \ + ); \ } #define AES_DECRYPT_BLOCK_CFB(prefix) \ @@ -81,12 +89,14 @@ typedef enum { AES_##prefix##_Block ciphertext, \ const AES_##prefix##_RoundKeys* encryption_keys, \ AES_##prefix##_Block init_vector, \ - AES_##prefix##_Block* next_init_vector) { \ + AES_##prefix##_Block* next_init_vector \ + ) { \ assert(encryption_keys); \ assert(next_init_vector); \ \ AES_##prefix##_Block plaintext = aes_##prefix##_xor_blocks( \ - aes_##prefix##_encrypt_block_(init_vector, encryption_keys), ciphertext); \ + aes_##prefix##_encrypt_block_(init_vector, encryption_keys), ciphertext \ + ); \ *next_init_vector = ciphertext; \ return plaintext; \ } @@ -96,7 +106,8 @@ typedef enum { AES_##prefix##_Block plaintext, \ const AES_##prefix##_RoundKeys* encryption_keys, \ AES_##prefix##_Block init_vector, \ - AES_##prefix##_Block* next_init_vector) { \ + AES_##prefix##_Block* next_init_vector \ + ) { \ assert(encryption_keys); \ assert(next_init_vector); \ \ @@ -110,12 +121,14 @@ typedef enum { AES_##prefix##_Block ciphertext, \ const AES_##prefix##_RoundKeys* encryption_keys, \ AES_##prefix##_Block init_vector, \ - AES_##prefix##_Block* next_init_vector) { \ + AES_##prefix##_Block* next_init_vector \ + ) { \ assert(encryption_keys); \ assert(next_init_vector); \ \ return aes_##prefix##_encrypt_block_OFB( \ - ciphertext, encryption_keys, init_vector, next_init_vector); \ + ciphertext, encryption_keys, init_vector, next_init_vector \ + ); \ } #define AES_ENCRYPT_BLOCK_CTR(prefix) \ @@ -123,12 +136,14 @@ typedef enum { AES_##prefix##_Block plaintext, \ const AES_##prefix##_RoundKeys* encryption_keys, \ AES_##prefix##_Block init_vector, \ - AES_##prefix##_Block* next_init_vector) { \ + AES_##prefix##_Block* next_init_vector \ + ) { \ assert(encryption_keys); \ assert(next_init_vector); \ \ AES_##prefix##_Block ciphertext = aes_##prefix##_xor_blocks( \ - plaintext, aes_##prefix##_encrypt_block_(init_vector, encryption_keys)); \ + plaintext, aes_##prefix##_encrypt_block_(init_vector, encryption_keys) \ + ); \ *next_init_vector = aes_##prefix##_inc_block(init_vector); \ return ciphertext; \ } @@ -138,12 +153,14 @@ typedef enum { AES_##prefix##_Block ciphertext, \ const AES_##prefix##_RoundKeys* encryption_keys, \ AES_##prefix##_Block init_vector, \ - AES_##prefix##_Block* next_init_vector) { \ + AES_##prefix##_Block* next_init_vector \ + ) { \ assert(encryption_keys); \ assert(next_init_vector); \ \ return aes_##prefix##_encrypt_block_CTR( \ - ciphertext, encryption_keys, init_vector, next_init_vector); \ + ciphertext, encryption_keys, init_vector, next_init_vector \ + ); \ } #ifdef __cplusplus diff --git a/aes/include/aes/padding.h b/aes/include/aes/padding.h index 727196b..92989a3 100644 --- a/aes/include/aes/padding.h +++ b/aes/include/aes/padding.h @@ -17,16 +17,20 @@ typedef enum { AES_PADDING_PKCS7, } AES_PaddingMethod; -AES_StatusCode aes_extract_padding_size(AES_PaddingMethod, - const void* src, - size_t src_size, - size_t* padding_size, - AES_ErrorDetails*); +AES_StatusCode aes_extract_padding_size( + AES_PaddingMethod, + const void* src, + size_t src_size, + size_t* padding_size, + AES_ErrorDetails* +); -AES_StatusCode aes_fill_with_padding(AES_PaddingMethod, - void* dest, - size_t padding_size, - AES_ErrorDetails*); +AES_StatusCode aes_fill_with_padding( + AES_PaddingMethod, + void* dest, + size_t padding_size, + AES_ErrorDetails* +); #ifdef __cplusplus } |
