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 | |
| 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?
31 files changed, 1195 insertions, 744 deletions
diff --git a/.clang-format b/.clang-format index 78868be..6414559 100644 --- a/.clang-format +++ b/.clang-format @@ -5,14 +5,17 @@ BasedOnStyle: Chromium IndentWidth: 4 AccessModifierOffset: -4 +AlignAfterOpenBracket: BlockIndent AlignConsecutiveMacros: AcrossComments AllowShortFunctionsOnASingleLine: Empty BinPackArguments: false +BinPackParameters: OnePerLine BreakConstructorInitializers: BeforeComma BreakInheritanceList: BeforeComma BreakStringLiterals: false ColumnLimit: 100 IncludeBlocks: Regroup +PenaltyReturnTypeOnItsOwnLine: 1000 SpacesBeforeTrailingComments: 1 WrapNamespaceBodyWithEmptyLines: Always 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 } diff --git a/aes/src/aes.c b/aes/src/aes.c index a409b5e..95b532d 100644 --- a/aes/src/aes.c +++ b/aes/src/aes.c @@ -11,9 +11,11 @@ #include <stdio.h> #include <string.h> -AES_StatusCode aes_AES_format_block(AES_AES_BlockString* str, - const AES_AES_Block* block, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_AES_format_block( + AES_AES_BlockString* str, + const AES_AES_Block* block, + AES_ErrorDetails* err_details +) { assert(str); assert(block); @@ -34,9 +36,11 @@ AES_StatusCode aes_AES_format_block(AES_AES_BlockString* str, return AES_SUCCESS; } -AES_StatusCode aes_AES_format_block_as_matrix(AES_AES_BlockMatrixString* str, - const AES_AES_Block* block, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_AES_format_block_as_matrix( + AES_AES_BlockMatrixString* str, + const AES_AES_Block* block, + AES_ErrorDetails* err_details +) { assert(str); assert(block); @@ -76,8 +80,10 @@ AES_StatusCode aes_AES_print_block(const AES_AES_Block* block, AES_ErrorDetails* return ec; } -AES_StatusCode aes_AES_print_block_as_matrix(const AES_AES_Block* block, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_AES_print_block_as_matrix( + const AES_AES_Block* block, + AES_ErrorDetails* err_details +) { assert(block); if (block == NULL) @@ -93,9 +99,11 @@ AES_StatusCode aes_AES_print_block_as_matrix(const AES_AES_Block* block, return ec; } -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 +) { assert(dest); assert(src); @@ -121,9 +129,11 @@ AES_StatusCode aes_AES_parse_block(AES_AES_Block* dest, return AES_SUCCESS; } -AES_StatusCode aes_AES128_format_key(AES_AES128_KeyString* str, - const AES_AES128_Key* key, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_AES128_format_key( + AES_AES128_KeyString* str, + const AES_AES128_Key* key, + AES_ErrorDetails* err_details +) { assert(str); assert(key); @@ -144,9 +154,11 @@ AES_StatusCode aes_AES128_format_key(AES_AES128_KeyString* str, return AES_SUCCESS; } -AES_StatusCode aes_AES192_format_key(AES_AES192_KeyString* str, - const AES_AES192_Key* key, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_AES192_format_key( + AES_AES192_KeyString* str, + const AES_AES192_Key* key, + AES_ErrorDetails* err_details +) { assert(str); assert(key); @@ -177,9 +189,11 @@ AES_StatusCode aes_AES192_format_key(AES_AES192_KeyString* str, return AES_SUCCESS; } -AES_StatusCode aes_AES256_format_key(AES_AES256_KeyString* str, - const AES_AES256_Key* key, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_AES256_format_key( + AES_AES256_KeyString* str, + const AES_AES256_Key* key, + AES_ErrorDetails* err_details +) { assert(str); assert(key); @@ -246,15 +260,19 @@ AES_StatusCode aes_AES256_print_key(const AES_AES256_Key* key, AES_ErrorDetails* return ec; } -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 +) { return aes_AES_parse_block(&dest->key, src, 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 +) { assert(dest); assert(src); @@ -299,9 +317,11 @@ AES_StatusCode aes_AES192_parse_key(AES_AES192_Key* dest, return AES_SUCCESS; } -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 +) { assert(dest); assert(src); diff --git a/aes/src/box.c b/aes/src/box.c index 48457c9..8d2c202 100644 --- a/aes/src/box.c +++ b/aes/src/box.c @@ -16,18 +16,22 @@ static const AES_BoxAlgorithmInterface* aes_box_algorithms[] = { &aes_box_algorithm_aes256, }; -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 status = AES_SUCCESS; box->algorithm = aes_box_algorithms[algorithm]; - if (aes_is_error(status = box->algorithm->calc_round_keys( - box_key, &box->encryption_keys, &box->decryption_keys, err_details))) + status = box->algorithm->calc_round_keys( + box_key, &box->encryption_keys, &box->decryption_keys, err_details + ); + if (aes_is_error(status)) return status; box->mode = mode; @@ -37,89 +41,107 @@ AES_StatusCode aes_box_init(AES_Box* box, return status; } -static AES_StatusCode aes_box_encrypt_block_ecb(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_block_ecb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { return box->algorithm->encrypt_block(input, &box->encryption_keys, output, err_details); } -static AES_StatusCode aes_box_encrypt_block_cbc(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_block_cbc( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; AES_BoxBlock xored_input = *input; - if (aes_is_error(status = box->algorithm->xor_block(&xored_input, &box->iv, err_details))) + status = box->algorithm->xor_block(&xored_input, &box->iv, err_details); + if (aes_is_error(status)) return status; - if (aes_is_error(status = box->algorithm->encrypt_block( - &xored_input, &box->encryption_keys, output, err_details))) + status = + box->algorithm->encrypt_block(&xored_input, &box->encryption_keys, output, err_details); + if (aes_is_error(status)) return status; box->iv = *output; return status; } -static AES_StatusCode aes_box_encrypt_block_cfb(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_block_cfb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; - if (aes_is_error(status = box->algorithm->encrypt_block( - &box->iv, &box->encryption_keys, output, err_details))) + status = box->algorithm->encrypt_block(&box->iv, &box->encryption_keys, output, err_details); + if (aes_is_error(status)) return status; - if (aes_is_error(status = box->algorithm->xor_block(output, input, err_details))) + status = box->algorithm->xor_block(output, input, err_details); + if (aes_is_error(status)) return status; box->iv = *output; return status; } -static AES_StatusCode aes_box_encrypt_block_ofb(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_block_ofb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; - if (aes_is_error(status = box->algorithm->encrypt_block( - &box->iv, &box->encryption_keys, &box->iv, err_details))) + status = box->algorithm->encrypt_block(&box->iv, &box->encryption_keys, &box->iv, err_details); + if (aes_is_error(status)) return status; *output = box->iv; - if (aes_is_error(status = box->algorithm->xor_block(output, input, err_details))) + status = box->algorithm->xor_block(output, input, err_details); + if (aes_is_error(status)) return status; return status; } -static AES_StatusCode aes_box_encrypt_block_ctr(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_block_ctr( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; - if (aes_is_error(status = box->algorithm->encrypt_block( - &box->iv, &box->encryption_keys, output, err_details))) + status = box->algorithm->encrypt_block(&box->iv, &box->encryption_keys, output, err_details); + if (aes_is_error(status)) return status; - if (aes_is_error(status = box->algorithm->xor_block(output, input, err_details))) + status = box->algorithm->xor_block(output, input, err_details); + if (aes_is_error(status)) return status; - if (aes_is_error(status = box->algorithm->inc_block(&box->iv, err_details))) + status = box->algorithm->inc_block(&box->iv, err_details); + if (aes_is_error(status)) return status; return status; } -typedef AES_StatusCode (*AES_BoxEncryptBlockInMode)(AES_Box*, - const AES_BoxBlock*, - AES_BoxBlock*, - AES_ErrorDetails*); +typedef AES_StatusCode (*AES_BoxEncryptBlockInMode)( + AES_Box*, + const AES_BoxBlock*, + AES_BoxBlock*, + AES_ErrorDetails* +); static AES_BoxEncryptBlockInMode aes_box_encrypt_block_in_mode[] = { &aes_box_encrypt_block_ecb, @@ -129,48 +151,58 @@ static AES_BoxEncryptBlockInMode aes_box_encrypt_block_in_mode[] = { &aes_box_encrypt_block_ctr, }; -AES_StatusCode aes_box_encrypt_block(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_box_encrypt_block( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { return aes_box_encrypt_block_in_mode[box->mode](box, input, output, err_details); } -static AES_StatusCode aes_box_decrypt_block_ecb(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_decrypt_block_ecb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { return box->algorithm->decrypt_block(input, &box->decryption_keys, output, err_details); } -static AES_StatusCode aes_box_decrypt_block_cbc(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_decrypt_block_cbc( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; - if (aes_is_error(status = box->algorithm->decrypt_block( - input, &box->decryption_keys, output, err_details))) + status = box->algorithm->decrypt_block(input, &box->decryption_keys, output, err_details); + if (aes_is_error(status)) return status; - if (aes_is_error(status = box->algorithm->xor_block(output, &box->iv, err_details))) + status = box->algorithm->xor_block(output, &box->iv, err_details); + if (aes_is_error(status)) return status; box->iv = *input; return status; } -static AES_StatusCode aes_box_decrypt_block_cfb(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_decrypt_block_cfb( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; - if (aes_is_error(status = box->algorithm->encrypt_block( - &box->iv, &box->encryption_keys, output, err_details))) + status = box->algorithm->encrypt_block(&box->iv, &box->encryption_keys, output, err_details); + if (aes_is_error(status)) return status; - if (aes_is_error(status = box->algorithm->xor_block(output, input, err_details))) + status = box->algorithm->xor_block(output, input, err_details); + if (aes_is_error(status)) return status; box->iv = *input; @@ -187,18 +219,22 @@ static AES_BoxDecryptBlockInMode aes_box_decrypt_block_in_mode[] = { &aes_box_encrypt_block_ctr, }; -AES_StatusCode aes_box_decrypt_block(AES_Box* box, - const AES_BoxBlock* input, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_box_decrypt_block( + AES_Box* box, + const AES_BoxBlock* input, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { return aes_box_decrypt_block_in_mode[box->mode](box, input, output, err_details); } -static AES_StatusCode aes_box_get_encrypted_buffer_size(AES_Box* box, - size_t src_size, - size_t* dest_size, - size_t* padding_size, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_get_encrypted_buffer_size( + AES_Box* box, + size_t src_size, + size_t* dest_size, + size_t* padding_size, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; switch (box->mode) { @@ -206,7 +242,8 @@ static AES_StatusCode aes_box_get_encrypted_buffer_size(AES_Box* box, case AES_CBC: { size_t block_size; - if (aes_is_error(status = box->algorithm->get_block_size(&block_size, err_details))) + status = box->algorithm->get_block_size(&block_size, err_details); + if (aes_is_error(status)) return status; *padding_size = block_size - src_size % block_size; @@ -226,23 +263,27 @@ static AES_StatusCode aes_box_get_encrypted_buffer_size(AES_Box* box, } } -static AES_StatusCode aes_box_encrypt_buffer_block(AES_Box* box, - const void* src, - void* dest, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_buffer_block( + AES_Box* box, + const void* src, + void* dest, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; - AES_BoxBlock plaintext; - if (aes_is_error(status = box->algorithm->load_block(&plaintext, src, err_details))) + status = box->algorithm->load_block(&plaintext, src, err_details); + if (aes_is_error(status)) return status; AES_BoxBlock ciphertext; - if (aes_is_error(status = aes_box_encrypt_block(box, &plaintext, &ciphertext, err_details))) + status = aes_box_encrypt_block(box, &plaintext, &ciphertext, err_details); + if (aes_is_error(status)) return status; - if (aes_is_error(status = box->algorithm->store_block(dest, &ciphertext, err_details))) + status = box->algorithm->store_block(dest, &ciphertext, err_details); + if (aes_is_error(status)) return status; return status; @@ -254,12 +295,14 @@ static AES_StatusCode aes_box_encrypt_buffer_partial_block_with_padding( size_t src_size, void* dest, size_t padding_size, - AES_ErrorDetails* err_details) { + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; size_t block_size; - if (aes_is_error(status = box->algorithm->get_block_size(&block_size, err_details))) + status = box->algorithm->get_block_size(&block_size, err_details); + if (aes_is_error(status)) return status; void* plaintext_buf = malloc(block_size); @@ -269,12 +312,14 @@ static AES_StatusCode aes_box_encrypt_buffer_partial_block_with_padding( memcpy(plaintext_buf, src, src_size); - if (aes_is_error( - status = aes_fill_with_padding( - AES_PADDING_PKCS7, (char*)plaintext_buf + src_size, padding_size, err_details))) + status = aes_fill_with_padding( + AES_PADDING_PKCS7, (char*)plaintext_buf + src_size, padding_size, err_details + ); + if (aes_is_error(status)) goto FREE_PLAINTEXT_BUF; - if (aes_is_error(status = aes_box_encrypt_buffer_block(box, plaintext_buf, dest, err_details))) + status = aes_box_encrypt_buffer_block(box, plaintext_buf, dest, err_details); + if (aes_is_error(status)) goto FREE_PLAINTEXT_BUF; FREE_PLAINTEXT_BUF: @@ -283,11 +328,13 @@ FREE_PLAINTEXT_BUF: return status; } -static AES_StatusCode aes_box_encrypt_buffer_partial_block(AES_Box* box, - const void* src, - size_t src_size, - void* dest, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_buffer_partial_block( + AES_Box* box, + const void* src, + size_t src_size, + void* dest, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; if (src_size == 0) @@ -295,7 +342,8 @@ static AES_StatusCode aes_box_encrypt_buffer_partial_block(AES_Box* box, size_t block_size; - if (aes_is_error(status = box->algorithm->get_block_size(&block_size, err_details))) + status = box->algorithm->get_block_size(&block_size, err_details); + if (aes_is_error(status)) return status; void* plaintext_buf = malloc(block_size); @@ -313,8 +361,8 @@ static AES_StatusCode aes_box_encrypt_buffer_partial_block(AES_Box* box, goto FREE_PLAINTEXT_BUF; } - if (aes_is_error( - status = aes_box_encrypt_buffer_block(box, plaintext_buf, ciphertext_buf, err_details))) + status = aes_box_encrypt_buffer_block(box, plaintext_buf, ciphertext_buf, err_details); + if (aes_is_error(status)) goto FREE_CIPHERTEXT_BUF; memcpy(dest, ciphertext_buf, src_size); @@ -328,12 +376,14 @@ FREE_PLAINTEXT_BUF: return status; } -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 status = AES_SUCCESS; if (box == NULL) @@ -343,8 +393,9 @@ AES_StatusCode aes_box_encrypt_buffer(AES_Box* box, size_t padding_size = 0; - if (aes_is_error(status = aes_box_get_encrypted_buffer_size( - box, src_size, dest_size, &padding_size, err_details))) + status = + aes_box_get_encrypted_buffer_size(box, src_size, dest_size, &padding_size, err_details); + if (aes_is_error(status)) return status; if (dest == NULL) @@ -354,13 +405,15 @@ AES_StatusCode aes_box_encrypt_buffer(AES_Box* box, size_t block_size; - if (aes_is_error(status = box->algorithm->get_block_size(&block_size, err_details))) + status = box->algorithm->get_block_size(&block_size, err_details); + if (aes_is_error(status)) return status; const size_t src_len = src_size / block_size; for (size_t i = 0; i < src_len; ++i) { - if (aes_is_error(status = aes_box_encrypt_buffer_block(box, src, dest, err_details))) + status = aes_box_encrypt_buffer_block(box, src, dest, err_details); + if (aes_is_error(status)) return status; src = (char*)src + block_size; @@ -369,17 +422,21 @@ AES_StatusCode aes_box_encrypt_buffer(AES_Box* box, if (padding_size == 0) return aes_box_encrypt_buffer_partial_block( - box, src, src_size % block_size, dest, err_details); + box, src, src_size % block_size, dest, err_details + ); else return aes_box_encrypt_buffer_partial_block_with_padding( - box, src, src_size % block_size, dest, padding_size, err_details); + box, src, src_size % block_size, dest, padding_size, err_details + ); } -static AES_StatusCode aes_box_get_decrypted_buffer_size(AES_Box* box, - size_t src_size, - size_t* dest_size, - size_t* max_padding_size, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_get_decrypted_buffer_size( + AES_Box* box, + size_t src_size, + size_t* dest_size, + size_t* max_padding_size, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; switch (box->mode) { @@ -387,7 +444,8 @@ static AES_StatusCode aes_box_get_decrypted_buffer_size(AES_Box* box, case AES_CBC: { size_t block_size; - if (aes_is_error(status = box->algorithm->get_block_size(&block_size, err_details))) + status = box->algorithm->get_block_size(&block_size, err_details); + if (aes_is_error(status)) return status; if (src_size == 0 || src_size % block_size != 0) @@ -410,33 +468,39 @@ static AES_StatusCode aes_box_get_decrypted_buffer_size(AES_Box* box, } } -static AES_StatusCode aes_box_decrypt_buffer_block(AES_Box* box, - const void* src, - void* dest, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_decrypt_buffer_block( + AES_Box* box, + const void* src, + void* dest, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; - AES_BoxBlock ciphertext; - if (aes_is_error(status = box->algorithm->load_block(&ciphertext, src, err_details))) + status = box->algorithm->load_block(&ciphertext, src, err_details); + if (aes_is_error(status)) return status; AES_BoxBlock plaintext; - if (aes_is_error(status = aes_box_decrypt_block(box, &ciphertext, &plaintext, err_details))) + status = aes_box_decrypt_block(box, &ciphertext, &plaintext, err_details); + if (aes_is_error(status)) return status; - if (aes_is_error(status = box->algorithm->store_block(dest, &plaintext, err_details))) + status = box->algorithm->store_block(dest, &plaintext, err_details); + if (aes_is_error(status)) return status; return status; } -static AES_StatusCode aes_box_decrypt_buffer_partial_block(AES_Box* box, - const void* src, - size_t src_size, - void* dest, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_decrypt_buffer_partial_block( + AES_Box* box, + const void* src, + size_t src_size, + void* dest, + AES_ErrorDetails* err_details +) { AES_StatusCode status = AES_SUCCESS; if (src_size == 0) @@ -444,7 +508,8 @@ static AES_StatusCode aes_box_decrypt_buffer_partial_block(AES_Box* box, size_t block_size; - if (aes_is_error(status = box->algorithm->get_block_size(&block_size, err_details))) + status = box->algorithm->get_block_size(&block_size, err_details); + if (aes_is_error(status)) return status; void* ciphertext_buf = malloc(block_size); @@ -462,8 +527,8 @@ static AES_StatusCode aes_box_decrypt_buffer_partial_block(AES_Box* box, goto FREE_CIPHERTEXT_BUF; } - if (aes_is_error( - status = aes_box_decrypt_buffer_block(box, ciphertext_buf, plaintext_buf, err_details))) + status = aes_box_decrypt_buffer_block(box, ciphertext_buf, plaintext_buf, err_details); + if (aes_is_error(status)) goto FREE_PLAINTEXT_BUF; memcpy(dest, plaintext_buf, src_size); @@ -477,12 +542,14 @@ FREE_CIPHERTEXT_BUF: return status; } -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 +) { if (box == NULL) return aes_error_null_argument(err_details, "box"); if (dest_size == NULL) @@ -491,8 +558,9 @@ AES_StatusCode aes_box_decrypt_buffer(AES_Box* box, AES_StatusCode status = AES_SUCCESS; size_t max_padding_size = 0; - if (aes_is_error(status = aes_box_get_decrypted_buffer_size( - box, src_size, dest_size, &max_padding_size, err_details))) + status = + aes_box_get_decrypted_buffer_size(box, src_size, dest_size, &max_padding_size, err_details); + if (aes_is_error(status)) return status; if (dest == NULL) @@ -502,13 +570,15 @@ AES_StatusCode aes_box_decrypt_buffer(AES_Box* box, size_t block_size; - if (aes_is_error(status = box->algorithm->get_block_size(&block_size, err_details))) + status = box->algorithm->get_block_size(&block_size, err_details); + if (aes_is_error(status)) return status; const size_t src_len = src_size / block_size; for (size_t i = 0; i < src_len; ++i) { - if (aes_is_error(status = aes_box_decrypt_buffer_block(box, src, dest, err_details))) + status = aes_box_decrypt_buffer_block(box, src, dest, err_details); + if (aes_is_error(status)) return status; src = (char*)src + block_size; @@ -517,15 +587,15 @@ AES_StatusCode aes_box_decrypt_buffer(AES_Box* box, if (max_padding_size == 0) { return aes_box_decrypt_buffer_partial_block( - box, src, src_size % block_size, dest, err_details); + box, src, src_size % block_size, dest, err_details + ); } else { size_t padding_size; - if (aes_is_error(status = aes_extract_padding_size(AES_PADDING_PKCS7, - (char*)dest - block_size, - block_size, - &padding_size, - err_details))) + status = aes_extract_padding_size( + AES_PADDING_PKCS7, (char*)dest - block_size, block_size, &padding_size, err_details + ); + if (aes_is_error(status)) return status; *dest_size -= padding_size; @@ -533,10 +603,12 @@ AES_StatusCode aes_box_decrypt_buffer(AES_Box* box, } } -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 +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); if (src == NULL) @@ -545,10 +617,12 @@ AES_StatusCode aes_box_parse_block(AES_BoxBlock* dest, return aes_box_algorithms[algorithm]->parse_block(dest, src, 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 +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); if (src == NULL) @@ -557,10 +631,12 @@ AES_StatusCode aes_box_parse_key(AES_BoxKey* dest, return aes_box_algorithms[algorithm]->parse_key(dest, src, 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 +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); if (src == NULL) @@ -569,10 +645,12 @@ AES_StatusCode aes_box_format_block(AES_BoxBlockString* dest, return aes_box_algorithms[algorithm]->format_block(dest, src, 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 +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); if (src == NULL) diff --git a/aes/src/box_aes.c b/aes/src/box_aes.c index 7e78a2c..4a91e97 100644 --- a/aes/src/box_aes.c +++ b/aes/src/box_aes.c @@ -10,80 +10,101 @@ #include <stdlib.h> #include <string.h> -static AES_StatusCode aes_box_derive_params_aes128(const AES_BoxKey* box_key, - AES_BoxEncryptionRoundKeys* encryption_keys, - AES_BoxDecryptionRoundKeys* decryption_keys, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_derive_params_aes128( + const AES_BoxKey* box_key, + AES_BoxEncryptionRoundKeys* encryption_keys, + AES_BoxDecryptionRoundKeys* decryption_keys, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); aes_AES128_expand_key_(box_key->aes128_key.key, &encryption_keys->aes128_encryption_keys); - aes_AES128_derive_decryption_keys_(&encryption_keys->aes128_encryption_keys, - &decryption_keys->aes128_decryption_keys); + aes_AES128_derive_decryption_keys_( + &encryption_keys->aes128_encryption_keys, &decryption_keys->aes128_decryption_keys + ); return AES_SUCCESS; } -static AES_StatusCode aes_box_derive_params_aes192(const AES_BoxKey* box_key, - AES_BoxEncryptionRoundKeys* encryption_keys, - AES_BoxDecryptionRoundKeys* decryption_keys, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_derive_params_aes192( + const AES_BoxKey* box_key, + AES_BoxEncryptionRoundKeys* encryption_keys, + AES_BoxDecryptionRoundKeys* decryption_keys, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); aes_AES192_expand_key_( - box_key->aes192_key.lo, box_key->aes192_key.hi, &encryption_keys->aes192_encryption_keys); - aes_AES192_derive_decryption_keys_(&encryption_keys->aes192_encryption_keys, - &decryption_keys->aes192_decryption_keys); + box_key->aes192_key.lo, box_key->aes192_key.hi, &encryption_keys->aes192_encryption_keys + ); + aes_AES192_derive_decryption_keys_( + &encryption_keys->aes192_encryption_keys, &decryption_keys->aes192_decryption_keys + ); return AES_SUCCESS; } -static AES_StatusCode aes_box_derive_params_aes256(const AES_BoxKey* box_key, - AES_BoxEncryptionRoundKeys* encryption_keys, - AES_BoxDecryptionRoundKeys* decryption_keys, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_derive_params_aes256( + const AES_BoxKey* box_key, + AES_BoxEncryptionRoundKeys* encryption_keys, + AES_BoxDecryptionRoundKeys* decryption_keys, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); aes_AES256_expand_key_( - box_key->aes256_key.lo, box_key->aes256_key.hi, &encryption_keys->aes256_encryption_keys); - aes_AES256_derive_decryption_keys_(&encryption_keys->aes256_encryption_keys, - &decryption_keys->aes256_decryption_keys); + box_key->aes256_key.lo, box_key->aes256_key.hi, &encryption_keys->aes256_encryption_keys + ); + aes_AES256_derive_decryption_keys_( + &encryption_keys->aes256_encryption_keys, &decryption_keys->aes256_decryption_keys + ); return AES_SUCCESS; } -static AES_StatusCode aes_box_parse_block_aes(AES_BoxBlock* dest, - const char* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_parse_block_aes( + AES_BoxBlock* dest, + const char* src, + AES_ErrorDetails* err_details +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); return aes_AES_parse_block(&dest->aes_block, src, err_details); } -static AES_StatusCode aes_box_parse_key_aes128(AES_BoxKey* dest, - const char* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_parse_key_aes128( + AES_BoxKey* dest, + const char* src, + AES_ErrorDetails* err_details +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); return aes_AES128_parse_key(&dest->aes128_key, src, err_details); } -static AES_StatusCode aes_box_parse_key_aes192(AES_BoxKey* dest, - const char* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_parse_key_aes192( + AES_BoxKey* dest, + const char* src, + AES_ErrorDetails* err_details +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); return aes_AES192_parse_key(&dest->aes192_key, src, err_details); } -static AES_StatusCode aes_box_parse_key_aes256(AES_BoxKey* dest, - const char* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_parse_key_aes256( + AES_BoxKey* dest, + const char* src, + AES_ErrorDetails* err_details +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); return aes_AES256_parse_key(&dest->aes256_key, src, err_details); } -static AES_StatusCode aes_box_format_block_aes(AES_BoxBlockString* dest, - const AES_BoxBlock* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_format_block_aes( + AES_BoxBlockString* dest, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); if (src == NULL) @@ -92,9 +113,11 @@ static AES_StatusCode aes_box_format_block_aes(AES_BoxBlockString* dest, return aes_AES128_format_block(&dest->aes, &src->aes_block, err_details); } -static AES_StatusCode aes_box_format_key_aes128(AES_BoxKeyString* dest, - const AES_BoxKey* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_format_key_aes128( + AES_BoxKeyString* dest, + const AES_BoxKey* src, + AES_ErrorDetails* err_details +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); if (src == NULL) @@ -103,9 +126,11 @@ static AES_StatusCode aes_box_format_key_aes128(AES_BoxKeyString* dest, return aes_AES128_format_key(&dest->aes128, &src->aes128_key, err_details); } -static AES_StatusCode aes_box_format_key_aes192(AES_BoxKeyString* dest, - const AES_BoxKey* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_format_key_aes192( + AES_BoxKeyString* dest, + const AES_BoxKey* src, + AES_ErrorDetails* err_details +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); if (src == NULL) @@ -114,9 +139,11 @@ static AES_StatusCode aes_box_format_key_aes192(AES_BoxKeyString* dest, return aes_AES192_format_key(&dest->aes192, &src->aes192_key, err_details); } -static AES_StatusCode aes_box_format_key_aes256(AES_BoxKeyString* dest, - const AES_BoxKey* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_format_key_aes256( + AES_BoxKeyString* dest, + const AES_BoxKey* src, + AES_ErrorDetails* err_details +) { if (dest == NULL) return aes_error_null_argument(err_details, "dest"); if (src == NULL) @@ -125,9 +152,11 @@ static AES_StatusCode aes_box_format_key_aes256(AES_BoxKeyString* dest, return aes_AES256_format_key(&dest->aes256, &src->aes256_key, err_details); } -static AES_StatusCode aes_box_xor_block_aes(AES_BoxBlock* dest, - const AES_BoxBlock* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_xor_block_aes( + AES_BoxBlock* dest, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); dest->aes_block = aes_AES_xor_blocks(dest->aes_block, src->aes_block); return AES_SUCCESS; @@ -139,83 +168,101 @@ static AES_StatusCode aes_box_inc_block_aes(AES_BoxBlock* ctr, AES_ErrorDetails* return AES_SUCCESS; } -static AES_StatusCode aes_box_get_block_size_aes(size_t* block_size, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_get_block_size_aes( + size_t* block_size, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); *block_size = 16; return AES_SUCCESS; } -static AES_StatusCode aes_box_store_block_aes(void* dest, - const AES_BoxBlock* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_store_block_aes( + void* dest, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); aes_store_block128(dest, src->aes_block); return AES_SUCCESS; } -static AES_StatusCode aes_box_load_block_aes(AES_BoxBlock* dest, - const void* src, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_load_block_aes( + AES_BoxBlock* dest, + const void* src, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); dest->aes_block = aes_load_block128(src); return AES_SUCCESS; } -static AES_StatusCode aes_box_encrypt_block_aes128(const AES_BoxBlock* input, - const AES_BoxEncryptionRoundKeys* params, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_block_aes128( + const AES_BoxBlock* input, + const AES_BoxEncryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); output->aes_block = aes_AES128_encrypt_block_(input->aes_block, ¶ms->aes128_encryption_keys); return AES_SUCCESS; } -static AES_StatusCode aes_box_decrypt_block_aes128(const AES_BoxBlock* input, - const AES_BoxDecryptionRoundKeys* params, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_decrypt_block_aes128( + const AES_BoxBlock* input, + const AES_BoxDecryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); output->aes_block = aes_AES128_decrypt_block_(input->aes_block, ¶ms->aes128_decryption_keys); return AES_SUCCESS; } -static AES_StatusCode aes_box_encrypt_block_aes192(const AES_BoxBlock* input, - const AES_BoxEncryptionRoundKeys* params, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_block_aes192( + const AES_BoxBlock* input, + const AES_BoxEncryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); output->aes_block = aes_AES192_encrypt_block_(input->aes_block, ¶ms->aes192_encryption_keys); return AES_SUCCESS; } -static AES_StatusCode aes_box_decrypt_block_aes192(const AES_BoxBlock* input, - const AES_BoxDecryptionRoundKeys* params, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_decrypt_block_aes192( + const AES_BoxBlock* input, + const AES_BoxDecryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); output->aes_block = aes_AES192_decrypt_block_(input->aes_block, ¶ms->aes192_decryption_keys); return AES_SUCCESS; } -static AES_StatusCode aes_box_encrypt_block_aes256(const AES_BoxBlock* input, - const AES_BoxEncryptionRoundKeys* params, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_encrypt_block_aes256( + const AES_BoxBlock* input, + const AES_BoxEncryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); output->aes_block = aes_AES256_encrypt_block_(input->aes_block, ¶ms->aes256_encryption_keys); return AES_SUCCESS; } -static AES_StatusCode aes_box_decrypt_block_aes256(const AES_BoxBlock* input, - const AES_BoxDecryptionRoundKeys* params, - AES_BoxBlock* output, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_box_decrypt_block_aes256( + const AES_BoxBlock* input, + const AES_BoxDecryptionRoundKeys* params, + AES_BoxBlock* output, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); output->aes_block = aes_AES256_decrypt_block_(input->aes_block, ¶ms->aes256_decryption_keys); diff --git a/aes/src/c/aes128.c b/aes/src/c/aes128.c index 6b3a96a..d7b7243 100644 --- a/aes/src/c/aes128.c +++ b/aes/src/c/aes128.c @@ -10,8 +10,10 @@ #include <emmintrin.h> #include <wmmintrin.h> -AES_AES_Block __fastcall aes_AES128_encrypt_block_(AES_AES_Block plaintext, - const AES_AES128_RoundKeys* encryption_keys) { +AES_AES_Block __fastcall aes_AES128_encrypt_block_( + AES_AES_Block plaintext, + const AES_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]); @@ -25,8 +27,10 @@ AES_AES_Block __fastcall aes_AES128_encrypt_block_(AES_AES_Block plaintext, return _mm_aesenclast_si128(plaintext, encryption_keys->keys[10]); } -AES_AES_Block __fastcall aes_AES128_decrypt_block_(AES_AES_Block ciphertext, - const AES_AES128_RoundKeys* decryption_keys) { +AES_AES_Block __fastcall aes_AES128_decrypt_block_( + AES_AES_Block ciphertext, + const AES_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]); @@ -40,8 +44,10 @@ AES_AES_Block __fastcall aes_AES128_decrypt_block_(AES_AES_Block ciphertext, return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[10]); } -static AES_AES_Block __fastcall aes_aes128_expand_key_assist(AES_AES_Block prev, - AES_AES_Block hwgen) { +static AES_AES_Block __fastcall aes_aes128_expand_key_assist( + AES_AES_Block prev, + AES_AES_Block hwgen +) { AES_AES_Block tmp = prev; tmp = _mm_slli_si128(tmp, 4); @@ -81,8 +87,10 @@ void __fastcall aes_AES128_expand_key_(AES_AES_Block key, AES_AES128_RoundKeys* aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36)); } -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 +) { decryption_keys->keys[0] = encryption_keys->keys[10]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[9]); decryption_keys->keys[2] = _mm_aesimc_si128(encryption_keys->keys[8]); diff --git a/aes/src/c/aes192.c b/aes/src/c/aes192.c index 01f6698..901b548 100644 --- a/aes/src/c/aes192.c +++ b/aes/src/c/aes192.c @@ -10,8 +10,10 @@ #include <emmintrin.h> #include <wmmintrin.h> -AES_AES_Block __fastcall aes_AES192_encrypt_block_(AES_AES_Block plaintext, - const AES_AES192_RoundKeys* encryption_keys) { +AES_AES_Block __fastcall aes_AES192_encrypt_block_( + AES_AES_Block plaintext, + const AES_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]); @@ -27,8 +29,10 @@ AES_AES_Block __fastcall aes_AES192_encrypt_block_(AES_AES_Block plaintext, return _mm_aesenclast_si128(plaintext, encryption_keys->keys[12]); } -AES_AES_Block __fastcall aes_AES192_decrypt_block_(AES_AES_Block ciphertext, - const AES_AES192_RoundKeys* decryption_keys) { +AES_AES_Block __fastcall aes_AES192_decrypt_block_( + AES_AES_Block ciphertext, + const AES_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]); @@ -44,9 +48,11 @@ AES_AES_Block __fastcall aes_AES192_decrypt_block_(AES_AES_Block ciphertext, return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[12]); } -static void __fastcall aes_aes192_expand_key_assist(AES_AES_Block* prev_lo, - AES_AES_Block* prev_hi, - AES_AES_Block hwgen) { +static void __fastcall aes_aes192_expand_key_assist( + AES_AES_Block* prev_lo, + AES_AES_Block* prev_hi, + AES_AES_Block hwgen +) { AES_AES_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); @@ -67,15 +73,18 @@ static void __fastcall aes_aes192_expand_key_assist(AES_AES_Block* prev_lo, *prev_hi = _mm_xor_si128(*prev_hi, tmp); } -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 +) { encryption_keys->keys[0] = key_lo; encryption_keys->keys[1] = key_hi; aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x01)); encryption_keys->keys[1] = _mm_castpd_si128( - _mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[1]), _mm_castsi128_pd(key_lo), 0)); + _mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[1]), _mm_castsi128_pd(key_lo), 0) + ); encryption_keys->keys[2] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); @@ -85,7 +94,8 @@ void __fastcall aes_AES192_expand_key_(AES_AES_Block key_lo, aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x04)); encryption_keys->keys[4] = _mm_castpd_si128( - _mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[4]), _mm_castsi128_pd(key_lo), 0)); + _mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[4]), _mm_castsi128_pd(key_lo), 0) + ); encryption_keys->keys[5] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); @@ -95,7 +105,8 @@ void __fastcall aes_AES192_expand_key_(AES_AES_Block key_lo, aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x10)); encryption_keys->keys[7] = _mm_castpd_si128( - _mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[7]), _mm_castsi128_pd(key_lo), 0)); + _mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[7]), _mm_castsi128_pd(key_lo), 0) + ); encryption_keys->keys[8] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); @@ -105,7 +116,8 @@ void __fastcall aes_AES192_expand_key_(AES_AES_Block key_lo, aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x40)); encryption_keys->keys[10] = _mm_castpd_si128( - _mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[10]), _mm_castsi128_pd(key_lo), 0)); + _mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[10]), _mm_castsi128_pd(key_lo), 0) + ); encryption_keys->keys[11] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1)); @@ -113,8 +125,10 @@ void __fastcall aes_AES192_expand_key_(AES_AES_Block key_lo, encryption_keys->keys[12] = key_lo; } -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 +) { decryption_keys->keys[0] = encryption_keys->keys[12]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[11]); decryption_keys->keys[2] = _mm_aesimc_si128(encryption_keys->keys[10]); diff --git a/aes/src/c/aes256.c b/aes/src/c/aes256.c index ea64f0f..5bce5b5 100644 --- a/aes/src/c/aes256.c +++ b/aes/src/c/aes256.c @@ -10,8 +10,10 @@ #include <emmintrin.h> #include <wmmintrin.h> -AES_AES_Block __fastcall aes_AES256_encrypt_block_(AES_AES_Block plaintext, - const AES_AES256_RoundKeys* encryption_keys) { +AES_AES_Block __fastcall aes_AES256_encrypt_block_( + AES_AES_Block plaintext, + const AES_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]); @@ -29,8 +31,10 @@ AES_AES_Block __fastcall aes_AES256_encrypt_block_(AES_AES_Block plaintext, return _mm_aesenclast_si128(plaintext, encryption_keys->keys[14]); } -AES_AES_Block __fastcall aes_AES256_decrypt_block_(AES_AES_Block ciphertext, - const AES_AES256_RoundKeys* decryption_keys) { +AES_AES_Block __fastcall aes_AES256_decrypt_block_( + AES_AES_Block ciphertext, + const AES_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]); @@ -48,9 +52,11 @@ AES_AES_Block __fastcall aes_AES256_decrypt_block_(AES_AES_Block ciphertext, return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[14]); } -static AES_AES_Block __fastcall aes_aes256_expand_key_assist(AES_AES_Block* prev_lo, - AES_AES_Block* prev_hi, - AES_AES_Block hwgen) { +static AES_AES_Block __fastcall aes_aes256_expand_key_assist( + AES_AES_Block* prev_lo, + AES_AES_Block* prev_hi, + AES_AES_Block hwgen +) { AES_AES_Block tmp = *prev_lo; tmp = _mm_slli_si128(tmp, 4); @@ -69,9 +75,11 @@ static AES_AES_Block __fastcall aes_aes256_expand_key_assist(AES_AES_Block* prev return *prev_hi; } -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 +) { AES_AES_Block prev_lo, prev_hi; AES_AES_Block hwgen; @@ -131,8 +139,10 @@ void __fastcall aes_AES256_expand_key_(AES_AES_Block key_lo, encryption_keys->keys[14] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen); } -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 +) { decryption_keys->keys[0] = encryption_keys->keys[14]; decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[13]); decryption_keys->keys[2] = _mm_aesimc_si128(encryption_keys->keys[12]); diff --git a/aes/src/error.c b/aes/src/error.c index e498458..7c6594f 100644 --- a/aes/src/error.c +++ b/aes/src/error.c @@ -61,9 +61,11 @@ const char* aes_strerror(AES_StatusCode ec) { return aes_strerror_messages[ec]; } -static size_t aes_format_error_strerror(const AES_ErrorDetails* err_details, - char* dest, - size_t dest_size) { +static size_t aes_format_error_strerror( + const AES_ErrorDetails* err_details, + char* dest, + size_t dest_size +) { const AES_StatusCode ec = aes_get_error_code(err_details); const char* const msg = aes_strerror(ec); @@ -74,9 +76,11 @@ static size_t aes_format_error_strerror(const AES_ErrorDetails* err_details, return strlen(dest); } -static size_t aes_format_null_argument_error(const AES_ErrorDetails* err_details, - char* dest, - size_t dest_size) { +static size_t aes_format_null_argument_error( + const AES_ErrorDetails* err_details, + char* dest, + size_t dest_size +) { static const char* const fmt = "Invalid argument value NULL for parameter '%s'"; const char* const param_name = err_details->params.null_arg.param_name; @@ -87,9 +91,11 @@ static size_t aes_format_null_argument_error(const AES_ErrorDetails* err_details return strlen(dest); } -static size_t aes_format_parse_error(const AES_ErrorDetails* err_details, - char* dest, - size_t dest_size) { +static size_t aes_format_parse_error( + const AES_ErrorDetails* err_details, + char* dest, + size_t dest_size +) { static const char* const fmt = "Couldn't parse '%s' (possibly not complete input) as %s"; const char* const src = err_details->params.parse_error.src; const char* const what = err_details->params.parse_error.what; @@ -101,9 +107,11 @@ static size_t aes_format_parse_error(const AES_ErrorDetails* err_details, return strlen(dest); } -static size_t aes_format_not_implemented_error(const AES_ErrorDetails* err_details, - char* dest, - size_t dest_size) { +static size_t aes_format_not_implemented_error( + const AES_ErrorDetails* err_details, + char* dest, + size_t dest_size +) { static const char* const fmt = "Not implemented: %s"; const char* const src = err_details->params.not_implemented.what; @@ -163,9 +171,11 @@ AES_StatusCode aes_error_null_argument(AES_ErrorDetails* err_details, const char AES_StatusCode status = aes_make_error(err_details, AES_NULL_ARGUMENT_ERROR); if (err_details != NULL) - aes_fill_string(err_details->params.null_arg.param_name, - sizeof(err_details->params.null_arg.param_name), - param_name); + aes_fill_string( + err_details->params.null_arg.param_name, + sizeof(err_details->params.null_arg.param_name), + param_name + ); return status; } @@ -175,10 +185,11 @@ AES_StatusCode aes_error_parse(AES_ErrorDetails* err_details, const char* src, c if (err_details != NULL) { aes_fill_string( - err_details->params.parse_error.src, sizeof(err_details->params.parse_error.src), src); - aes_fill_string(err_details->params.parse_error.what, - sizeof(err_details->params.parse_error.what), - what); + err_details->params.parse_error.src, sizeof(err_details->params.parse_error.src), src + ); + aes_fill_string( + err_details->params.parse_error.what, sizeof(err_details->params.parse_error.what), what + ); } return status; @@ -192,9 +203,11 @@ AES_StatusCode aes_error_not_implemented(AES_ErrorDetails* err_details, const ch AES_StatusCode status = aes_make_error(err_details, AES_NOT_IMPLEMENTED_ERROR); if (err_details != NULL) - aes_fill_string(err_details->params.not_implemented.what, - sizeof(err_details->params.not_implemented.what), - what); + aes_fill_string( + err_details->params.not_implemented.what, + sizeof(err_details->params.not_implemented.what), + what + ); return status; } diff --git a/aes/src/padding.c b/aes/src/padding.c index 5647ea6..54c6c9c 100644 --- a/aes/src/padding.c +++ b/aes/src/padding.c @@ -11,10 +11,12 @@ #include <stdlib.h> #include <string.h> -static AES_StatusCode aes_extract_padding_size_pkcs7(const void* src, - size_t src_size, - size_t* padding_size, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_extract_padding_size_pkcs7( + const void* src, + size_t src_size, + size_t* padding_size, + AES_ErrorDetails* err_details +) { const unsigned char* cursor = (const unsigned char*)src + src_size - 1; *padding_size = *cursor; @@ -25,11 +27,13 @@ static AES_StatusCode aes_extract_padding_size_pkcs7(const void* src, return AES_SUCCESS; } -AES_StatusCode aes_extract_padding_size(AES_PaddingMethod method, - const void* src, - size_t src_size, - size_t* padding_size, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_extract_padding_size( + AES_PaddingMethod method, + const void* src, + size_t src_size, + size_t* padding_size, + AES_ErrorDetails* err_details +) { assert(src); assert(padding_size); @@ -47,18 +51,22 @@ AES_StatusCode aes_extract_padding_size(AES_PaddingMethod method, } } -static AES_StatusCode aes_fill_with_padding_pkcs7(void* dest, - size_t padding_size, - AES_ErrorDetails* err_details) { +static AES_StatusCode aes_fill_with_padding_pkcs7( + void* dest, + size_t padding_size, + AES_ErrorDetails* err_details +) { AES_UNUSED_PARAMETER(err_details); memset(dest, (int)padding_size, padding_size); return AES_SUCCESS; } -AES_StatusCode aes_fill_with_padding(AES_PaddingMethod method, - void* dest, - size_t padding_size, - AES_ErrorDetails* err_details) { +AES_StatusCode aes_fill_with_padding( + AES_PaddingMethod method, + void* dest, + size_t padding_size, + AES_ErrorDetails* err_details +) { assert(dest); if (dest == NULL) diff --git a/aesxx/include/aesxx/aes.hpp b/aesxx/include/aesxx/aes.hpp index dedd366..241e051 100644 --- a/aesxx/include/aesxx/aes.hpp +++ b/aesxx/include/aesxx/aes.hpp @@ -74,8 +74,10 @@ inline void expand_key<AES_AES128>(const aes128::Key& key, aes128::RoundKeys& en } template <> -inline void derive_decryption_keys<AES_AES128>(const aes128::RoundKeys& encryption_keys, - aes128::RoundKeys& decryption_keys) { +inline void derive_decryption_keys<AES_AES128>( + const aes128::RoundKeys& encryption_keys, + aes128::RoundKeys& decryption_keys +) { aes_AES128_derive_decryption_keys(&encryption_keys, &decryption_keys); } @@ -147,8 +149,10 @@ inline void expand_key<AES_AES192>(const aes192::Key& key, aes192::RoundKeys& en } template <> -inline void derive_decryption_keys<AES_AES192>(const aes192::RoundKeys& encryption_keys, - aes192::RoundKeys& decryption_keys) { +inline void derive_decryption_keys<AES_AES192>( + const aes192::RoundKeys& encryption_keys, + aes192::RoundKeys& decryption_keys +) { aes_AES192_derive_decryption_keys(&encryption_keys, &decryption_keys); } @@ -220,8 +224,10 @@ inline void expand_key<AES_AES256>(const aes256::Key& key, aes256::RoundKeys& en } template <> -inline void derive_decryption_keys<AES_AES256>(const aes256::RoundKeys& encryption_keys, - aes256::RoundKeys& decryption_keys) { +inline void derive_decryption_keys<AES_AES256>( + const aes256::RoundKeys& encryption_keys, + aes256::RoundKeys& decryption_keys +) { aes_AES256_derive_decryption_keys(&encryption_keys, &decryption_keys); } diff --git a/aesxx/include/aesxx/api.hpp b/aesxx/include/aesxx/api.hpp index 4c1c868..1797a85 100644 --- a/aesxx/include/aesxx/api.hpp +++ b/aesxx/include/aesxx/api.hpp @@ -37,73 +37,99 @@ template <Algorithm algorithm> std::string to_string(const typename Types<algorithm>::Key&); template <Algorithm algorithm> -void expand_key(const typename Types<algorithm>::Key& key, - typename Types<algorithm>::RoundKeys& encryption_keys); +void expand_key( + const typename Types<algorithm>::Key& key, + typename Types<algorithm>::RoundKeys& encryption_keys +); template <Algorithm algorithm> -void derive_decryption_keys(const typename Types<algorithm>::RoundKeys& encryption_keys, - typename Types<algorithm>::RoundKeys& decryption_keys); +void derive_decryption_keys( + const typename Types<algorithm>::RoundKeys& encryption_keys, + typename Types<algorithm>::RoundKeys& decryption_keys +); -template <Algorithm algorithm, - Mode mode, - typename std::enable_if<ModeRequiresInitVector<mode>::value>::type* = nullptr> -void encrypt_block(const typename Types<algorithm>::Block& plaintext, - const typename Types<algorithm>::RoundKeys& round_keys, - typename Types<algorithm>::Block& iv, - typename Types<algorithm>::Block& ciphertext); +template < + Algorithm algorithm, + Mode mode, + typename std::enable_if<ModeRequiresInitVector<mode>::value>::type* = nullptr> +void encrypt_block( + const typename Types<algorithm>::Block& plaintext, + const typename Types<algorithm>::RoundKeys& round_keys, + typename Types<algorithm>::Block& iv, + typename Types<algorithm>::Block& ciphertext +); -template <Algorithm algorithm, - Mode mode, - typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> -void encrypt_block(const typename Types<algorithm>::Block& plaintext, - const typename Types<algorithm>::RoundKeys& round_keys, - typename Types<algorithm>::Block& ciphertext); +template < + Algorithm algorithm, + Mode mode, + typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> +void encrypt_block( + const typename Types<algorithm>::Block& plaintext, + const typename Types<algorithm>::RoundKeys& round_keys, + typename Types<algorithm>::Block& ciphertext +); -template <Algorithm algorithm, - Mode mode, - typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> -void encrypt_block(const typename Types<algorithm>::Block& plaintext, - const typename Types<algorithm>::RoundKeys& round_keys, - typename Types<algorithm>::Block&, - typename Types<algorithm>::Block& ciphertext) { +template < + Algorithm algorithm, + Mode mode, + typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> +void encrypt_block( + const typename Types<algorithm>::Block& plaintext, + const typename Types<algorithm>::RoundKeys& round_keys, + typename Types<algorithm>::Block&, + typename Types<algorithm>::Block& ciphertext +) { encrypt_block<algorithm, mode>(plaintext, round_keys, ciphertext); } -template <Algorithm algorithm, - Mode mode, - typename std::enable_if<ModeRequiresInitVector<mode>::value>::type* = nullptr> -void decrypt_block(const typename Types<algorithm>::Block& ciphertext, - const typename Types<algorithm>::RoundKeys& round_keys, - typename Types<algorithm>::Block& iv, - typename Types<algorithm>::Block& plaintext); +template < + Algorithm algorithm, + Mode mode, + typename std::enable_if<ModeRequiresInitVector<mode>::value>::type* = nullptr> +void decrypt_block( + const typename Types<algorithm>::Block& ciphertext, + const typename Types<algorithm>::RoundKeys& round_keys, + typename Types<algorithm>::Block& iv, + typename Types<algorithm>::Block& plaintext +); -template <Algorithm algorithm, - Mode mode, - typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> -void decrypt_block(const typename Types<algorithm>::Block& ciphertext, - const typename Types<algorithm>::RoundKeys& round_keys, - typename Types<algorithm>::Block& plaintext); +template < + Algorithm algorithm, + Mode mode, + typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> +void decrypt_block( + const typename Types<algorithm>::Block& ciphertext, + const typename Types<algorithm>::RoundKeys& round_keys, + typename Types<algorithm>::Block& plaintext +); -template <Algorithm algorithm, - Mode mode, - typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> -void decrypt_block(const typename Types<algorithm>::Block& ciphertext, - const typename Types<algorithm>::RoundKeys& round_keys, - typename Types<algorithm>::Block&, - typename Types<algorithm>::Block& plaintext) { +template < + Algorithm algorithm, + Mode mode, + typename std::enable_if<!ModeRequiresInitVector<mode>::value>::type* = nullptr> +void decrypt_block( + const typename Types<algorithm>::Block& ciphertext, + const typename Types<algorithm>::RoundKeys& round_keys, + typename Types<algorithm>::Block&, + typename Types<algorithm>::Block& plaintext +) { decrypt_block<algorithm, mode>(ciphertext, round_keys, plaintext); } template <Algorithm algorithm, Mode mode> struct EncryptWrapper { - EncryptWrapper(const typename Types<algorithm>::Key& key, - const typename Types<algorithm>::Block& iv) + EncryptWrapper( + const typename Types<algorithm>::Key& key, + const typename Types<algorithm>::Block& iv + ) : iv{iv} { expand_key<algorithm>(key, encryption_keys); } - void encrypt_block(const typename Types<algorithm>::Block& plaintext, - typename Types<algorithm>::Block& ciphertext) { + void encrypt_block( + const typename Types<algorithm>::Block& plaintext, + typename Types<algorithm>::Block& ciphertext + ) { aes::encrypt_block<algorithm, mode>(plaintext, encryption_keys, iv, ciphertext); } @@ -113,8 +139,10 @@ struct EncryptWrapper { template <Algorithm algorithm, Mode mode> struct DecryptWrapper { - DecryptWrapper(const typename Types<algorithm>::Key& key, - const typename Types<algorithm>::Block& iv) + DecryptWrapper( + const typename Types<algorithm>::Key& key, + const typename Types<algorithm>::Block& iv + ) : iv{iv} { typename Types<algorithm>::RoundKeys encryption_keys; expand_key<algorithm>(key, encryption_keys); @@ -126,8 +154,10 @@ struct DecryptWrapper { } } - void decrypt_block(const typename Types<algorithm>::Block& ciphertext, - typename Types<algorithm>::Block& plaintext) { + void decrypt_block( + const typename Types<algorithm>::Block& ciphertext, + typename Types<algorithm>::Block& plaintext + ) { aes::decrypt_block<algorithm, mode>(ciphertext, decryption_keys, iv, plaintext); } diff --git a/aesxx/include/aesxx/box.hpp b/aesxx/include/aesxx/box.hpp index fb42525..72e3be2 100644 --- a/aesxx/include/aesxx/box.hpp +++ b/aesxx/include/aesxx/box.hpp @@ -64,17 +64,20 @@ public: std::size_t dest_size = 0; aes_box_encrypt_buffer( - &impl, src_buf, src_size, nullptr, &dest_size, aes::ErrorDetailsThrowsInDestructor{}); + &impl, src_buf, src_size, nullptr, &dest_size, aes::ErrorDetailsThrowsInDestructor{} + ); std::vector<unsigned char> dest_buf; dest_buf.resize(dest_size); - aes_box_encrypt_buffer(&impl, - src_buf, - src_size, - dest_buf.data(), - &dest_size, - aes::ErrorDetailsThrowsInDestructor{}); + aes_box_encrypt_buffer( + &impl, + src_buf, + src_size, + dest_buf.data(), + &dest_size, + aes::ErrorDetailsThrowsInDestructor{} + ); dest_buf.resize(dest_size); return dest_buf; @@ -84,17 +87,20 @@ public: std::size_t dest_size = 0; aes_box_decrypt_buffer( - &impl, src_buf, src_size, nullptr, &dest_size, aes::ErrorDetailsThrowsInDestructor{}); + &impl, src_buf, src_size, nullptr, &dest_size, aes::ErrorDetailsThrowsInDestructor{} + ); std::vector<unsigned char> dest_buf; dest_buf.resize(dest_size); - aes_box_decrypt_buffer(&impl, - src_buf, - src_size, - dest_buf.data(), - &dest_size, - aes::ErrorDetailsThrowsInDestructor{}); + aes_box_decrypt_buffer( + &impl, + src_buf, + src_size, + dest_buf.data(), + &dest_size, + aes::ErrorDetailsThrowsInDestructor{} + ); dest_buf.resize(dest_size); return dest_buf; diff --git a/aesxx/include/aesxx/debug.hpp b/aesxx/include/aesxx/debug.hpp index 019603d..845986e 100644 --- a/aesxx/include/aesxx/debug.hpp +++ b/aesxx/include/aesxx/debug.hpp @@ -53,9 +53,11 @@ private: return format_module(symbol_name, offset); } - static std::string format_symbol(std::string_view module_name, - std::string_view symbol_name, - const void* offset = nullptr) { + static std::string format_symbol( + std::string_view module_name, + std::string_view symbol_name, + const void* offset = nullptr + ) { return format_symbol(std::format("{}!{}", module_name, symbol_name), offset); } @@ -99,22 +101,26 @@ private: DWORD64 symbol_offset; const auto symbol_resolved = SymFromAddr( - GetCurrentProcess(), reinterpret_cast<DWORD64>(addr), &symbol_offset, symbol_info); + GetCurrentProcess(), reinterpret_cast<DWORD64>(addr), &symbol_offset, symbol_info + ); if (symbol_resolved) { const auto module_resolved = SymGetModuleInfo64(GetCurrentProcess(), symbol_info->ModBase, &module_info); if (module_resolved) { - return format_symbol(module_info.ModuleName, - symbol_info->Name, - reinterpret_cast<const void*>(symbol_offset)); + return format_symbol( + module_info.ModuleName, + symbol_info->Name, + reinterpret_cast<const void*>(symbol_offset) + ); } else { return format_symbol(symbol_info->Name, addr); } } else { const auto module_resolved = SymGetModuleInfo64( - GetCurrentProcess(), reinterpret_cast<DWORD64>(addr), &module_info); + GetCurrentProcess(), reinterpret_cast<DWORD64>(addr), &module_info + ); if (module_resolved) { const auto module_offset = diff --git a/aesxx/include/aesxx/error.hpp b/aesxx/include/aesxx/error.hpp index 2dde936..eeef7c6 100644 --- a/aesxx/include/aesxx/error.hpp +++ b/aesxx/include/aesxx/error.hpp @@ -34,7 +34,8 @@ public: std::for_each( call_stack, call_stack + call_stack_len, [&formatter, &callback](const void* addr) { callback(addr, formatter.format_address(addr)); - }); + } + ); } private: diff --git a/aesxx/include/aesxx/mode.hpp b/aesxx/include/aesxx/mode.hpp index 999db3a..e4391a4 100644 --- a/aesxx/include/aesxx/mode.hpp +++ b/aesxx/include/aesxx/mode.hpp @@ -41,7 +41,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { inline void encrypt_block<AES_##prefix, AES_ECB>( \ const typename Types<AES_##prefix>::Block& plaintext, \ const typename Types<AES_##prefix>::RoundKeys& encryption_keys, \ - typename Types<AES_##prefix>::Block& ciphertext) { \ + typename Types<AES_##prefix>::Block& ciphertext \ + ) { \ ciphertext = aes_##prefix##_encrypt_block_ECB(plaintext, &encryption_keys); \ } @@ -50,7 +51,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { inline void decrypt_block<AES_##prefix, AES_ECB>( \ const typename Types<AES_##prefix>::Block& ciphertext, \ const typename Types<AES_##prefix>::RoundKeys& decryption_keys, \ - typename Types<AES_##prefix>::Block& plaintext) { \ + typename Types<AES_##prefix>::Block& plaintext \ + ) { \ plaintext = aes_##prefix##_decrypt_block_ECB(ciphertext, &decryption_keys); \ } @@ -60,7 +62,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { const typename Types<AES_##prefix>::Block& plaintext, \ const typename Types<AES_##prefix>::RoundKeys& encryption_keys, \ typename Types<AES_##prefix>::Block& iv, \ - typename Types<AES_##prefix>::Block& ciphertext) { \ + typename Types<AES_##prefix>::Block& ciphertext \ + ) { \ ciphertext = aes_##prefix##_encrypt_block_CBC(plaintext, &encryption_keys, iv, &iv); \ } @@ -70,7 +73,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { const typename Types<AES_##prefix>::Block& ciphertext, \ const typename Types<AES_##prefix>::RoundKeys& decryption_keys, \ typename Types<AES_##prefix>::Block& iv, \ - typename Types<AES_##prefix>::Block& plaintext) { \ + typename Types<AES_##prefix>::Block& plaintext \ + ) { \ plaintext = aes_##prefix##_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &iv); \ } @@ -80,7 +84,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { const typename Types<AES_##prefix>::Block& plaintext, \ const typename Types<AES_##prefix>::RoundKeys& encryption_keys, \ typename Types<AES_##prefix>::Block& iv, \ - typename Types<AES_##prefix>::Block& ciphertext) { \ + typename Types<AES_##prefix>::Block& ciphertext \ + ) { \ ciphertext = aes_##prefix##_encrypt_block_CFB(plaintext, &encryption_keys, iv, &iv); \ } @@ -90,7 +95,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { const typename Types<AES_##prefix>::Block& ciphertext, \ const typename Types<AES_##prefix>::RoundKeys& encryption_keys, \ typename Types<AES_##prefix>::Block& iv, \ - typename Types<AES_##prefix>::Block& plaintext) { \ + typename Types<AES_##prefix>::Block& plaintext \ + ) { \ plaintext = aes_##prefix##_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &iv); \ } @@ -100,7 +106,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { const typename Types<AES_##prefix>::Block& plaintext, \ const typename Types<AES_##prefix>::RoundKeys& encryption_keys, \ typename Types<AES_##prefix>::Block& iv, \ - typename Types<AES_##prefix>::Block& ciphertext) { \ + typename Types<AES_##prefix>::Block& ciphertext \ + ) { \ ciphertext = aes_##prefix##_encrypt_block_OFB(plaintext, &encryption_keys, iv, &iv); \ } @@ -110,7 +117,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { const typename Types<AES_##prefix>::Block& ciphertext, \ const typename Types<AES_##prefix>::RoundKeys& encryption_keys, \ typename Types<AES_##prefix>::Block& iv, \ - typename Types<AES_##prefix>::Block& plaintext) { \ + typename Types<AES_##prefix>::Block& plaintext \ + ) { \ plaintext = aes_##prefix##_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &iv); \ } @@ -120,7 +128,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { const typename Types<AES_##prefix>::Block& plaintext, \ const typename Types<AES_##prefix>::RoundKeys& encryption_keys, \ typename Types<AES_##prefix>::Block& iv, \ - typename Types<AES_##prefix>::Block& ciphertext) { \ + typename Types<AES_##prefix>::Block& ciphertext \ + ) { \ ciphertext = aes_##prefix##_encrypt_block_CTR(plaintext, &encryption_keys, iv, &iv); \ } @@ -130,7 +139,8 @@ inline bool mode_uses_encryption_keys_only(Mode mode) { const typename Types<AES_##prefix>::Block& ciphertext, \ const typename Types<AES_##prefix>::RoundKeys& encryption_keys, \ typename Types<AES_##prefix>::Block& iv, \ - typename Types<AES_##prefix>::Block& plaintext) { \ + typename Types<AES_##prefix>::Block& plaintext \ + ) { \ plaintext = aes_##prefix##_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &iv); \ } diff --git a/aesxx/utils/block_cmd_parser.hpp b/aesxx/utils/block_cmd_parser.hpp index c179556..5bfdb1e 100644 --- a/aesxx/utils/block_cmd_parser.hpp +++ b/aesxx/utils/block_cmd_parser.hpp @@ -32,22 +32,30 @@ public: explicit BlockSettings(std::string_view argv0) : SettingsParser{argv0} { visible.add_options()( - "verbose,v", boost::program_options::bool_switch(&verbose), "enable verbose output"); - visible.add_options()("algorithm,a", - boost::program_options::value<aes::Algorithm>(&algorithm) - ->required() - ->value_name("NAME"), - "set algorithm"); + "verbose,v", boost::program_options::bool_switch(&verbose), "enable verbose output" + ); + visible.add_options()( + "algorithm,a", + boost::program_options::value<aes::Algorithm>(&algorithm) + ->required() + ->value_name("NAME"), + "set algorithm" + ); visible.add_options()( "mode,m", boost::program_options::value<aes::Mode>(&mode)->required()->value_name("MODE"), - "set mode of operation"); - visible.add_options()("use-boxes,b", - boost::program_options::bool_switch(&use_boxes), - "use the \"boxes\" interface"); - hidden.add_options()("args", - boost::program_options::value<std::vector<std::string>>(&args), - "shouldn't be visible"); + "set mode of operation" + ); + visible.add_options()( + "use-boxes,b", + boost::program_options::bool_switch(&use_boxes), + "use the \"boxes\" interface" + ); + hidden.add_options()( + "args", + boost::program_options::value<std::vector<std::string>>(&args), + "shouldn't be visible" + ); positional.add("args", -1); } @@ -58,8 +66,11 @@ public: void parse(int argc, char* argv[]) override { SettingsParser::parse(argc, argv); - parse_inputs(std::deque<std::string>{std::make_move_iterator(args.begin()), - std::make_move_iterator(args.end())}); + parse_inputs( + std::deque<std::string>{ + std::make_move_iterator(args.begin()), std::make_move_iterator(args.end()) + } + ); } private: @@ -77,7 +88,8 @@ private: if (aes::mode_requires_init_vector(mode)) { if (src.empty()) { throw boost::program_options::error{ - "an initialization vector is required for the selected mode of operation"}; + "an initialization vector is required for the selected mode of operation" + }; } iv = std::move(src.front()); src.pop_front(); diff --git a/aesxx/utils/block_dumper.hpp b/aesxx/utils/block_dumper.hpp index c725670..f05d41c 100644 --- a/aesxx/utils/block_dumper.hpp +++ b/aesxx/utils/block_dumper.hpp @@ -40,8 +40,10 @@ void dump_iv(const typename aes::Types<algorithm>::Block& iv) { } template <aes::Algorithm algorithm> -void dump_round_keys(const char* header, - const typename aes::Types<algorithm>::RoundKeys& round_keys) { +void dump_round_keys( + const char* header, + const typename aes::Types<algorithm>::RoundKeys& round_keys +) { std::cout << std::format("{}:\n", header); for (std::size_t i = 0; i < aes::get_number_of_rounds<algorithm>(); ++i) std::cout << std::format("\t[{}]: {}\n", i, aes::to_string<algorithm>(round_keys.keys[i])); @@ -68,26 +70,30 @@ void dump_wrapper(const aes::DecryptWrapper<algorithm, mode>& wrapper) { dump_decryption_keys<algorithm>(wrapper.decryption_keys); } -template <aes::Algorithm algorithm, - aes::Mode mode, - typename std::enable_if<aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> +template < + aes::Algorithm algorithm, + aes::Mode mode, + typename std::enable_if<aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> void dump_next_iv(const aes::EncryptWrapper<algorithm, mode>& wrapper) { dump_block<algorithm>("Next initialization vector", wrapper.iv); } -template <aes::Algorithm algorithm, - aes::Mode mode, - typename std::enable_if<!aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> +template < + aes::Algorithm algorithm, + aes::Mode mode, + typename std::enable_if<!aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> void dump_next_iv(const aes::EncryptWrapper<algorithm, mode>&) {} -template <aes::Algorithm algorithm, - aes::Mode mode, - typename std::enable_if<aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> +template < + aes::Algorithm algorithm, + aes::Mode mode, + typename std::enable_if<aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> void dump_next_iv(const aes::DecryptWrapper<algorithm, mode>& wrapper) { dump_block<algorithm>("Next initialization vector", wrapper.iv); } -template <aes::Algorithm algorithm, - aes::Mode mode, - typename std::enable_if<!aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> +template < + aes::Algorithm algorithm, + aes::Mode mode, + typename std::enable_if<!aes::ModeRequiresInitVector<mode>::value>::type* = nullptr> void dump_next_iv(const aes::DecryptWrapper<algorithm, mode>&) {} diff --git a/aesxx/utils/decrypt_block.cpp b/aesxx/utils/decrypt_block.cpp index d432e31..317e6fd 100644 --- a/aesxx/utils/decrypt_block.cpp +++ b/aesxx/utils/decrypt_block.cpp @@ -83,10 +83,12 @@ void decrypt_with_algorithm(aes::Mode mode, const Input& input, bool verbose = f } } -void decrypt_using_cxx_api(aes::Algorithm algorithm, - aes::Mode mode, - const Input& input, - bool verbose = false) { +void decrypt_using_cxx_api( + aes::Algorithm algorithm, + aes::Mode mode, + const Input& input, + bool verbose = false +) { switch (algorithm) { case AES_AES128: decrypt_with_algorithm<AES_AES128>(mode, input, verbose); diff --git a/aesxx/utils/decrypt_bmp.cpp b/aesxx/utils/decrypt_bmp.cpp index 397ec02..50060eb 100644 --- a/aesxx/utils/decrypt_bmp.cpp +++ b/aesxx/utils/decrypt_bmp.cpp @@ -20,9 +20,11 @@ namespace { -void decrypt_bmp(aes::Box& box, - const std::string& ciphertext_path, - const std::string& plaintext_path) { +void decrypt_bmp( + aes::Box& box, + const std::string& ciphertext_path, + const std::string& plaintext_path +) { bmp::BmpFile bmp{file::read_file(ciphertext_path)}; bmp.replace_pixels(box.decrypt_buffer(bmp.get_pixels(), bmp.get_pixels_size())); file::write_file(plaintext_path, bmp.get_buffer(), bmp.get_size()); diff --git a/aesxx/utils/decrypt_file.cpp b/aesxx/utils/decrypt_file.cpp index 192f1f6..892d07b 100644 --- a/aesxx/utils/decrypt_file.cpp +++ b/aesxx/utils/decrypt_file.cpp @@ -18,9 +18,11 @@ namespace { -void decrypt_file(aes::Box& box, - const std::string& ciphertext_path, - const std::string& plaintext_path) { +void decrypt_file( + aes::Box& box, + const std::string& ciphertext_path, + const std::string& plaintext_path +) { const auto ciphertext_buf = file::read_file(ciphertext_path); const auto plaintext_buf = box.decrypt_buffer(ciphertext_buf.data(), ciphertext_buf.size()); file::write_file(plaintext_path, plaintext_buf); diff --git a/aesxx/utils/encrypt_block.cpp b/aesxx/utils/encrypt_block.cpp index e132256..5fdefd0 100644 --- a/aesxx/utils/encrypt_block.cpp +++ b/aesxx/utils/encrypt_block.cpp @@ -83,10 +83,12 @@ void encrypt_with_algorithm(aes::Mode mode, const Input& input, bool verbose = f } } -void encrypt_using_cxx_api(aes::Algorithm algorithm, - aes::Mode mode, - const Input& input, - bool verbose = false) { +void encrypt_using_cxx_api( + aes::Algorithm algorithm, + aes::Mode mode, + const Input& input, + bool verbose = false +) { switch (algorithm) { case AES_AES128: encrypt_with_algorithm<AES_AES128>(mode, input, verbose); @@ -106,8 +108,10 @@ void encrypt_using_cxx_api(aes::Algorithm algorithm, } } -void encrypt_using_particular_box(aes::Box& box, - const std::vector<std::string>& input_block_strings) { +void encrypt_using_particular_box( + aes::Box& box, + const std::vector<std::string>& input_block_strings +) { for (const auto& input_block_string : input_block_strings) { aes::Box::Block plaintext; box.parse_block(plaintext, input_block_string); diff --git a/aesxx/utils/encrypt_bmp.cpp b/aesxx/utils/encrypt_bmp.cpp index 5b74fb9..f206537 100644 --- a/aesxx/utils/encrypt_bmp.cpp +++ b/aesxx/utils/encrypt_bmp.cpp @@ -18,9 +18,11 @@ namespace { -void encrypt_bmp(aes::Box& box, - const std::string& plaintext_path, - const std::string& ciphertext_path) { +void encrypt_bmp( + aes::Box& box, + const std::string& plaintext_path, + const std::string& ciphertext_path +) { bmp::BmpFile bmp{file::read_file(plaintext_path)}; bmp.replace_pixels(box.encrypt_buffer(bmp.get_pixels(), bmp.get_pixels_size())); file::write_file(ciphertext_path, bmp.get_buffer(), bmp.get_size()); diff --git a/aesxx/utils/encrypt_file.cpp b/aesxx/utils/encrypt_file.cpp index 2862bfb..4ac544c 100644 --- a/aesxx/utils/encrypt_file.cpp +++ b/aesxx/utils/encrypt_file.cpp @@ -18,9 +18,11 @@ namespace { -void encrypt_file(aes::Box& box, - const std::string& plaintext_path, - const std::string& ciphertext_path) { +void encrypt_file( + aes::Box& box, + const std::string& plaintext_path, + const std::string& ciphertext_path +) { const auto plaintext_buf = file::read_file(plaintext_path); const auto ciphertext_buf = box.encrypt_buffer(plaintext_buf.data(), plaintext_buf.size()); file::write_file(ciphertext_path, ciphertext_buf); diff --git a/aesxx/utils/file_cmd_parser.hpp b/aesxx/utils/file_cmd_parser.hpp index 5dec009..dc0c27e 100644 --- a/aesxx/utils/file_cmd_parser.hpp +++ b/aesxx/utils/file_cmd_parser.hpp @@ -28,31 +28,40 @@ public: std::string iv; explicit FileSettings(std::string_view argv0) : SettingsParser{argv0} { - visible.add_options()("algorithm,a", - boost::program_options::value<aes::Algorithm>(&algorithm) - ->required() - ->value_name("NAME"), - "set algorithm"); + visible.add_options()( + "algorithm,a", + boost::program_options::value<aes::Algorithm>(&algorithm) + ->required() + ->value_name("NAME"), + "set algorithm" + ); visible.add_options()( "mode,m", boost::program_options::value<aes::Mode>(&mode)->required()->value_name("MODE"), - "set mode of operation"); + "set mode of operation" + ); visible.add_options()( "key,k", boost::program_options::value<std::string>(&key)->required()->value_name("KEY"), - "set encryption key"); - visible.add_options()("iv,v", - boost::program_options::value<std::string>(&iv)->value_name("BLOCK"), - "set initialization vector"); + "set encryption key" + ); + visible.add_options()( + "iv,v", + boost::program_options::value<std::string>(&iv)->value_name("BLOCK"), + "set initialization vector" + ); visible.add_options()( "input,i", boost::program_options::value<std::string>(&input_path)->required()->value_name("PATH"), - "set input file path"); - visible.add_options()("output,o", - boost::program_options::value<std::string>(&output_path) - ->required() - ->value_name("PATH"), - "set output file path"); + "set input file path" + ); + visible.add_options()( + "output,o", + boost::program_options::value<std::string>(&output_path) + ->required() + ->value_name("PATH"), + "set output file path" + ); } const char* get_short_description() const override { @@ -66,7 +75,8 @@ public: if (aes::mode_requires_init_vector(mode) && iv.empty()) { throw boost::program_options::error{ - "an initialization vector is required for the selected mode of operation"}; + "an initialization vector is required for the selected mode of operation" + }; } } }; diff --git a/aesxx/utils/helpers/command_line.hpp b/aesxx/utils/helpers/command_line.hpp index cc05a6a..c68d739 100644 --- a/aesxx/utils/helpers/command_line.hpp +++ b/aesxx/utils/helpers/command_line.hpp @@ -33,11 +33,13 @@ public: boost::program_options::options_description all; all.add(hidden).add(visible); boost::program_options::variables_map vm; - boost::program_options::store(boost::program_options::command_line_parser{argc, argv} - .options(all) - .positional(positional) - .run(), - vm); + boost::program_options::store( + boost::program_options::command_line_parser{argc, argv} + .options(all) + .positional(positional) + .run(), + vm + ); if (vm.count("help")) exit_with_usage = true; else |
