aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/aesni/aes.h (renamed from include/aesni/block.h)342
-rw-r--r--include/aesni/all.h3
-rw-r--r--include/aesni/box.h12
-rw-r--r--include/aesni/buffer.h4
-rw-r--r--include/aesni/data.h18
-rw-r--r--include/aesni/raw.h218
6 files changed, 191 insertions, 406 deletions
diff --git a/include/aesni/block.h b/include/aesni/aes.h
index 208e9d4..dcee06b 100644
--- a/include/aesni/block.h
+++ b/include/aesni/aes.h
@@ -4,47 +4,11 @@
* \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 <assert.h>
@@ -53,10 +17,76 @@ extern "C"
{
#endif
-/**
- * \defgroup aesni_block_api_aes128 AES-128
- * \{
- */
+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.
@@ -65,13 +95,13 @@ extern "C"
* \param[out] key_schedule The AES-128 encryption key schedule. Must not be
* `NULL`.
*/
-static __inline void __fastcall aesni_expand_key_schedule128(
+static __inline void __fastcall aesni_aes128_expand_key(
AesNI_Block128 key,
- AesNI_KeySchedule128* key_schedule)
+ AesNI_Aes128_RoundKeys* key_schedule)
{
assert(key_schedule);
- aesni_raw_expand_key_schedule128(key, key_schedule);
+ aesni_aes128_expand_key_(key, key_schedule);
}
/**
@@ -82,14 +112,14 @@ static __inline void __fastcall aesni_expand_key_schedule128(
* \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)
+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_raw_invert_key_schedule128(key_schedule, inverted_schedule);
+ aesni_aes128_derive_decryption_keys_(key_schedule, inverted_schedule);
}
/**
@@ -100,13 +130,13 @@ static __inline void __fastcall aesni_invert_key_schedule128(
* `NULL`.
* \return The encrypted 128-bit ciphertext.
*/
-static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb128(
+static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ecb(
AesNI_Block128 plain,
- AesNI_KeySchedule128* key_schedule)
+ const AesNI_Aes128_RoundKeys* key_schedule)
{
assert(key_schedule);
- return aesni_raw_encrypt_block128(plain, key_schedule);
+ return aesni_aes128_encrypt_block_(plain, key_schedule);
}
/**
@@ -117,13 +147,13 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb128(
* be `NULL`.
* \return The decrypted 128-bit plaintext.
*/
-static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb128(
+static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ecb(
AesNI_Block128 cipher,
- AesNI_KeySchedule128* inverted_schedule)
+ const AesNI_Aes128_RoundKeys* inverted_schedule)
{
assert(inverted_schedule);
- return aesni_raw_decrypt_block128(cipher, inverted_schedule);
+ return aesni_aes128_decrypt_block_(cipher, inverted_schedule);
}
/**
@@ -137,16 +167,16 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb128(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_cbc(
AesNI_Block128 plain,
- AesNI_KeySchedule128* key_schedule,
+ 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_raw_encrypt_block128(
+ AesNI_Block128 cipher = aesni_aes128_encrypt_block_(
aesni_xor_block128(plain, init_vector),
key_schedule);
*next_init_vector = cipher;
@@ -164,9 +194,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cbc128(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_cbc(
AesNI_Block128 cipher,
- AesNI_KeySchedule128* inverted_schedule,
+ const AesNI_Aes128_RoundKeys* inverted_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -174,7 +204,7 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc128(
assert(next_init_vector);
AesNI_Block128 plain = aesni_xor_block128(
- aesni_raw_decrypt_block128(cipher, inverted_schedule),
+ aesni_aes128_decrypt_block_(cipher, inverted_schedule),
init_vector);
*next_init_vector = cipher;
return plain;
@@ -191,9 +221,9 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc128(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_cfb(
AesNI_Block128 plain,
- AesNI_KeySchedule128* key_schedule,
+ const AesNI_Aes128_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -201,7 +231,7 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb128(
assert(next_init_vector);
AesNI_Block128 cipher = aesni_xor_block128(
- aesni_raw_encrypt_block128(init_vector, key_schedule),
+ aesni_aes128_encrypt_block_(init_vector, key_schedule),
plain);
*next_init_vector = cipher;
return cipher;
@@ -218,9 +248,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb128(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_cfb(
AesNI_Block128 cipher,
- AesNI_KeySchedule128* key_schedule,
+ const AesNI_Aes128_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -228,7 +258,7 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb128(
assert(next_init_vector);
AesNI_Block128 plain = aesni_xor_block128(
- aesni_raw_encrypt_block128(init_vector, key_schedule),
+ aesni_aes128_encrypt_block_(init_vector, key_schedule),
cipher);
*next_init_vector = cipher;
return plain;
@@ -245,16 +275,16 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb128(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ofb(
AesNI_Block128 plain,
- AesNI_KeySchedule128* key_schedule,
+ 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_raw_encrypt_block128(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_aes128_encrypt_block_(init_vector, key_schedule);
*next_init_vector = tmp;
return aesni_xor_block128(tmp, plain);
}
@@ -270,16 +300,16 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ofb128(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ofb(
AesNI_Block128 cipher,
- AesNI_KeySchedule128* key_schedule,
+ 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_raw_encrypt_block128(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_aes128_encrypt_block_(init_vector, key_schedule);
*next_init_vector = tmp;
return aesni_xor_block128(tmp, cipher);
}
@@ -295,9 +325,9 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ofb128(
* calls.
* \return The encrypted 128-bit ciphertext.
*/
-static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr128(
+static __inline AesNI_Block128 __fastcall aesni_aes128_encrypt_block_ctr(
AesNI_Block128 plain,
- AesNI_KeySchedule128* key_schedule,
+ const AesNI_Aes128_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
int counter)
{
@@ -309,7 +339,7 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr128(
return aesni_xor_block128(
plain,
- aesni_raw_encrypt_block128(init_vector, key_schedule));
+ aesni_aes128_encrypt_block_(init_vector, key_schedule));
}
/**
@@ -323,9 +353,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr128(
* calls.
* \return The decrypted 128-bit plaintext.
*/
-static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr128(
+static __inline AesNI_Block128 __fastcall aesni_aes128_decrypt_block_ctr(
AesNI_Block128 cipher,
- AesNI_KeySchedule128* key_schedule,
+ const AesNI_Aes128_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
int counter)
{
@@ -337,7 +367,7 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr128(
return aesni_xor_block128(
cipher,
- aesni_raw_encrypt_block128(init_vector, key_schedule));
+ aesni_aes128_encrypt_block_(init_vector, key_schedule));
}
/**
@@ -354,14 +384,14 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr128(
* \param[out] key_schedule The AES-192 encryption key schedule. Must not be
* `NULL`.
*/
-static __inline void __fastcall aesni_expand_key_schedule192(
+static __inline void __fastcall aesni_aes192_expand_key(
AesNI_Block192* key,
- AesNI_KeySchedule192* key_schedule)
+ AesNI_Aes192_RoundKeys* key_schedule)
{
assert(key);
assert(key_schedule);
- aesni_raw_expand_key_schedule192(key->lo, key->hi, key_schedule);
+ aesni_aes192_expand_key_(key->lo, key->hi, key_schedule);
}
/**
@@ -372,14 +402,14 @@ static __inline void __fastcall aesni_expand_key_schedule192(
* \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)
+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_raw_invert_key_schedule192(key_schedule, inverted_schedule);
+ aesni_aes192_derive_decryption_keys_(key_schedule, inverted_schedule);
}
/**
@@ -390,13 +420,13 @@ static __inline void __fastcall aesni_invert_key_schedule192(
* `NULL`.
* \return The encrypted 128-bit ciphertext.
*/
-static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb192(
+static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ecb(
AesNI_Block128 plain,
- AesNI_KeySchedule192* key_schedule)
+ const AesNI_Aes192_RoundKeys* key_schedule)
{
assert(key_schedule);
- return aesni_raw_encrypt_block192(plain, key_schedule);
+ return aesni_aes192_encrypt_block_(plain, key_schedule);
}
/**
@@ -407,13 +437,13 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb192(
* be `NULL`.
* \return The decrypted 128-bit plaintext.
*/
-static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb192(
+static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ecb(
AesNI_Block128 cipher,
- AesNI_KeySchedule192* inverted_schedule)
+ const AesNI_Aes192_RoundKeys* inverted_schedule)
{
assert(inverted_schedule);
- return aesni_raw_decrypt_block192(cipher, inverted_schedule);
+ return aesni_aes192_decrypt_block_(cipher, inverted_schedule);
}
/**
@@ -427,16 +457,16 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb192(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_cbc(
AesNI_Block128 plain,
- AesNI_KeySchedule192* key_schedule,
+ 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_raw_encrypt_block192(
+ AesNI_Block128 cipher = aesni_aes192_encrypt_block_(
aesni_xor_block128(plain, init_vector),
key_schedule);
*next_init_vector = cipher;
@@ -454,9 +484,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cbc192(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_cbc(
AesNI_Block128 cipher,
- AesNI_KeySchedule192* inverted_schedule,
+ const AesNI_Aes192_RoundKeys* inverted_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -464,7 +494,7 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc192(
assert(next_init_vector);
AesNI_Block128 plain = aesni_xor_block128(
- aesni_raw_decrypt_block192(cipher, inverted_schedule),
+ aesni_aes192_decrypt_block_(cipher, inverted_schedule),
init_vector);
*next_init_vector = cipher;
return plain;
@@ -481,9 +511,9 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc192(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_cfb(
AesNI_Block128 plain,
- AesNI_KeySchedule192* key_schedule,
+ const AesNI_Aes192_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -491,7 +521,7 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb192(
assert(next_init_vector);
AesNI_Block128 cipher = aesni_xor_block128(
- aesni_raw_encrypt_block192(init_vector, key_schedule),
+ aesni_aes192_encrypt_block_(init_vector, key_schedule),
plain);
*next_init_vector = cipher;
return cipher;
@@ -508,9 +538,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb192(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_cfb(
AesNI_Block128 cipher,
- AesNI_KeySchedule192* key_schedule,
+ const AesNI_Aes192_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -518,7 +548,7 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb192(
assert(next_init_vector);
AesNI_Block128 plain = aesni_xor_block128(
- aesni_raw_encrypt_block192(init_vector, key_schedule),
+ aesni_aes192_encrypt_block_(init_vector, key_schedule),
cipher);
*next_init_vector = cipher;
return plain;
@@ -535,16 +565,16 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb192(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ofb(
AesNI_Block128 plain,
- AesNI_KeySchedule192* key_schedule,
+ 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_raw_encrypt_block192(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_aes192_encrypt_block_(init_vector, key_schedule);
*next_init_vector = tmp;
return aesni_xor_block128(tmp, plain);
}
@@ -560,16 +590,16 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ofb192(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ofb(
AesNI_Block128 cipher,
- AesNI_KeySchedule192* key_schedule,
+ 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_raw_encrypt_block192(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_aes192_encrypt_block_(init_vector, key_schedule);
*next_init_vector = tmp;
return aesni_xor_block128(tmp, cipher);
}
@@ -585,9 +615,9 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ofb192(
* calls.
* \return The encrypted 128-bit ciphertext.
*/
-static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr192(
+static __inline AesNI_Block128 __fastcall aesni_aes192_encrypt_block_ctr(
AesNI_Block128 plain,
- AesNI_KeySchedule192* key_schedule,
+ const AesNI_Aes192_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
int counter)
{
@@ -599,7 +629,7 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr192(
return aesni_xor_block128(
plain,
- aesni_raw_encrypt_block192(init_vector, key_schedule));
+ aesni_aes192_encrypt_block_(init_vector, key_schedule));
}
/**
@@ -613,9 +643,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr192(
* calls.
* \return The decrypted 128-bit plaintext.
*/
-static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr192(
+static __inline AesNI_Block128 __fastcall aesni_aes192_decrypt_block_ctr(
AesNI_Block128 cipher,
- AesNI_KeySchedule192* key_schedule,
+ const AesNI_Aes192_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
int counter)
{
@@ -627,7 +657,7 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr192(
return aesni_xor_block128(
cipher,
- aesni_raw_encrypt_block192(init_vector, key_schedule));
+ aesni_aes192_encrypt_block_(init_vector, key_schedule));
}
/**
@@ -644,14 +674,14 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr192(
* \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)
+static __inline void __fastcall aesni_aes256_expand_key(
+ const AesNI_Block256* key,
+ AesNI_Aes256_RoundKeys* key_schedule)
{
assert(key);
assert(key_schedule);
- aesni_raw_expand_key_schedule256(key->lo, key->hi, key_schedule);
+ aesni_aes256_expand_key_(key->lo, key->hi, key_schedule);
}
/**
@@ -662,14 +692,14 @@ static __inline void __fastcall aesni_expand_key_schedule256(
* \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)
+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_raw_invert_key_schedule256(key_schedule, inverted_schedule);
+ aesni_aes256_derive_decryption_keys_(key_schedule, inverted_schedule);
}
/**
@@ -680,13 +710,13 @@ static __inline void __fastcall aesni_invert_key_schedule256(
* `NULL`.
* \return The encrypted 128-bit ciphertext.
*/
-static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb256(
+static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ecb(
AesNI_Block128 plain,
- AesNI_KeySchedule256* key_schedule)
+ const AesNI_Aes256_RoundKeys* key_schedule)
{
assert(key_schedule);
- return aesni_raw_encrypt_block256(plain, key_schedule);
+ return aesni_aes256_encrypt_block_(plain, key_schedule);
}
/**
@@ -697,13 +727,13 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb256(
* be `NULL`.
* \return The decrypted 128-bit plaintext.
*/
-static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb256(
+static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ecb(
AesNI_Block128 cipher,
- AesNI_KeySchedule256* inverted_schedule)
+ const AesNI_Aes256_RoundKeys* inverted_schedule)
{
assert(inverted_schedule);
- return aesni_raw_decrypt_block256(cipher, inverted_schedule);
+ return aesni_aes256_decrypt_block_(cipher, inverted_schedule);
}
/**
@@ -717,16 +747,16 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb256(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_cbc(
AesNI_Block128 plain,
- AesNI_KeySchedule256* key_schedule,
+ 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_raw_encrypt_block256(
+ AesNI_Block128 cipher = aesni_aes256_encrypt_block_(
aesni_xor_block128(plain, init_vector),
key_schedule);
*next_init_vector = cipher;
@@ -744,9 +774,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cbc256(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_cbc(
AesNI_Block128 cipher,
- AesNI_KeySchedule256* inverted_schedule,
+ const AesNI_Aes256_RoundKeys* inverted_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -754,7 +784,7 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc256(
assert(next_init_vector);
AesNI_Block128 plain = aesni_xor_block128(
- aesni_raw_decrypt_block256(cipher, inverted_schedule),
+ aesni_aes256_decrypt_block_(cipher, inverted_schedule),
init_vector);
*next_init_vector = cipher;
return plain;
@@ -771,9 +801,9 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cbc256(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_cfb(
AesNI_Block128 plain,
- AesNI_KeySchedule256* key_schedule,
+ const AesNI_Aes256_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -781,7 +811,7 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb256(
assert(next_init_vector);
AesNI_Block128 cipher = aesni_xor_block128(
- aesni_raw_encrypt_block256(init_vector, key_schedule),
+ aesni_aes256_encrypt_block_(init_vector, key_schedule),
plain);
*next_init_vector = cipher;
return cipher;
@@ -798,9 +828,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_cfb256(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_cfb(
AesNI_Block128 cipher,
- AesNI_KeySchedule256* key_schedule,
+ const AesNI_Aes256_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
AesNI_Block128* next_init_vector)
{
@@ -808,7 +838,7 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb256(
assert(next_init_vector);
AesNI_Block128 plain = aesni_xor_block128(
- aesni_raw_encrypt_block256(init_vector, key_schedule),
+ aesni_aes256_encrypt_block_(init_vector, key_schedule),
cipher);
*next_init_vector = cipher;
return plain;
@@ -825,16 +855,16 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_cfb256(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ofb(
AesNI_Block128 plain,
- AesNI_KeySchedule256* key_schedule,
+ 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_raw_encrypt_block256(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_aes256_encrypt_block_(init_vector, key_schedule);
*next_init_vector = tmp;
return aesni_xor_block128(tmp, plain);
}
@@ -850,16 +880,16 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ofb256(
* 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(
+static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ofb(
AesNI_Block128 cipher,
- AesNI_KeySchedule256* key_schedule,
+ 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_raw_encrypt_block256(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_aes256_encrypt_block_(init_vector, key_schedule);
*next_init_vector = tmp;
return aesni_xor_block128(tmp, cipher);
}
@@ -875,9 +905,9 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ofb256(
* calls.
* \return The encrypted 128-bit ciphertext.
*/
-static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr256(
+static __inline AesNI_Block128 __fastcall aesni_aes256_encrypt_block_ctr(
AesNI_Block128 plain,
- AesNI_KeySchedule256* key_schedule,
+ const AesNI_Aes256_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
int counter)
{
@@ -889,7 +919,7 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr256(
return aesni_xor_block128(
plain,
- aesni_raw_encrypt_block256(init_vector, key_schedule));
+ aesni_aes256_encrypt_block_(init_vector, key_schedule));
}
/**
@@ -903,9 +933,9 @@ static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr256(
* calls.
* \return The decrypted 128-bit plaintext.
*/
-static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr256(
+static __inline AesNI_Block128 __fastcall aesni_aes256_decrypt_block_ctr(
AesNI_Block128 cipher,
- AesNI_KeySchedule256* key_schedule,
+ const AesNI_Aes256_RoundKeys* key_schedule,
AesNI_Block128 init_vector,
int counter)
{
@@ -917,17 +947,9 @@ static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr256(
return aesni_xor_block128(
cipher,
- aesni_raw_encrypt_block256(init_vector, key_schedule));
+ 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/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 <Egor.Tensin@gmail.com>
- * \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
-
-/**
- * \}
- */