diff options
Diffstat (limited to '')
-rw-r--r-- | examples/aes192_example.c | 21 | ||||
-rw-r--r-- | examples/aes256cbc_example.c | 25 | ||||
-rw-r--r-- | examples/aes256ecb_example.c | 21 | ||||
-rw-r--r-- | include/aesni/all.h | 1 | ||||
-rw-r--r-- | include/aesni/api.h | 70 | ||||
-rw-r--r-- | include/aesni/raw.h | 16 | ||||
-rw-r--r-- | src/aes128.asm | 8 | ||||
-rw-r--r-- | src/aes192.asm | 10 | ||||
-rw-r--r-- | src/aes256cbc.asm | 10 | ||||
-rw-r--r-- | src/aes256ecb.asm | 10 |
10 files changed, 121 insertions, 71 deletions
diff --git a/examples/aes192_example.c b/examples/aes192_example.c index a310ab2..c936ab7 100644 --- a/examples/aes192_example.c +++ b/examples/aes192_example.c @@ -13,33 +13,26 @@ int main() { __declspec(align(16)) AesBlock128 plain, cypher, decrypted; - __declspec(align(16)) AesBlock128 key_low, key_high; + __declspec(align(16)) AesBlock192 key; - plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); - key_low = make_aes_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); - key_high = make_aes_block128( 0, 0, 0x17161514, 0x13121110); + plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); + key = make_aes_block192(0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); printf("Plain: %s\n", format_aes_block128(&plain).str); printf(" %s\n", format_aes_block128_fips_style(&plain).str); print_aes_block128_fips_matrix_style(&plain); printf("\n"); - printf("Key (low): %s\n", format_aes_block128(&key_low).str); - printf(" %s\n", format_aes_block128_fips_style(&key_low).str); - print_aes_block128_fips_matrix_style(&key_low); + printf("Key: %s\n", format_aes_block192(&key).str); + printf(" %s\n", format_aes_block192_fips_style(&key).str); - printf("\n"); - printf("Key (high): %s\n", format_aes_block128(&key_high).str); - printf(" %s\n", format_aes_block128_fips_style(&key_high).str); - print_aes_block128_fips_matrix_style(&key_high); - - cypher = aes192ecb_encrypt(plain, key_low, key_high); + cypher = aes192ecb_encrypt(plain, &key); printf("\n"); printf("Cypher: %s\n", format_aes_block128(&cypher).str); printf(" %s\n", format_aes_block128_fips_style(&cypher).str); print_aes_block128_fips_matrix_style(&cypher); - decrypted = aes192ecb_decrypt(cypher, key_low, key_high); + decrypted = aes192ecb_decrypt(cypher, &key); printf("\n"); printf("Decrypted: %s\n", format_aes_block128(&decrypted).str); printf(" %s\n", format_aes_block128_fips_style(&decrypted).str); diff --git a/examples/aes256cbc_example.c b/examples/aes256cbc_example.c index 2847f41..4ce50d9 100644 --- a/examples/aes256cbc_example.c +++ b/examples/aes256cbc_example.c @@ -12,40 +12,33 @@ int main() { - __declspec(align(16)) AesBlock128 plain, cypher, decrypted; - __declspec(align(16)) AesBlock128 key_low, key_high, iv; + __declspec(align(16)) AesBlock128 plain, cypher, decrypted, iv; + __declspec(align(16)) AesBlock256 key; - plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); - key_low = make_aes_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); - key_high = make_aes_block128(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110); - iv = make_aes_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210); + plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); + key = make_aes_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); + iv = make_aes_block128(0xfedcba98, 0x76543210, 0xfedcba98, 0x76543210); printf("Plain: %s\n", format_aes_block128(&plain).str); printf(" %s\n", format_aes_block128_fips_style(&plain).str); print_aes_block128_fips_matrix_style(&plain); printf("\n"); - printf("Key (low): %s\n", format_aes_block128(&key_low).str); - printf(" %s\n", format_aes_block128_fips_style(&key_low).str); - print_aes_block128_fips_matrix_style(&key_low); - - printf("\n"); - printf("Key (high): %s\n", format_aes_block128(&key_high).str); - printf(" %s\n", format_aes_block128_fips_style(&key_high).str); - print_aes_block128_fips_matrix_style(&key_high); + printf("Key: %s\n", format_aes_block256(&key).str); + printf(" %s\n", format_aes_block256_fips_style(&key).str); printf("\n"); printf("Initialization vector: %s\n", format_aes_block128(&iv).str); printf(" %s\n", format_aes_block128_fips_style(&iv).str); print_aes_block128_fips_matrix_style(&iv); - cypher = aes256cbc_encrypt(plain, key_low, key_high, &iv); + cypher = aes256cbc_encrypt(plain, &key, &iv); printf("\n"); printf("Cypher: %s\n", format_aes_block128(&cypher).str); printf(" %s\n", format_aes_block128_fips_style(&cypher).str); print_aes_block128_fips_matrix_style(&cypher); - decrypted = aes256cbc_decrypt(cypher, key_low, key_high, &iv); + decrypted = aes256cbc_decrypt(cypher, &key, &iv); printf("\n"); printf("Decrypted: %s\n", format_aes_block128(&decrypted).str); printf(" %s\n", format_aes_block128_fips_style(&decrypted).str); diff --git a/examples/aes256ecb_example.c b/examples/aes256ecb_example.c index c15082d..fe7f9b9 100644 --- a/examples/aes256ecb_example.c +++ b/examples/aes256ecb_example.c @@ -13,33 +13,26 @@ int main() { __declspec(align(16)) AesBlock128 plain, cypher, decrypted; - __declspec(align(16)) AesBlock128 key_low, key_high; + __declspec(align(16)) AesBlock256 key; - plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); - key_low = make_aes_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); - key_high = make_aes_block128(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110); + plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); + key = make_aes_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); printf("Plain: %s\n", format_aes_block128(&plain).str); printf(" %s\n", format_aes_block128_fips_style(&plain).str); print_aes_block128_fips_matrix_style(&plain); printf("\n"); - printf("Key (low): %s\n", format_aes_block128(&key_low).str); - printf(" %s\n", format_aes_block128_fips_style(&key_low).str); - print_aes_block128_fips_matrix_style(&key_low); + printf("Key: %s\n", format_aes_block256(&key).str); + printf(" %s\n", format_aes_block256_fips_style(&key).str); - printf("\n"); - printf("Key (high): %s\n", format_aes_block128(&key_high).str); - printf(" %s\n", format_aes_block128_fips_style(&key_high).str); - print_aes_block128_fips_matrix_style(&key_high); - - cypher = aes256ecb_encrypt(plain, key_low, key_high); + cypher = aes256ecb_encrypt(plain, &key); printf("\n"); printf("Cypher: %s\n", format_aes_block128(&cypher).str); printf(" %s\n", format_aes_block128_fips_style(&cypher).str); print_aes_block128_fips_matrix_style(&cypher); - decrypted = aes256ecb_decrypt(cypher, key_low, key_high); + decrypted = aes256ecb_decrypt(cypher, &key); printf("\n"); printf("Decrypted: %s\n", format_aes_block128(&decrypted).str); printf(" %s\n", format_aes_block128_fips_style(&decrypted).str); diff --git a/include/aesni/all.h b/include/aesni/all.h index f16d2a6..3935d2a 100644 --- a/include/aesni/all.h +++ b/include/aesni/all.h @@ -8,5 +8,6 @@ #pragma once +#include "api.h" #include "data.h" #include "raw.h" diff --git a/include/aesni/api.h b/include/aesni/api.h new file mode 100644 index 0000000..64d169c --- /dev/null +++ b/include/aesni/api.h @@ -0,0 +1,70 @@ +/** + * \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. + */ + +#pragma once + +#include "data.h" +#include "raw.h" + +static __inline AesBlock128 __fastcall aes128ecb_encrypt( + AesBlock128 plain, + AesBlock128 key) +{ + return raw_aes128ecb_encrypt(plain, key); +} + +static __inline AesBlock128 __fastcall aes128ecb_decrypt( + AesBlock128 cypher, + AesBlock128 key) +{ + return raw_aes128ecb_decrypt(cypher, key); +} + +static __inline AesBlock128 __fastcall aes192ecb_encrypt( + AesBlock128 plain, + AesBlock192* key) +{ + return raw_aes192ecb_encrypt(plain, key->lo, key->hi); +} + +static __inline AesBlock128 __fastcall aes192ecb_decrypt( + AesBlock128 cypher, + AesBlock192* key) +{ + return raw_aes192ecb_decrypt(cypher, key->lo, key->hi); +} + +static __inline AesBlock128 __fastcall aes256ecb_encrypt( + AesBlock128 plain, + AesBlock256* key) +{ + return raw_aes256ecb_encrypt(plain, key->lo, key->hi); +} + +static __inline AesBlock128 __fastcall aes256ecb_decrypt( + AesBlock128 cypher, + AesBlock256* key) +{ + return raw_aes256ecb_decrypt(cypher, key->lo, key->hi); +} + +static __inline AesBlock128 __fastcall aes256cbc_encrypt( + AesBlock128 plain, + AesBlock256* key, + AesBlock128* initialization_vector) +{ + return raw_aes256cbc_encrypt(plain, key->lo, key->hi, initialization_vector); +} + +static __inline AesBlock128 __fastcall aes256cbc_decrypt( + AesBlock128 cypher, + AesBlock256* key, + AesBlock128* initialization_vector) +{ + return raw_aes256cbc_decrypt(cypher, key->lo, key->hi, initialization_vector); +} diff --git a/include/aesni/raw.h b/include/aesni/raw.h index 9ee6ae9..d648cac 100644 --- a/include/aesni/raw.h +++ b/include/aesni/raw.h @@ -10,37 +10,37 @@ #include "data.h" -AesBlock128 __fastcall aes128ecb_encrypt( +AesBlock128 __fastcall raw_aes128ecb_encrypt( AesBlock128 plain, AesBlock128 key); -AesBlock128 __fastcall aes128ecb_decrypt( +AesBlock128 __fastcall raw_aes128ecb_decrypt( AesBlock128 cypher, AesBlock128 key); -AesBlock128 __fastcall aes192ecb_encrypt( +AesBlock128 __fastcall raw_aes192ecb_encrypt( AesBlock128 plain, AesBlock128 key_lo, AesBlock128 key_hi); -AesBlock128 __fastcall aes192ecb_decrypt( +AesBlock128 __fastcall raw_aes192ecb_decrypt( AesBlock128 cypher, AesBlock128 key_lo, AesBlock128 key_hi); -AesBlock128 __fastcall aes256ecb_encrypt( +AesBlock128 __fastcall raw_aes256ecb_encrypt( AesBlock128 plain, AesBlock128 key_lo, AesBlock128 key_hi); -AesBlock128 __fastcall aes256ecb_decrypt( +AesBlock128 __fastcall raw_aes256ecb_decrypt( AesBlock128 cypher, AesBlock128 key_lo, AesBlock128 key_hi); -AesBlock128 __fastcall aes256cbc_encrypt( +AesBlock128 __fastcall raw_aes256cbc_encrypt( AesBlock128 plain, AesBlock128 key_lo, AesBlock128 key_hi, AesBlock128 *iv); -AesBlock128 __fastcall aes256cbc_decrypt( +AesBlock128 __fastcall raw_aes256cbc_decrypt( AesBlock128 cypher, AesBlock128 key_lo, AesBlock128 key_hi, diff --git a/src/aes128.asm b/src/aes128.asm index dfa7a7d..b375daf 100644 --- a/src/aes128.asm +++ b/src/aes128.asm @@ -16,7 +16,7 @@ inverted_key_schedule oword 11 dup(0) .code -@aes128ecb_encrypt@32 proc +@raw_aes128ecb_encrypt@32 proc call expand_keys_128ecb pxor xmm0, [key_schedule] aesenc xmm0, [key_schedule + 10h] @@ -30,9 +30,9 @@ inverted_key_schedule oword 11 dup(0) aesenc xmm0, [key_schedule + 90h] aesenclast xmm0, [key_schedule + 0A0h] ret -@aes128ecb_encrypt@32 endp +@raw_aes128ecb_encrypt@32 endp -@aes128ecb_decrypt@32 proc +@raw_aes128ecb_decrypt@32 proc call expand_keys_128ecb pxor xmm0, [inverted_key_schedule] aesdec xmm0, [inverted_key_schedule + 10h] @@ -46,7 +46,7 @@ inverted_key_schedule oword 11 dup(0) aesdec xmm0, [inverted_key_schedule + 90h] aesdeclast xmm0, [inverted_key_schedule + 0A0h] ret -@aes128ecb_decrypt@32 endp +@raw_aes128ecb_decrypt@32 endp expand_keys_128ecb proc lea ecx, [key_schedule + 10h] diff --git a/src/aes192.asm b/src/aes192.asm index fd92426..9695961 100644 --- a/src/aes192.asm +++ b/src/aes192.asm @@ -16,7 +16,7 @@ inverted_key_schedule oword 13 dup(0) .code -@aes192ecb_encrypt@48 proc +@raw_aes192ecb_encrypt@48 proc call expand_keys_192ecb pxor xmm0, [key_schedule] aesenc xmm0, [key_schedule + 10h] @@ -32,9 +32,9 @@ inverted_key_schedule oword 13 dup(0) aesenc xmm0, [key_schedule + 0B0h] aesenclast xmm0, [key_schedule + 0C0h] ret -@aes192ecb_encrypt@48 endp +@raw_aes192ecb_encrypt@48 endp -@aes192ecb_decrypt@48 proc +@raw_aes192ecb_decrypt@48 proc call expand_keys_192ecb pxor xmm0, [inverted_key_schedule] aesdec xmm0, [inverted_key_schedule + 10h] @@ -50,7 +50,7 @@ inverted_key_schedule oword 13 dup(0) aesdec xmm0, [inverted_key_schedule + 0B0h] aesdeclast xmm0, [inverted_key_schedule + 0C0h] ret -@aes192ecb_decrypt@48 endp +@raw_aes192ecb_decrypt@48 endp expand_keys_192ecb proc ; key = k0 k1 k2 k3 k4 k5 @@ -189,7 +189,7 @@ invert_key_schedule: aesimc xmm7, [key_schedule + 60h] movdqa [inverted_key_schedule + 60h], xmm7 - + ret expand_keys_192ecb endp diff --git a/src/aes256cbc.asm b/src/aes256cbc.asm index 3446d31..1a5c8f0 100644 --- a/src/aes256cbc.asm +++ b/src/aes256cbc.asm @@ -16,7 +16,7 @@ inverse_key_schedule oword 15 dup(0) .code -@aes256cbc_encrypt@52 proc +@raw_aes256cbc_encrypt@52 proc call expand_keys_256cbc pxor xmm0, [ecx] pxor xmm0, [key_schedule] @@ -35,7 +35,7 @@ inverse_key_schedule oword 15 dup(0) aesenc xmm0, [key_schedule + 0D0h] aesenclast xmm0, [key_schedule + 0E0h] ret -@aes256cbc_encrypt@52 endp +@raw_aes256cbc_encrypt@52 endp expand_keys_256cbc proc lea edx, [key_schedule + 20h] @@ -159,7 +159,7 @@ invert_key_schedule: ret expand_keys_256cbc endp -@aes256cbc_decrypt@52 proc +@raw_aes256cbc_decrypt@52 proc call expand_keys_256cbc pxor xmm0, [inverse_key_schedule] aesdec xmm0, [inverse_key_schedule + 10h] @@ -175,9 +175,9 @@ expand_keys_256cbc endp aesdec xmm0, [inverse_key_schedule + 0B0h] aesdec xmm0, [inverse_key_schedule + 0C0h] aesdec xmm0, [inverse_key_schedule + 0D0h] - aesdeclast xmm0, [inverse_key_schedule + 0E0h] + aesdeclast xmm0, [inverse_key_schedule + 0E0h] pxor xmm0, [ecx] ret -@aes256cbc_decrypt@52 endp +@raw_aes256cbc_decrypt@52 endp end diff --git a/src/aes256ecb.asm b/src/aes256ecb.asm index 4246dee..f67f4bd 100644 --- a/src/aes256ecb.asm +++ b/src/aes256ecb.asm @@ -16,7 +16,7 @@ inverse_key_schedule oword 15 dup(0) .code -@aes256ecb_encrypt@48 proc +@raw_aes256ecb_encrypt@48 proc call expand_keys_256ecb pxor xmm0, [key_schedule] aesenc xmm0, [key_schedule + 10h] @@ -34,7 +34,7 @@ inverse_key_schedule oword 15 dup(0) aesenc xmm0, [key_schedule + 0D0h] aesenclast xmm0, [key_schedule + 0E0h] ret -@aes256ecb_encrypt@48 endp +@raw_aes256ecb_encrypt@48 endp expand_keys_256ecb proc lea edx, [key_schedule + 20h] @@ -158,7 +158,7 @@ invert_key_schedule: ret expand_keys_256ecb endp -@aes256ecb_decrypt@48 proc +@raw_aes256ecb_decrypt@48 proc call expand_keys_256ecb pxor xmm0, [inverse_key_schedule] aesdec xmm0, [inverse_key_schedule + 10h] @@ -174,8 +174,8 @@ expand_keys_256ecb endp aesdec xmm0, [inverse_key_schedule + 0B0h] aesdec xmm0, [inverse_key_schedule + 0C0h] aesdec xmm0, [inverse_key_schedule + 0D0h] - aesdeclast xmm0, [inverse_key_schedule + 0E0h] + aesdeclast xmm0, [inverse_key_schedule + 0E0h] ret -@aes256ecb_decrypt@48 endp +@raw_aes256ecb_decrypt@48 endp end |