aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/aesni/block.h408
-rw-r--r--include/aesni/buffer.h18
-rw-r--r--include/aesni/data.h156
-rw-r--r--include/aesni/raw.h76
4 files changed, 329 insertions, 329 deletions
diff --git a/include/aesni/block.h b/include/aesni/block.h
index 6de2632..7f8be7b 100644
--- a/include/aesni/block.h
+++ b/include/aesni/block.h
@@ -16,358 +16,358 @@ extern "C"
{
#endif
-static __inline void __fastcall aes128_expand_key_schedule(
- AesBlock128 key,
- Aes128KeySchedule* key_schedule)
+static __inline void __fastcall aesni_expand_key_schedule128(
+ AesNI_Block128 key,
+ AesNI_KeySchedule128* key_schedule)
{
- raw_aes128_expand_key_schedule(key, key_schedule);
+ aesni_raw_expand_key_schedule128(key, key_schedule);
}
-static __inline void __fastcall aes128_invert_key_schedule(
- Aes128KeySchedule* key_schedule,
- Aes128KeySchedule* inverted_schedule)
+static __inline void __fastcall aesni_invert_key_schedule128(
+ AesNI_KeySchedule128* key_schedule,
+ AesNI_KeySchedule128* inverted_schedule)
{
- raw_aes128_invert_key_schedule(key_schedule, inverted_schedule);
+ aesni_raw_invert_key_schedule128(key_schedule, inverted_schedule);
}
-static __inline AesBlock128 __fastcall aes128ecb_encrypt_block(
- AesBlock128 plain,
- Aes128KeySchedule* key_schedule)
+static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb128(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule128* key_schedule)
{
- return raw_aes128_encrypt_block(plain, key_schedule);
+ return aesni_raw_encrypt_block128(plain, key_schedule);
}
-static __inline AesBlock128 __fastcall aes128ecb_decrypt_block(
- AesBlock128 cipher,
- Aes128KeySchedule* inverted_schedule)
+static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb128(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule128* inverted_schedule)
{
- return raw_aes128_decrypt_block(cipher, inverted_schedule);
+ return aesni_raw_decrypt_block128(cipher, inverted_schedule);
}
-static __inline AesBlock128 __fastcall aes128cbc_encrypt_block(
- AesBlock128 plain,
- Aes128KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 cipher = raw_aes128_encrypt_block(_mm_xor_si128(plain, init_vector), key_schedule);
+ AesNI_Block128 cipher = aesni_raw_encrypt_block128(_mm_xor_si128(plain, init_vector), key_schedule);
*next_init_vector = cipher;
return cipher;
}
-static __inline AesBlock128 __fastcall aes128cbc_decrypt_block(
- AesBlock128 cipher,
- Aes128KeySchedule* inverted_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 plain = _mm_xor_si128(raw_aes128_decrypt_block(cipher, inverted_schedule), init_vector);
+ AesNI_Block128 plain = _mm_xor_si128(aesni_raw_decrypt_block128(cipher, inverted_schedule), init_vector);
*next_init_vector = cipher;
return plain;
}
-static __inline AesBlock128 __fastcall aes128cfb_encrypt_block(
- AesBlock128 plain,
- Aes128KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 cipher = _mm_xor_si128(raw_aes128_encrypt_block(init_vector, key_schedule), plain);
+ AesNI_Block128 cipher = _mm_xor_si128(aesni_raw_encrypt_block128(init_vector, key_schedule), plain);
*next_init_vector = cipher;
return cipher;
}
-static __inline AesBlock128 __fastcall aes128cfb_decrypt_block(
- AesBlock128 cipher,
- Aes128KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 plain = _mm_xor_si128(raw_aes128_encrypt_block(init_vector, key_schedule), cipher);
+ AesNI_Block128 plain = _mm_xor_si128(aesni_raw_encrypt_block128(init_vector, key_schedule), cipher);
*next_init_vector = cipher;
return plain;
}
-static __inline AesBlock128 __fastcall aes128ofb_encrypt_block(
- AesBlock128 plain,
- Aes128KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 tmp = raw_aes128_encrypt_block(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_raw_encrypt_block128(init_vector, key_schedule);
*next_init_vector = tmp;
return _mm_xor_si128(tmp, plain);
}
-static __inline AesBlock128 __fastcall aes128ofb_decrypt_block(
- AesBlock128 cipher,
- Aes128KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 tmp = raw_aes128_encrypt_block(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_raw_encrypt_block128(init_vector, key_schedule);
*next_init_vector = tmp;
return _mm_xor_si128(tmp, cipher);
}
-static __inline AesBlock128 __fastcall aes128ctr_encrypt_block(
- AesBlock128 plain,
- Aes128KeySchedule* key_schedule,
- AesBlock128 init_vector,
+static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr128(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule128* key_schedule,
+ AesNI_Block128 init_vector,
int counter)
{
- init_vector = aes128_le2be(init_vector);
- init_vector = _mm_add_epi32(init_vector, make_aes_block128(0, 0, 0, counter));
- init_vector = aes128_be2le(init_vector);
- return _mm_xor_si128(plain, raw_aes128_encrypt_block(init_vector, key_schedule));
+ init_vector = aesni_le2be128(init_vector);
+ init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter));
+ init_vector = aesni_be2le128(init_vector);
+ return _mm_xor_si128(plain, aesni_raw_encrypt_block128(init_vector, key_schedule));
}
-static __inline AesBlock128 __fastcall aes128ctr_decrypt_block(
- AesBlock128 cipher,
- Aes128KeySchedule* key_schedule,
- AesBlock128 init_vector,
+static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr128(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule128* key_schedule,
+ AesNI_Block128 init_vector,
int counter)
{
- init_vector = aes128_le2be(init_vector);
- init_vector = _mm_add_epi32(init_vector, make_aes_block128(0, 0, 0, counter));
- init_vector = aes128_be2le(init_vector);
- return _mm_xor_si128(cipher, raw_aes128_encrypt_block(init_vector, key_schedule));
+ init_vector = aesni_le2be128(init_vector);
+ init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter));
+ init_vector = aesni_be2le128(init_vector);
+ return _mm_xor_si128(cipher, aesni_raw_encrypt_block128(init_vector, key_schedule));
}
-static __inline void __fastcall aes192_expand_key_schedule(
- AesBlock192* key,
- Aes192KeySchedule* key_schedule)
+static __inline void __fastcall aesni_expand_key_schedule192(
+ AesNI_Block192* key,
+ AesNI_KeySchedule192* key_schedule)
{
- raw_aes192_expand_key_schedule(key->lo, key->hi, key_schedule);
+ aesni_raw_expand_key_schedule192(key->lo, key->hi, key_schedule);
}
-static __inline void __fastcall aes192_invert_key_schedule(
- Aes192KeySchedule* key_schedule,
- Aes192KeySchedule* inverted_schedule)
+static __inline void __fastcall aesni_invert_key_schedule192(
+ AesNI_KeySchedule192* key_schedule,
+ AesNI_KeySchedule192* inverted_schedule)
{
- raw_aes192_invert_key_schedule(key_schedule, inverted_schedule);
+ aesni_raw_invert_key_schedule192(key_schedule, inverted_schedule);
}
-static __inline AesBlock128 __fastcall aes192ecb_encrypt_block(
- AesBlock128 plain,
- Aes192KeySchedule* key_schedule)
+static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb192(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule192* key_schedule)
{
- return raw_aes192_encrypt_block(plain, key_schedule);
+ return aesni_raw_encrypt_block192(plain, key_schedule);
}
-static __inline AesBlock128 __fastcall aes192ecb_decrypt_block(
- AesBlock128 cipher,
- Aes192KeySchedule* inverted_schedule)
+static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb192(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule192* inverted_schedule)
{
- return raw_aes192_decrypt_block(cipher, inverted_schedule);
+ return aesni_raw_decrypt_block192(cipher, inverted_schedule);
}
-static __inline AesBlock128 __fastcall aes192cbc_encrypt_block(
- AesBlock128 plain,
- Aes192KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 cipher = raw_aes192_encrypt_block(_mm_xor_si128(plain, init_vector), key_schedule);
+ AesNI_Block128 cipher = aesni_raw_encrypt_block192(_mm_xor_si128(plain, init_vector), key_schedule);
*next_init_vector = cipher;
return cipher;
}
-static __inline AesBlock128 __fastcall aes192cbc_decrypt_block(
- AesBlock128 cipher,
- Aes192KeySchedule* inverted_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 plain = _mm_xor_si128(raw_aes192_decrypt_block(cipher, inverted_schedule), init_vector);
+ AesNI_Block128 plain = _mm_xor_si128(aesni_raw_decrypt_block192(cipher, inverted_schedule), init_vector);
*next_init_vector = cipher;
return plain;
}
-static __inline AesBlock128 __fastcall aes192cfb_encrypt_block(
- AesBlock128 plain,
- Aes192KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 cipher = _mm_xor_si128(raw_aes192_encrypt_block(init_vector, key_schedule), plain);
+ AesNI_Block128 cipher = _mm_xor_si128(aesni_raw_encrypt_block192(init_vector, key_schedule), plain);
*next_init_vector = cipher;
return cipher;
}
-static __inline AesBlock128 __fastcall aes192cfb_decrypt_block(
- AesBlock128 cipher,
- Aes192KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 plain = _mm_xor_si128(raw_aes192_encrypt_block(init_vector, key_schedule), cipher);
+ AesNI_Block128 plain = _mm_xor_si128(aesni_raw_encrypt_block192(init_vector, key_schedule), cipher);
*next_init_vector = cipher;
return plain;
}
-static __inline AesBlock128 __fastcall aes192ofb_encrypt_block(
- AesBlock128 plain,
- Aes192KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 tmp = raw_aes192_encrypt_block(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_raw_encrypt_block192(init_vector, key_schedule);
*next_init_vector = tmp;
return _mm_xor_si128(tmp, plain);
}
-static __inline AesBlock128 __fastcall aes192ofb_decrypt_block(
- AesBlock128 cipher,
- Aes192KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 tmp = raw_aes192_encrypt_block(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_raw_encrypt_block192(init_vector, key_schedule);
*next_init_vector = tmp;
return _mm_xor_si128(tmp, cipher);
}
-static __inline AesBlock128 __fastcall aes192ctr_encrypt_block(
- AesBlock128 plain,
- Aes192KeySchedule* key_schedule,
- AesBlock128 init_vector,
+static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr192(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule192* key_schedule,
+ AesNI_Block128 init_vector,
int counter)
{
- init_vector = aes128_le2be(init_vector);
- init_vector = _mm_add_epi32(init_vector, make_aes_block128(0, 0, 0, counter));
- init_vector = aes128_be2le(init_vector);
- return _mm_xor_si128(plain, raw_aes192_encrypt_block(init_vector, key_schedule));
+ init_vector = aesni_le2be128(init_vector);
+ init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter));
+ init_vector = aesni_be2le128(init_vector);
+ return _mm_xor_si128(plain, aesni_raw_encrypt_block192(init_vector, key_schedule));
}
-static __inline AesBlock128 __fastcall aes192ctr_decrypt_block(
- AesBlock128 cipher,
- Aes192KeySchedule* key_schedule,
- AesBlock128 init_vector,
+static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr192(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule192* key_schedule,
+ AesNI_Block128 init_vector,
int counter)
{
- init_vector = aes128_le2be(init_vector);
- init_vector = _mm_add_epi32(init_vector, make_aes_block128(0, 0, 0, counter));
- init_vector = aes128_be2le(init_vector);
- return _mm_xor_si128(cipher, raw_aes192_encrypt_block(init_vector, key_schedule));
+ init_vector = aesni_le2be128(init_vector);
+ init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter));
+ init_vector = aesni_be2le128(init_vector);
+ return _mm_xor_si128(cipher, aesni_raw_encrypt_block192(init_vector, key_schedule));
}
-static __inline void __fastcall aes256_expand_key_schedule(
- AesBlock256* key,
- Aes256KeySchedule* key_schedule)
+static __inline void __fastcall aesni_expand_key_schedule256(
+ AesNI_Block256* key,
+ AesNI_KeySchedule256* key_schedule)
{
- raw_aes256_expand_key_schedule(key->lo, key->hi, key_schedule);
+ aesni_raw_expand_key_schedule256(key->lo, key->hi, key_schedule);
}
-static __inline void __fastcall aes256_invert_key_schedule(
- Aes256KeySchedule* key_schedule,
- Aes256KeySchedule* inverted_schedule)
+static __inline void __fastcall aesni_invert_key_schedule256(
+ AesNI_KeySchedule256* key_schedule,
+ AesNI_KeySchedule256* inverted_schedule)
{
- raw_aes256_invert_key_schedule(key_schedule, inverted_schedule);
+ aesni_raw_invert_key_schedule256(key_schedule, inverted_schedule);
}
-static __inline AesBlock128 __fastcall aes256ecb_encrypt_block(
- AesBlock128 plain,
- Aes256KeySchedule* key_schedule)
+static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ecb256(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule256* key_schedule)
{
- return raw_aes256_encrypt_block(plain, key_schedule);
+ return aesni_raw_encrypt_block256(plain, key_schedule);
}
-static __inline AesBlock128 __fastcall aes256ecb_decrypt_block(
- AesBlock128 cipher,
- Aes256KeySchedule* inverted_schedule)
+static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ecb256(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule256* inverted_schedule)
{
- return raw_aes256_decrypt_block(cipher, inverted_schedule);
+ return aesni_raw_decrypt_block256(cipher, inverted_schedule);
}
-static __inline AesBlock128 __fastcall aes256cbc_encrypt_block(
- AesBlock128 plain,
- Aes256KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 cipher = raw_aes256_encrypt_block(_mm_xor_si128(plain, init_vector), key_schedule);
+ AesNI_Block128 cipher = aesni_raw_encrypt_block256(_mm_xor_si128(plain, init_vector), key_schedule);
*next_init_vector = cipher;
return cipher;
}
-static __inline AesBlock128 __fastcall aes256cbc_decrypt_block(
- AesBlock128 cipher,
- Aes256KeySchedule* inverted_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 plain = _mm_xor_si128(raw_aes256_decrypt_block(cipher, inverted_schedule), init_vector);
+ AesNI_Block128 plain = _mm_xor_si128(aesni_raw_decrypt_block256(cipher, inverted_schedule), init_vector);
*next_init_vector = cipher;
return plain;
}
-static __inline AesBlock128 __fastcall aes256cfb_encrypt_block(
- AesBlock128 plain,
- Aes256KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 cipher = _mm_xor_si128(raw_aes256_encrypt_block(init_vector, key_schedule), plain);
+ AesNI_Block128 cipher = _mm_xor_si128(aesni_raw_encrypt_block256(init_vector, key_schedule), plain);
*next_init_vector = cipher;
return cipher;
}
-static __inline AesBlock128 __fastcall aes256cfb_decrypt_block(
- AesBlock128 cipher,
- Aes256KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 plain = _mm_xor_si128(raw_aes256_encrypt_block(init_vector, key_schedule), cipher);
+ AesNI_Block128 plain = _mm_xor_si128(aesni_raw_encrypt_block256(init_vector, key_schedule), cipher);
*next_init_vector = cipher;
return plain;
}
-static __inline AesBlock128 __fastcall aes256ofb_encrypt_block(
- AesBlock128 plain,
- Aes256KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 tmp = raw_aes256_encrypt_block(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_raw_encrypt_block256(init_vector, key_schedule);
*next_init_vector = tmp;
return _mm_xor_si128(tmp, plain);
}
-static __inline AesBlock128 __fastcall aes256ofb_decrypt_block(
- AesBlock128 cipher,
- Aes256KeySchedule* key_schedule,
- AesBlock128 init_vector,
- AesBlock128* next_init_vector)
+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)
{
- AesBlock128 tmp = raw_aes256_encrypt_block(init_vector, key_schedule);
+ AesNI_Block128 tmp = aesni_raw_encrypt_block256(init_vector, key_schedule);
*next_init_vector = tmp;
return _mm_xor_si128(tmp, cipher);
}
-static __inline AesBlock128 __fastcall aes256ctr_encrypt_block(
- AesBlock128 plain,
- Aes256KeySchedule* key_schedule,
- AesBlock128 init_vector,
+static __inline AesNI_Block128 __fastcall aesni_encrypt_block_ctr256(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule256* key_schedule,
+ AesNI_Block128 init_vector,
int counter)
{
- init_vector = aes128_le2be(init_vector);
- init_vector = _mm_add_epi32(init_vector, make_aes_block128(0, 0, 0, counter));
- init_vector = aes128_be2le(init_vector);
- return _mm_xor_si128(plain, raw_aes256_encrypt_block(init_vector, key_schedule));
+ init_vector = aesni_le2be128(init_vector);
+ init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter));
+ init_vector = aesni_be2le128(init_vector);
+ return _mm_xor_si128(plain, aesni_raw_encrypt_block256(init_vector, key_schedule));
}
-static __inline AesBlock128 __fastcall aes256ctr_decrypt_block(
- AesBlock128 cipher,
- Aes256KeySchedule* key_schedule,
- AesBlock128 init_vector,
+static __inline AesNI_Block128 __fastcall aesni_decrypt_block_ctr256(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule256* key_schedule,
+ AesNI_Block128 init_vector,
int counter)
{
- init_vector = aes128_le2be(init_vector);
- init_vector = _mm_add_epi32(init_vector, make_aes_block128(0, 0, 0, counter));
- init_vector = aes128_be2le(init_vector);
- return _mm_xor_si128(cipher, raw_aes256_encrypt_block(init_vector, key_schedule));
+ init_vector = aesni_le2be128(init_vector);
+ init_vector = _mm_add_epi32(init_vector, aesni_make_block128(0, 0, 0, counter));
+ init_vector = aesni_be2le128(init_vector);
+ return _mm_xor_si128(cipher, aesni_raw_encrypt_block256(init_vector, key_schedule));
}
#ifdef __cplusplus
diff --git a/include/aesni/buffer.h b/include/aesni/buffer.h
index c0a3805..daafc3e 100644
--- a/include/aesni/buffer.h
+++ b/include/aesni/buffer.h
@@ -8,23 +8,23 @@
#pragma once
-#include <stdio.h>
+#include <stdlib.h>
#ifdef __cplusplus
extern "C"
{
#endif
-size_t aes128ecb_encrypt_buffer(
- const unsigned char* src,
+size_t aesni_encrypt_buffer_ecb128(
+ const void* src,
size_t src_size,
- unsigned char* dest,
- Aes128KeySchedule* key_schedule);
-size_t aes128ecb_decrypt_buffer(
- const unsigned char* src,
+ void* dest,
+ AesNI_KeySchedule128* key_schedule);
+size_t aesni_decrypt_buffer_ecb128(
+ const void* src,
size_t src_size,
- unsigned char* dest,
- Aes128KeySchedule* inverted_schedule);
+ void* dest,
+ AesNI_KeySchedule128* inverted_schedule);
#ifdef __cplusplus
}
diff --git a/include/aesni/data.h b/include/aesni/data.h
index d104f9d..de03110 100644
--- a/include/aesni/data.h
+++ b/include/aesni/data.h
@@ -16,146 +16,146 @@ extern "C"
{
#endif
-typedef __m128i AesBlock128;
+typedef __m128i AesNI_Block128;
-static __inline AesBlock128 load_aes_block128(const unsigned char* src)
+static __inline AesNI_Block128 aesni_load_block128(const void* src)
{
- return _mm_loadu_si128((AesBlock128*) src);
+ return _mm_loadu_si128((AesNI_Block128*) src);
}
-static __inline void __fastcall store_aes_block128(AesBlock128 block,
- unsigned char* dest)
+static __inline void __fastcall aesni_store_block128(
+ void* dest, AesNI_Block128 block)
{
- _mm_storeu_si128((AesBlock128*) dest, block);
+ _mm_storeu_si128((AesNI_Block128*) dest, block);
}
-static __inline AesBlock128 __fastcall make_aes_block128(int hi3, int hi2, int lo1, int lo0)
+static __inline AesNI_Block128 __fastcall aesni_make_block128(int hi3, int hi2, int lo1, int lo0)
{
return _mm_set_epi32(hi3, hi2, lo1, lo0);
}
typedef struct
{
- AesBlock128 hi;
- AesBlock128 lo;
+ AesNI_Block128 hi;
+ AesNI_Block128 lo;
}
-AesBlock192;
+AesNI_Block192;
-static __inline AesBlock192 __fastcall make_aes_block192(int hi5, int hi4, int lo3, int lo2, int lo1, int lo0)
+static __inline AesNI_Block192 __fastcall aesni_make_block192(int hi5, int hi4, int lo3, int lo2, int lo1, int lo0)
{
- AesBlock192 result;
- result.hi = make_aes_block128( 0, 0, hi5, hi4);
- result.lo = make_aes_block128(lo3, lo2, lo1, lo0);
+ AesNI_Block192 result;
+ result.hi = aesni_make_block128( 0, 0, hi5, hi4);
+ result.lo = aesni_make_block128(lo3, lo2, lo1, lo0);
return result;
}
typedef struct
{
- AesBlock128 hi;
- AesBlock128 lo;
+ AesNI_Block128 hi;
+ AesNI_Block128 lo;
}
-AesBlock256;
+AesNI_Block256;
-static __inline AesBlock256 __fastcall make_aes_block256(int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0)
+static __inline AesNI_Block256 __fastcall aesni_make_block256(int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0)
{
- AesBlock256 result;
- result.hi = make_aes_block128(hi7, hi6, hi5, hi4);
- result.lo = make_aes_block128(lo3, lo2, lo1, lo0);
+ AesNI_Block256 result;
+ result.hi = aesni_make_block128(hi7, hi6, hi5, hi4);
+ result.lo = aesni_make_block128(lo3, lo2, lo1, lo0);
return result;
}
typedef struct
{
- AesBlock128 keys[11];
+ AesNI_Block128 keys[11];
}
-Aes128KeySchedule;
+AesNI_KeySchedule128;
typedef struct
{
- AesBlock128 keys[13];
+ AesNI_Block128 keys[13];
}
-Aes192KeySchedule;
+AesNI_KeySchedule192;
typedef struct
{
- AesBlock128 keys[15];
+ AesNI_Block128 keys[15];
}
-Aes256KeySchedule;
+AesNI_KeySchedule256;
-static __inline AesBlock128 __fastcall aes128_reverse_byte_order(AesBlock128 block)
+static __inline AesNI_Block128 __fastcall aesni_reverse_byte_order128(AesNI_Block128 block)
{
- return _mm_shuffle_epi8(block, make_aes_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f));
+ return _mm_shuffle_epi8(block, aesni_make_block128(0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f));
}
-static __inline AesBlock128 __fastcall aes128_le2be(AesBlock128 block)
+static __inline AesNI_Block128 __fastcall aesni_le2be128(AesNI_Block128 block)
{
- return aes128_reverse_byte_order(block);
+ return aesni_reverse_byte_order128(block);
}
-static __inline AesBlock128 __fastcall aes128_be2le(AesBlock128 block)
+static __inline AesNI_Block128 __fastcall aesni_be2le128(AesNI_Block128 block)
{
- return aes128_reverse_byte_order(block);
+ return aesni_reverse_byte_order128(block);
}
-typedef struct { char str[33]; } AesBlockString128;
-typedef struct { char str[49]; } AesBlockString192;
-typedef struct { char str[65]; } AesBlockString256;
+typedef struct { char str[33]; } AesNI_BlockString128;
+typedef struct { char str[49]; } AesNI_BlockString192;
+typedef struct { char str[65]; } AesNI_BlockString256;
-AesBlockString128 format_aes_block128(AesBlock128*);
-AesBlockString192 format_aes_block192(AesBlock192*);
-AesBlockString256 format_aes_block256(AesBlock256*);
+AesNI_BlockString128 aesni_format_block128(AesNI_Block128*);
+AesNI_BlockString192 aesni_format_block192(AesNI_Block192*);
+AesNI_BlockString256 aesni_format_block256(AesNI_Block256*);
-AesBlockString128 format_aes_block128_le(AesBlock128*);
-AesBlockString192 format_aes_block192_le(AesBlock192*);
-AesBlockString256 format_aes_block256_le(AesBlock256*);
+AesNI_BlockString128 aesni_format_block128_le(AesNI_Block128*);
+AesNI_BlockString192 aesni_format_block192_le(AesNI_Block192*);
+AesNI_BlockString256 aesni_format_block256_le(AesNI_Block256*);
-AesBlockString128 format_aes_block128_be(AesBlock128*);
-AesBlockString192 format_aes_block192_be(AesBlock192*);
-AesBlockString256 format_aes_block256_be(AesBlock256*);
+AesNI_BlockString128 aesni_format_block128_be(AesNI_Block128*);
+AesNI_BlockString192 aesni_format_block192_be(AesNI_Block192*);
+AesNI_BlockString256 aesni_format_block256_be(AesNI_Block256*);
-typedef struct { char str[49]; } AesBlockMatrixString128;
-typedef struct { char str[73]; } AesBlockMatrixString192;
-typedef struct { char str[97]; } AesBlockMatrixString256;
+typedef struct { char str[49]; } AesNI_BlockMatrixString128;
+typedef struct { char str[73]; } AesNI_BlockMatrixString192;
+typedef struct { char str[97]; } AesNI_BlockMatrixString256;
-AesBlockMatrixString128 format_aes_block128_as_matrix(AesBlock128*);
-AesBlockMatrixString192 format_aes_block192_as_matrix(AesBlock192*);
-AesBlockMatrixString256 format_aes_block256_as_matrix(AesBlock256*);
+AesNI_BlockMatrixString128 aesni_format_block128_as_matrix(AesNI_Block128*);
+AesNI_BlockMatrixString192 aesni_format_block192_as_matrix(AesNI_Block192*);
+AesNI_BlockMatrixString256 aesni_format_block256_as_matrix(AesNI_Block256*);
-AesBlockMatrixString128 format_aes_block128_be_as_matrix(AesBlock128*);
-AesBlockMatrixString192 format_aes_block192_be_as_matrix(AesBlock192*);
-AesBlockMatrixString256 format_aes_block256_be_as_matrix(AesBlock256*);
+AesNI_BlockMatrixString128 aesni_format_block128_be_as_matrix(AesNI_Block128*);
+AesNI_BlockMatrixString192 aesni_format_block192_be_as_matrix(AesNI_Block192*);
+AesNI_BlockMatrixString256 aesni_format_block256_be_as_matrix(AesNI_Block256*);
-void print_aes_block128(AesBlock128*);
-void print_aes_block192(AesBlock192*);
-void print_aes_block256(AesBlock256*);
+void aesni_print_block128(AesNI_Block128*);
+void aesni_print_block192(AesNI_Block192*);
+void aesni_print_block256(AesNI_Block256*);
-void print_aes_block128_le(AesBlock128*);
-void print_aes_block192_le(AesBlock192*);
-void print_aes_block256_le(AesBlock256*);
+void aesni_print_block128_le(AesNI_Block128*);
+void aesni_print_block192_le(AesNI_Block192*);
+void aesni_print_block256_le(AesNI_Block256*);
-void print_aes_block128_be(AesBlock128*);
-void print_aes_block192_be(AesBlock192*);
-void print_aes_block256_be(AesBlock256*);
+void aesni_print_block128_be(AesNI_Block128*);
+void aesni_print_block192_be(AesNI_Block192*);
+void aesni_print_block256_be(AesNI_Block256*);
-void print_aes_block128_as_matrix(AesBlock128*);
-void print_aes_block192_as_matrix(AesBlock192*);
-void print_aes_block256_as_matrix(AesBlock256*);
+void aesni_print_block128_as_matrix(AesNI_Block128*);
+void aesni_print_block192_as_matrix(AesNI_Block192*);
+void aesni_print_block256_as_matrix(AesNI_Block256*);
-void print_aes_block128_be_as_matrix(AesBlock128*);
-void print_aes_block192_be_as_matrix(AesBlock192*);
-void print_aes_block256_be_as_matrix(AesBlock256*);
+void aesni_print_block128_be_as_matrix(AesNI_Block128*);
+void aesni_print_block192_be_as_matrix(AesNI_Block192*);
+void aesni_print_block256_be_as_matrix(AesNI_Block256*);
-int parse_aes_block128(AesBlock128*, const char*);
-int parse_aes_block192(AesBlock192*, const char*);
-int parse_aes_block256(AesBlock256*, const char*);
+int aesni_parse_block128(AesNI_Block128*, const char*);
+int aesni_parse_block192(AesNI_Block192*, const char*);
+int aesni_parse_block256(AesNI_Block256*, const char*);
-int parse_aes_block128_le(AesBlock128*, const char*);
-int parse_aes_block192_le(AesBlock192*, const char*);
-int parse_aes_block256_le(AesBlock256*, const char*);
+int aesni_parse_block128_le(AesNI_Block128*, const char*);
+int aesni_parse_block192_le(AesNI_Block192*, const char*);
+int aesni_parse_block256_le(AesNI_Block256*, const char*);
-int parse_aes_block128_be(AesBlock128*, const char*);
-int parse_aes_block192_be(AesBlock192*, const char*);
-int parse_aes_block256_be(AesBlock256*, const char*);
+int aesni_parse_block128_be(AesNI_Block128*, const char*);
+int aesni_parse_block192_be(AesNI_Block192*, const char*);
+int aesni_parse_block256_be(AesNI_Block256*, const char*);
#ifdef __cplusplus
}
diff --git a/include/aesni/raw.h b/include/aesni/raw.h
index 562ac0c..4432231 100644
--- a/include/aesni/raw.h
+++ b/include/aesni/raw.h
@@ -15,49 +15,49 @@ extern "C"
{
#endif
-void __fastcall raw_aes128_expand_key_schedule(
- AesBlock128 key,
- Aes128KeySchedule* key_schedule);
-void __fastcall raw_aes128_invert_key_schedule(
- Aes128KeySchedule* key_schedule,
- Aes128KeySchedule* inverted_schedule);
+void __fastcall aesni_raw_expand_key_schedule128(
+ AesNI_Block128 key,
+ AesNI_KeySchedule128* key_schedule);
+void __fastcall aesni_raw_invert_key_schedule128(
+ AesNI_KeySchedule128* key_schedule,
+ AesNI_KeySchedule128* inverted_schedule);
-AesBlock128 __fastcall raw_aes128_encrypt_block(
- AesBlock128 plain,
- Aes128KeySchedule* key_schedule);
-AesBlock128 __fastcall raw_aes128_decrypt_block(
- AesBlock128 cipher,
- Aes128KeySchedule* inverted_schedule);
+AesNI_Block128 __fastcall aesni_raw_encrypt_block128(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule128* key_schedule);
+AesNI_Block128 __fastcall aesni_raw_decrypt_block128(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule128* inverted_schedule);
-void __fastcall raw_aes192_expand_key_schedule(
- AesBlock128 key_lo,
- AesBlock128 key_hi,
- Aes192KeySchedule* key_schedule);
-void __fastcall raw_aes192_invert_key_schedule(
- Aes192KeySchedule* key_schedule,
- Aes192KeySchedule* inverted_schedule);
+void __fastcall aesni_raw_expand_key_schedule192(
+ AesNI_Block128 key_lo,
+ AesNI_Block128 key_hi,
+ AesNI_KeySchedule192* key_schedule);
+void __fastcall aesni_raw_invert_key_schedule192(
+ AesNI_KeySchedule192* key_schedule,
+ AesNI_KeySchedule192* inverted_schedule);
-AesBlock128 __fastcall raw_aes192_encrypt_block(
- AesBlock128 plain,
- Aes192KeySchedule* key_schedule);
-AesBlock128 __fastcall raw_aes192_decrypt_block(
- AesBlock128 cipher,
- Aes192KeySchedule* inverted_schedule);
+AesNI_Block128 __fastcall aesni_raw_encrypt_block192(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule192* key_schedule);
+AesNI_Block128 __fastcall aesni_raw_decrypt_block192(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule192* inverted_schedule);
-void __fastcall raw_aes256_expand_key_schedule(
- AesBlock128 key_lo,
- AesBlock128 key_hi,
- Aes256KeySchedule* key_schedule);
-void __fastcall raw_aes256_invert_key_schedule(
- Aes256KeySchedule* key_schedule,
- Aes256KeySchedule* inverted_schedule);
+void __fastcall aesni_raw_expand_key_schedule256(
+ AesNI_Block128 key_lo,
+ AesNI_Block128 key_hi,
+ AesNI_KeySchedule256* key_schedule);
+void __fastcall aesni_raw_invert_key_schedule256(
+ AesNI_KeySchedule256* key_schedule,
+ AesNI_KeySchedule256* inverted_schedule);
-AesBlock128 __fastcall raw_aes256_encrypt_block(
- AesBlock128 plain,
- Aes256KeySchedule* key_schedule);
-AesBlock128 __fastcall raw_aes256_decrypt_block(
- AesBlock128 cipher,
- Aes256KeySchedule* inverted_schedule);
+AesNI_Block128 __fastcall aesni_raw_encrypt_block256(
+ AesNI_Block128 plain,
+ AesNI_KeySchedule256* key_schedule);
+AesNI_Block128 __fastcall aesni_raw_decrypt_block256(
+ AesNI_Block128 cipher,
+ AesNI_KeySchedule256* inverted_schedule);
#ifdef __cplusplus
}