aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-06-17 18:29:40 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-06-17 18:29:40 +0300
commit0651133db30c0932877780c2f98901e4ca1072e1 (patch)
tree2b87823b4b9f4b5a75affa4b1606abb06a598c97 /src/c
parentfactor out 128-bit XORing (diff)
downloadaes-tools-0651133db30c0932877780c2f98901e4ca1072e1.tar.gz
aes-tools-0651133db30c0932877780c2f98901e4ca1072e1.zip
refactoring
Diffstat (limited to 'src/c')
-rw-r--r--src/c/aes128.c40
-rw-r--r--src/c/aes192.c36
-rw-r--r--src/c/aes256.c46
3 files changed, 61 insertions, 61 deletions
diff --git a/src/c/aes128.c b/src/c/aes128.c
index 92bc4a6..49ebc4a 100644
--- a/src/c/aes128.c
+++ b/src/c/aes128.c
@@ -11,9 +11,9 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AesNI_Block128 __fastcall aesni_raw_encrypt_block128(
+AesNI_Block128 __fastcall aesni_aes128_encrypt_block_(
AesNI_Block128 plain,
- const AesNI_KeySchedule128* key_schedule)
+ const AesNI_Aes128_RoundKeys* key_schedule)
{
plain = _mm_xor_si128(plain, key_schedule->keys[0]);
plain = _mm_aesenc_si128(plain, key_schedule->keys[1]);
@@ -28,9 +28,9 @@ AesNI_Block128 __fastcall aesni_raw_encrypt_block128(
return _mm_aesenclast_si128(plain, key_schedule->keys[10]);
}
-AesNI_Block128 __fastcall aesni_raw_decrypt_block128(
+AesNI_Block128 __fastcall aesni_aes128_decrypt_block_(
AesNI_Block128 cipher,
- const AesNI_KeySchedule128* inverted_schedule)
+ const AesNI_Aes128_RoundKeys* inverted_schedule)
{
cipher = _mm_xor_si128(cipher, inverted_schedule->keys[0]);
cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[1]);
@@ -45,7 +45,7 @@ AesNI_Block128 __fastcall aesni_raw_decrypt_block128(
return _mm_aesdeclast_si128(cipher, inverted_schedule->keys[10]);
}
-static AesNI_Block128 __fastcall aes128_keygen_assist(
+static AesNI_Block128 __fastcall aesni_aes128_expand_key_assist(
AesNI_Block128 prev,
AesNI_Block128 hwgen)
{
@@ -64,26 +64,26 @@ static AesNI_Block128 __fastcall aes128_keygen_assist(
return prev;
}
-void __fastcall aesni_raw_expand_key_schedule128(
+void __fastcall aesni_aes128_expand_key_(
AesNI_Block128 key,
- AesNI_KeySchedule128* key_schedule)
+ AesNI_Aes128_RoundKeys* key_schedule)
{
AesNI_Block128 prev = key_schedule->keys[0] = key;
- prev = key_schedule->keys[1] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01));
- prev = key_schedule->keys[2] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x02));
- prev = key_schedule->keys[3] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x04));
- prev = key_schedule->keys[4] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x08));
- prev = key_schedule->keys[5] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x10));
- prev = key_schedule->keys[6] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x20));
- prev = key_schedule->keys[7] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x40));
- prev = key_schedule->keys[8] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x80));
- prev = key_schedule->keys[9] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x1b));
- prev = key_schedule->keys[10] = aes128_keygen_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36));
+ prev = key_schedule->keys[1] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01));
+ prev = key_schedule->keys[2] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x02));
+ prev = key_schedule->keys[3] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x04));
+ prev = key_schedule->keys[4] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x08));
+ prev = key_schedule->keys[5] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x10));
+ prev = key_schedule->keys[6] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x20));
+ prev = key_schedule->keys[7] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x40));
+ prev = key_schedule->keys[8] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x80));
+ prev = key_schedule->keys[9] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x1b));
+ prev = key_schedule->keys[10] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36));
}
-void __fastcall aesni_raw_invert_key_schedule128(
- const AesNI_KeySchedule128* key_schedule,
- AesNI_KeySchedule128* inverted_schedule)
+void __fastcall aesni_aes128_derive_decryption_keys_(
+ const AesNI_Aes128_RoundKeys* key_schedule,
+ AesNI_Aes128_RoundKeys* inverted_schedule)
{
inverted_schedule->keys[0] = key_schedule->keys[10];
inverted_schedule->keys[1] = _mm_aesimc_si128(key_schedule->keys[9]);
diff --git a/src/c/aes192.c b/src/c/aes192.c
index b3a7e9f..d6ecea1 100644
--- a/src/c/aes192.c
+++ b/src/c/aes192.c
@@ -11,9 +11,9 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AesNI_Block128 __fastcall aesni_raw_encrypt_block192(
+AesNI_Block128 __fastcall aesni_aes192_encrypt_block_(
AesNI_Block128 plain,
- const AesNI_KeySchedule192* key_schedule)
+ const AesNI_Aes192_RoundKeys* key_schedule)
{
plain = _mm_xor_si128(plain, key_schedule->keys[0]);
plain = _mm_aesenc_si128(plain, key_schedule->keys[1]);
@@ -30,9 +30,9 @@ AesNI_Block128 __fastcall aesni_raw_encrypt_block192(
return _mm_aesenclast_si128(plain, key_schedule->keys[12]);
}
-AesNI_Block128 __fastcall aesni_raw_decrypt_block192(
+AesNI_Block128 __fastcall aesni_aes192_decrypt_block_(
AesNI_Block128 cipher,
- const AesNI_KeySchedule192* inverted_schedule)
+ const AesNI_Aes192_RoundKeys* inverted_schedule)
{
cipher = _mm_xor_si128(cipher, inverted_schedule->keys[0]);
cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[1]);
@@ -49,7 +49,7 @@ AesNI_Block128 __fastcall aesni_raw_decrypt_block192(
return _mm_aesdeclast_si128(cipher, inverted_schedule->keys[12]);
}
-static void __fastcall aes192_keygen_assist(
+static void __fastcall aesni_aes192_expand_key_assist(
AesNI_Block128* prev_lo,
AesNI_Block128* prev_hi,
AesNI_Block128 hwgen)
@@ -74,49 +74,49 @@ static void __fastcall aes192_keygen_assist(
*prev_hi = _mm_xor_si128(*prev_hi, tmp);
}
-void __fastcall aesni_raw_expand_key_schedule192(
+void __fastcall aesni_aes192_expand_key_(
AesNI_Block128 key_lo,
AesNI_Block128 key_hi,
- AesNI_KeySchedule192* key_schedule)
+ AesNI_Aes192_RoundKeys* key_schedule)
{
key_schedule->keys[0] = key_lo;
key_schedule->keys[1] = key_hi;
- aes192_keygen_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x01));
+ aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x01));
key_schedule->keys[1] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule->keys[1]), _mm_castsi128_pd(key_lo), 0));
key_schedule->keys[2] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1));
- aes192_keygen_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x02));
+ aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x02));
key_schedule->keys[3] = key_lo;
key_schedule->keys[4] = key_hi;
- aes192_keygen_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x04));
+ aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x04));
key_schedule->keys[4] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule->keys[4]), _mm_castsi128_pd(key_lo), 0));
key_schedule->keys[5] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1));
- aes192_keygen_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x08));
+ aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x08));
key_schedule->keys[6] = key_lo;
key_schedule->keys[7] = key_hi;
- aes192_keygen_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x10));
+ aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x10));
key_schedule->keys[7] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule->keys[7]), _mm_castsi128_pd(key_lo), 0));
key_schedule->keys[8] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1));
- aes192_keygen_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x20));
+ aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x20));
key_schedule->keys[9] = key_lo;
key_schedule->keys[10] = key_hi;
- aes192_keygen_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x40));
+ aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x40));
key_schedule->keys[10] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_schedule->keys[10]), _mm_castsi128_pd(key_lo), 0));
key_schedule->keys[11] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1));
- aes192_keygen_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x80));
+ aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x80));
key_schedule->keys[12] = key_lo;
}
-void __fastcall aesni_raw_invert_key_schedule192(
- const AesNI_KeySchedule192* key_schedule,
- AesNI_KeySchedule192* inverted_schedule)
+void __fastcall aesni_aes192_derive_decryption_keys_(
+ const AesNI_Aes192_RoundKeys* key_schedule,
+ AesNI_Aes192_RoundKeys* inverted_schedule)
{
inverted_schedule->keys[0] = key_schedule->keys[12];
inverted_schedule->keys[1] = _mm_aesimc_si128(key_schedule->keys[11]);
diff --git a/src/c/aes256.c b/src/c/aes256.c
index cd48d0d..05e643e 100644
--- a/src/c/aes256.c
+++ b/src/c/aes256.c
@@ -11,9 +11,9 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AesNI_Block128 __fastcall aesni_raw_encrypt_block256(
+AesNI_Block128 __fastcall aesni_aes256_encrypt_block_(
AesNI_Block128 plain,
- const AesNI_KeySchedule256* key_schedule)
+ const AesNI_Aes256_RoundKeys* key_schedule)
{
plain = _mm_xor_si128(plain, key_schedule->keys[0]);
plain = _mm_aesenc_si128(plain, key_schedule->keys[1]);
@@ -32,9 +32,9 @@ AesNI_Block128 __fastcall aesni_raw_encrypt_block256(
return _mm_aesenclast_si128(plain, key_schedule->keys[14]);
}
-AesNI_Block128 __fastcall aesni_raw_decrypt_block256(
+AesNI_Block128 __fastcall aesni_aes256_decrypt_block_(
AesNI_Block128 cipher,
- const AesNI_KeySchedule256* inverted_schedule)
+ const AesNI_Aes256_RoundKeys* inverted_schedule)
{
cipher = _mm_xor_si128(cipher, inverted_schedule->keys[0]);
cipher = _mm_aesdec_si128(cipher, inverted_schedule->keys[1]);
@@ -53,7 +53,7 @@ AesNI_Block128 __fastcall aesni_raw_decrypt_block256(
return _mm_aesdeclast_si128(cipher, inverted_schedule->keys[14]);
}
-static AesNI_Block128 __fastcall aes256_keygen_assist(
+static AesNI_Block128 __fastcall aesni_aes256_expand_key_assist(
AesNI_Block128* prev_lo,
AesNI_Block128* prev_hi,
AesNI_Block128 hwgen)
@@ -76,10 +76,10 @@ static AesNI_Block128 __fastcall aes256_keygen_assist(
return *prev_hi;
}
-void __fastcall aesni_raw_expand_key_schedule256(
+void __fastcall aesni_aes256_expand_key_(
AesNI_Block128 key_lo,
AesNI_Block128 key_hi,
- AesNI_KeySchedule256* key_schedule)
+ AesNI_Aes256_RoundKeys* key_schedule)
{
AesNI_Block128 prev_lo, prev_hi;
AesNI_Block128 hwgen;
@@ -89,60 +89,60 @@ void __fastcall aesni_raw_expand_key_schedule256(
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x01);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- key_schedule->keys[2] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[2] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- key_schedule->keys[3] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[3] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x02);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- key_schedule->keys[4] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[4] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- key_schedule->keys[5] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[5] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x04);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- key_schedule->keys[6] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[6] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- key_schedule->keys[7] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[7] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x08);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- key_schedule->keys[8] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[8] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- key_schedule->keys[9] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[9] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x10);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- key_schedule->keys[10] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[10] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- key_schedule->keys[11] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[11] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x20);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- key_schedule->keys[12] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[12] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- key_schedule->keys[13] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[13] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x40);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- key_schedule->keys[14] = aes256_keygen_assist(&prev_lo, &prev_hi, hwgen);
+ key_schedule->keys[14] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
}
-void __fastcall aesni_raw_invert_key_schedule256(
- const AesNI_KeySchedule256* key_schedule,
- AesNI_KeySchedule256* inverted_schedule)
+void __fastcall aesni_aes256_derive_decryption_keys_(
+ const AesNI_Aes256_RoundKeys* key_schedule,
+ AesNI_Aes256_RoundKeys* inverted_schedule)
{
inverted_schedule->keys[0] = key_schedule->keys[14];
inverted_schedule->keys[1] = _mm_aesimc_si128(key_schedule->keys[13]);