From 0651133db30c0932877780c2f98901e4ca1072e1 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 17 Jun 2015 18:29:40 +0300 Subject: refactoring --- include/aesni/aes.h | 955 +++++++++++++++++++++++++++++++++++++++++++++++++ include/aesni/all.h | 3 +- include/aesni/block.h | 933 ----------------------------------------------- include/aesni/box.h | 12 +- include/aesni/buffer.h | 4 +- include/aesni/data.h | 18 - include/aesni/raw.h | 218 ----------- 7 files changed, 964 insertions(+), 1179 deletions(-) create mode 100644 include/aesni/aes.h delete mode 100644 include/aesni/block.h delete mode 100644 include/aesni/raw.h (limited to 'include/aesni') diff --git a/include/aesni/aes.h b/include/aesni/aes.h new file mode 100644 index 0000000..dcee06b --- /dev/null +++ b/include/aesni/aes.h @@ -0,0 +1,955 @@ +/** + * \file + * \author Egor Tensin + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#pragma once + +#include "data.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct +{ + AesNI_Block128 keys[11]; +} +AesNI_Aes128_RoundKeys; + +typedef struct +{ + AesNI_Block128 keys[13]; +} +AesNI_Aes192_RoundKeys; + +typedef struct +{ + AesNI_Block128 keys[15]; +} +AesNI_Aes256_RoundKeys; + +void __fastcall aesni_aes128_expand_key_( + AesNI_Block128 key, + AesNI_Aes128_RoundKeys* encryption_keys); + +void __fastcall aesni_aes192_expand_key_( + AesNI_Block128 key_lo, + AesNI_Block128 key_hi, + AesNI_Aes192_RoundKeys* encryption_keys); + +void __fastcall aesni_aes256_expand_key_( + AesNI_Block128 key_lo, + AesNI_Block128 key_hi, + AesNI_Aes256_RoundKeys* encryption_keys); + +void __fastcall aesni_aes128_derive_decryption_keys_( + const AesNI_Aes128_RoundKeys* encryption_keys, + AesNI_Aes128_RoundKeys* decryption_keys); + +void __fastcall aesni_aes192_derive_decryption_keys_( + const AesNI_Aes192_RoundKeys* encryption_keys, + AesNI_Aes192_RoundKeys* decryption_keys); + +void __fastcall aesni_aes256_derive_decryption_keys_( + const AesNI_Aes256_RoundKeys* encryption_keys, + AesNI_Aes256_RoundKeys* decryption_keys); + +AesNI_Block128 __fastcall aesni_aes128_encrypt_block_( + AesNI_Block128 plaintext, + const AesNI_Aes128_RoundKeys*); + +AesNI_Block128 __fastcall aesni_aes192_encrypt_block_( + AesNI_Block128 plaintext, + const AesNI_Aes192_RoundKeys*); + +AesNI_Block128 __fastcall aesni_aes256_encrypt_block_( + AesNI_Block128 plaintext, + const AesNI_Aes256_RoundKeys*); + +AesNI_Block128 __fastcall aesni_aes128_decrypt_block_( + AesNI_Block128 ciphertext, + const AesNI_Aes128_RoundKeys*); + +AesNI_Block128 __fastcall aesni_aes192_decrypt_block_( + AesNI_Block128 ciphertext, + const AesNI_Aes192_RoundKeys*); + +AesNI_Block128 __fastcall aesni_aes256_decrypt_block_( + AesNI_Block128 ciphertext, + const AesNI_Aes256_RoundKeys*); + + + + +/** + * \brief Expands a key schedule for AES-128 encryption. + * + * \param[in] key The AES-128 key. + * \param[out] key_schedule The AES-128 encryption key schedule. Must not be + * `NULL`. + */ +static __inline void __fastcall aesni_aes128_expand_key( + AesNI_Block128 key, + AesNI_Aes128_RoundKeys* key_schedule) +{ + assert(key_schedule); + + aesni_aes128_expand_key_(key, key_schedule); +} + +/** + * \brief "Inverts" an AES-128 key schedule to prepare for decryption. + * + * \param[in] key_schedule The AES-128 encryption key schedule. Must not be + * `NULL`. + * \param[out] inverted_schedule The AES-128 decryption key schedule. Must not + * be `NULL`. + */ +static __inline void __fastcall aesni_aes128_derive_decryption_keys( + const AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Aes128_RoundKeys* inverted_schedule) +{ + assert(key_schedule); + assert(inverted_schedule); + + aesni_aes128_derive_decryption_keys_(key_schedule, inverted_schedule); +} + +/** + * \brief Encrypts a 128-bit block using AES-128 in ECB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-128 encryption key schedule. Must not be + * `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ecb( + AesNI_Block128 plain, + const AesNI_Aes128_RoundKeys* key_schedule) +{ + assert(key_schedule); + + return aesni_aes128_encrypt_block_(plain, key_schedule); +} + +/** + * \brief Decrypts a 128-bit block using AES-128 in ECB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] inverted_schedule The AES-128 decryption key schedule. Must not + * be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ecb( + AesNI_Block128 cipher, + const AesNI_Aes128_RoundKeys* inverted_schedule) +{ + assert(inverted_schedule); + + return aesni_aes128_decrypt_block_(cipher, inverted_schedule); +} + +/** + * \brief Encrypts a 128-bit block using AES-128 in CBC mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-128 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CBC initialization vector. + * \param[out] next_init_vector The next CBC initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_cbc( + AesNI_Block128 plain, + const AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 cipher = aesni_aes128_encrypt_block_( + aesni_xor_block128(plain, init_vector), + key_schedule); + *next_init_vector = cipher; + return cipher; +} + +/** + * \brief Decrypts a 128-bit block using AES-128 in CBC mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] inverted_schedule The AES-128 decryption key schedule. Must not + * be `NULL`. + * \param[in] init_vector The CBC initialization vector. + * \param[out] next_init_vector The next CBC initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_cbc( + AesNI_Block128 cipher, + const AesNI_Aes128_RoundKeys* inverted_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(inverted_schedule); + assert(next_init_vector); + + AesNI_Block128 plain = aesni_xor_block128( + aesni_aes128_decrypt_block_(cipher, inverted_schedule), + init_vector); + *next_init_vector = cipher; + return plain; +} + +/** + * \brief Encrypts a 128-bit block using AES-128 in CFB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-128 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CFB initialization vector. + * \param[out] next_init_vector The next CFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_cfb( + AesNI_Block128 plain, + const AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 cipher = aesni_xor_block128( + aesni_aes128_encrypt_block_(init_vector, key_schedule), + plain); + *next_init_vector = cipher; + return cipher; +} + +/** + * \brief Decrypts a 128-bit block using AES-128 in CFB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-128 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CFB initialization vector. + * \param[out] next_init_vector The next CFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_cfb( + AesNI_Block128 cipher, + const AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 plain = aesni_xor_block128( + aesni_aes128_encrypt_block_(init_vector, key_schedule), + cipher); + *next_init_vector = cipher; + return plain; +} + +/** + * \brief Encrypts a 128-bit block using AES-128 in OFB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-128 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The OFB initialization vector. + * \param[out] next_init_vector The next OFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ofb( + AesNI_Block128 plain, + const AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 tmp = aesni_aes128_encrypt_block_(init_vector, key_schedule); + *next_init_vector = tmp; + return aesni_xor_block128(tmp, plain); +} + +/** + * \brief Decrypts a 128-bit block using AES-128 in OFB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-128 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The OFB initialization vector. + * \param[out] next_init_vector The next OFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ofb( + AesNI_Block128 cipher, + const AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 tmp = aesni_aes128_encrypt_block_(init_vector, key_schedule); + *next_init_vector = tmp; + return aesni_xor_block128(tmp, cipher); +} + +/** + * \brief Encrypts a 128-bit block using AES-128 in CTR mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-128 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CTR initialization vector. + * \param[in] counter The counter, typically incremented between consecutive + * calls. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ctr( + AesNI_Block128 plain, + const AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + int counter) +{ + assert(key_schedule); + + init_vector = aesni_be2le128(_mm_add_epi32( + aesni_le2be128(init_vector), + aesni_make_block128(0, 0, 0, counter))); + + return aesni_xor_block128( + plain, + aesni_aes128_encrypt_block_(init_vector, key_schedule)); +} + +/** + * \brief Decrypts a 128-bit block using AES-128 in CTR mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-128 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CTR initialization vector. + * \param[in] counter The counter, typically incremented between consecutive + * calls. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ctr( + AesNI_Block128 cipher, + const AesNI_Aes128_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + int counter) +{ + assert(key_schedule); + + init_vector = aesni_be2le128(_mm_add_epi32( + aesni_le2be128(init_vector), + aesni_make_block128(0, 0, 0, counter))); + + return aesni_xor_block128( + cipher, + aesni_aes128_encrypt_block_(init_vector, key_schedule)); +} + +/** + * \} + * + * \defgroup aesni_block_api_aes192 AES-192 + * \{ + */ + +/** + * \brief Expands a key schedule for AES-192 encryption. + * + * \param[in] key The AES-192 key. Must not be `NULL`. + * \param[out] key_schedule The AES-192 encryption key schedule. Must not be + * `NULL`. + */ +static __inline void __fastcall aesni_aes192_expand_key( + AesNI_Block192* key, + AesNI_Aes192_RoundKeys* key_schedule) +{ + assert(key); + assert(key_schedule); + + aesni_aes192_expand_key_(key->lo, key->hi, key_schedule); +} + +/** + * \brief "Inverts" an AES-192 key schedule to prepare for decryption. + * + * \param[in] key_schedule The AES-192 encryption key schedule. Must not be + * `NULL`. + * \param[out] inverted_schedule The AES-192 decryption key schedule. Must not + * be `NULL`. + */ +static __inline void __fastcall aesni_aes192_derive_decryption_keys( + const AesNI_Aes192_RoundKeys* key_schedule, + AesNI_Aes192_RoundKeys* inverted_schedule) +{ + assert(key_schedule); + assert(inverted_schedule); + + aesni_aes192_derive_decryption_keys_(key_schedule, inverted_schedule); +} + +/** + * \brief Encrypts a 128-bit block using AES-192 in ECB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-192 encryption key schedule. Must not be + * `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ecb( + AesNI_Block128 plain, + const AesNI_Aes192_RoundKeys* key_schedule) +{ + assert(key_schedule); + + return aesni_aes192_encrypt_block_(plain, key_schedule); +} + +/** + * \brief Decrypts a 128-bit block using AES-192 in ECB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] inverted_schedule The AES-192 decryption key schedule. Must not + * be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ecb( + AesNI_Block128 cipher, + const AesNI_Aes192_RoundKeys* inverted_schedule) +{ + assert(inverted_schedule); + + return aesni_aes192_decrypt_block_(cipher, inverted_schedule); +} + +/** + * \brief Encrypts a 128-bit block using AES-192 in CBC mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-192 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CBC initialization vector. + * \param[out] next_init_vector The next CBC initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_cbc( + AesNI_Block128 plain, + const AesNI_Aes192_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 cipher = aesni_aes192_encrypt_block_( + aesni_xor_block128(plain, init_vector), + key_schedule); + *next_init_vector = cipher; + return cipher; +} + +/** + * \brief Decrypts a 128-bit block using AES-192 in CBC mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] inverted_schedule The AES-192 decryption key schedule. Must not + * be `NULL`. + * \param[in] init_vector The CBC initialization vector. + * \param[out] next_init_vector The next CBC initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_cbc( + AesNI_Block128 cipher, + const AesNI_Aes192_RoundKeys* inverted_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(inverted_schedule); + assert(next_init_vector); + + AesNI_Block128 plain = aesni_xor_block128( + aesni_aes192_decrypt_block_(cipher, inverted_schedule), + init_vector); + *next_init_vector = cipher; + return plain; +} + +/** + * \brief Encrypts a 128-bit block using AES-192 in CFB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-192 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CFB initialization vector. + * \param[out] next_init_vector The next CFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_cfb( + AesNI_Block128 plain, + const AesNI_Aes192_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 cipher = aesni_xor_block128( + aesni_aes192_encrypt_block_(init_vector, key_schedule), + plain); + *next_init_vector = cipher; + return cipher; +} + +/** + * \brief Decrypts a 128-bit block using AES-192 in CFB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-192 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CFB initialization vector. + * \param[out] next_init_vector The next CFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_cfb( + AesNI_Block128 cipher, + const AesNI_Aes192_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 plain = aesni_xor_block128( + aesni_aes192_encrypt_block_(init_vector, key_schedule), + cipher); + *next_init_vector = cipher; + return plain; +} + +/** + * \brief Encrypts a 128-bit block using AES-192 in OFB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-192 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The OFB initialization vector. + * \param[out] next_init_vector The next OFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ofb( + AesNI_Block128 plain, + const AesNI_Aes192_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 tmp = aesni_aes192_encrypt_block_(init_vector, key_schedule); + *next_init_vector = tmp; + return aesni_xor_block128(tmp, plain); +} + +/** + * \brief Decrypts a 128-bit block using AES-192 in OFB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-192 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The OFB initialization vector. + * \param[out] next_init_vector The next OFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ofb( + AesNI_Block128 cipher, + const AesNI_Aes192_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 tmp = aesni_aes192_encrypt_block_(init_vector, key_schedule); + *next_init_vector = tmp; + return aesni_xor_block128(tmp, cipher); +} + +/** + * \brief Encrypts a 128-bit block using AES-192 in CTR mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-192 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CTR initialization vector. + * \param[in] counter The counter, typically incremented between consecutive + * calls. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ctr( + AesNI_Block128 plain, + const AesNI_Aes192_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + int counter) +{ + assert(key_schedule); + + init_vector = aesni_be2le128(_mm_add_epi32( + aesni_le2be128(init_vector), + aesni_make_block128(0, 0, 0, counter))); + + return aesni_xor_block128( + plain, + aesni_aes192_encrypt_block_(init_vector, key_schedule)); +} + +/** + * \brief Decrypts a 128-bit block using AES-192 in CTR mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-192 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CTR initialization vector. + * \param[in] counter The counter, typically incremented between consecutive + * calls. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ctr( + AesNI_Block128 cipher, + const AesNI_Aes192_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + int counter) +{ + assert(key_schedule); + + init_vector = aesni_be2le128(_mm_add_epi32( + aesni_le2be128(init_vector), + aesni_make_block128(0, 0, 0, counter))); + + return aesni_xor_block128( + cipher, + aesni_aes192_encrypt_block_(init_vector, key_schedule)); +} + +/** + * \} + * + * \defgroup aesni_block_api_aes256 AES-256 + * \{ + */ + +/** + * \brief Expands a key schedule for AES-256 encryption. + * + * \param[in] key The AES-256 key. Must not be `NULL`. + * \param[out] key_schedule The AES-256 encryption key schedule. Must not be + * `NULL`. + */ +static __inline void __fastcall aesni_aes256_expand_key( + const AesNI_Block256* key, + AesNI_Aes256_RoundKeys* key_schedule) +{ + assert(key); + assert(key_schedule); + + aesni_aes256_expand_key_(key->lo, key->hi, key_schedule); +} + +/** + * \brief "Inverts" an AES-256 key schedule to prepare for decryption. + * + * \param[in] key_schedule The AES-256 encryption key schedule. Must not be + * `NULL`. + * \param[out] inverted_schedule The AES-256 decryption key schedule. Must not + * be `NULL`. + */ +static __inline void __fastcall aesni_aes256_derive_decryption_keys( + const AesNI_Aes256_RoundKeys* key_schedule, + AesNI_Aes256_RoundKeys* inverted_schedule) +{ + assert(key_schedule); + assert(inverted_schedule); + + aesni_aes256_derive_decryption_keys_(key_schedule, inverted_schedule); +} + +/** + * \brief Encrypts a 128-bit block using AES-256 in ECB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-256 encryption key schedule. Must not be + * `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ecb( + AesNI_Block128 plain, + const AesNI_Aes256_RoundKeys* key_schedule) +{ + assert(key_schedule); + + return aesni_aes256_encrypt_block_(plain, key_schedule); +} + +/** + * \brief Decrypts a 128-bit block using AES-256 in ECB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] inverted_schedule The AES-256 decryption key schedule. Must not + * be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ecb( + AesNI_Block128 cipher, + const AesNI_Aes256_RoundKeys* inverted_schedule) +{ + assert(inverted_schedule); + + return aesni_aes256_decrypt_block_(cipher, inverted_schedule); +} + +/** + * \brief Encrypts a 128-bit block using AES-256 in CBC mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-256 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CBC initialization vector. + * \param[out] next_init_vector The next CBC initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_cbc( + AesNI_Block128 plain, + const AesNI_Aes256_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 cipher = aesni_aes256_encrypt_block_( + aesni_xor_block128(plain, init_vector), + key_schedule); + *next_init_vector = cipher; + return cipher; +} + +/** + * \brief Decrypts a 128-bit block using AES-256 in CBC mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] inverted_schedule The AES-256 decryption key schedule. Must not + * be `NULL`. + * \param[in] init_vector The CBC initialization vector. + * \param[out] next_init_vector The next CBC initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_cbc( + AesNI_Block128 cipher, + const AesNI_Aes256_RoundKeys* inverted_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(inverted_schedule); + assert(next_init_vector); + + AesNI_Block128 plain = aesni_xor_block128( + aesni_aes256_decrypt_block_(cipher, inverted_schedule), + init_vector); + *next_init_vector = cipher; + return plain; +} + +/** + * \brief Encrypts a 128-bit block using AES-256 in CFB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-256 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CFB initialization vector. + * \param[out] next_init_vector The next CFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_cfb( + AesNI_Block128 plain, + const AesNI_Aes256_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 cipher = aesni_xor_block128( + aesni_aes256_encrypt_block_(init_vector, key_schedule), + plain); + *next_init_vector = cipher; + return cipher; +} + +/** + * \brief Decrypts a 128-bit block using AES-256 in CFB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-256 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CFB initialization vector. + * \param[out] next_init_vector The next CFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_cfb( + AesNI_Block128 cipher, + const AesNI_Aes256_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 plain = aesni_xor_block128( + aesni_aes256_encrypt_block_(init_vector, key_schedule), + cipher); + *next_init_vector = cipher; + return plain; +} + +/** + * \brief Encrypts a 128-bit block using AES-256 in OFB mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-256 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The OFB initialization vector. + * \param[out] next_init_vector The next OFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ofb( + AesNI_Block128 plain, + const AesNI_Aes256_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 tmp = aesni_aes256_encrypt_block_(init_vector, key_schedule); + *next_init_vector = tmp; + return aesni_xor_block128(tmp, plain); +} + +/** + * \brief Decrypts a 128-bit block using AES-256 in OFB mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-256 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The OFB initialization vector. + * \param[out] next_init_vector The next OFB initialization vector to be used + * as the initialization vector for the next call. Must not be `NULL`. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ofb( + AesNI_Block128 cipher, + const AesNI_Aes256_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + AesNI_Block128* next_init_vector) +{ + assert(key_schedule); + assert(next_init_vector); + + AesNI_Block128 tmp = aesni_aes256_encrypt_block_(init_vector, key_schedule); + *next_init_vector = tmp; + return aesni_xor_block128(tmp, cipher); +} + +/** + * \brief Encrypts a 128-bit block using AES-256 in CTR mode of operation. + * + * \param[in] plain The plaintext to be encrypted. + * \param[in] key_schedule The AES-256 encryption key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CTR initialization vector. + * \param[in] counter The counter, typically incremented between consecutive + * calls. + * \return The encrypted 128-bit ciphertext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ctr( + AesNI_Block128 plain, + const AesNI_Aes256_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + int counter) +{ + assert(key_schedule); + + init_vector = aesni_be2le128(_mm_add_epi32( + aesni_le2be128(init_vector), + aesni_make_block128(0, 0, 0, counter))); + + return aesni_xor_block128( + plain, + aesni_aes256_encrypt_block_(init_vector, key_schedule)); +} + +/** + * \brief Decrypts a 128-bit block using AES-256 in CTR mode of operation. + * + * \param[in] cipher The ciphertext to be decrypted. + * \param[in] key_schedule The AES-256 **encryption** key schedule. Must not be + * `NULL`. + * \param[in] init_vector The CTR initialization vector. + * \param[in] counter The counter, typically incremented between consecutive + * calls. + * \return The decrypted 128-bit plaintext. + */ +static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ctr( + AesNI_Block128 cipher, + const AesNI_Aes256_RoundKeys* key_schedule, + AesNI_Block128 init_vector, + int counter) +{ + assert(key_schedule); + + init_vector = aesni_be2le128(_mm_add_epi32( + aesni_le2be128(init_vector), + aesni_make_block128(0, 0, 0, counter))); + + return aesni_xor_block128( + cipher, + aesni_aes256_encrypt_block_(init_vector, key_schedule)); +} + +#ifdef __cplusplus +} +#endif diff --git a/include/aesni/all.h b/include/aesni/all.h index 70f5e7e..26f7a41 100644 --- a/include/aesni/all.h +++ b/include/aesni/all.h @@ -15,11 +15,10 @@ * \defgroup aesni AesNI */ +#include "aes.h" #include "algorithm.h" -#include "block.h" #include "box.h" #include "buffer.h" #include "data.h" #include "error.h" #include "mode.h" -#include "raw.h" diff --git a/include/aesni/block.h b/include/aesni/block.h deleted file mode 100644 index 208e9d4..0000000 --- a/include/aesni/block.h +++ /dev/null @@ -1,933 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - * - * \brief Declares 128-bit block encryption/decryption functions. - */ - -#pragma once - -/** - * \defgroup aesni_block_api Block API - * \brief 128-bit block encryption/decryption functions. - * \ingroup aesni - * \{ - * - * For each of AES-128/192/256, two functions are defined: - * - * * a key schedule "expansion" function to prepare for encryption, - * * a key schedule "reversion" function to prepare for decryption. - * - * The functions, respectively, are: - * - * * `aesni_expand_key_scheduleNNN`, - * * `aesni_reverse_key_scheduleNNN`, - * - * where `NNN` is either `128`, `192` or `256`. - * - * For each of AES-128/192/256 and modes of operation ECB, CBC, CFB, OFB, and - * CTR, two functions are defined: - * - * * a 128-bit block encryption function, - * * a 128-bit block decryption function. - * - * The functions, respectively, are: - * - * * `aesni_encrypt_block_XXXNNN`, - * * `aesni_decrypt_block_XXXNNN`, - * - * where `XXX` is either `ecb`, `cbc`, `cfb`, `ofb` or `ctr`, and `NNN` is - * either `128`, `192` or `256`. - */ - -#include "data.h" -#include "raw.h" - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** - * \defgroup aesni_block_api_aes128 AES-128 - * \{ - */ - -/** - * \brief Expands a key schedule for AES-128 encryption. - * - * \param[in] key The AES-128 key. - * \param[out] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - */ -static __inline void __fastcall aesni_expand_key_schedule128( - AesNI_Block128 key, - AesNI_KeySchedule128* key_schedule) -{ - assert(key_schedule); - - aesni_raw_expand_key_schedule128(key, key_schedule); -} - -/** - * \brief "Inverts" an AES-128 key schedule to prepare for decryption. - * - * \param[in] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - * \param[out] inverted_schedule The AES-128 decryption key schedule. Must not - * be `NULL`. - */ -static __inline void __fastcall aesni_invert_key_schedule128( - AesNI_KeySchedule128* key_schedule, - AesNI_KeySchedule128* inverted_schedule) -{ - assert(key_schedule); - assert(inverted_schedule); - - aesni_raw_invert_key_schedule128(key_schedule, inverted_schedule); -} - -/** - * \brief Encrypts a 128-bit block using AES-128 in ECB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb128( - AesNI_Block128 plain, - AesNI_KeySchedule128* key_schedule) -{ - assert(key_schedule); - - return aesni_raw_encrypt_block128(plain, key_schedule); -} - -/** - * \brief Decrypts a 128-bit block using AES-128 in ECB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-128 decryption key schedule. Must not - * be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb128( - AesNI_Block128 cipher, - AesNI_KeySchedule128* inverted_schedule) -{ - assert(inverted_schedule); - - return aesni_raw_decrypt_block128(cipher, inverted_schedule); -} - -/** - * \brief Encrypts a 128-bit block using AES-128 in CBC mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CBC initialization vector. - * \param[out] next_init_vector The next CBC initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cbc128( - AesNI_Block128 plain, - AesNI_KeySchedule128* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 cipher = aesni_raw_encrypt_block128( - aesni_xor_block128(plain, init_vector), - key_schedule); - *next_init_vector = cipher; - return cipher; -} - -/** - * \brief Decrypts a 128-bit block using AES-128 in CBC mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-128 decryption key schedule. Must not - * be `NULL`. - * \param[in] init_vector The CBC initialization vector. - * \param[out] next_init_vector The next CBC initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc128( - AesNI_Block128 cipher, - AesNI_KeySchedule128* inverted_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(inverted_schedule); - assert(next_init_vector); - - AesNI_Block128 plain = aesni_xor_block128( - aesni_raw_decrypt_block128(cipher, inverted_schedule), - init_vector); - *next_init_vector = cipher; - return plain; -} - -/** - * \brief Encrypts a 128-bit block using AES-128 in CFB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CFB initialization vector. - * \param[out] next_init_vector The next CFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb128( - AesNI_Block128 plain, - AesNI_KeySchedule128* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 cipher = aesni_xor_block128( - aesni_raw_encrypt_block128(init_vector, key_schedule), - plain); - *next_init_vector = cipher; - return cipher; -} - -/** - * \brief Decrypts a 128-bit block using AES-128 in CFB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-128 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CFB initialization vector. - * \param[out] next_init_vector The next CFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb128( - AesNI_Block128 cipher, - AesNI_KeySchedule128* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 plain = aesni_xor_block128( - aesni_raw_encrypt_block128(init_vector, key_schedule), - cipher); - *next_init_vector = cipher; - return plain; -} - -/** - * \brief Encrypts a 128-bit block using AES-128 in OFB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The OFB initialization vector. - * \param[out] next_init_vector The next OFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ofb128( - AesNI_Block128 plain, - AesNI_KeySchedule128* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 tmp = aesni_raw_encrypt_block128(init_vector, key_schedule); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, plain); -} - -/** - * \brief Decrypts a 128-bit block using AES-128 in OFB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-128 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The OFB initialization vector. - * \param[out] next_init_vector The next OFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ofb128( - AesNI_Block128 cipher, - AesNI_KeySchedule128* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 tmp = aesni_raw_encrypt_block128(init_vector, key_schedule); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, cipher); -} - -/** - * \brief Encrypts a 128-bit block using AES-128 in CTR mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CTR initialization vector. - * \param[in] counter The counter, typically incremented between consecutive - * calls. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr128( - AesNI_Block128 plain, - AesNI_KeySchedule128* key_schedule, - AesNI_Block128 init_vector, - int counter) -{ - assert(key_schedule); - - init_vector = aesni_be2le128(_mm_add_epi32( - aesni_le2be128(init_vector), - aesni_make_block128(0, 0, 0, counter))); - - return aesni_xor_block128( - plain, - aesni_raw_encrypt_block128(init_vector, key_schedule)); -} - -/** - * \brief Decrypts a 128-bit block using AES-128 in CTR mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-128 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CTR initialization vector. - * \param[in] counter The counter, typically incremented between consecutive - * calls. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr128( - AesNI_Block128 cipher, - AesNI_KeySchedule128* key_schedule, - AesNI_Block128 init_vector, - int counter) -{ - assert(key_schedule); - - init_vector = aesni_be2le128(_mm_add_epi32( - aesni_le2be128(init_vector), - aesni_make_block128(0, 0, 0, counter))); - - return aesni_xor_block128( - cipher, - aesni_raw_encrypt_block128(init_vector, key_schedule)); -} - -/** - * \} - * - * \defgroup aesni_block_api_aes192 AES-192 - * \{ - */ - -/** - * \brief Expands a key schedule for AES-192 encryption. - * - * \param[in] key The AES-192 key. Must not be `NULL`. - * \param[out] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - */ -static __inline void __fastcall aesni_expand_key_schedule192( - AesNI_Block192* key, - AesNI_KeySchedule192* key_schedule) -{ - assert(key); - assert(key_schedule); - - aesni_raw_expand_key_schedule192(key->lo, key->hi, key_schedule); -} - -/** - * \brief "Inverts" an AES-192 key schedule to prepare for decryption. - * - * \param[in] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - * \param[out] inverted_schedule The AES-192 decryption key schedule. Must not - * be `NULL`. - */ -static __inline void __fastcall aesni_invert_key_schedule192( - AesNI_KeySchedule192* key_schedule, - AesNI_KeySchedule192* inverted_schedule) -{ - assert(key_schedule); - assert(inverted_schedule); - - aesni_raw_invert_key_schedule192(key_schedule, inverted_schedule); -} - -/** - * \brief Encrypts a 128-bit block using AES-192 in ECB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb192( - AesNI_Block128 plain, - AesNI_KeySchedule192* key_schedule) -{ - assert(key_schedule); - - return aesni_raw_encrypt_block192(plain, key_schedule); -} - -/** - * \brief Decrypts a 128-bit block using AES-192 in ECB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-192 decryption key schedule. Must not - * be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb192( - AesNI_Block128 cipher, - AesNI_KeySchedule192* inverted_schedule) -{ - assert(inverted_schedule); - - return aesni_raw_decrypt_block192(cipher, inverted_schedule); -} - -/** - * \brief Encrypts a 128-bit block using AES-192 in CBC mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CBC initialization vector. - * \param[out] next_init_vector The next CBC initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cbc192( - AesNI_Block128 plain, - AesNI_KeySchedule192* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 cipher = aesni_raw_encrypt_block192( - aesni_xor_block128(plain, init_vector), - key_schedule); - *next_init_vector = cipher; - return cipher; -} - -/** - * \brief Decrypts a 128-bit block using AES-192 in CBC mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-192 decryption key schedule. Must not - * be `NULL`. - * \param[in] init_vector The CBC initialization vector. - * \param[out] next_init_vector The next CBC initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc192( - AesNI_Block128 cipher, - AesNI_KeySchedule192* inverted_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(inverted_schedule); - assert(next_init_vector); - - AesNI_Block128 plain = aesni_xor_block128( - aesni_raw_decrypt_block192(cipher, inverted_schedule), - init_vector); - *next_init_vector = cipher; - return plain; -} - -/** - * \brief Encrypts a 128-bit block using AES-192 in CFB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CFB initialization vector. - * \param[out] next_init_vector The next CFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb192( - AesNI_Block128 plain, - AesNI_KeySchedule192* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 cipher = aesni_xor_block128( - aesni_raw_encrypt_block192(init_vector, key_schedule), - plain); - *next_init_vector = cipher; - return cipher; -} - -/** - * \brief Decrypts a 128-bit block using AES-192 in CFB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-192 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CFB initialization vector. - * \param[out] next_init_vector The next CFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb192( - AesNI_Block128 cipher, - AesNI_KeySchedule192* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 plain = aesni_xor_block128( - aesni_raw_encrypt_block192(init_vector, key_schedule), - cipher); - *next_init_vector = cipher; - return plain; -} - -/** - * \brief Encrypts a 128-bit block using AES-192 in OFB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The OFB initialization vector. - * \param[out] next_init_vector The next OFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ofb192( - AesNI_Block128 plain, - AesNI_KeySchedule192* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 tmp = aesni_raw_encrypt_block192(init_vector, key_schedule); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, plain); -} - -/** - * \brief Decrypts a 128-bit block using AES-192 in OFB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-192 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The OFB initialization vector. - * \param[out] next_init_vector The next OFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ofb192( - AesNI_Block128 cipher, - AesNI_KeySchedule192* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 tmp = aesni_raw_encrypt_block192(init_vector, key_schedule); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, cipher); -} - -/** - * \brief Encrypts a 128-bit block using AES-192 in CTR mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CTR initialization vector. - * \param[in] counter The counter, typically incremented between consecutive - * calls. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr192( - AesNI_Block128 plain, - AesNI_KeySchedule192* key_schedule, - AesNI_Block128 init_vector, - int counter) -{ - assert(key_schedule); - - init_vector = aesni_be2le128(_mm_add_epi32( - aesni_le2be128(init_vector), - aesni_make_block128(0, 0, 0, counter))); - - return aesni_xor_block128( - plain, - aesni_raw_encrypt_block192(init_vector, key_schedule)); -} - -/** - * \brief Decrypts a 128-bit block using AES-192 in CTR mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-192 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CTR initialization vector. - * \param[in] counter The counter, typically incremented between consecutive - * calls. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr192( - AesNI_Block128 cipher, - AesNI_KeySchedule192* key_schedule, - AesNI_Block128 init_vector, - int counter) -{ - assert(key_schedule); - - init_vector = aesni_be2le128(_mm_add_epi32( - aesni_le2be128(init_vector), - aesni_make_block128(0, 0, 0, counter))); - - return aesni_xor_block128( - cipher, - aesni_raw_encrypt_block192(init_vector, key_schedule)); -} - -/** - * \} - * - * \defgroup aesni_block_api_aes256 AES-256 - * \{ - */ - -/** - * \brief Expands a key schedule for AES-256 encryption. - * - * \param[in] key The AES-256 key. Must not be `NULL`. - * \param[out] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - */ -static __inline void __fastcall aesni_expand_key_schedule256( - AesNI_Block256* key, - AesNI_KeySchedule256* key_schedule) -{ - assert(key); - assert(key_schedule); - - aesni_raw_expand_key_schedule256(key->lo, key->hi, key_schedule); -} - -/** - * \brief "Inverts" an AES-256 key schedule to prepare for decryption. - * - * \param[in] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - * \param[out] inverted_schedule The AES-256 decryption key schedule. Must not - * be `NULL`. - */ -static __inline void __fastcall aesni_invert_key_schedule256( - AesNI_KeySchedule256* key_schedule, - AesNI_KeySchedule256* inverted_schedule) -{ - assert(key_schedule); - assert(inverted_schedule); - - aesni_raw_invert_key_schedule256(key_schedule, inverted_schedule); -} - -/** - * \brief Encrypts a 128-bit block using AES-256 in ECB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb256( - AesNI_Block128 plain, - AesNI_KeySchedule256* key_schedule) -{ - assert(key_schedule); - - return aesni_raw_encrypt_block256(plain, key_schedule); -} - -/** - * \brief Decrypts a 128-bit block using AES-256 in ECB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-256 decryption key schedule. Must not - * be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb256( - AesNI_Block128 cipher, - AesNI_KeySchedule256* inverted_schedule) -{ - assert(inverted_schedule); - - return aesni_raw_decrypt_block256(cipher, inverted_schedule); -} - -/** - * \brief Encrypts a 128-bit block using AES-256 in CBC mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CBC initialization vector. - * \param[out] next_init_vector The next CBC initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cbc256( - AesNI_Block128 plain, - AesNI_KeySchedule256* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 cipher = aesni_raw_encrypt_block256( - aesni_xor_block128(plain, init_vector), - key_schedule); - *next_init_vector = cipher; - return cipher; -} - -/** - * \brief Decrypts a 128-bit block using AES-256 in CBC mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-256 decryption key schedule. Must not - * be `NULL`. - * \param[in] init_vector The CBC initialization vector. - * \param[out] next_init_vector The next CBC initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc256( - AesNI_Block128 cipher, - AesNI_KeySchedule256* inverted_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(inverted_schedule); - assert(next_init_vector); - - AesNI_Block128 plain = aesni_xor_block128( - aesni_raw_decrypt_block256(cipher, inverted_schedule), - init_vector); - *next_init_vector = cipher; - return plain; -} - -/** - * \brief Encrypts a 128-bit block using AES-256 in CFB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CFB initialization vector. - * \param[out] next_init_vector The next CFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb256( - AesNI_Block128 plain, - AesNI_KeySchedule256* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 cipher = aesni_xor_block128( - aesni_raw_encrypt_block256(init_vector, key_schedule), - plain); - *next_init_vector = cipher; - return cipher; -} - -/** - * \brief Decrypts a 128-bit block using AES-256 in CFB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-256 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CFB initialization vector. - * \param[out] next_init_vector The next CFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb256( - AesNI_Block128 cipher, - AesNI_KeySchedule256* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 plain = aesni_xor_block128( - aesni_raw_encrypt_block256(init_vector, key_schedule), - cipher); - *next_init_vector = cipher; - return plain; -} - -/** - * \brief Encrypts a 128-bit block using AES-256 in OFB mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The OFB initialization vector. - * \param[out] next_init_vector The next OFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ofb256( - AesNI_Block128 plain, - AesNI_KeySchedule256* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 tmp = aesni_raw_encrypt_block256(init_vector, key_schedule); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, plain); -} - -/** - * \brief Decrypts a 128-bit block using AES-256 in OFB mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-256 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The OFB initialization vector. - * \param[out] next_init_vector The next OFB initialization vector to be used - * as the initialization vector for the next call. Must not be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ofb256( - AesNI_Block128 cipher, - AesNI_KeySchedule256* key_schedule, - AesNI_Block128 init_vector, - AesNI_Block128* next_init_vector) -{ - assert(key_schedule); - assert(next_init_vector); - - AesNI_Block128 tmp = aesni_raw_encrypt_block256(init_vector, key_schedule); - *next_init_vector = tmp; - return aesni_xor_block128(tmp, cipher); -} - -/** - * \brief Encrypts a 128-bit block using AES-256 in CTR mode of operation. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CTR initialization vector. - * \param[in] counter The counter, typically incremented between consecutive - * calls. - * \return The encrypted 128-bit ciphertext. - */ -static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr256( - AesNI_Block128 plain, - AesNI_KeySchedule256* key_schedule, - AesNI_Block128 init_vector, - int counter) -{ - assert(key_schedule); - - init_vector = aesni_be2le128(_mm_add_epi32( - aesni_le2be128(init_vector), - aesni_make_block128(0, 0, 0, counter))); - - return aesni_xor_block128( - plain, - aesni_raw_encrypt_block256(init_vector, key_schedule)); -} - -/** - * \brief Decrypts a 128-bit block using AES-256 in CTR mode of operation. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] key_schedule The AES-256 **encryption** key schedule. Must not be - * `NULL`. - * \param[in] init_vector The CTR initialization vector. - * \param[in] counter The counter, typically incremented between consecutive - * calls. - * \return The decrypted 128-bit plaintext. - */ -static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr256( - AesNI_Block128 cipher, - AesNI_KeySchedule256* key_schedule, - AesNI_Block128 init_vector, - int counter) -{ - assert(key_schedule); - - init_vector = aesni_be2le128(_mm_add_epi32( - aesni_le2be128(init_vector), - aesni_make_block128(0, 0, 0, counter))); - - return aesni_xor_block128( - cipher, - aesni_raw_encrypt_block256(init_vector, key_schedule)); -} - -/** - * \} - */ - -#ifdef __cplusplus -} -#endif - -/** - * \} - */ diff --git a/include/aesni/box.h b/include/aesni/box.h index 2ae6533..70b2787 100644 --- a/include/aesni/box.h +++ b/include/aesni/box.h @@ -20,17 +20,17 @@ extern "C" typedef union { - AesNI_KeySchedule128 aes128_key_schedule; - AesNI_KeySchedule192 aes192_key_schedule; - AesNI_KeySchedule256 aes256_key_schedule; + AesNI_Aes128_RoundKeys aes128_key_schedule; + AesNI_Aes192_RoundKeys aes192_key_schedule; + AesNI_Aes256_RoundKeys aes256_key_schedule; } AesNI_EncryptionParams; typedef union { - AesNI_KeySchedule128 aes128_key_schedule; - AesNI_KeySchedule192 aes192_key_schedule; - AesNI_KeySchedule256 aes256_key_schedule; + AesNI_Aes128_RoundKeys aes128_key_schedule; + AesNI_Aes192_RoundKeys aes192_key_schedule; + AesNI_Aes256_RoundKeys aes256_key_schedule; } AesNI_DecryptionParams; diff --git a/include/aesni/buffer.h b/include/aesni/buffer.h index 2e5ecb9..d153c1b 100644 --- a/include/aesni/buffer.h +++ b/include/aesni/buffer.h @@ -24,14 +24,14 @@ AesNI_StatusCode aesni_encrypt_buffer_ecb128( size_t src_size, void* dest, size_t* dest_size, - AesNI_KeySchedule128* key_schedule, + AesNI_Aes128_RoundKeys* key_schedule, AesNI_ErrorDetails* err_details); AesNI_StatusCode aesni_decrypt_buffer_ecb128( const void* src, size_t src_size, void* dest, size_t* dest_size, - AesNI_KeySchedule128* inverted_schedule, + AesNI_Aes128_RoundKeys* inverted_schedule, AesNI_ErrorDetails* err_details); #ifdef __cplusplus diff --git a/include/aesni/data.h b/include/aesni/data.h index fbe6e31..a6dc71f 100644 --- a/include/aesni/data.h +++ b/include/aesni/data.h @@ -204,24 +204,6 @@ static __inline AesNI_Block256 __fastcall aesni_make_block256( return result; } -typedef struct -{ - AesNI_Block128 keys[11]; -} -AesNI_KeySchedule128; - -typedef struct -{ - AesNI_Block128 keys[13]; -} -AesNI_KeySchedule192; - -typedef struct -{ - AesNI_Block128 keys[15]; -} -AesNI_KeySchedule256; - static __inline AesNI_Block128 __fastcall aesni_reverse_byte_order128(AesNI_Block128 block) { return _mm_shuffle_epi8(block, aesni_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f)); diff --git a/include/aesni/raw.h b/include/aesni/raw.h deleted file mode 100644 index 03a89e4..0000000 --- a/include/aesni/raw.h +++ /dev/null @@ -1,218 +0,0 @@ -/** - * \file - * \author Egor Tensin - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - * - * \brief *Don't use.* Declares "raw" 128-bit block encryption/decryption - * functions. - */ - -#pragma once - -/** - * \defgroup aesni_raw_api Raw API - * \brief *Don't use.* "Raw" 128-bit block encryption/decryption functions. - * \ingroup aesni - * \{ - * - * For each of AES-128/192/256, four functions are defined: - * - * * a key schedule "expansion" function to prepare for encryption, - * * a 128-bit block encryption function using the key schedule, - * * a key schedule "inversion" function to prepare for decryption, - * * a 128-bit block decryption function using the "inverted" key schedule. - * - * The functions, respectively, are: - * - * * `aesni_raw_expand_key_scheduleNNN`, - * * `aesni_raw_encrypt_blockNNN`, - * * `aesni_raw_invert_key_scheduleNNN`, - * * `aesni_raw_decrypt_blockNNN`, - * - * where `NNN` is key length (either `128`, `192` or `256`). - */ - -#include "data.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** - * \defgroup aesni_raw_api_aes128 AES-128 - * \{ - */ - -/** - * \brief Expands a key schedule for AES-128 encryption. - * - * \param[in] key The AES-128 key. - * \param[out] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - */ -void __fastcall aesni_raw_expand_key_schedule128( - AesNI_Block128 key, - AesNI_KeySchedule128* key_schedule); - -/** - * \brief "Inverts" an AES-128 key schedule to prepare for decryption. - * - * \param[in] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - * \param[out] inverted_schedule The AES-128 decryption key schedule. Must not - * be `NULL`. - */ -void __fastcall aesni_raw_invert_key_schedule128( - const AesNI_KeySchedule128* key_schedule, - AesNI_KeySchedule128* inverted_schedule); - -/** - * \brief Encrypts a 128-bit block using AES-128. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-128 encryption key schedule. Must not be - * `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -AesNI_Block128 __fastcall aesni_raw_encrypt_block128( - AesNI_Block128 plain, - const AesNI_KeySchedule128* key_schedule); - -/** - * \brief Decrypts a 128-bit block using AES-128. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-128 decryption key schedule. Must not - * be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -AesNI_Block128 __fastcall aesni_raw_decrypt_block128( - AesNI_Block128 cipher, - const AesNI_KeySchedule128* inverted_schedule); - -/** - * \} - * - * \defgroup aesni_raw_api_aes192 AES-192 - * \{ - */ - -/** - * \brief Expands a key schedule for AES-192 encryption. - * - * \param[in] key_lo The least significant part of the AES-192 key. - * \param[in] key_hi The most significant part of the AES-192 key. - * \param[out] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - */ -void __fastcall aesni_raw_expand_key_schedule192( - AesNI_Block128 key_lo, - AesNI_Block128 key_hi, - AesNI_KeySchedule192* key_schedule); - -/** - * \brief "Inverts" an AES-192 key schedule to prepare for decryption. - * - * \param[in] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - * \param[out] inverted_schedule The AES-192 decryption key schedule. Must not - * be `NULL`. - */ -void __fastcall aesni_raw_invert_key_schedule192( - const AesNI_KeySchedule192* key_schedule, - AesNI_KeySchedule192* inverted_schedule); - -/** - * \brief Encrypts a 128-bit block using AES-192. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-192 encryption key schedule. Must not be - * `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -AesNI_Block128 __fastcall aesni_raw_encrypt_block192( - AesNI_Block128 plain, - const AesNI_KeySchedule192* key_schedule); - -/** - * \brief Decrypts a 128-bit block using AES-192. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-192 decryption key schedule. Must not - * be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -AesNI_Block128 __fastcall aesni_raw_decrypt_block192( - AesNI_Block128 cipher, - const AesNI_KeySchedule192* inverted_schedule); - -/** - * \} - * - * \defgroup aesni_raw_api_aes256 AES-256 - * \{ - */ - -/** - * \brief Expands a key schedule for AES-256 encryption. - * - * \param[in] key_lo The least significant part of the AES-256 key. - * \param[in] key_hi The most significant part of the AES-256 key. - * \param[out] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - */ -void __fastcall aesni_raw_expand_key_schedule256( - AesNI_Block128 key_lo, - AesNI_Block128 key_hi, - AesNI_KeySchedule256* key_schedule); - -/** - * \brief "Inverts" a AES-256 key schedule to prepare for decryption. - * - * \param[in] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - * \param[out] inverted_schedule The AES-256 decryption key schedule. Must not - * be `NULL`. - */ -void __fastcall aesni_raw_invert_key_schedule256( - const AesNI_KeySchedule256* key_schedule, - AesNI_KeySchedule256* inverted_schedule); - -/** - * \brief Encrypts a 128-bit block using AES-256. - * - * \param[in] plain The plaintext to be encrypted. - * \param[in] key_schedule The AES-256 encryption key schedule. Must not be - * `NULL`. - * \return The encrypted 128-bit ciphertext. - */ -AesNI_Block128 __fastcall aesni_raw_encrypt_block256( - AesNI_Block128 plain, - const AesNI_KeySchedule256* key_schedule); - -/** - * \brief Decrypts a 128-bit block using AES-256. - * - * \param[in] cipher The ciphertext to be decrypted. - * \param[in] inverted_schedule The AES-256 decryption key schedule. Must not - * be `NULL`. - * \return The decrypted 128-bit plaintext. - */ -AesNI_Block128 __fastcall aesni_raw_decrypt_block256( - AesNI_Block128 cipher, - const AesNI_KeySchedule256* inverted_schedule); - -/** - * \} - */ - -#ifdef __cplusplus -} -#endif - -/** - * \} - */ -- cgit v1.2.3