diff options
Diffstat (limited to '')
-rw-r--r-- | include/aes/aes.h | 560 | ||||
-rw-r--r-- | include/aes/algorithm.h | 8 | ||||
-rw-r--r-- | include/aes/all.h | 2 | ||||
-rw-r--r-- | include/aes/box.h | 82 | ||||
-rw-r--r-- | include/aes/box_aes.h | 6 | ||||
-rw-r--r-- | include/aes/box_data.h | 180 | ||||
-rw-r--r-- | include/aes/data.h | 38 | ||||
-rw-r--r-- | include/aes/error.h | 74 | ||||
-rw-r--r-- | include/aes/mode.h | 158 | ||||
-rw-r--r-- | include/aes/padding.h | 16 |
10 files changed, 562 insertions, 562 deletions
diff --git a/include/aes/aes.h b/include/aes/aes.h index ea859a3..62a301b 100644 --- a/include/aes/aes.h +++ b/include/aes/aes.h @@ -19,415 +19,415 @@ extern "C" { #endif -typedef AesNI_Block128 AesNI_AES_Block; -typedef AesNI_AES_Block AesNI_AES128_Block; -typedef AesNI_AES_Block AesNI_AES192_Block; -typedef AesNI_AES_Block AesNI_AES256_Block; +typedef AES_Block128 AES_AES_Block; +typedef AES_AES_Block AES_AES128_Block; +typedef AES_AES_Block AES_AES192_Block; +typedef AES_AES_Block AES_AES256_Block; typedef struct { - AesNI_AES_Block key; + AES_AES_Block key; } -AesNI_AES128_Key; +AES_AES128_Key; typedef struct { - AesNI_AES_Block hi; - AesNI_AES_Block lo; + AES_AES_Block hi; + AES_AES_Block lo; } -AesNI_AES192_Key; +AES_AES192_Key; typedef struct { - AesNI_AES_Block hi; - AesNI_AES_Block lo; + AES_AES_Block hi; + AES_AES_Block lo; } -AesNI_AES256_Key; +AES_AES256_Key; -static __inline void aesni_AES_make_block(AesNI_AES_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES_make_block(AES_AES_Block* dest, int hi3, int hi2, int lo1, int lo0) { - *dest = aesni_make_block128(hi3, hi2, lo1, lo0); + *dest = aes_make_block128(hi3, hi2, lo1, lo0); } -static __inline void aesni_AES128_make_block(AesNI_AES128_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES128_make_block(AES_AES128_Block* dest, int hi3, int hi2, int lo1, int lo0) { - aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); + aes_AES_make_block(dest, hi3, hi2, lo1, lo0); } -static __inline void aesni_AES192_make_block(AesNI_AES192_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES192_make_block(AES_AES192_Block* dest, int hi3, int hi2, int lo1, int lo0) { - aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); + aes_AES_make_block(dest, hi3, hi2, lo1, lo0); } -static __inline void aesni_AES256_make_block(AesNI_AES256_Block* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES256_make_block(AES_AES256_Block* dest, int hi3, int hi2, int lo1, int lo0) { - aesni_AES_make_block(dest, hi3, hi2, lo1, lo0); + aes_AES_make_block(dest, hi3, hi2, lo1, lo0); } -static __inline void aesni_AES128_make_key(AesNI_AES128_Key* dest, int hi3, int hi2, int lo1, int lo0) +static __inline void aes_AES128_make_key(AES_AES128_Key* dest, int hi3, int hi2, int lo1, int lo0) { - aesni_AES_make_block(&dest->key, hi3, hi2, lo1, lo0); + aes_AES_make_block(&dest->key, hi3, hi2, lo1, lo0); } -static __inline void aesni_AES192_make_key(AesNI_AES192_Key* dest, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) +static __inline void aes_AES192_make_key(AES_AES192_Key* dest, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) { - aesni_AES_make_block(&dest->hi, 0, 0, hi5, hi4); - aesni_AES_make_block(&dest->lo, lo3, lo2, lo1, lo0); + aes_AES_make_block(&dest->hi, 0, 0, hi5, hi4); + aes_AES_make_block(&dest->lo, lo3, lo2, lo1, lo0); } -static __inline void aesni_AES256_make_key(AesNI_AES256_Key* dest, int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) +static __inline void aes_AES256_make_key(AES_AES256_Key* dest, int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0) { - aesni_AES_make_block(&dest->hi, hi7, hi6, hi5, hi4); - aesni_AES_make_block(&dest->lo, lo3, lo2, lo1, lo0); + aes_AES_make_block(&dest->hi, hi7, hi6, hi5, hi4); + aes_AES_make_block(&dest->lo, lo3, lo2, lo1, lo0); } -typedef struct { char str[33]; } AesNI_AES_BlockString; -typedef AesNI_AES_BlockString AesNI_AES128_BlockString; -typedef AesNI_AES_BlockString AesNI_AES192_BlockString; -typedef AesNI_AES_BlockString AesNI_AES256_BlockString; +typedef struct { char str[33]; } AES_AES_BlockString; +typedef AES_AES_BlockString AES_AES128_BlockString; +typedef AES_AES_BlockString AES_AES192_BlockString; +typedef AES_AES_BlockString AES_AES256_BlockString; -typedef struct { char str[49]; } AesNI_AES_BlockMatrixString; -typedef AesNI_AES_BlockMatrixString AesNI_AES128_BlockMatrixString; -typedef AesNI_AES_BlockMatrixString AesNI_AES192_BlockMatrixString; -typedef AesNI_AES_BlockMatrixString AesNI_AES256_BlockMatrixString; +typedef struct { char str[49]; } AES_AES_BlockMatrixString; +typedef AES_AES_BlockMatrixString AES_AES128_BlockMatrixString; +typedef AES_AES_BlockMatrixString AES_AES192_BlockMatrixString; +typedef AES_AES_BlockMatrixString AES_AES256_BlockMatrixString; -AesNI_StatusCode aesni_AES_format_block( - AesNI_AES_BlockString*, - const AesNI_AES_Block*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES_format_block( + AES_AES_BlockString*, + const AES_AES_Block*, + AES_ErrorDetails*); -static __inline AesNI_StatusCode aesni_AES128_format_block( - AesNI_AES128_BlockString* dest, - const AesNI_AES128_Block* src, - AesNI_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 aesni_AES_format_block(dest, src, err_details); + return aes_AES_format_block(dest, src, err_details); } -static __inline AesNI_StatusCode aesni_AES192_format_block( - AesNI_AES192_BlockString* dest, - const AesNI_AES192_Block* src, - AesNI_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 aesni_AES_format_block(dest, src, err_details); + return aes_AES_format_block(dest, src, err_details); } -static __inline AesNI_StatusCode aesni_AES256_format_block( - AesNI_AES256_BlockString* dest, - const AesNI_AES256_Block* src, - AesNI_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 aesni_AES_format_block(dest, src, err_details); + return aes_AES_format_block(dest, src, err_details); } -AesNI_StatusCode aesni_AES_format_block_as_matrix( - AesNI_AES_BlockMatrixString*, - const AesNI_AES_Block*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES_format_block_as_matrix( + AES_AES_BlockMatrixString*, + const AES_AES_Block*, + AES_ErrorDetails*); -static __inline AesNI_StatusCode aesni_AES128_format_block_as_matrix( - AesNI_AES128_BlockMatrixString* dest, - const AesNI_AES128_Block* src, - AesNI_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 aesni_AES_format_block_as_matrix(dest, src, err_details); + return aes_AES_format_block_as_matrix(dest, src, err_details); } -static __inline AesNI_StatusCode aesni_AES192_format_block_as_matrix( - AesNI_AES192_BlockMatrixString* dest, - const AesNI_AES192_Block* src, - AesNI_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 aesni_AES_format_block_as_matrix(dest, src, err_details); + return aes_AES_format_block_as_matrix(dest, src, err_details); } -static __inline AesNI_StatusCode aesni_AES256_format_block_as_matrix( - AesNI_AES256_BlockMatrixString* dest, - const AesNI_AES256_Block* src, - AesNI_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 aesni_AES_format_block_as_matrix(dest, src, err_details); + return aes_AES_format_block_as_matrix(dest, src, err_details); } -AesNI_StatusCode aesni_AES_print_block( - const AesNI_AES_Block*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES_print_block( + const AES_AES_Block*, + AES_ErrorDetails*); -static __inline AesNI_StatusCode aesni_AES128_print_block( - const AesNI_AES128_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES128_print_block( + const AES_AES128_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block(block, err_details); + return aes_AES_print_block(block, err_details); } -static __inline AesNI_StatusCode aesni_AES192_print_block( - const AesNI_AES192_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES192_print_block( + const AES_AES192_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block(block, err_details); + return aes_AES_print_block(block, err_details); } -static __inline AesNI_StatusCode aesni_AES256_print_block( - const AesNI_AES256_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES256_print_block( + const AES_AES256_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block(block, err_details); + return aes_AES_print_block(block, err_details); } -AesNI_StatusCode aesni_AES_print_block_as_matrix( - const AesNI_AES_Block*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES_print_block_as_matrix( + const AES_AES_Block*, + AES_ErrorDetails*); -static __inline AesNI_StatusCode aesni_AES128_print_block_as_matrix( - const AesNI_AES128_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES128_print_block_as_matrix( + const AES_AES128_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block_as_matrix(block, err_details); + return aes_AES_print_block_as_matrix(block, err_details); } -static __inline AesNI_StatusCode aesni_AES192_print_block_as_matrix( - const AesNI_AES192_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES192_print_block_as_matrix( + const AES_AES192_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block_as_matrix(block, err_details); + return aes_AES_print_block_as_matrix(block, err_details); } -static __inline AesNI_StatusCode aesni_AES256_print_block_as_matrix( - const AesNI_AES256_Block* block, - AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_AES256_print_block_as_matrix( + const AES_AES256_Block* block, + AES_ErrorDetails* err_details) { - return aesni_AES_print_block_as_matrix(block, err_details); + return aes_AES_print_block_as_matrix(block, err_details); } -AesNI_StatusCode aesni_AES_parse_block( - AesNI_AES_Block* dest, +AES_StatusCode aes_AES_parse_block( + AES_AES_Block* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -static __inline AesNI_StatusCode aesni_AES128_parse_block( - AesNI_AES128_Block* dest, +static __inline AES_StatusCode aes_AES128_parse_block( + AES_AES128_Block* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - return aesni_AES_parse_block(dest, src, err_details); + return aes_AES_parse_block(dest, src, err_details); } -static __inline AesNI_StatusCode aesni_AES192_parse_block( - AesNI_AES192_Block* dest, +static __inline AES_StatusCode aes_AES192_parse_block( + AES_AES192_Block* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - return aesni_AES_parse_block(dest, src, err_details); + return aes_AES_parse_block(dest, src, err_details); } -static __inline AesNI_StatusCode aesni_AES256_parse_block( - AesNI_AES256_Block* dest, +static __inline AES_StatusCode aes_AES256_parse_block( + AES_AES256_Block* dest, const char* src, - AesNI_ErrorDetails* err_details) + AES_ErrorDetails* err_details) { - return aesni_AES_parse_block(dest, src, err_details); + return aes_AES_parse_block(dest, src, err_details); } -typedef struct { char str[33]; } AesNI_AES128_KeyString; -typedef struct { char str[49]; } AesNI_AES192_KeyString; -typedef struct { char str[65]; } AesNI_AES256_KeyString; +typedef struct { char str[33]; } AES_AES128_KeyString; +typedef struct { char str[49]; } AES_AES192_KeyString; +typedef struct { char str[65]; } AES_AES256_KeyString; -AesNI_StatusCode aesni_AES128_format_key( - AesNI_AES128_KeyString*, - const AesNI_AES128_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES128_format_key( + AES_AES128_KeyString*, + const AES_AES128_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES192_format_key( - AesNI_AES192_KeyString*, - const AesNI_AES192_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES192_format_key( + AES_AES192_KeyString*, + const AES_AES192_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES256_format_key( - AesNI_AES256_KeyString*, - const AesNI_AES256_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES256_format_key( + AES_AES256_KeyString*, + const AES_AES256_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES128_print_key( - const AesNI_AES128_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES128_print_key( + const AES_AES128_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES192_print_key( - const AesNI_AES192_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES192_print_key( + const AES_AES192_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES256_print_key( - const AesNI_AES256_Key*, - AesNI_ErrorDetails*); +AES_StatusCode aes_AES256_print_key( + const AES_AES256_Key*, + AES_ErrorDetails*); -AesNI_StatusCode aesni_AES128_parse_key( - AesNI_AES128_Key* dest, +AES_StatusCode aes_AES128_parse_key( + AES_AES128_Key* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_AES192_parse_key( - AesNI_AES192_Key* dest, +AES_StatusCode aes_AES192_parse_key( + AES_AES192_Key* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_AES256_parse_key( - AesNI_AES256_Key* dest, +AES_StatusCode aes_AES256_parse_key( + AES_AES256_Key* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); typedef struct { - AesNI_AES_Block keys[11]; + AES_AES_Block keys[11]; } -AesNI_AES128_RoundKeys; +AES_AES128_RoundKeys; typedef struct { - AesNI_AES_Block keys[13]; + AES_AES_Block keys[13]; } -AesNI_AES192_RoundKeys; +AES_AES192_RoundKeys; typedef struct { - AesNI_AES_Block keys[15]; + AES_AES_Block keys[15]; } -AesNI_AES256_RoundKeys; +AES_AES256_RoundKeys; -void __fastcall aesni_AES128_expand_key_( - AesNI_AES_Block key, - AesNI_AES128_RoundKeys* encryption_keys); +void __fastcall aes_AES128_expand_key_( + AES_AES_Block key, + AES_AES128_RoundKeys* encryption_keys); -void __fastcall aesni_AES192_expand_key_( - AesNI_AES_Block key_lo, - AesNI_AES_Block key_hi, - AesNI_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 aesni_AES256_expand_key_( - AesNI_AES_Block key_lo, - AesNI_AES_Block key_hi, - AesNI_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 aesni_AES128_derive_decryption_keys_( - const AesNI_AES128_RoundKeys* encryption_keys, - AesNI_AES128_RoundKeys* decryption_keys); +void __fastcall aes_AES128_derive_decryption_keys_( + const AES_AES128_RoundKeys* encryption_keys, + AES_AES128_RoundKeys* decryption_keys); -void __fastcall aesni_AES192_derive_decryption_keys_( - const AesNI_AES192_RoundKeys* encryption_keys, - AesNI_AES192_RoundKeys* decryption_keys); +void __fastcall aes_AES192_derive_decryption_keys_( + const AES_AES192_RoundKeys* encryption_keys, + AES_AES192_RoundKeys* decryption_keys); -void __fastcall aesni_AES256_derive_decryption_keys_( - const AesNI_AES256_RoundKeys* encryption_keys, - AesNI_AES256_RoundKeys* decryption_keys); +void __fastcall aes_AES256_derive_decryption_keys_( + const AES_AES256_RoundKeys* encryption_keys, + AES_AES256_RoundKeys* decryption_keys); -AesNI_AES_Block __fastcall aesni_AES128_encrypt_block_( - AesNI_AES_Block plaintext, - const AesNI_AES128_RoundKeys*); +AES_AES_Block __fastcall aes_AES128_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES128_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES192_encrypt_block_( - AesNI_AES_Block plaintext, - const AesNI_AES192_RoundKeys*); +AES_AES_Block __fastcall aes_AES192_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES192_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES256_encrypt_block_( - AesNI_AES_Block plaintext, - const AesNI_AES256_RoundKeys*); +AES_AES_Block __fastcall aes_AES256_encrypt_block_( + AES_AES_Block plaintext, + const AES_AES256_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES128_decrypt_block_( - AesNI_AES_Block ciphertext, - const AesNI_AES128_RoundKeys*); +AES_AES_Block __fastcall aes_AES128_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES128_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES192_decrypt_block_( - AesNI_AES_Block ciphertext, - const AesNI_AES192_RoundKeys*); +AES_AES_Block __fastcall aes_AES192_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES192_RoundKeys*); -AesNI_AES_Block __fastcall aesni_AES256_decrypt_block_( - AesNI_AES_Block ciphertext, - const AesNI_AES256_RoundKeys*); +AES_AES_Block __fastcall aes_AES256_decrypt_block_( + AES_AES_Block ciphertext, + const AES_AES256_RoundKeys*); -static __inline AesNI_AES_Block __fastcall aesni_AES_xor_blocks( - AesNI_AES_Block a, - AesNI_AES_Block b) +static __inline AES_AES_Block __fastcall aes_AES_xor_blocks( + AES_AES_Block a, + AES_AES_Block b) { - return aesni_xor_block128(a, b); + return aes_xor_block128(a, b); } -static __inline AesNI_AES_Block __fastcall aesni_AES128_xor_blocks( - AesNI_AES128_Block a, - AesNI_AES128_Block b) +static __inline AES_AES_Block __fastcall aes_AES128_xor_blocks( + AES_AES128_Block a, + AES_AES128_Block b) { - return aesni_AES_xor_blocks(a, b); + return aes_AES_xor_blocks(a, b); } -static __inline AesNI_AES_Block __fastcall aesni_AES192_xor_blocks( - AesNI_AES192_Block a, - AesNI_AES192_Block b) +static __inline AES_AES_Block __fastcall aes_AES192_xor_blocks( + AES_AES192_Block a, + AES_AES192_Block b) { - return aesni_AES_xor_blocks(a, b); + return aes_AES_xor_blocks(a, b); } -static __inline AesNI_AES_Block __fastcall aesni_AES256_xor_blocks( - AesNI_AES256_Block a, - AesNI_AES256_Block b) +static __inline AES_AES_Block __fastcall aes_AES256_xor_blocks( + AES_AES256_Block a, + AES_AES256_Block b) { - return aesni_AES_xor_blocks(a, b); + return aes_AES_xor_blocks(a, b); } -static __inline AesNI_AES_Block __fastcall aesni_AES_inc_block( - AesNI_AES_Block block) +static __inline AES_AES_Block __fastcall aes_AES_inc_block( + AES_AES_Block block) { - block = aesni_reverse_byte_order_block128(block); - block = aesni_inc_block128(block); - return aesni_reverse_byte_order_block128(block); + block = aes_reverse_byte_order_block128(block); + block = aes_inc_block128(block); + return aes_reverse_byte_order_block128(block); } -static __inline AesNI_AES_Block __fastcall aesni_AES128_inc_block( - AesNI_AES128_Block block) +static __inline AES_AES_Block __fastcall aes_AES128_inc_block( + AES_AES128_Block block) { - return aesni_AES_inc_block(block); + return aes_AES_inc_block(block); } -static __inline AesNI_AES_Block __fastcall aesni_AES192_inc_block( - AesNI_AES192_Block block) +static __inline AES_AES_Block __fastcall aes_AES192_inc_block( + AES_AES192_Block block) { - return aesni_AES_inc_block(block); + return aes_AES_inc_block(block); } -static __inline AesNI_AES_Block __fastcall aesni_AES256_inc_block( - AesNI_AES256_Block block) +static __inline AES_AES_Block __fastcall aes_AES256_inc_block( + AES_AES256_Block block) { - return aesni_AES_inc_block(block); + return aes_AES_inc_block(block); } -AESNI_ENCRYPT_BLOCK_ECB(AES128); -AESNI_DECRYPT_BLOCK_ECB(AES128); -AESNI_ENCRYPT_BLOCK_CBC(AES128); -AESNI_DECRYPT_BLOCK_CBC(AES128); -AESNI_ENCRYPT_BLOCK_CFB(AES128); -AESNI_DECRYPT_BLOCK_CFB(AES128); -AESNI_ENCRYPT_BLOCK_OFB(AES128); -AESNI_DECRYPT_BLOCK_OFB(AES128); -AESNI_ENCRYPT_BLOCK_CTR(AES128); -AESNI_DECRYPT_BLOCK_CTR(AES128); +AES_ENCRYPT_BLOCK_ECB(AES128); +AES_DECRYPT_BLOCK_ECB(AES128); +AES_ENCRYPT_BLOCK_CBC(AES128); +AES_DECRYPT_BLOCK_CBC(AES128); +AES_ENCRYPT_BLOCK_CFB(AES128); +AES_DECRYPT_BLOCK_CFB(AES128); +AES_ENCRYPT_BLOCK_OFB(AES128); +AES_DECRYPT_BLOCK_OFB(AES128); +AES_ENCRYPT_BLOCK_CTR(AES128); +AES_DECRYPT_BLOCK_CTR(AES128); -AESNI_ENCRYPT_BLOCK_ECB(AES192); -AESNI_DECRYPT_BLOCK_ECB(AES192); -AESNI_ENCRYPT_BLOCK_CBC(AES192); -AESNI_DECRYPT_BLOCK_CBC(AES192); -AESNI_ENCRYPT_BLOCK_CFB(AES192); -AESNI_DECRYPT_BLOCK_CFB(AES192); -AESNI_ENCRYPT_BLOCK_OFB(AES192); -AESNI_DECRYPT_BLOCK_OFB(AES192); -AESNI_ENCRYPT_BLOCK_CTR(AES192); -AESNI_DECRYPT_BLOCK_CTR(AES192); +AES_ENCRYPT_BLOCK_ECB(AES192); +AES_DECRYPT_BLOCK_ECB(AES192); +AES_ENCRYPT_BLOCK_CBC(AES192); +AES_DECRYPT_BLOCK_CBC(AES192); +AES_ENCRYPT_BLOCK_CFB(AES192); +AES_DECRYPT_BLOCK_CFB(AES192); +AES_ENCRYPT_BLOCK_OFB(AES192); +AES_DECRYPT_BLOCK_OFB(AES192); +AES_ENCRYPT_BLOCK_CTR(AES192); +AES_DECRYPT_BLOCK_CTR(AES192); -AESNI_ENCRYPT_BLOCK_ECB(AES256); -AESNI_DECRYPT_BLOCK_ECB(AES256); -AESNI_ENCRYPT_BLOCK_CBC(AES256); -AESNI_DECRYPT_BLOCK_CBC(AES256); -AESNI_ENCRYPT_BLOCK_CFB(AES256); -AESNI_DECRYPT_BLOCK_CFB(AES256); -AESNI_ENCRYPT_BLOCK_OFB(AES256); -AESNI_DECRYPT_BLOCK_OFB(AES256); -AESNI_ENCRYPT_BLOCK_CTR(AES256); -AESNI_DECRYPT_BLOCK_CTR(AES256); +AES_ENCRYPT_BLOCK_ECB(AES256); +AES_DECRYPT_BLOCK_ECB(AES256); +AES_ENCRYPT_BLOCK_CBC(AES256); +AES_DECRYPT_BLOCK_CBC(AES256); +AES_ENCRYPT_BLOCK_CFB(AES256); +AES_DECRYPT_BLOCK_CFB(AES256); +AES_ENCRYPT_BLOCK_OFB(AES256); +AES_DECRYPT_BLOCK_OFB(AES256); +AES_ENCRYPT_BLOCK_CTR(AES256); +AES_DECRYPT_BLOCK_CTR(AES256); /** * \brief Expands an AES-128 key into 10 encryption round keys. @@ -435,13 +435,13 @@ AESNI_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 aesni_AES128_expand_key( - const AesNI_AES128_Key* key, - AesNI_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); - aesni_AES128_expand_key_(key->key, encryption_keys); + aes_AES128_expand_key_(key->key, encryption_keys); } /** @@ -450,14 +450,14 @@ static __inline void __fastcall aesni_AES128_expand_key( * \param[in] encryption_keys The AES-128 encryption round keys. Must not be `NULL`. * \param[out] decryption_keys The AES-128 decryption round keys. Must not be `NULL`. */ -static __inline void __fastcall aesni_AES128_derive_decryption_keys( - const AesNI_AES128_RoundKeys* encryption_keys, - AesNI_AES128_RoundKeys* decryption_keys) +static __inline void __fastcall aes_AES128_derive_decryption_keys( + const AES_AES128_RoundKeys* encryption_keys, + AES_AES128_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_AES128_derive_decryption_keys_(encryption_keys, decryption_keys); + aes_AES128_derive_decryption_keys_(encryption_keys, decryption_keys); } /** @@ -466,14 +466,14 @@ static __inline void __fastcall aesni_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 aesni_AES192_expand_key( - const AesNI_AES192_Key* key, - AesNI_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); - aesni_AES192_expand_key_(key->lo, key->hi, encryption_keys); + aes_AES192_expand_key_(key->lo, key->hi, encryption_keys); } /** @@ -482,14 +482,14 @@ static __inline void __fastcall aesni_AES192_expand_key( * \param[in] encryption_keys The AES-192 encryption round keys. Must not be `NULL`. * \param[out] decryption_keys The AES-192 decryption round keys. Must not be `NULL`. */ -static __inline void __fastcall aesni_AES192_derive_decryption_keys( - const AesNI_AES192_RoundKeys* encryption_keys, - AesNI_AES192_RoundKeys* decryption_keys) +static __inline void __fastcall aes_AES192_derive_decryption_keys( + const AES_AES192_RoundKeys* encryption_keys, + AES_AES192_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_AES192_derive_decryption_keys_(encryption_keys, decryption_keys); + aes_AES192_derive_decryption_keys_(encryption_keys, decryption_keys); } /** @@ -498,14 +498,14 @@ static __inline void __fastcall aesni_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 aesni_AES256_expand_key( - const AesNI_AES256_Key* key, - AesNI_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); - aesni_AES256_expand_key_(key->lo, key->hi, encryption_keys); + aes_AES256_expand_key_(key->lo, key->hi, encryption_keys); } /** @@ -514,14 +514,14 @@ static __inline void __fastcall aesni_AES256_expand_key( * \param[in] encryption_keys The AES-256 encryption round keys. Must not be `NULL`. * \param[out] decryption_keys The AES-256 decryption round keys. Must not be `NULL`. */ -static __inline void __fastcall aesni_AES256_derive_decryption_keys( - const AesNI_AES256_RoundKeys* encryption_keys, - AesNI_AES256_RoundKeys* decryption_keys) +static __inline void __fastcall aes_AES256_derive_decryption_keys( + const AES_AES256_RoundKeys* encryption_keys, + AES_AES256_RoundKeys* decryption_keys) { assert(encryption_keys); assert(decryption_keys); - aesni_AES256_derive_decryption_keys_(encryption_keys, decryption_keys); + aes_AES256_derive_decryption_keys_(encryption_keys, decryption_keys); } #ifdef __cplusplus diff --git a/include/aes/algorithm.h b/include/aes/algorithm.h index a73b412..61b211d 100644 --- a/include/aes/algorithm.h +++ b/include/aes/algorithm.h @@ -15,11 +15,11 @@ extern "C" typedef enum { - AESNI_AES128, - AESNI_AES192, - AESNI_AES256, + AES_AES128, + AES_AES192, + AES_AES256, } -AesNI_Algorithm; +AES_Algorithm; #ifdef __cplusplus } diff --git a/include/aes/all.h b/include/aes/all.h index bbea6f9..363a9a8 100644 --- a/include/aes/all.h +++ b/include/aes/all.h @@ -12,7 +12,7 @@ #pragma once /** - * \defgroup aesni AesNI + * \defgroup aes AES */ #include "aes.h" diff --git a/include/aes/box.h b/include/aes/box.h index 58517e1..dc5bc50 100644 --- a/include/aes/box.h +++ b/include/aes/box.h @@ -19,65 +19,65 @@ extern "C" { #endif -AesNI_StatusCode aesni_box_init( - AesNI_Box* box, - AesNI_Algorithm algorithm, - const AesNI_BoxKey* box_key, - AesNI_Mode mode, - const AesNI_BoxBlock* iv, - AesNI_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); -AesNI_StatusCode aesni_box_parse_key( - AesNI_BoxKey* dest, - AesNI_Algorithm algorithm, +AES_StatusCode aes_box_parse_key( + AES_BoxKey* dest, + AES_Algorithm algorithm, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_parse_block( - AesNI_BoxBlock* dest, - AesNI_Algorithm algorithm, +AES_StatusCode aes_box_parse_block( + AES_BoxBlock* dest, + AES_Algorithm algorithm, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_format_key( - AesNI_BoxKeyString* dest, - AesNI_Algorithm algorithm, - const AesNI_BoxKey* src, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_format_key( + AES_BoxKeyString* dest, + AES_Algorithm algorithm, + const AES_BoxKey* src, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_format_block( - AesNI_BoxBlockString* dest, - AesNI_Algorithm algorithm, - const AesNI_BoxBlock* src, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_format_block( + AES_BoxBlockString* dest, + AES_Algorithm algorithm, + const AES_BoxBlock* src, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_encrypt_block( - AesNI_Box* box, - const AesNI_BoxBlock* plaintext, - AesNI_BoxBlock* ciphertext, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_encrypt_block( + AES_Box* box, + const AES_BoxBlock* plaintext, + AES_BoxBlock* ciphertext, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_decrypt_block( - AesNI_Box* box, - const AesNI_BoxBlock* ciphertext, - AesNI_BoxBlock* plaintext, - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_box_decrypt_block( + AES_Box* box, + const AES_BoxBlock* ciphertext, + AES_BoxBlock* plaintext, + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_encrypt_buffer( - AesNI_Box* box, +AES_StatusCode aes_box_encrypt_buffer( + AES_Box* box, const void* src, size_t src_size, void* dest, size_t* dest_size, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_box_decrypt_buffer( - AesNI_Box* box, +AES_StatusCode aes_box_decrypt_buffer( + AES_Box* box, const void* src, size_t src_size, void* dest, size_t* dest_size, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); #ifdef __cplusplus } diff --git a/include/aes/box_aes.h b/include/aes/box_aes.h index 3d7faec..e13b39a 100644 --- a/include/aes/box_aes.h +++ b/include/aes/box_aes.h @@ -15,9 +15,9 @@ extern "C" { #endif -extern AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes128; -extern AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes192; -extern AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes256; +extern AES_BoxAlgorithmInterface aes_box_algorithm_aes128; +extern AES_BoxAlgorithmInterface aes_box_algorithm_aes192; +extern AES_BoxAlgorithmInterface aes_box_algorithm_aes256; #ifdef __cplusplus } diff --git a/include/aes/box_data.h b/include/aes/box_data.h index 888c7c0..bd970eb 100644 --- a/include/aes/box_data.h +++ b/include/aes/box_data.h @@ -21,135 +21,135 @@ extern "C" typedef union { - AesNI_AES128_Key aes128_key; - AesNI_AES192_Key aes192_key; - AesNI_AES256_Key aes256_key; + AES_AES128_Key aes128_key; + AES_AES192_Key aes192_key; + AES_AES256_Key aes256_key; } -AesNI_BoxKey; +AES_BoxKey; typedef union { - AesNI_AES128_RoundKeys aes128_encryption_keys; - AesNI_AES192_RoundKeys aes192_encryption_keys; - AesNI_AES256_RoundKeys aes256_encryption_keys; + AES_AES128_RoundKeys aes128_encryption_keys; + AES_AES192_RoundKeys aes192_encryption_keys; + AES_AES256_RoundKeys aes256_encryption_keys; } -AesNI_BoxEncryptionRoundKeys; +AES_BoxEncryptionRoundKeys; typedef union { - AesNI_AES128_RoundKeys aes128_decryption_keys; - AesNI_AES192_RoundKeys aes192_decryption_keys; - AesNI_AES256_RoundKeys aes256_decryption_keys; + AES_AES128_RoundKeys aes128_decryption_keys; + AES_AES192_RoundKeys aes192_decryption_keys; + AES_AES256_RoundKeys aes256_decryption_keys; } -AesNI_BoxDecryptionRoundKeys; +AES_BoxDecryptionRoundKeys; typedef union { - AesNI_AES128_KeyString aes128; - AesNI_AES192_KeyString aes192; - AesNI_AES256_KeyString aes256; + AES_AES128_KeyString aes128; + AES_AES192_KeyString aes192; + AES_AES256_KeyString aes256; } -AesNI_BoxKeyString; +AES_BoxKeyString; typedef union { - AesNI_AES_Block aes_block; + AES_AES_Block aes_block; } -AesNI_BoxBlock; +AES_BoxBlock; typedef union { - AesNI_AES_BlockString aes; + AES_AES_BlockString aes; } -AesNI_BoxBlockString; +AES_BoxBlockString; -typedef AesNI_StatusCode (*AesNI_BoxCalculateRoundKeys)( - const AesNI_BoxKey* params, - AesNI_BoxEncryptionRoundKeys*, - AesNI_BoxDecryptionRoundKeys*, - AesNI_ErrorDetails* err_details); +typedef AES_StatusCode (*AES_BoxCalculateRoundKeys)( + const AES_BoxKey* params, + AES_BoxEncryptionRoundKeys*, + AES_BoxDecryptionRoundKeys*, + AES_ErrorDetails* err_details); -typedef AesNI_StatusCode (*AesNI_BoxParseBlock)( - AesNI_BoxBlock* dest, +typedef AES_StatusCode (*AES_BoxParseBlock)( + AES_BoxBlock* dest, const char* src, - AesNI_ErrorDetails* err_details); + AES_ErrorDetails* err_details); -typedef AesNI_StatusCode (*AesNI_BoxParseKey)( - AesNI_BoxKey* dest, +typedef AES_StatusCode (*AES_BoxParseKey)( + AES_BoxKey* dest, const char* src, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxFormatBlock)( - AesNI_BoxBlockString* dest, - const AesNI_BoxBlock* src, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxFormatKey)( - AesNI_BoxKeyString* dest, - const AesNI_BoxKey* src, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxEncryptBlock)( - const AesNI_BoxBlock* plaintext, - const AesNI_BoxEncryptionRoundKeys* params, - AesNI_BoxBlock* ciphertext, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxDecryptBlock)( - const AesNI_BoxBlock* ciphertext, - const AesNI_BoxDecryptionRoundKeys* params, - AesNI_BoxBlock* plaintext, - AesNI_ErrorDetails* err_details); - -typedef AesNI_StatusCode (*AesNI_BoxXorBlock)( - AesNI_BoxBlock*, - const AesNI_BoxBlock*, - AesNI_ErrorDetails*); - -typedef AesNI_StatusCode (*AesNI_BoxIncBlock)( - AesNI_BoxBlock*, - AesNI_ErrorDetails*); - -typedef AesNI_StatusCode (*AesNI_BoxGetBlockSize)( + 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_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_BoxXorBlock)( + AES_BoxBlock*, + const AES_BoxBlock*, + AES_ErrorDetails*); + +typedef AES_StatusCode (*AES_BoxIncBlock)( + AES_BoxBlock*, + AES_ErrorDetails*); + +typedef AES_StatusCode (*AES_BoxGetBlockSize)( size_t*, - AesNI_ErrorDetails*); + AES_ErrorDetails*); -typedef AesNI_StatusCode (*AesNI_BoxStoreBlock)( +typedef AES_StatusCode (*AES_BoxStoreBlock)( void*, - const AesNI_BoxBlock*, - AesNI_ErrorDetails*); + const AES_BoxBlock*, + AES_ErrorDetails*); -typedef AesNI_StatusCode (*AesNI_BoxLoadBlock)( - AesNI_BoxBlock*, +typedef AES_StatusCode (*AES_BoxLoadBlock)( + AES_BoxBlock*, const void*, - AesNI_ErrorDetails*); + AES_ErrorDetails*); typedef struct { - AesNI_BoxCalculateRoundKeys calc_round_keys; - AesNI_BoxParseBlock parse_block; - AesNI_BoxParseKey parse_key; - AesNI_BoxFormatBlock format_block; - AesNI_BoxFormatKey format_key; - AesNI_BoxEncryptBlock encrypt_block; - AesNI_BoxDecryptBlock decrypt_block; - AesNI_BoxXorBlock xor_block; - AesNI_BoxIncBlock inc_block; - AesNI_BoxGetBlockSize get_block_size; - AesNI_BoxStoreBlock store_block; - AesNI_BoxLoadBlock load_block; + AES_BoxCalculateRoundKeys calc_round_keys; + AES_BoxParseBlock parse_block; + AES_BoxParseKey parse_key; + AES_BoxFormatBlock format_block; + AES_BoxFormatKey format_key; + AES_BoxEncryptBlock encrypt_block; + AES_BoxDecryptBlock decrypt_block; + AES_BoxXorBlock xor_block; + AES_BoxIncBlock inc_block; + AES_BoxGetBlockSize get_block_size; + AES_BoxStoreBlock store_block; + AES_BoxLoadBlock load_block; } -AesNI_BoxAlgorithmInterface; +AES_BoxAlgorithmInterface; typedef struct { - const AesNI_BoxAlgorithmInterface* algorithm; - AesNI_BoxEncryptionRoundKeys encryption_keys; - AesNI_BoxDecryptionRoundKeys decryption_keys; - AesNI_Mode mode; - AesNI_BoxBlock iv; + const AES_BoxAlgorithmInterface* algorithm; + AES_BoxEncryptionRoundKeys encryption_keys; + AES_BoxDecryptionRoundKeys decryption_keys; + AES_Mode mode; + AES_BoxBlock iv; } -AesNI_Box; +AES_Box; #ifdef __cplusplus } diff --git a/include/aes/data.h b/include/aes/data.h index 94cff2c..e8391cc 100644 --- a/include/aes/data.h +++ b/include/aes/data.h @@ -19,7 +19,7 @@ extern "C" /** * \brief Represents a 128-bit block. */ -typedef __m128i AesNI_Block128; +typedef __m128i AES_Block128; /** * \brief Loads a 128-bit block from a memory location. @@ -28,9 +28,9 @@ typedef __m128i AesNI_Block128; * * \return The loaded 128-bit block. */ -static __inline AesNI_Block128 aesni_load_block128(const void* src) +static __inline AES_Block128 aes_load_block128(const void* src) { - return _mm_loadu_si128((AesNI_Block128*) src); + return _mm_loadu_si128((AES_Block128*) src); } /** @@ -40,9 +40,9 @@ static __inline AesNI_Block128 aesni_load_block128(const void* src) * * \return The loaded 128-bit block. */ -static __inline AesNI_Block128 aesni_load_block128_aligned(const void* src) +static __inline AES_Block128 aes_load_block128_aligned(const void* src) { - return _mm_load_si128((AesNI_Block128*) src); + return _mm_load_si128((AES_Block128*) src); } /** @@ -52,11 +52,11 @@ static __inline AesNI_Block128 aesni_load_block128_aligned(const void* src) * * \param[in] block The block to be stored. */ -static __inline void __fastcall aesni_store_block128( +static __inline void __fastcall aes_store_block128( void* dest, - AesNI_Block128 block) + AES_Block128 block) { - _mm_storeu_si128((AesNI_Block128*) dest, block); + _mm_storeu_si128((AES_Block128*) dest, block); } /** @@ -66,11 +66,11 @@ static __inline void __fastcall aesni_store_block128( * * \param[in] block The block to be stored. */ -static __inline void __fastcall aesni_store_block128_aligned( +static __inline void __fastcall aes_store_block128_aligned( void* dest, - AesNI_Block128 block) + AES_Block128 block) { - _mm_store_si128((AesNI_Block128*) dest, block); + _mm_store_si128((AES_Block128*) dest, block); } /** @@ -81,9 +81,9 @@ static __inline void __fastcall aesni_store_block128_aligned( * * \return `a^b`. */ -static __inline AesNI_Block128 __fastcall aesni_xor_block128( - AesNI_Block128 a, - AesNI_Block128 b) +static __inline AES_Block128 __fastcall aes_xor_block128( + AES_Block128 a, + AES_Block128 b) { return _mm_xor_si128(a, b); } @@ -105,19 +105,19 @@ static __inline AesNI_Block128 __fastcall aesni_xor_block128( * * \return The built 128-bit block. */ -static __inline AesNI_Block128 __fastcall aesni_make_block128(int hi3, int hi2, int lo1, int lo0) +static __inline AES_Block128 __fastcall aes_make_block128(int hi3, int hi2, int lo1, int lo0) { return _mm_set_epi32(hi3, hi2, lo1, lo0); } -static __inline AesNI_Block128 __fastcall aesni_reverse_byte_order_block128(AesNI_Block128 block) +static __inline AES_Block128 __fastcall aes_reverse_byte_order_block128(AES_Block128 block) { - return _mm_shuffle_epi8(block, aesni_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f)); + return _mm_shuffle_epi8(block, aes_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f)); } -static __inline AesNI_Block128 __fastcall aesni_inc_block128(AesNI_Block128 x) +static __inline AES_Block128 __fastcall aes_inc_block128(AES_Block128 x) { - return _mm_add_epi32(x, aesni_make_block128(0, 0, 0, 1)); + return _mm_add_epi32(x, aes_make_block128(0, 0, 0, 1)); } #ifdef __cplusplus diff --git a/include/aes/error.h b/include/aes/error.h index a51284f..a92f17b 100644 --- a/include/aes/error.h +++ b/include/aes/error.h @@ -9,14 +9,14 @@ #pragma once /** - * \defgroup aesni_error_handling Error handling - * \ingroup aesni + * \defgroup aes_error_handling Error handling + * \ingroup aes * \brief Error data structures and formatting functions. * * Some library functions cannot fail, which is simple. * Other functions return an error code. * You can check if a function exited with an error by passing the returned - * error code to aesni_is_error(). + * error code to aes_is_error(). * * Some possibly-may-fail functions accept a pointer to an "error details" * structure. @@ -42,19 +42,19 @@ extern "C" */ typedef enum { - AESNI_SUCCESS, ///< Everything went fine - AESNI_NULL_ARGUMENT_ERROR, ///< Invalid argument value NULL - AESNI_PARSE_ERROR, ///< Couldn't parse - AESNI_INVALID_PKCS7_PADDING_ERROR, ///< Invalid PKCS7 padding while decrypting - AESNI_NOT_IMPLEMENTED_ERROR, ///< Not implemented - AESNI_MISSING_PADDING_ERROR, - AESNI_MEMORY_ALLOCATION_ERROR, + AES_SUCCESS, ///< Everything went fine + AES_NULL_ARGUMENT_ERROR, ///< Invalid argument value NULL + AES_PARSE_ERROR, ///< Couldn't parse + AES_INVALID_PKCS7_PADDING_ERROR, ///< Invalid PKCS7 padding while decrypting + AES_NOT_IMPLEMENTED_ERROR, ///< Not implemented + AES_MISSING_PADDING_ERROR, + AES_MEMORY_ALLOCATION_ERROR, } -AesNI_StatusCode; +AES_StatusCode; -static __inline int aesni_is_error(AesNI_StatusCode ec) +static __inline int aes_is_error(AES_StatusCode ec) { - return ec != AESNI_SUCCESS; + return ec != AES_SUCCESS; } /** @@ -62,7 +62,7 @@ static __inline int aesni_is_error(AesNI_StatusCode ec) * * For example, * \code{.c} - * printf("%s\n", aesni_strerror(AESNI_NULL_ARGUMENT_ERROR)); + * printf("%s\n", aes_strerror(AES_NULL_ARGUMENT_ERROR)); * \endcode * would print * \code @@ -72,16 +72,16 @@ static __inline int aesni_is_error(AesNI_StatusCode ec) * \param[in] ec The error code. * \return A pointer to a statically-allocated C string. */ -const char* aesni_strerror(AesNI_StatusCode ec); +const char* aes_strerror(AES_StatusCode ec); -#define AESNI_MAX_CALL_STACK_LENGTH 32 +#define AES_MAX_CALL_STACK_LENGTH 32 /** * \brief Stores error details: error code & possibly a few parameters. */ typedef struct { - AesNI_StatusCode ec; ///< Error code + AES_StatusCode ec; ///< Error code union { @@ -96,10 +96,10 @@ typedef struct } params; - void* call_stack[AESNI_MAX_CALL_STACK_LENGTH]; + void* call_stack[AES_MAX_CALL_STACK_LENGTH]; size_t call_stack_size; } -AesNI_ErrorDetails; +AES_ErrorDetails; /** * \brief Extracts an error code from error details. @@ -107,8 +107,8 @@ AesNI_ErrorDetails; * \param[in] err_details The error details structure. Must not be `NULL`. * \return The error code stored in the error details. */ -static __inline AesNI_StatusCode aesni_get_error_code( - const AesNI_ErrorDetails* err_details) +static __inline AES_StatusCode aes_get_error_code( + const AES_ErrorDetails* err_details) { return err_details->ec; } @@ -123,8 +123,8 @@ static __inline AesNI_StatusCode aesni_get_error_code( * error message, and the number of characters written (excluding the * terminating '\0' character) otherwise. */ -size_t aesni_format_error( - const AesNI_ErrorDetails* err_details, +size_t aes_format_error( + const AES_ErrorDetails* err_details, char* dest, size_t dest_size); @@ -133,8 +133,8 @@ size_t aesni_format_error( * * \param[out] err_details The error details structure to fill. */ -AesNI_StatusCode aesni_success( - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_success( + AES_ErrorDetails* err_details); /** * \brief Builds error details from a `NULL` argument error. @@ -142,8 +142,8 @@ AesNI_StatusCode aesni_success( * \param[out] err_details The error details structure to fill. * \param[in] param_name The parameter name. Must not be `NULL`. */ -AesNI_StatusCode aesni_error_null_argument( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_null_argument( + AES_ErrorDetails* err_details, const char* param_name); /** @@ -152,8 +152,8 @@ AesNI_StatusCode aesni_error_null_argument( * \param[out] err_details The error details structure to fill. * \param[in] src The string that failed to be parsed. */ -AesNI_StatusCode aesni_error_parse( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_parse( + AES_ErrorDetails* err_details, const char* src, const char* what); @@ -162,18 +162,18 @@ AesNI_StatusCode aesni_error_parse( * * \param[out] err_details The error details structure to fill. */ -AesNI_StatusCode aesni_error_invalid_pkcs7_padding( - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_error_invalid_pkcs7_padding( + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_error_not_implemented( - AesNI_ErrorDetails* err_details, +AES_StatusCode aes_error_not_implemented( + AES_ErrorDetails* err_details, const char* what); -AesNI_StatusCode aesni_error_missing_padding( - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_error_missing_padding( + AES_ErrorDetails* err_details); -AesNI_StatusCode aesni_error_memory_allocation( - AesNI_ErrorDetails* err_details); +AES_StatusCode aes_error_memory_allocation( + AES_ErrorDetails* err_details); #ifdef __cplusplus } diff --git a/include/aes/mode.h b/include/aes/mode.h index 7650ec0..dccfc43 100644 --- a/include/aes/mode.h +++ b/include/aes/mode.h @@ -17,150 +17,150 @@ extern "C" typedef enum { - AESNI_ECB, - AESNI_CBC, - AESNI_CFB, - AESNI_OFB, - AESNI_CTR, + AES_ECB, + AES_CBC, + AES_CFB, + AES_OFB, + AES_CTR, } -AesNI_Mode; +AES_Mode; -#define AESNI_ENCRYPT_BLOCK_ECB(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_ECB( \ - AesNI_## prefix ##_Block plaintext, \ - const AesNI_## prefix ##_RoundKeys* 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 aesni_## prefix ##_encrypt_block_(plaintext, encryption_keys); \ + return aes_## prefix ##_encrypt_block_(plaintext, encryption_keys); \ } -#define AESNI_DECRYPT_BLOCK_ECB(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_ECB( \ - AesNI_## prefix ##_Block ciphertext, \ - const AesNI_## prefix ##_RoundKeys* 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 aesni_## prefix ##_decrypt_block_(ciphertext, decryption_keys); \ + return aes_## prefix ##_decrypt_block_(ciphertext, decryption_keys); \ } -#define AESNI_ENCRYPT_BLOCK_CBC(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_CBC( \ - AesNI_## prefix ##_Block plaintext, \ - const AesNI_## prefix ##_RoundKeys* encryption_keys, \ - AesNI_## prefix ##_Block init_vector, \ - AesNI_## prefix ##_Block* next_init_vector) \ +#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 = aesni_## prefix ##_encrypt_block_( \ - aesni_## prefix ##_xor_blocks(plaintext, init_vector), encryption_keys); \ + return *next_init_vector = aes_## prefix ##_encrypt_block_( \ + aes_## prefix ##_xor_blocks(plaintext, init_vector), encryption_keys); \ } -#define AESNI_DECRYPT_BLOCK_CBC(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_CBC( \ - AesNI_## prefix ##_Block ciphertext, \ - const AesNI_## prefix ##_RoundKeys* decryption_keys, \ - AesNI_## prefix ##_Block init_vector, \ - AesNI_## prefix ##_Block* next_init_vector) \ +#define AES_DECRYPT_BLOCK_CBC(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_CBC( \ + AES_## prefix ##_Block ciphertext, \ + const AES_## prefix ##_RoundKeys* decryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(decryption_keys); \ assert(next_init_vector); \ \ - AesNI_## prefix ##_Block plaintext = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_decrypt_block_(ciphertext, decryption_keys), init_vector); \ + AES_## prefix ##_Block plaintext = aes_## prefix ##_xor_blocks( \ + aes_## prefix ##_decrypt_block_(ciphertext, decryption_keys), init_vector); \ *next_init_vector = ciphertext; \ return plaintext; \ } -#define AESNI_ENCRYPT_BLOCK_CFB(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_CFB( \ - AesNI_## prefix ##_Block plaintext, \ - const AesNI_## prefix ##_RoundKeys* encryption_keys, \ - AesNI_## prefix ##_Block init_vector, \ - AesNI_## prefix ##_Block* next_init_vector) \ +#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 = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys), plaintext); \ + return *next_init_vector = aes_## prefix ##_xor_blocks( \ + aes_## prefix ##_encrypt_block_(init_vector, encryption_keys), plaintext); \ } -#define AESNI_DECRYPT_BLOCK_CFB(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_CFB( \ - AesNI_## prefix ##_Block ciphertext, \ - const AesNI_## prefix ##_RoundKeys* encryption_keys, \ - AesNI_## prefix ##_Block init_vector, \ - AesNI_## prefix ##_Block* next_init_vector) \ +#define AES_DECRYPT_BLOCK_CFB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_CFB( \ + AES_## prefix ##_Block ciphertext, \ + const AES_## prefix ##_RoundKeys* encryption_keys, \ + AES_## prefix ##_Block init_vector, \ + AES_## prefix ##_Block* next_init_vector) \ { \ assert(encryption_keys); \ assert(next_init_vector); \ \ - AesNI_## prefix ##_Block plaintext = aesni_## prefix ##_xor_blocks( \ - aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys), ciphertext); \ + AES_## prefix ##_Block plaintext = aes_## prefix ##_xor_blocks( \ + aes_## prefix ##_encrypt_block_(init_vector, encryption_keys), ciphertext); \ *next_init_vector = ciphertext; \ return plaintext; \ } -#define AESNI_ENCRYPT_BLOCK_OFB(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_OFB( \ - AesNI_## prefix ##_Block plaintext, \ - const AesNI_## prefix ##_RoundKeys* encryption_keys, \ - AesNI_## prefix ##_Block init_vector, \ - AesNI_## prefix ##_Block* next_init_vector) \ +#define AES_ENCRYPT_BLOCK_OFB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_encrypt_block_OFB( \ + 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); \ \ - AesNI_## prefix ##_Block tmp = aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys); \ + AES_## prefix ##_Block tmp = aes_## prefix ##_encrypt_block_(init_vector, encryption_keys); \ *next_init_vector = tmp; \ - return aesni_## prefix ##_xor_blocks(tmp, plaintext); \ + return aes_## prefix ##_xor_blocks(tmp, plaintext); \ } -#define AESNI_DECRYPT_BLOCK_OFB(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_OFB( \ - AesNI_## prefix ##_Block ciphertext, \ - const AesNI_## prefix ##_RoundKeys* encryption_keys, \ - AesNI_## prefix ##_Block init_vector, \ - AesNI_## prefix ##_Block* next_init_vector) \ +#define AES_DECRYPT_BLOCK_OFB(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_OFB( \ + AES_## prefix ##_Block ciphertext, \ + 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 aesni_## prefix ##_encrypt_block_OFB( \ + return aes_## prefix ##_encrypt_block_OFB( \ ciphertext, encryption_keys, init_vector, next_init_vector); \ } -#define AESNI_ENCRYPT_BLOCK_CTR(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_encrypt_block_CTR( \ - AesNI_## prefix ##_Block plaintext, \ - const AesNI_## prefix ##_RoundKeys* encryption_keys, \ - AesNI_## prefix ##_Block init_vector, \ - AesNI_## prefix ##_Block* next_init_vector) \ +#define AES_ENCRYPT_BLOCK_CTR(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_encrypt_block_CTR( \ + 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); \ \ - AesNI_## prefix ##_Block ciphertext = aesni_## prefix ##_xor_blocks( \ - plaintext, aesni_## prefix ##_encrypt_block_(init_vector, encryption_keys)); \ - *next_init_vector = aesni_## prefix ##_inc_block(init_vector); \ + AES_## prefix ##_Block ciphertext = aes_## prefix ##_xor_blocks( \ + plaintext, aes_## prefix ##_encrypt_block_(init_vector, encryption_keys)); \ + *next_init_vector = aes_## prefix ##_inc_block(init_vector); \ return ciphertext; \ } -#define AESNI_DECRYPT_BLOCK_CTR(prefix) \ -static __inline AesNI_## prefix ##_Block __fastcall aesni_## prefix ##_decrypt_block_CTR( \ - AesNI_## prefix ##_Block ciphertext, \ - const AesNI_## prefix ##_RoundKeys* encryption_keys, \ - AesNI_## prefix ##_Block init_vector, \ - AesNI_## prefix ##_Block* next_init_vector) \ +#define AES_DECRYPT_BLOCK_CTR(prefix) \ +static __inline AES_## prefix ##_Block __fastcall aes_## prefix ##_decrypt_block_CTR( \ + AES_## prefix ##_Block ciphertext, \ + 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 aesni_## prefix ##_encrypt_block_CTR( \ + return aes_## prefix ##_encrypt_block_CTR( \ ciphertext, encryption_keys, init_vector, next_init_vector); \ } diff --git a/include/aes/padding.h b/include/aes/padding.h index 7f19b18..7f0db65 100644 --- a/include/aes/padding.h +++ b/include/aes/padding.h @@ -19,22 +19,22 @@ extern "C" typedef enum { - AESNI_PADDING_PKCS7, + AES_PADDING_PKCS7, } -AesNI_PaddingMethod; +AES_PaddingMethod; -AesNI_StatusCode aesni_extract_padding_size( - AesNI_PaddingMethod, +AES_StatusCode aes_extract_padding_size( + AES_PaddingMethod, const void* src, size_t src_size, size_t* padding_size, - AesNI_ErrorDetails*); + AES_ErrorDetails*); -AesNI_StatusCode aesni_fill_with_padding( - AesNI_PaddingMethod, +AES_StatusCode aes_fill_with_padding( + AES_PaddingMethod, void* dest, size_t padding_size, - AesNI_ErrorDetails*); + AES_ErrorDetails*); #ifdef __cplusplus } |