diff options
-rw-r--r-- | examples/aes128cbc_example.c | 25 | ||||
-rw-r--r-- | examples/aes128ecb_example.c | 25 | ||||
-rw-r--r-- | examples/aes192cbc_example.c | 25 | ||||
-rw-r--r-- | examples/aes192ecb_example.c | 25 | ||||
-rw-r--r-- | examples/aes256cbc_example.c | 25 | ||||
-rw-r--r-- | examples/aes256ecb_example.c | 25 | ||||
-rw-r--r-- | include/aesni/api.h | 94 | ||||
-rw-r--r-- | include/aesni/data.h | 19 | ||||
-rw-r--r-- | include/aesni/raw.h | 53 | ||||
-rw-r--r-- | src/aes128.asm | 209 | ||||
-rw-r--r-- | src/aes192.asm | 261 | ||||
-rw-r--r-- | src/aes256.asm | 302 | ||||
-rw-r--r-- | test/aes128cbc_decrypt_block.c | 6 | ||||
-rw-r--r-- | test/aes128cbc_encrypt_block.c | 5 | ||||
-rw-r--r-- | test/aes128ecb_decrypt_block.c | 6 | ||||
-rw-r--r-- | test/aes128ecb_encrypt_block.c | 5 | ||||
-rw-r--r-- | test/aes192cbc_decrypt_block.c | 6 | ||||
-rw-r--r-- | test/aes192cbc_encrypt_block.c | 5 | ||||
-rw-r--r-- | test/aes192ecb_decrypt_block.c | 6 | ||||
-rw-r--r-- | test/aes192ecb_encrypt_block.c | 5 | ||||
-rw-r--r-- | test/aes256cbc_decrypt_block.c | 6 | ||||
-rw-r--r-- | test/aes256cbc_encrypt_block.c | 5 | ||||
-rw-r--r-- | test/aes256ecb_decrypt_block.c | 6 | ||||
-rw-r--r-- | test/aes256ecb_encrypt_block.c | 5 |
24 files changed, 679 insertions, 475 deletions
diff --git a/examples/aes128cbc_example.c b/examples/aes128cbc_example.c index ce568ea..94fb0d4 100644 --- a/examples/aes128cbc_example.c +++ b/examples/aes128cbc_example.c @@ -13,6 +13,7 @@ int main() { __declspec(align(16)) AesBlock128 plain, key, cypher, decrypted, iv; + __declspec(align(16)) Aes128KeySchedule key_schedule, inverted_schedule; plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); key = make_aes_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); @@ -32,13 +33,33 @@ int main() printf(" %s\n", format_aes_block128_fips_style(&iv).str); print_aes_block128_fips_matrix_style(&iv); - cypher = aes128cbc_encrypt(plain, key, &iv); + aes128_expand_key_schedule(key, &key_schedule); + + printf("\n"); + printf("Key schedule:\n"); + for (int i = 0; i < 11; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&key_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&key_schedule.keys[i]).str); + } + + cypher = aes128cbc_encrypt(plain, &key_schedule, &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 = aes128cbc_decrypt(cypher, key, &iv); + aes128_invert_key_schedule(&key_schedule, &inverted_schedule); + + printf("\n"); + printf("Inverted key schedule:\n"); + for (int i = 0; i < 11; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&inverted_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&inverted_schedule.keys[i]).str); + } + + decrypted = aes128cbc_decrypt(cypher, &inverted_schedule, &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/aes128ecb_example.c b/examples/aes128ecb_example.c index afb8dd9..aff4182 100644 --- a/examples/aes128ecb_example.c +++ b/examples/aes128ecb_example.c @@ -13,6 +13,7 @@ int main() { __declspec(align(16)) AesBlock128 plain, key, cypher, decrypted; + __declspec(align(16)) Aes128KeySchedule key_schedule, inverted_schedule; plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); key = make_aes_block128(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); @@ -26,13 +27,33 @@ int main() printf(" %s\n", format_aes_block128_fips_style(&key).str); print_aes_block128_fips_matrix_style(&key); - cypher = aes128ecb_encrypt(plain, key); + aes128_expand_key_schedule(key, &key_schedule); + + printf("\n"); + printf("Key schedule:\n"); + for (int i = 0; i < 11; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&key_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&key_schedule.keys[i]).str); + } + + cypher = aes128ecb_encrypt(plain, &key_schedule); 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 = aes128ecb_decrypt(cypher, key); + aes128_invert_key_schedule(&key_schedule, &inverted_schedule); + + printf("\n"); + printf("Inverted key schedule:\n"); + for (int i = 0; i < 11; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&inverted_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&inverted_schedule.keys[i]).str); + } + + decrypted = aes128ecb_decrypt(cypher, &inverted_schedule); 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/aes192cbc_example.c b/examples/aes192cbc_example.c index 25719c8..4b583b6 100644 --- a/examples/aes192cbc_example.c +++ b/examples/aes192cbc_example.c @@ -14,6 +14,7 @@ int main() { __declspec(align(16)) AesBlock128 plain, cypher, decrypted, iv; __declspec(align(16)) AesBlock192 key; + __declspec(align(16)) Aes192KeySchedule key_schedule, inverted_schedule; plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); key = make_aes_block192(0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); @@ -33,13 +34,33 @@ int main() printf(" %s\n", format_aes_block128_fips_style(&iv).str); print_aes_block128_fips_matrix_style(&iv); - cypher = aes192cbc_encrypt(plain, &key, &iv); + aes192_expand_key_schedule(&key, &key_schedule); + + printf("\n"); + printf("Key schedule:\n"); + for (int i = 0; i < 13; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&key_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&key_schedule.keys[i]).str); + } + + cypher = aes192cbc_encrypt(plain, &key_schedule, &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 = aes192cbc_decrypt(cypher, &key, &iv); + aes192_invert_key_schedule(&key_schedule, &inverted_schedule); + + printf("\n"); + printf("Inverted key schedule:\n"); + for (int i = 0; i < 13; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&inverted_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&inverted_schedule.keys[i]).str); + } + + decrypted = aes192cbc_decrypt(cypher, &inverted_schedule, &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/aes192ecb_example.c b/examples/aes192ecb_example.c index eb9b79d..eb3b329 100644 --- a/examples/aes192ecb_example.c +++ b/examples/aes192ecb_example.c @@ -14,6 +14,7 @@ int main() { __declspec(align(16)) AesBlock128 plain, cypher, decrypted; __declspec(align(16)) AesBlock192 key; + __declspec(align(16)) Aes192KeySchedule key_schedule, inverted_schedule; plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); key = make_aes_block192(0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); @@ -27,13 +28,33 @@ int main() printf(" %s\n", format_aes_block192_fips_style(&key).str); print_aes_block192_fips_matrix_style(&key); - cypher = aes192ecb_encrypt(plain, &key); + aes192_expand_key_schedule(&key, &key_schedule); + + printf("\n"); + printf("Key schedule:\n"); + for (int i = 0; i < 13; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&key_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&key_schedule.keys[i]).str); + } + + cypher = aes192ecb_encrypt(plain, &key_schedule); 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); + aes192_invert_key_schedule(&key_schedule, &inverted_schedule); + + printf("\n"); + printf("Inverted key schedule:\n"); + for (int i = 0; i < 13; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&inverted_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&inverted_schedule.keys[i]).str); + } + + decrypted = aes192ecb_decrypt(cypher, &inverted_schedule); 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 275b947..816683b 100644 --- a/examples/aes256cbc_example.c +++ b/examples/aes256cbc_example.c @@ -14,6 +14,7 @@ int main() { __declspec(align(16)) AesBlock128 plain, cypher, decrypted, iv; __declspec(align(16)) AesBlock256 key; + __declspec(align(16)) Aes256KeySchedule key_schedule, inverted_schedule; plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); key = make_aes_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); @@ -33,13 +34,33 @@ int main() printf(" %s\n", format_aes_block128_fips_style(&iv).str); print_aes_block128_fips_matrix_style(&iv); - cypher = aes256cbc_encrypt(plain, &key, &iv); + aes256_expand_key_schedule(&key, &key_schedule); + + printf("\n"); + printf("Key schedule:\n"); + for (int i = 0; i < 15; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&key_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&key_schedule.keys[i]).str); + } + + cypher = aes256cbc_encrypt(plain, &key_schedule, &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, &iv); + aes256_invert_key_schedule(&key_schedule, &inverted_schedule); + + printf("\n"); + printf("Inverted key schedule:\n"); + for (int i = 0; i < 15; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&inverted_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&inverted_schedule.keys[i]).str); + } + + decrypted = aes256cbc_decrypt(cypher, &inverted_schedule, &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 d7a82ee..cd36b50 100644 --- a/examples/aes256ecb_example.c +++ b/examples/aes256ecb_example.c @@ -14,6 +14,7 @@ int main() { __declspec(align(16)) AesBlock128 plain, cypher, decrypted; __declspec(align(16)) AesBlock256 key; + __declspec(align(16)) Aes256KeySchedule key_schedule, inverted_schedule; plain = make_aes_block128(0xffeeddcc, 0xbbaa9988, 0x77665544, 0x33221100); key = make_aes_block256(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110, 0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100); @@ -27,13 +28,33 @@ int main() printf(" %s\n", format_aes_block256_fips_style(&key).str); print_aes_block256_fips_matrix_style(&key); - cypher = aes256ecb_encrypt(plain, &key); + aes256_expand_key_schedule(&key, &key_schedule); + + printf("\n"); + printf("Key schedule:\n"); + for (int i = 0; i < 15; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&key_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&key_schedule.keys[i]).str); + } + + cypher = aes256ecb_encrypt(plain, &key_schedule); 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); + aes256_invert_key_schedule(&key_schedule, &inverted_schedule); + + printf("\n"); + printf("Inverted key schedule:\n"); + for (int i = 0; i < 15; ++i) + { + printf("\t[%d]: %s\n", i, format_aes_block128(&inverted_schedule.keys[i]).str); + printf("\t[%d]: %s\n", i, format_aes_block128_fips_style(&inverted_schedule.keys[i]).str); + } + + decrypted = aes256ecb_decrypt(cypher, &inverted_schedule); 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/api.h b/include/aesni/api.h index d64b225..efcecc4 100644 --- a/include/aesni/api.h +++ b/include/aesni/api.h @@ -11,92 +11,134 @@ #include "data.h" #include "raw.h" +static __inline void __fastcall aes128_expand_key_schedule( + AesBlock128 key, + Aes128KeySchedule* key_schedule) +{ + raw_aes128_expand_key_schedule(key, key_schedule); +} + +static __inline void __fastcall aes128_invert_key_schedule( + Aes128KeySchedule* key_schedule, + Aes128KeySchedule* inverted_schedule) +{ + raw_aes128_invert_key_schedule(key_schedule, inverted_schedule); +} + static __inline AesBlock128 __fastcall aes128ecb_encrypt( AesBlock128 plain, - AesBlock128 key) + Aes128KeySchedule* key_schedule) { - return raw_aes128ecb_encrypt(plain, key); + return raw_aes128ecb_encrypt(plain, key_schedule); } static __inline AesBlock128 __fastcall aes128ecb_decrypt( AesBlock128 cypher, - AesBlock128 key) + Aes128KeySchedule* inverted_schedule) { - return raw_aes128ecb_decrypt(cypher, key); + return raw_aes128ecb_decrypt(cypher, inverted_schedule); } static __inline AesBlock128 __fastcall aes128cbc_encrypt( AesBlock128 plain, - AesBlock128 key, - AesBlock128* initialization_vector) + Aes128KeySchedule* key_schedule, + AesBlock128* init_vector) { - return raw_aes128cbc_encrypt(plain, key, initialization_vector); + return raw_aes128cbc_encrypt(plain, key_schedule, init_vector); } static __inline AesBlock128 __fastcall aes128cbc_decrypt( AesBlock128 cypher, - AesBlock128 key, - AesBlock128* initialization_vector) + Aes128KeySchedule* inverted_schedule, + AesBlock128* init_vector) +{ + return raw_aes128cbc_decrypt(cypher, inverted_schedule, init_vector); +} + +static __inline void __fastcall aes192_expand_key_schedule( + AesBlock192* key, + Aes192KeySchedule* key_schedule) { - return raw_aes128cbc_decrypt(cypher, key, initialization_vector); + raw_aes192_expand_key_schedule(key->lo, key->hi, key_schedule); +} + +static __inline void __fastcall aes192_invert_key_schedule( + Aes192KeySchedule* key_schedule, + Aes192KeySchedule* inverted_schedule) +{ + raw_aes192_invert_key_schedule(key_schedule, inverted_schedule); } static __inline AesBlock128 __fastcall aes192ecb_encrypt( AesBlock128 plain, - AesBlock192* key) + Aes192KeySchedule* key_schedule) { - return raw_aes192ecb_encrypt(plain, key->lo, key->hi); + return raw_aes192ecb_encrypt(plain, key_schedule); } static __inline AesBlock128 __fastcall aes192ecb_decrypt( AesBlock128 cypher, - AesBlock192* key) + Aes192KeySchedule* inverted_schedule) { - return raw_aes192ecb_decrypt(cypher, key->lo, key->hi); + return raw_aes192ecb_decrypt(cypher, inverted_schedule); } static __inline AesBlock128 __fastcall aes192cbc_encrypt( AesBlock128 plain, - AesBlock192* key, + Aes192KeySchedule* key_schedule, AesBlock128* initialization_vector) { - return raw_aes192cbc_encrypt(plain, key->lo, key->hi, initialization_vector); + return raw_aes192cbc_encrypt(plain, key_schedule, initialization_vector); } static __inline AesBlock128 __fastcall aes192cbc_decrypt( AesBlock128 cypher, - AesBlock192* key, + Aes192KeySchedule* inverted_schedule, AesBlock128* initialization_vector) { - return raw_aes192cbc_decrypt(cypher, key->lo, key->hi, initialization_vector); + return raw_aes192cbc_decrypt(cypher, inverted_schedule, initialization_vector); +} + +static __inline void __fastcall aes256_expand_key_schedule( + AesBlock256* key, + Aes256KeySchedule* key_schedule) +{ + raw_aes256_expand_key_schedule(key->lo, key->hi, key_schedule); +} + +static __inline void __fastcall aes256_invert_key_schedule( + Aes256KeySchedule* key_schedule, + Aes256KeySchedule* inverted_schedule) +{ + raw_aes256_invert_key_schedule(key_schedule, inverted_schedule); } static __inline AesBlock128 __fastcall aes256ecb_encrypt( AesBlock128 plain, - AesBlock256* key) + Aes256KeySchedule* key_schedule) { - return raw_aes256ecb_encrypt(plain, key->lo, key->hi); + return raw_aes256ecb_encrypt(plain, key_schedule); } static __inline AesBlock128 __fastcall aes256ecb_decrypt( AesBlock128 cypher, - AesBlock256* key) + Aes256KeySchedule* inverted_schedule) { - return raw_aes256ecb_decrypt(cypher, key->lo, key->hi); + return raw_aes256ecb_decrypt(cypher, inverted_schedule); } static __inline AesBlock128 __fastcall aes256cbc_encrypt( AesBlock128 plain, - AesBlock256* key, + Aes256KeySchedule* key_schedule, AesBlock128* initialization_vector) { - return raw_aes256cbc_encrypt(plain, key->lo, key->hi, initialization_vector); + return raw_aes256cbc_encrypt(plain, key_schedule, initialization_vector); } static __inline AesBlock128 __fastcall aes256cbc_decrypt( AesBlock128 cypher, - AesBlock256* key, + Aes256KeySchedule* inverted_schedule, AesBlock128* initialization_vector) { - return raw_aes256cbc_decrypt(cypher, key->lo, key->hi, initialization_vector); + return raw_aes256cbc_decrypt(cypher, inverted_schedule, initialization_vector); } diff --git a/include/aesni/data.h b/include/aesni/data.h index 49cf5e5..889a9ff 100644 --- a/include/aesni/data.h +++ b/include/aesni/data.h @@ -26,6 +26,25 @@ typedef struct } AesBlock256; +typedef struct +{ + AesBlock128 keys[11]; +} +Aes128KeySchedule; + +typedef struct +{ + AesBlock128 keys[13]; + char fillers[8]; +} +Aes192KeySchedule; + +typedef struct +{ + AesBlock128 keys[15]; +} +Aes256KeySchedule; + AesBlock128 make_aes_block128(int hi3, int hi2, int lo1, int lo0); AesBlock192 make_aes_block192(int hi5, int hi4, int lo3, int lo2, int lo1, int lo0); AesBlock256 make_aes_block256(int hi7, int hi6, int hi5, int hi4, int lo3, int lo2, int lo1, int lo0); diff --git a/include/aesni/raw.h b/include/aesni/raw.h index ffda8d2..db342c7 100644 --- a/include/aesni/raw.h +++ b/include/aesni/raw.h @@ -10,58 +10,73 @@ #include "data.h" +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); + AesBlock128 __fastcall raw_aes128ecb_encrypt( AesBlock128 plain, - AesBlock128 key); + Aes128KeySchedule* key_schedule); AesBlock128 __fastcall raw_aes128ecb_decrypt( AesBlock128 cypher, - AesBlock128 key); + Aes128KeySchedule* inverted_schedule); AesBlock128 __fastcall raw_aes128cbc_encrypt( AesBlock128 plain, - AesBlock128 key, + Aes128KeySchedule* key_schedule, AesBlock128* iv); AesBlock128 __fastcall raw_aes128cbc_decrypt( AesBlock128 cypher, - AesBlock128 key, + Aes128KeySchedule* inverted_schedule, AesBlock128* iv); +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); + AesBlock128 __fastcall raw_aes192ecb_encrypt( AesBlock128 plain, - AesBlock128 key_lo, - AesBlock128 key_hi); + Aes192KeySchedule* key_schedule); AesBlock128 __fastcall raw_aes192ecb_decrypt( AesBlock128 cypher, - AesBlock128 key_lo, - AesBlock128 key_hi); + Aes192KeySchedule* inverted_schedule); AesBlock128 __fastcall raw_aes192cbc_encrypt( AesBlock128 plain, - AesBlock128 key_lo, - AesBlock128 key_hi, + Aes192KeySchedule* key_schedule, AesBlock128 *iv); AesBlock128 __fastcall raw_aes192cbc_decrypt( AesBlock128 cypher, + Aes192KeySchedule* inverted_schedule, + AesBlock128 *iv); + +void __fastcall raw_aes256_expand_key_schedule( AesBlock128 key_lo, AesBlock128 key_hi, - AesBlock128 *iv); + Aes256KeySchedule* key_schedule); +void __fastcall raw_aes256_invert_key_schedule( + Aes256KeySchedule* key_schedule, + Aes256KeySchedule* inverted_schedule); AesBlock128 __fastcall raw_aes256ecb_encrypt( AesBlock128 plain, - AesBlock128 key_lo, - AesBlock128 key_hi); + Aes256KeySchedule* key_schedule); AesBlock128 __fastcall raw_aes256ecb_decrypt( AesBlock128 cypher, - AesBlock128 key_lo, - AesBlock128 key_hi); + Aes256KeySchedule* inverted_schedule); AesBlock128 __fastcall raw_aes256cbc_encrypt( AesBlock128 plain, - AesBlock128 key_lo, - AesBlock128 key_hi, + Aes256KeySchedule* key_schedule, AesBlock128 *iv); AesBlock128 __fastcall raw_aes256cbc_decrypt( AesBlock128 cypher, - AesBlock128 key_lo, - AesBlock128 key_hi, + Aes256KeySchedule* inverted_schedule, AesBlock128 *iv); diff --git a/src/aes128.asm b/src/aes128.asm index 5d62621..577e582 100644 --- a/src/aes128.asm +++ b/src/aes128.asm @@ -6,68 +6,55 @@ .xmm .model flat -.data - -align 10h -key_schedule oword 11 dup(0) - -align 10h -inverted_key_schedule oword 11 dup(0) - .code -@raw_aes128ecb_encrypt@32 proc - call expand_keys128 - pxor xmm0, [key_schedule] - aesenc xmm0, [key_schedule + 10h] - aesenc xmm0, [key_schedule + 20h] - aesenc xmm0, [key_schedule + 30h] - aesenc xmm0, [key_schedule + 40h] - aesenc xmm0, [key_schedule + 50h] - aesenc xmm0, [key_schedule + 60h] - aesenc xmm0, [key_schedule + 70h] - aesenc xmm0, [key_schedule + 80h] - aesenc xmm0, [key_schedule + 90h] - aesenclast xmm0, [key_schedule + 0A0h] +@raw_aes128ecb_encrypt@20 proc + pxor xmm0, [ecx] + aesenc xmm0, [ecx + 10h] + aesenc xmm0, [ecx + 20h] + aesenc xmm0, [ecx + 30h] + aesenc xmm0, [ecx + 40h] + aesenc xmm0, [ecx + 50h] + aesenc xmm0, [ecx + 60h] + aesenc xmm0, [ecx + 70h] + aesenc xmm0, [ecx + 80h] + aesenc xmm0, [ecx + 90h] + aesenclast xmm0, [ecx + 0A0h] ret -@raw_aes128ecb_encrypt@32 endp +@raw_aes128ecb_encrypt@20 endp + +@raw_aes128cbc_encrypt@24 proc + pxor xmm0, [edx] + jmp @raw_aes128ecb_encrypt@20 +@raw_aes128cbc_encrypt@24 endp -@raw_aes128cbc_encrypt@36 proc +@raw_aes128ecb_decrypt@20 proc pxor xmm0, [ecx] - jmp @raw_aes128ecb_encrypt@32 -@raw_aes128cbc_encrypt@36 endp - -@raw_aes128ecb_decrypt@32 proc - call expand_keys128 - pxor xmm0, [inverted_key_schedule] - aesdec xmm0, [inverted_key_schedule + 10h] - aesdec xmm0, [inverted_key_schedule + 20h] - aesdec xmm0, [inverted_key_schedule + 30h] - aesdec xmm0, [inverted_key_schedule + 40h] - aesdec xmm0, [inverted_key_schedule + 50h] - aesdec xmm0, [inverted_key_schedule + 60h] - aesdec xmm0, [inverted_key_schedule + 70h] - aesdec xmm0, [inverted_key_schedule + 80h] - aesdec xmm0, [inverted_key_schedule + 90h] - aesdeclast xmm0, [inverted_key_schedule + 0A0h] + aesdec xmm0, [ecx + 10h] + aesdec xmm0, [ecx + 20h] + aesdec xmm0, [ecx + 30h] + aesdec xmm0, [ecx + 40h] + aesdec xmm0, [ecx + 50h] + aesdec xmm0, [ecx + 60h] + aesdec xmm0, [ecx + 70h] + aesdec xmm0, [ecx + 80h] + aesdec xmm0, [ecx + 90h] + aesdeclast xmm0, [ecx + 0A0h] ret -@raw_aes128ecb_decrypt@32 endp +@raw_aes128ecb_decrypt@20 endp -@raw_aes128cbc_decrypt@36 proc - push ecx - call @raw_aes128ecb_decrypt@32 - pop ecx - pxor xmm0, [ecx] +@raw_aes128cbc_decrypt@24 proc + call @raw_aes128ecb_decrypt@20 + pxor xmm0, [edx] ret -@raw_aes128cbc_decrypt@36 endp +@raw_aes128cbc_decrypt@24 endp -expand_keys128 proc +@raw_aes128_expand_key_schedule@20 proc ; A "word" (in terms of the FIPS 187 standard) is a 32-bit block. ; Words are denoted by `w[N]`. ; ; A key schedule is composed of 10 "regular" keys and a dumb key for ; the "whitening" step. - ; It's stored in `key_schedule`. ; ; A key schedule is thus composed of 44 "words". ; The FIPS standard includes an algorithm to calculate these words via @@ -104,52 +91,51 @@ expand_keys128 proc ; and RotWord using `aeskeygenassist`, which is used in this routine. ; ; Preconditions: - ; * xmm1[127:96] == w[3], - ; * xmm1[95:64] == w[2], - ; * xmm1[63:32] == w[1], - ; * xmm1[31:0] == w[0]. + ; * xmm0[127:96] == w[3], + ; * xmm0[95:64] == w[2], + ; * xmm0[63:32] == w[1], + ; * xmm0[31:0] == w[0]. - movdqa [key_schedule], xmm1 ; sets w[0], w[1], w[2], w[3] + movdqa [ecx], xmm0 ; sets w[0], w[1], w[2], w[3] + add ecx, 10h ; ecx = &w[4] - lea ecx, [key_schedule + 10h] ; ecx = &w[4] - aeskeygenassist xmm7, xmm1, 01h ; xmm7[127:96] = RotWord(SubWord(w[3]))^Rcon + aeskeygenassist xmm7, xmm0, 01h ; xmm7[127:96] = RotWord(SubWord(w[3]))^Rcon call gen_round_key ; sets w[4], w[5], w[6], w[7] - aeskeygenassist xmm7, xmm1, 02h ; xmm7[127:96] = RotWord(SubWord(w[7]))^Rcon + aeskeygenassist xmm7, xmm0, 02h ; xmm7[127:96] = RotWord(SubWord(w[7]))^Rcon call gen_round_key ; sets w[8], w[9], w[10], w[11] - aeskeygenassist xmm7, xmm1, 04h ; xmm7[127:96] = RotWord(SubWord(w[11]))^Rcon + aeskeygenassist xmm7, xmm0, 04h ; xmm7[127:96] = RotWord(SubWord(w[11]))^Rcon call gen_round_key ; sets w[12], w[13], w[14], w[15] - aeskeygenassist xmm7, xmm1, 08h ; xmm7[127:96] = RotWord(SubWord(w[15]))^Rcon + aeskeygenassist xmm7, xmm0, 08h ; xmm7[127:96] = RotWord(SubWord(w[15]))^Rcon call gen_round_key ; sets w[16], w[17], w[18], w[19] - aeskeygenassist xmm7, xmm1, 10h ; xmm7[127:96] = RotWord(SubWord(w[19]))^Rcon + aeskeygenassist xmm7, xmm0, 10h ; xmm7[127:96] = RotWord(SubWord(w[19]))^Rcon call gen_round_key ; sets w[20], w[21], w[22], w[23] - aeskeygenassist xmm7, xmm1, 20h ; xmm7[127:96] = RotWord(SubWord(w[23]))^Rcon + aeskeygenassist xmm7, xmm0, 20h ; xmm7[127:96] = RotWord(SubWord(w[23]))^Rcon call gen_round_key ; sets w[24], w[25], w[26], w[27] - aeskeygenassist xmm7, xmm1, 40h ; xmm7[127:96] = RotWord(SubWord(w[27]))^Rcon + aeskeygenassist xmm7, xmm0, 40h ; xmm7[127:96] = RotWord(SubWord(w[27]))^Rcon call gen_round_key ; sets w[28], w[29], w[30], w[31] - aeskeygenassist xmm7, xmm1, 80h ; xmm7[127:96] = RotWord(SubWord(w[31]))^Rcon + aeskeygenassist xmm7, xmm0, 80h ; xmm7[127:96] = RotWord(SubWord(w[31]))^Rcon call gen_round_key ; sets w[32], w[33], w[34], w[35] - aeskeygenassist xmm7, xmm1, 1Bh ; xmm7[127:96] = RotWord(SubWord(w[35]))^Rcon + aeskeygenassist xmm7, xmm0, 1Bh ; xmm7[127:96] = RotWord(SubWord(w[35]))^Rcon call gen_round_key ; sets w[36], w[37], w[38], w[39] - aeskeygenassist xmm7, xmm1, 36h ; xmm7[127:96] = RotWord(SubWord(w[39]))^Rcon + aeskeygenassist xmm7, xmm0, 36h ; xmm7[127:96] = RotWord(SubWord(w[39]))^Rcon call gen_round_key ; sets w[40], w[41], w[42], w[43] - call invert_key_schedule ret gen_round_key: ; Preconditions: - ; * xmm1[127:96] == w[i+3], - ; * xmm1[95:64] == w[i+2], - ; * xmm1[63:32] == w[i+1], - ; * xmm1[31:0] == w[i], + ; * xmm0[127:96] == w[i+3], + ; * xmm0[95:64] == w[i+2], + ; * xmm0[63:32] == w[i+1], + ; * xmm0[31:0] == w[i], ; * xmm7[127:96] == RotWord(SubWord(w[i+3]))^Rcon, ; * ecx == &w[i+4]. ; ; Postconditions: - ; * xmm1[127:96] == w[i+7] == RotWord(SubWord(w[i+3]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i], - ; * xmm1[95:64] == w[i+6] == RotWord(SubWord(w[i+3]))^Rcon^w[i+2]^w[i+1]^w[i], - ; * xmm1[63:32] == w[i+5] == RotWord(SubWord(w[i+3]))^Rcon^w[i+1]^w[i], - ; * xmm1[31:0] == w[i+4] == RotWord(SubWord(w[i+3]))^Rcon^w[i], + ; * xmm0[127:96] == w[i+7] == RotWord(SubWord(w[i+3]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i], + ; * xmm0[95:64] == w[i+6] == RotWord(SubWord(w[i+3]))^Rcon^w[i+2]^w[i+1]^w[i], + ; * xmm0[63:32] == w[i+5] == RotWord(SubWord(w[i+3]))^Rcon^w[i+1]^w[i], + ; * xmm0[31:0] == w[i+4] == RotWord(SubWord(w[i+3]))^Rcon^w[i], ; * ecx == &w[i+8], ; * the value in xmm6 is also modified. @@ -158,17 +144,17 @@ gen_round_key: ; w[i+2]^w[i+1]^w[i], ; w[i+1]^w[i] and ; w[i]. - movdqa xmm6, xmm1 ; xmm6 = xmm1 + movdqa xmm6, xmm0 ; xmm6 = xmm0 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 + pxor xmm0, xmm6 ; xmm0 ^= xmm6 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 + pxor xmm0, xmm6 ; xmm0 ^= xmm6 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 - ; xmm1[127:96] == w[i+3]^w[i+2]^w[i+1]^w[i] - ; xmm1[95:64] == w[i+2]^w[i+1]^w[i] - ; xmm1[63:32] == w[i+1]^w[i] - ; xmm1[31:0] == w[i] + pxor xmm0, xmm6 ; xmm0 ^= xmm6 + ; xmm0[127:96] == w[i+3]^w[i+2]^w[i+1]^w[i] + ; xmm0[95:64] == w[i+2]^w[i+1]^w[i] + ; xmm0[63:32] == w[i+1]^w[i] + ; xmm0[31:0] == w[i] ; Calculate ; w[i+7] == RotWord(SubWord(w[i+3]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i], @@ -176,51 +162,52 @@ gen_round_key: ; w[i+5] == RotWord(SubWord(w[i+3]))^Rcon^w[i+1]^w[i] and ; w[i+4] == RotWord(SubWord(w[i+3]))^Rcon^w[i]. pshufd xmm6, xmm7, 0FFh ; xmm6[127:96] = xmm6[95:64] = xmm6[63:32] = xmm6[31:0] = xmm7[127:96] - pxor xmm1, xmm6 ; xmm1 ^= xmm6 - ; xmm1[127:96] == w[i+7] == RotWord(SubWord(w[i+3]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i] - ; xmm1[95:64] == w[i+6] == RotWord(SubWord(w[i+3]))^Rcon^w[i+2]^w[i+1]^w[i] - ; xmm1[63:32] == w[i+5] == RotWord(SubWord(w[i+3]))^Rcon^w[i+1]^w[i] - ; xmm1[31:0] == w[i+4] == RotWord(SubWord(w[i+3]))^Rcon^w[i] + pxor xmm0, xmm6 ; xmm0 ^= xmm6 + ; xmm0[127:96] == w[i+7] == RotWord(SubWord(w[i+3]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i] + ; xmm0[95:64] == w[i+6] == RotWord(SubWord(w[i+3]))^Rcon^w[i+2]^w[i+1]^w[i] + ; xmm0[63:32] == w[i+5] == RotWord(SubWord(w[i+3]))^Rcon^w[i+1]^w[i] + ; xmm0[31:0] == w[i+4] == RotWord(SubWord(w[i+3]))^Rcon^w[i] ; Set w[i+4], w[i+5], w[i+6] and w[i+7]. - movdqa [ecx], xmm1 ; w[i+7] = RotWord(SubWord(w[i+3]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i] + movdqa [ecx], xmm0 ; w[i+7] = RotWord(SubWord(w[i+3]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i] ; w[i+6] = RotWord(SubWord(w[i+3]))^Rcon^w[i+2]^w[i+1]^w[i] ; w[i+5] = RotWord(SubWord(w[i+3]))^Rcon^w[i+1]^w[i] ; w[i+4] = RotWord(SubWord(w[i+3]))^Rcon^w[i] add ecx, 10h ; ecx = &w[i+8] ret +@raw_aes128_expand_key_schedule@20 endp -invert_key_schedule: - movdqa xmm7, [key_schedule] - movdqa xmm6, [key_schedule + 0A0h] - movdqa [inverted_key_schedule], xmm6 - movdqa [inverted_key_schedule + 0A0h], xmm7 +@raw_aes128_invert_key_schedule@8 proc + movdqa xmm7, [ecx] + movdqa xmm6, [ecx + 0A0h] + movdqa [edx], xmm6 + movdqa [edx + 0A0h], xmm7 - aesimc xmm7, [key_schedule + 10h] - aesimc xmm6, [key_schedule + 90h] - movdqa [inverted_key_schedule + 10h], xmm6 - movdqa [inverted_key_schedule + 90h], xmm7 + aesimc xmm7, [ecx + 10h] + aesimc xmm6, [ecx + 90h] + movdqa [edx + 10h], xmm6 + movdqa [edx + 90h], xmm7 - aesimc xmm7, [key_schedule + 20h] - aesimc xmm6, [key_schedule + 80h] - movdqa [inverted_key_schedule + 20h], xmm6 - movdqa [inverted_key_schedule + 80h], xmm7 + aesimc xmm7, [ecx + 20h] + aesimc xmm6, [ecx + 80h] + movdqa [edx + 20h], xmm6 + movdqa [edx + 80h], xmm7 - aesimc xmm7, [key_schedule + 30h] - aesimc xmm6, [key_schedule + 70h] - movdqa [inverted_key_schedule + 30h], xmm6 - movdqa [inverted_key_schedule + 70h], xmm7 + aesimc xmm7, [ecx + 30h] + aesimc xmm6, [ecx + 70h] + movdqa [edx + 30h], xmm6 + movdqa [edx + 70h], xmm7 - aesimc xmm7, [key_schedule + 40h] - aesimc xmm6, [key_schedule + 60h] - movdqa [inverted_key_schedule + 40h], xmm6 - movdqa [inverted_key_schedule + 60h], xmm7 + aesimc xmm7, [ecx + 40h] + aesimc xmm6, [ecx + 60h] + movdqa [edx + 40h], xmm6 + movdqa [edx + 60h], xmm7 - aesimc xmm7, [key_schedule + 50h] - movdqa [inverted_key_schedule + 50h], xmm7 + aesimc xmm7, [ecx + 50h] + movdqa [edx + 50h], xmm7 ret -expand_keys128 endp +@raw_aes128_invert_key_schedule@8 endp end diff --git a/src/aes192.asm b/src/aes192.asm index 55fd540..21e0fa1 100644 --- a/src/aes192.asm +++ b/src/aes192.asm @@ -6,72 +6,59 @@ .xmm .model flat -.data - -align 10h -key_schedule oword 13 dup(0) - -align 10h -inverted_key_schedule oword 13 dup(0) - .code -@raw_aes192ecb_encrypt@48 proc - call expand_keys192 - pxor xmm0, [key_schedule] - aesenc xmm0, [key_schedule + 10h] - aesenc xmm0, [key_schedule + 20h] - aesenc xmm0, [key_schedule + 30h] - aesenc xmm0, [key_schedule + 40h] - aesenc xmm0, [key_schedule + 50h] - aesenc xmm0, [key_schedule + 60h] - aesenc xmm0, [key_schedule + 70h] - aesenc xmm0, [key_schedule + 80h] - aesenc xmm0, [key_schedule + 90h] - aesenc xmm0, [key_schedule + 0A0h] - aesenc xmm0, [key_schedule + 0B0h] - aesenclast xmm0, [key_schedule + 0C0h] +@raw_aes192ecb_encrypt@20 proc + pxor xmm0, [ecx] + aesenc xmm0, [ecx + 10h] + aesenc xmm0, [ecx + 20h] + aesenc xmm0, [ecx + 30h] + aesenc xmm0, [ecx + 40h] + aesenc xmm0, [ecx + 50h] + aesenc xmm0, [ecx + 60h] + aesenc xmm0, [ecx + 70h] + aesenc xmm0, [ecx + 80h] + aesenc xmm0, [ecx + 90h] + aesenc xmm0, [ecx + 0A0h] + aesenc xmm0, [ecx + 0B0h] + aesenclast xmm0, [ecx + 0C0h] ret -@raw_aes192ecb_encrypt@48 endp +@raw_aes192ecb_encrypt@20 endp -@raw_aes192cbc_encrypt@52 proc - pxor xmm0, [ecx] - jmp @raw_aes192ecb_encrypt@48 -@raw_aes192cbc_encrypt@52 endp +@raw_aes192cbc_encrypt@24 proc + pxor xmm0, [edx] + jmp @raw_aes192ecb_encrypt@20 +@raw_aes192cbc_encrypt@24 endp -@raw_aes192ecb_decrypt@48 proc - call expand_keys192 - pxor xmm0, [inverted_key_schedule] - aesdec xmm0, [inverted_key_schedule + 10h] - aesdec xmm0, [inverted_key_schedule + 20h] - aesdec xmm0, [inverted_key_schedule + 30h] - aesdec xmm0, [inverted_key_schedule + 40h] - aesdec xmm0, [inverted_key_schedule + 50h] - aesdec xmm0, [inverted_key_schedule + 60h] - aesdec xmm0, [inverted_key_schedule + 70h] - aesdec xmm0, [inverted_key_schedule + 80h] - aesdec xmm0, [inverted_key_schedule + 90h] - aesdec xmm0, [inverted_key_schedule + 0A0h] - aesdec xmm0, [inverted_key_schedule + 0B0h] - aesdeclast xmm0, [inverted_key_schedule + 0C0h] +@raw_aes192ecb_decrypt@20 proc + pxor xmm0, [ecx] + aesdec xmm0, [ecx + 10h] + aesdec xmm0, [ecx + 20h] + aesdec xmm0, [ecx + 30h] + aesdec xmm0, [ecx + 40h] + aesdec xmm0, [ecx + 50h] + aesdec xmm0, [ecx + 60h] + aesdec xmm0, [ecx + 70h] + aesdec xmm0, [ecx + 80h] + aesdec xmm0, [ecx + 90h] + aesdec xmm0, [ecx + 0A0h] + aesdec xmm0, [ecx + 0B0h] + aesdeclast xmm0, [ecx + 0C0h] ret -@raw_aes192ecb_decrypt@48 endp +@raw_aes192ecb_decrypt@20 endp -@raw_aes192cbc_decrypt@52 proc - push ecx - call @raw_aes192ecb_decrypt@48 - pop ecx - pxor xmm0, [ecx] +@raw_aes192cbc_decrypt@24 proc + call @raw_aes192ecb_decrypt@20 + pxor xmm0, [edx] ret -@raw_aes192cbc_decrypt@52 endp +@raw_aes192cbc_decrypt@24 endp -expand_keys192 proc +@raw_aes192_expand_key_schedule@36 proc ; A "word" (in terms of the FIPS 187 standard) is a 32-bit block. ; Words are denoted by `w[N]`. ; ; A key schedule is composed of 12 "regular" keys and a dumb key for ; the "whitening" step. - ; It's stored in `key_schedule`. ; ; A key schedule is thus composed of 52 "words". ; The FIPS standard includes an algorithm to calculate these words via @@ -116,59 +103,58 @@ expand_keys192 proc ; and RotWord using `aeskeygenassist`, which is used in this routine. ; ; Preconditions: - ; * xmm2[63:32] == w[5], - ; * xmm2[31:0] == w[4], - ; * xmm1[127:96] == w[3], - ; * xmm1[95:64] == w[2], - ; * xmm1[63:32] == w[1], - ; * xmm1[31:0] == w[0]. + ; * xmm1[63:32] == w[5], + ; * xmm1[31:0] == w[4], + ; * xmm0[127:96] == w[3], + ; * xmm0[95:64] == w[2], + ; * xmm0[63:32] == w[1], + ; * xmm0[31:0] == w[0]. - movdqa [key_schedule], xmm1 ; sets w[0], w[1], w[2], w[3] - movdqa [key_schedule + 10h], xmm2 ; sets w[4], w[5] + movdqa [ecx], xmm0 ; sets w[0], w[1], w[2], w[3] + movdqa [ecx + 10h], xmm1 ; sets w[4], w[5] + add ecx, 18h ; ecx = &w[6] - lea ecx, [key_schedule + 18h] ; ecx = &w[6] - aeskeygenassist xmm7, xmm2, 1 ; xmm7[63:32] = RotWord(SubWord(w[5]))^Rcon, + aeskeygenassist xmm7, xmm1, 1 ; xmm7[63:32] = RotWord(SubWord(w[5]))^Rcon, call gen_round_key ; sets w[6], w[7], w[8], w[9], w[10], w[11] - aeskeygenassist xmm7, xmm2, 2 ; xmm7[63:32] = RotWord(SubWord(w[11]))^Rcon + aeskeygenassist xmm7, xmm1, 2 ; xmm7[63:32] = RotWord(SubWord(w[11]))^Rcon call gen_round_key ; sets w[12], w[13], w[14], w[15], w[16], w[17] - aeskeygenassist xmm7, xmm2, 4 ; xmm7[63:32] = RotWord(SubWord(w[17]))^Rcon + aeskeygenassist xmm7, xmm1, 4 ; xmm7[63:32] = RotWord(SubWord(w[17]))^Rcon call gen_round_key ; sets w[18], w[19], w[20], w[21], w[22], w[23] - aeskeygenassist xmm7, xmm2, 8 ; xmm7[63:32] = RotWord(SubWord(w[23]))^Rcon + aeskeygenassist xmm7, xmm1, 8 ; xmm7[63:32] = RotWord(SubWord(w[23]))^Rcon call gen_round_key ; sets w[24], w[25], w[26], w[27], w[28], w[29] - aeskeygenassist xmm7, xmm2, 10h ; xmm7[63:32] = RotWord(SubWord(w[29]))^Rcon + aeskeygenassist xmm7, xmm1, 10h ; xmm7[63:32] = RotWord(SubWord(w[29]))^Rcon call gen_round_key ; sets w[30], w[31], w[32], w[33], w[34], w[35] - aeskeygenassist xmm7, xmm2, 20h ; xmm7[63:32] = RotWord(SubWord(w[35]))^Rcon + aeskeygenassist xmm7, xmm1, 20h ; xmm7[63:32] = RotWord(SubWord(w[35]))^Rcon call gen_round_key ; sets w[36], w[37], w[38], w[39], w[40], w[41] - aeskeygenassist xmm7, xmm2, 40h ; xmm7[63:32] = RotWord(SubWord(w[41]))^Rcon + aeskeygenassist xmm7, xmm1, 40h ; xmm7[63:32] = RotWord(SubWord(w[41]))^Rcon call gen_round_key ; sets w[42], w[43], w[44], w[45], w[46], w[47] - aeskeygenassist xmm7, xmm2, 80h ; xmm7[63:32] = RotWord(SubWord(w[49]))^Rcon + aeskeygenassist xmm7, xmm1, 80h ; xmm7[63:32] = RotWord(SubWord(w[49]))^Rcon call gen_round_key ; sets w[48], w[49], w[50], w[51], w[52], w[53] // FIXME - call invert_key_schedule ret gen_round_key: ; Preconditions: - ; * xmm2[127:96] == 0, - ; * xmm2[95:64] == 0, - ; * xmm2[63:32] == w[i+5], - ; * xmm2[31:0] == w[i+4], - ; * xmm1[127:96] == w[i+3], - ; * xmm1[95:64] == w[i+2], - ; * xmm1[63:32] == w[i+1], - ; * xmm1[31:0] == w[i], + ; * xmm1[127:96] == 0, + ; * xmm1[95:64] == 0, + ; * xmm1[63:32] == w[i+5], + ; * xmm1[31:0] == w[i+4], + ; * xmm0[127:96] == w[i+3], + ; * xmm0[95:64] == w[i+2], + ; * xmm0[63:32] == w[i+1], + ; * xmm0[31:0] == w[i], ; * xmm7[63:32] == RotWord(SubWord(w[i+5]))^Rcon, ; * ecx == &w[i+6]. ; ; Postconditions: - ; * xmm2[127:96] == 0, - ; * xmm2[95:64] == 0, - ; * xmm2[63:32] == w[i+11] == RotWord(SubWord(w[i+5]))^Rcon^w[i+5]^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i], - ; * xmm2[31:0] == w[i+10] == RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i], - ; * xmm1[127:96] == w[i+9] == RotWord(SubWord(w[i+5]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i], - ; * xmm1[95:64] == w[i+8] == RotWord(SubWord(w[i+5]))^Rcon^w[i+2]^w[i+1]^w[i], - ; * xmm1[63:32] == w[i+7] == RotWord(SubWord(w[i+5]))^Rcon^w[i+1]^w[i], - ; * xmm1[31:0] == w[i+6] == RotWord(SubWord(w[i+5]))^Rcon^w[i], + ; * xmm1[127:96] == 0, + ; * xmm1[95:64] == 0, + ; * xmm1[63:32] == w[i+11] == RotWord(SubWord(w[i+5]))^Rcon^w[i+5]^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i], + ; * xmm1[31:0] == w[i+10] == RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i], + ; * xmm0[127:96] == w[i+9] == RotWord(SubWord(w[i+5]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i], + ; * xmm0[95:64] == w[i+8] == RotWord(SubWord(w[i+5]))^Rcon^w[i+2]^w[i+1]^w[i], + ; * xmm0[63:32] == w[i+7] == RotWord(SubWord(w[i+5]))^Rcon^w[i+1]^w[i], + ; * xmm0[31:0] == w[i+6] == RotWord(SubWord(w[i+5]))^Rcon^w[i], ; * ecx == &w[i+12], ; * the value in xmm6 is also modified. @@ -177,17 +163,17 @@ gen_round_key: ; w[i+2]^w[i+1]^w[i], ; w[i+1]^w[i] and ; w[i]. - movdqa xmm6, xmm1 ; xmm6 = xmm1 + movdqa xmm6, xmm0 ; xmm6 = xmm0 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 + pxor xmm0, xmm6 ; xmm0 ^= xmm6 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 + pxor xmm0, xmm6 ; xmm0 ^= xmm6 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 - ; xmm1[127:96] == w[i+3]^w[i+2]^w[i+1]^w[i] - ; xmm1[95:64] == w[i+2]^w[i+1]^w[i] - ; xmm1[63:32] == w[i+1]^w[i] - ; xmm1[31:0] == w[i] + pxor xmm0, xmm6 ; xmm0 ^= xmm6 + ; xmm0[127:96] == w[i+3]^w[i+2]^w[i+1]^w[i] + ; xmm0[95:64] == w[i+2]^w[i+1]^w[i] + ; xmm0[63:32] == w[i+1]^w[i] + ; xmm0[31:0] == w[i] ; Calculate ; w[i+9] == RotWord(SubWord(w[i+5]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i], @@ -195,14 +181,14 @@ gen_round_key: ; w[i+7] == RotWord(SubWord(w[i+5]))^Rcon^w[i+1]^w[i] and ; w[i+6] == RotWord(SubWord(w[i+5]))^Rcon^w[i]. pshufd xmm6, xmm7, 55h ; xmm6[127:96] = xmm6[95:64] = xmm6[63:32] = xmm6[31:0] = xmm7[63:32] - pxor xmm1, xmm6 ; xmm1 ^= xmm6 - ; xmm1[127:96] == w[i+9] == RotWord(SubWord(w[i+5]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i] - ; xmm1[95:64] == w[i+8] == RotWord(SubWord(w[i+5]))^Rcon^w[i+2]^w[i+1]^w[i] - ; xmm1[63:32] == w[i+7] == RotWord(SubWord(w[i+5]))^Rcon^w[i+1]^w[i] - ; xmm1[31:0] == w[i+6] == RotWord(SubWord(w[i+5]))^Rcon^w[i] + pxor xmm0, xmm6 ; xmm0 ^= xmm6 + ; xmm0[127:96] == w[i+9] == RotWord(SubWord(w[i+5]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i] + ; xmm0[95:64] == w[i+8] == RotWord(SubWord(w[i+5]))^Rcon^w[i+2]^w[i+1]^w[i] + ; xmm0[63:32] == w[i+7] == RotWord(SubWord(w[i+5]))^Rcon^w[i+1]^w[i] + ; xmm0[31:0] == w[i+6] == RotWord(SubWord(w[i+5]))^Rcon^w[i] ; Set w[i+6], w[i+7], w[i+8] and w[i+9]. - movdqu [ecx], xmm1 ; w[i+6] = RotWord(SubWord(w[i+5]))^Rcon^w[i] + movdqu [ecx], xmm0 ; w[i+6] = RotWord(SubWord(w[i+5]))^Rcon^w[i] ; w[i+7] = RotWord(SubWord(w[i+5]))^Rcon^w[i+1]^w[i] ; w[i+8] = RotWord(SubWord(w[i+5]))^Rcon^w[i+2]^w[i+1]^w[i] ; w[i+9] = RotWord(SubWord(w[i+5]))^Rcon^w[i+3]^w[i+2]^w[i+1]^w[i] @@ -211,62 +197,63 @@ gen_round_key: ; Calculate ; w[i+5]^w[i+4], ; w[i+4]. - pshufd xmm6, xmm2, 0F3h ; xmm6 = xmm2[31:0] << 32 - pxor xmm2, xmm6 ; xmm2 ^= xmm7 - ; xmm2[63:32] == w[i+5]^w[i+4] - ; xmm2[31:0] == w[i+4] + pshufd xmm6, xmm1, 0F3h ; xmm6 = xmm1[31:0] << 32 + pxor xmm1, xmm6 ; xmm1 ^= xmm7 + ; xmm1[63:32] == w[i+5]^w[i+4] + ; xmm1[31:0] == w[i+4] ; Calculate ; w[i+10] == RotWord(SubWord(w[i+5]))^Rcon^w[i+5]^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i], ; w[i+11] == RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i]. - pshufd xmm6, xmm1, 0FFh ; xmm6[127:96] = xmm6[95:64] = xmm6[63:32] = xmm6[31:0] = xmm1[127:96] + pshufd xmm6, xmm0, 0FFh ; xmm6[127:96] = xmm6[95:64] = xmm6[63:32] = xmm6[31:0] = xmm0[127:96] psrldq xmm6, 8 ; xmm6 >>= 64 - pxor xmm2, xmm6 ; xmm2 ^= xmm6 - ; xmm2[63:32] == w[i+11] == RotWord(SubWord(w[i+5]))^Rcon^w[i+5]^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i] - ; xmm2[31:0] == w[i+10] == RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i] + pxor xmm1, xmm6 ; xmm1 ^= xmm6 + ; xmm1[63:32] == w[i+11] == RotWord(SubWord(w[i+5]))^Rcon^w[i+5]^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i] + ; xmm1[31:0] == w[i+10] == RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i] ; Set w[i+10] and w[i+11]. - movq qword ptr [ecx], xmm2 ; w[i+10] = RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i] + movq qword ptr [ecx], xmm1 ; w[i+10] = RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i] ; w[i+11] = RotWord(SubWord(w[i+5]))^Rcon^w[i+5]^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i] add ecx, 8 ; ecx = &w[i+12] ret +@raw_aes192_expand_key_schedule@36 endp -invert_key_schedule: - movdqa xmm7, [key_schedule] - movdqa xmm6, [key_schedule + 0C0h] - movdqa [inverted_key_schedule], xmm6 - movdqa [inverted_key_schedule + 0C0h], xmm7 +@raw_aes192_invert_key_schedule@8 proc + movdqa xmm7, [ecx] + movdqa xmm6, [ecx + 0C0h] + movdqa [edx], xmm6 + movdqa [edx + 0C0h], xmm7 - aesimc xmm7, [key_schedule + 10h] - aesimc xmm6, [key_schedule + 0B0h] - movdqa [inverted_key_schedule + 10h], xmm6 - movdqa [inverted_key_schedule + 0B0h], xmm7 + aesimc xmm7, [ecx + 10h] + aesimc xmm6, [ecx + 0B0h] + movdqa [edx + 10h], xmm6 + movdqa [edx + 0B0h], xmm7 - aesimc xmm7, [key_schedule + 20h] - aesimc xmm6, [key_schedule + 0A0h] - movdqa [inverted_key_schedule + 20h], xmm6 - movdqa [inverted_key_schedule + 0A0h], xmm7 + aesimc xmm7, [ecx + 20h] + aesimc xmm6, [ecx + 0A0h] + movdqa [edx + 20h], xmm6 + movdqa [edx + 0A0h], xmm7 - aesimc xmm7, [key_schedule + 30h] - aesimc xmm6, [key_schedule + 90h] - movdqa [inverted_key_schedule + 30h], xmm6 - movdqa [inverted_key_schedule + 90h], xmm7 + aesimc xmm7, [ecx + 30h] + aesimc xmm6, [ecx + 90h] + movdqa [edx + 30h], xmm6 + movdqa [edx + 90h], xmm7 - aesimc xmm7, [key_schedule + 40h] - aesimc xmm6, [key_schedule + 80h] - movdqa [inverted_key_schedule + 40h], xmm6 - movdqa [inverted_key_schedule + 80h], xmm7 + aesimc xmm7, [ecx + 40h] + aesimc xmm6, [ecx + 80h] + movdqa [edx + 40h], xmm6 + movdqa [edx + 80h], xmm7 - aesimc xmm7, [key_schedule + 50h] - aesimc xmm6, [key_schedule + 70h] - movdqa [inverted_key_schedule + 50h], xmm6 - movdqa [inverted_key_schedule + 70h], xmm7 + aesimc xmm7, [ecx + 50h] + aesimc xmm6, [ecx + 70h] + movdqa [edx + 50h], xmm6 + movdqa [edx + 70h], xmm7 - aesimc xmm7, [key_schedule + 60h] - movdqa [inverted_key_schedule + 60h], xmm7 + aesimc xmm7, [ecx + 60h] + movdqa [edx + 60h], xmm7 ret -expand_keys192 endp +@raw_aes192_invert_key_schedule@8 endp end diff --git a/src/aes256.asm b/src/aes256.asm index acea8e3..e59a253 100644 --- a/src/aes256.asm +++ b/src/aes256.asm @@ -6,76 +6,63 @@ .xmm .model flat -.data - -align 10h -key_schedule oword 15 dup(0) - -align 10h -inverse_key_schedule oword 15 dup(0) - .code -@raw_aes256ecb_encrypt@48 proc - call expand_keys256 - pxor xmm0, [key_schedule] - aesenc xmm0, [key_schedule + 10h] - aesenc xmm0, [key_schedule + 20h] - aesenc xmm0, [key_schedule + 30h] - aesenc xmm0, [key_schedule + 40h] - aesenc xmm0, [key_schedule + 50h] - aesenc xmm0, [key_schedule + 60h] - aesenc xmm0, [key_schedule + 70h] - aesenc xmm0, [key_schedule + 80h] - aesenc xmm0, [key_schedule + 90h] - aesenc xmm0, [key_schedule + 0A0h] - aesenc xmm0, [key_schedule + 0B0h] - aesenc xmm0, [key_schedule + 0C0h] - aesenc xmm0, [key_schedule + 0D0h] - aesenclast xmm0, [key_schedule + 0E0h] +@raw_aes256ecb_encrypt@20 proc + pxor xmm0, [ecx] + aesenc xmm0, [ecx + 10h] + aesenc xmm0, [ecx + 20h] + aesenc xmm0, [ecx + 30h] + aesenc xmm0, [ecx + 40h] + aesenc xmm0, [ecx + 50h] + aesenc xmm0, [ecx + 60h] + aesenc xmm0, [ecx + 70h] + aesenc xmm0, [ecx + 80h] + aesenc xmm0, [ecx + 90h] + aesenc xmm0, [ecx + 0A0h] + aesenc xmm0, [ecx + 0B0h] + aesenc xmm0, [ecx + 0C0h] + aesenc xmm0, [ecx + 0D0h] + aesenclast xmm0, [ecx + 0E0h] ret -@raw_aes256ecb_encrypt@48 endp +@raw_aes256ecb_encrypt@20 endp + +@raw_aes256cbc_encrypt@24 proc + pxor xmm0, [edx] + jmp @raw_aes256ecb_encrypt@20 +@raw_aes256cbc_encrypt@24 endp -@raw_aes256cbc_encrypt@52 proc +@raw_aes256ecb_decrypt@20 proc pxor xmm0, [ecx] - jmp @raw_aes256ecb_encrypt@48 -@raw_aes256cbc_encrypt@52 endp - -@raw_aes256ecb_decrypt@48 proc - call expand_keys256 - pxor xmm0, [inverse_key_schedule] - aesdec xmm0, [inverse_key_schedule + 10h] - aesdec xmm0, [inverse_key_schedule + 20h] - aesdec xmm0, [inverse_key_schedule + 30h] - aesdec xmm0, [inverse_key_schedule + 40h] - aesdec xmm0, [inverse_key_schedule + 50h] - aesdec xmm0, [inverse_key_schedule + 60h] - aesdec xmm0, [inverse_key_schedule + 70h] - aesdec xmm0, [inverse_key_schedule + 80h] - aesdec xmm0, [inverse_key_schedule + 90h] - aesdec xmm0, [inverse_key_schedule + 0A0h] - aesdec xmm0, [inverse_key_schedule + 0B0h] - aesdec xmm0, [inverse_key_schedule + 0C0h] - aesdec xmm0, [inverse_key_schedule + 0D0h] - aesdeclast xmm0, [inverse_key_schedule + 0E0h] + aesdec xmm0, [ecx + 10h] + aesdec xmm0, [ecx + 20h] + aesdec xmm0, [ecx + 30h] + aesdec xmm0, [ecx + 40h] + aesdec xmm0, [ecx + 50h] + aesdec xmm0, [ecx + 60h] + aesdec xmm0, [ecx + 70h] + aesdec xmm0, [ecx + 80h] + aesdec xmm0, [ecx + 90h] + aesdec xmm0, [ecx + 0A0h] + aesdec xmm0, [ecx + 0B0h] + aesdec xmm0, [ecx + 0C0h] + aesdec xmm0, [ecx + 0D0h] + aesdeclast xmm0, [ecx + 0E0h] ret -@raw_aes256ecb_decrypt@48 endp +@raw_aes256ecb_decrypt@20 endp -@raw_aes256cbc_decrypt@52 proc - push ecx - call @raw_aes256ecb_decrypt@48 - pop ecx - pxor xmm0, [ecx] +@raw_aes256cbc_decrypt@24 proc + call @raw_aes256ecb_decrypt@20 + pxor xmm0, [edx] ret -@raw_aes256cbc_decrypt@52 endp +@raw_aes256cbc_decrypt@24 endp -expand_keys256 proc +@raw_aes256_expand_key_schedule@36 proc ; A "word" (in terms of the FIPS 187 standard) is a 32-bit block. ; Words are denoted by `w[N]`. ; ; A key schedule is composed of 14 "regular" keys and a dumb key for ; the "whitening" step. - ; It's stored in `key_schedule`. ; ; A key schedule is thus composed of 60 "words". ; The FIPS standard includes an algorithm to calculate these words via @@ -128,99 +115,97 @@ expand_keys256 proc ; and RotWord using `aeskeygenassist`, which is used in this routine. ; ; Preconditions: - ; * xmm2[127:96] == w[7], - ; * xmm2[95:64] == w[6], - ; * xmm2[63:32] == w[5], - ; * xmm2[31:0] == w[4], - ; * xmm1[127:96] == w[3], - ; * xmm1[95:64] == w[2], - ; * xmm1[63:32] == w[1], - ; * xmm1[31:0] == w[0]. - - movdqa [key_schedule], xmm1 ; sets w[0], w[1], w[2], w[3] - movdqa [key_schedule + 10h], xmm2 ; sets w[4], w[5], w[6], w[7] - - lea ecx, [key_schedule + 20h] ; ecx = &w[8] - - aeskeygenassist xmm7, xmm2, 1h ; xmm7[127:96] = RotWord(SubWord(w[7]))^Rcon + ; * xmm1[127:96] == w[7], + ; * xmm1[95:64] == w[6], + ; * xmm1[63:32] == w[5], + ; * xmm1[31:0] == w[4], + ; * xmm0[127:96] == w[3], + ; * xmm0[95:64] == w[2], + ; * xmm0[63:32] == w[1], + ; * xmm0[31:0] == w[0]. + + movdqa [ecx], xmm0 ; sets w[0], w[1], w[2], w[3] + movdqa [ecx + 10h], xmm1 ; sets w[4], w[5], w[6], w[7] + lea ecx, [ecx + 20h] ; ecx = &w[8] + + aeskeygenassist xmm7, xmm1, 1h ; xmm7[127:96] = RotWord(SubWord(w[7]))^Rcon pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] call gen_round_key ; sets w[8], w[9], w[10], w[11] - aeskeygenassist xmm7, xmm2, 0 ; xmm7[95:64] = SubWord(w[11]) + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[11]) pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] call gen_round_key ; sets w[12], w[13], w[14], w[15] - aeskeygenassist xmm7, xmm2, 2h ; xmm7[127:96] = RotWord(SubWord(w[15]))^Rcon + aeskeygenassist xmm7, xmm1, 2h ; xmm7[127:96] = RotWord(SubWord(w[15]))^Rcon pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] call gen_round_key ; sets w[16], w[17], w[18], w[19] - aeskeygenassist xmm7, xmm2, 0 ; xmm7[95:64] = SubWord(w[19]) + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[19]) pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] call gen_round_key ; sets w[20], w[21], w[22], w[23] - aeskeygenassist xmm7, xmm2, 4h ; xmm7[127:96] = RotWord(SubWord(w[23]))^Rcon + aeskeygenassist xmm7, xmm1, 4h ; xmm7[127:96] = RotWord(SubWord(w[23]))^Rcon pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] call gen_round_key ; sets w[24], w[25], w[26], w[27] - aeskeygenassist xmm7, xmm2, 0 ; xmm7[95:64] = SubWord(w[27]) + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[27]) pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] call gen_round_key ; sets w[28], w[29], w[30], w[31] - aeskeygenassist xmm7, xmm2, 8h ; xmm7[127:96] = RotWord(SubWord(w[31]))^Rcon + aeskeygenassist xmm7, xmm1, 8h ; xmm7[127:96] = RotWord(SubWord(w[31]))^Rcon pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] call gen_round_key ; sets w[32], w[33], w[34], w[35] - aeskeygenassist xmm7, xmm2, 0 ; xmm7[95:64] = SubWord(w[35]) + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[35]) pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] call gen_round_key ; sets w[36], w[37], w[38], w[39] - aeskeygenassist xmm7, xmm2, 10h ; xmm7[127:96] = RotWord(SubWord(w[39]))^Rcon + aeskeygenassist xmm7, xmm1, 10h ; xmm7[127:96] = RotWord(SubWord(w[39]))^Rcon pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] call gen_round_key ; sets w[40], w[41], w[42], w[43] - aeskeygenassist xmm7, xmm2, 0 ; xmm7[95:64] = SubWord(w[43]) + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[43]) pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] call gen_round_key ; sets w[44], w[45], w[46], w[47] - aeskeygenassist xmm7, xmm2, 20h ; xmm7[127:96] = RotWord(SubWord(w[47]))^Rcon + aeskeygenassist xmm7, xmm1, 20h ; xmm7[127:96] = RotWord(SubWord(w[47]))^Rcon pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] call gen_round_key ; sets w[48], w[49], w[50], w[51] - aeskeygenassist xmm7, xmm2, 0 ; xmm7[95:64] = SubWord(w[51]) + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[51]) pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] call gen_round_key ; sets w[52], w[53], w[54], w[55] - aeskeygenassist xmm7, xmm2, 40h ; xmm7[127:96] = RotWord(SubWord(w[55]))^Rcon + aeskeygenassist xmm7, xmm1, 40h ; xmm7[127:96] = RotWord(SubWord(w[55]))^Rcon pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] call gen_round_key ; sets w[56], w[57], w[58], w[59] - call invert_key_schedule ret gen_round_key: ; Preconditions: - ; * xmm2[127:96] == w[i+7], - ; * xmm2[95:64] == w[i+6], - ; * xmm2[63:32] == w[i+5], - ; * xmm2[31:0] == w[i+4], - ; * xmm1[127:96] == w[i+3], - ; * xmm1[95:64] == w[i+2], - ; * xmm1[63:32] == w[i+1], - ; * xmm1[31:0] == w[i], + ; * xmm1[127:96] == w[i+7], + ; * xmm1[95:64] == w[i+6], + ; * xmm1[63:32] == w[i+5], + ; * xmm1[31:0] == w[i+4], + ; * xmm0[127:96] == w[i+3], + ; * xmm0[95:64] == w[i+2], + ; * xmm0[63:32] == w[i+1], + ; * xmm0[31:0] == w[i], ; * xmm7[127:96] == xmm7[95:64] == xmm7[63:32] == xmm7[31:0] == HWGEN, ; where HWGEN is either RotWord(SubWord(w[i+7]))^Rcon or SubWord(w[i+7]), ; depending on the number of the round being processed, ; * ecx == &w[i+8]. ; ; Postconditions: - ; * xmm2[127:96] == w[i+11] == HWGEN^w[i+3]^w[i+2]^w[i+1]^w[i], - ; * xmm2[95:64] == w[i+10] == HWGEN^w[i+2]^w[i+1]^w[i], - ; * xmm2[63:32] == w[i+9] == HWGEN^w[i+1]^w[i], - ; * xmm2[31:0] == w[i+8] == HWGEN^w[i], - ; * xmm1[127:96] == w[i+7], - ; * xmm1[95:64] == w[i+6], - ; * xmm1[63:32] == w[i+5], - ; * xmm1[31:0] == w[i+4], + ; * xmm1[127:96] == w[i+11] == HWGEN^w[i+3]^w[i+2]^w[i+1]^w[i], + ; * xmm1[95:64] == w[i+10] == HWGEN^w[i+2]^w[i+1]^w[i], + ; * xmm1[63:32] == w[i+9] == HWGEN^w[i+1]^w[i], + ; * xmm1[31:0] == w[i+8] == HWGEN^w[i], + ; * xmm0[127:96] == w[i+7], + ; * xmm0[95:64] == w[i+6], + ; * xmm0[63:32] == w[i+5], + ; * xmm0[31:0] == w[i+4], ; * ecx == &w[i+12], ; * the value in xmm6 is also modified. @@ -229,83 +214,84 @@ gen_round_key: ; w[i+2]^w[i+1]^w[i], ; w[i+1]^w[i] and ; w[i]. - movdqa xmm6, xmm1 ; xmm6 = xmm1 + movdqa xmm6, xmm0 ; xmm6 = xmm0 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 + pxor xmm0, xmm6 ; xmm0 ^= xmm6 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 + pxor xmm0, xmm6 ; xmm0 ^= xmm6 pslldq xmm6, 4 ; xmm6 <<= 32 - pxor xmm1, xmm6 ; xmm1 ^= xmm6 - ; xmm1[127:96] == w[i+3]^w[i+2]^w[i+1]^w[i] - ; xmm1[95:64] == w[i+2]^w[i+1]^w[i] - ; xmm1[63:32] == w[i+1]^w[i] - ; xmm1[31:0] == w[i] + pxor xmm0, xmm6 ; xmm0 ^= xmm6 + ; xmm0[127:96] == w[i+3]^w[i+2]^w[i+1]^w[i] + ; xmm0[95:64] == w[i+2]^w[i+1]^w[i] + ; xmm0[63:32] == w[i+1]^w[i] + ; xmm0[31:0] == w[i] ; Calculate ; HWGEN^w[i+3]^w[i+2]^w[i+1]^w[i], ; HWGEN^w[i+2]^w[i+1]^w[i], ; HWGEN^w[i+1]^w[i] and ; HWGEN^w[i]. - pxor xmm1, xmm7 ; xmm1 ^= xmm7 - ; xmm1[127:96] == w[i+11] == HWGEN^w[i+3]^w[i+2]^w[i+1]^w[i] - ; xmm1[95:64] == w[i+10] == HWGEN^w[i+2]^w[i+1]^w[i] - ; xmm1[63:32] == w[i+9] == HWGEN^w[i+1]^w[i] - ; xmm1[31:0] == w[i+8] == HWGEN^w[i] + pxor xmm0, xmm7 ; xmm0 ^= xmm7 + ; xmm0[127:96] == w[i+11] == HWGEN^w[i+3]^w[i+2]^w[i+1]^w[i] + ; xmm0[95:64] == w[i+10] == HWGEN^w[i+2]^w[i+1]^w[i] + ; xmm0[63:32] == w[i+9] == HWGEN^w[i+1]^w[i] + ; xmm0[31:0] == w[i+8] == HWGEN^w[i] ; Set w[i+8], w[i+9], w[i+10] and w[i+11]. - movdqa [ecx], xmm1 ; w[i+8] = HWGEN^w[i] + movdqa [ecx], xmm0 ; w[i+8] = HWGEN^w[i] ; w[i+9] = HWGEN^w[i+1]^w[i] ; w[i+10] = HWGEN^w[i+2]^w[i+1]^w[i] ; w[i+11] = HWGEN^w[i+3]^w[i+2]^w[i+1]^w[i] add ecx, 10h ; ecx = &w[i+12] - ; Swap the values in xmm1 and xmm2. - pxor xmm1, xmm2 - pxor xmm2, xmm1 - pxor xmm1, xmm2 + ; Swap the values in xmm0 and xmm1. + pxor xmm0, xmm1 + pxor xmm1, xmm0 + pxor xmm0, xmm1 ret - -invert_key_schedule: - movdqa xmm7, [key_schedule ] - movdqa xmm6, [key_schedule + 0E0h] - movdqa [inverse_key_schedule ], xmm6 - movdqa [inverse_key_schedule + 0E0h], xmm7 - - aesimc xmm7, [key_schedule + 10h] - aesimc xmm6, [key_schedule + 0D0h] - movdqa [inverse_key_schedule + 10h], xmm6 - movdqa [inverse_key_schedule + 0D0h], xmm7 - - aesimc xmm7, [key_schedule + 20h] - aesimc xmm6, [key_schedule + 0C0h] - movdqa [inverse_key_schedule + 20h], xmm6 - movdqa [inverse_key_schedule + 0C0h], xmm7 - - aesimc xmm7, [key_schedule + 30h] - aesimc xmm6, [key_schedule + 0B0h] - movdqa [inverse_key_schedule + 30h], xmm6 - movdqa [inverse_key_schedule + 0B0h], xmm7 - - aesimc xmm7, [key_schedule + 40h] - aesimc xmm6, [key_schedule + 0A0h] - movdqa [inverse_key_schedule + 40h], xmm6 - movdqa [inverse_key_schedule + 0A0h], xmm7 - - aesimc xmm7, [key_schedule + 50h] - aesimc xmm6, [key_schedule + 90h] - movdqa [inverse_key_schedule + 50h], xmm6 - movdqa [inverse_key_schedule + 90h], xmm7 - - aesimc xmm7, [key_schedule + 60h] - aesimc xmm6, [key_schedule + 80h] - movdqa [inverse_key_schedule + 60h], xmm6 - movdqa [inverse_key_schedule + 80h], xmm7 - - aesimc xmm7, [key_schedule + 70h] - movdqa [inverse_key_schedule + 70h], xmm7 +@raw_aes256_expand_key_schedule@36 endp + +@raw_aes256_invert_key_schedule@8 proc + movdqa xmm7, [ecx] + movdqa xmm6, [ecx + 0E0h] + movdqa [edx], xmm6 + movdqa [edx + 0E0h], xmm7 + + aesimc xmm7, [ecx + 10h] + aesimc xmm6, [ecx + 0D0h] + movdqa [edx + 10h], xmm6 + movdqa [edx + 0D0h], xmm7 + + aesimc xmm7, [ecx + 20h] + aesimc xmm6, [ecx + 0C0h] + movdqa [edx + 20h], xmm6 + movdqa [edx + 0C0h], xmm7 + + aesimc xmm7, [ecx + 30h] + aesimc xmm6, [ecx + 0B0h] + movdqa [edx + 30h], xmm6 + movdqa [edx + 0B0h], xmm7 + + aesimc xmm7, [ecx + 40h] + aesimc xmm6, [ecx + 0A0h] + movdqa [edx + 40h], xmm6 + movdqa [edx + 0A0h], xmm7 + + aesimc xmm7, [ecx + 50h] + aesimc xmm6, [ecx + 90h] + movdqa [edx + 50h], xmm6 + movdqa [edx + 90h], xmm7 + + aesimc xmm7, [ecx + 60h] + aesimc xmm6, [ecx + 80h] + movdqa [edx + 60h], xmm6 + movdqa [edx + 80h], xmm7 + + aesimc xmm7, [ecx + 70h] + movdqa [edx + 70h], xmm7 ret -expand_keys256 endp +@raw_aes256_invert_key_schedule@8 endp end diff --git a/test/aes128cbc_decrypt_block.c b/test/aes128cbc_decrypt_block.c index 1a77cdf..3bd5d74 100644 --- a/test/aes128cbc_decrypt_block.c +++ b/test/aes128cbc_decrypt_block.c @@ -20,6 +20,7 @@ static void exit_with_usage(const char* argv0) int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, key, cipher, iv; + __declspec(align(16)) Aes128KeySchedule key_schedule, inverted_schedule; if (argc < 3) exit_with_usage(argv[0]); @@ -36,6 +37,9 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes128_expand_key_schedule(key, &key_schedule); + aes128_invert_key_schedule(&key_schedule, &inverted_schedule); + for (int i = 3; i < argc; ++i) { if (parse_aes_block128(&cipher, argv[i]) != 0) @@ -43,7 +47,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - plain = aes128cbc_decrypt(cipher, key, &iv); + plain = aes128cbc_decrypt(cipher, &inverted_schedule, &iv); print_aes_block128(&plain); } diff --git a/test/aes128cbc_encrypt_block.c b/test/aes128cbc_encrypt_block.c index 31bb479..e35a1bf 100644 --- a/test/aes128cbc_encrypt_block.c +++ b/test/aes128cbc_encrypt_block.c @@ -20,6 +20,7 @@ static void exit_with_usage(const char* argv0) int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, key, cipher, iv; + __declspec(align(16)) Aes128KeySchedule key_schedule; if (argc < 3) exit_with_usage(argv[0]); @@ -36,6 +37,8 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes128_expand_key_schedule(key, &key_schedule); + for (int i = 3; i < argc; ++i) { if (parse_aes_block128(&plain, argv[i]) != 0) @@ -43,7 +46,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - cipher = aes128cbc_encrypt(plain, key, &iv); + cipher = aes128cbc_encrypt(plain, &key_schedule, &iv); print_aes_block128(&cipher); } diff --git a/test/aes128ecb_decrypt_block.c b/test/aes128ecb_decrypt_block.c index 188524b..70c7285 100644 --- a/test/aes128ecb_decrypt_block.c +++ b/test/aes128ecb_decrypt_block.c @@ -20,6 +20,7 @@ static void exit_with_usage(const char* argv0) int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, key, cipher; + __declspec(align(16)) Aes128KeySchedule key_schedule, inverted_schedule; if (argc < 2) exit_with_usage(argv[0]); @@ -30,6 +31,9 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes128_expand_key_schedule(key, &key_schedule); + aes128_invert_key_schedule(&key_schedule, &inverted_schedule); + for (int i = 2; i < argc; ++i) { if (parse_aes_block128(&cipher, argv[i]) != 0) @@ -37,7 +41,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - plain = aes128ecb_decrypt(cipher, key); + plain = aes128ecb_decrypt(cipher, &inverted_schedule); print_aes_block128(&plain); } diff --git a/test/aes128ecb_encrypt_block.c b/test/aes128ecb_encrypt_block.c index 27c7a0e..8f0bf0a 100644 --- a/test/aes128ecb_encrypt_block.c +++ b/test/aes128ecb_encrypt_block.c @@ -20,6 +20,7 @@ static void exit_with_usage(const char* argv0) int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, key, cipher; + __declspec(align(16)) Aes128KeySchedule key_schedule; if (argc < 2) exit_with_usage(argv[0]); @@ -30,6 +31,8 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes128_expand_key_schedule(key, &key_schedule); + for (int i = 2; i < argc; ++i) { if (parse_aes_block128(&plain, argv[i]) != 0) @@ -37,7 +40,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - cipher = aes128ecb_encrypt(plain, key); + cipher = aes128ecb_encrypt(plain, &key_schedule); print_aes_block128(&cipher); } diff --git a/test/aes192cbc_decrypt_block.c b/test/aes192cbc_decrypt_block.c index 0fddf43..3d912ba 100644 --- a/test/aes192cbc_decrypt_block.c +++ b/test/aes192cbc_decrypt_block.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, cipher, iv; __declspec(align(16)) AesBlock192 key; + __declspec(align(16)) Aes192KeySchedule key_schedule, inverted_schedule; if (argc < 3) exit_with_usage(argv[0]); @@ -37,6 +38,9 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes192_expand_key_schedule(&key, &key_schedule); + aes192_invert_key_schedule(&key_schedule, &inverted_schedule); + for (int i = 3; i < argc; ++i) { if (parse_aes_block128(&cipher, argv[i]) != 0) @@ -44,7 +48,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - plain = aes192cbc_decrypt(cipher, &key, &iv); + plain = aes192cbc_decrypt(cipher, &inverted_schedule, &iv); print_aes_block128(&plain); } diff --git a/test/aes192cbc_encrypt_block.c b/test/aes192cbc_encrypt_block.c index 069c408..21765f5 100644 --- a/test/aes192cbc_encrypt_block.c +++ b/test/aes192cbc_encrypt_block.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, cipher, iv; __declspec(align(16)) AesBlock192 key; + __declspec(align(16)) Aes192KeySchedule key_schedule; if (argc < 3) exit_with_usage(argv[0]); @@ -37,6 +38,8 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes192_expand_key_schedule(&key, &key_schedule); + for (int i = 3; i < argc; ++i) { if (parse_aes_block128(&plain, argv[i]) != 0) @@ -44,7 +47,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - cipher = aes192cbc_encrypt(plain, &key, &iv); + cipher = aes192cbc_encrypt(plain, &key_schedule, &iv); print_aes_block128(&cipher); } diff --git a/test/aes192ecb_decrypt_block.c b/test/aes192ecb_decrypt_block.c index 73827a2..e6e749a 100644 --- a/test/aes192ecb_decrypt_block.c +++ b/test/aes192ecb_decrypt_block.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, cipher; __declspec(align(16)) AesBlock192 key; + __declspec(align(16)) Aes192KeySchedule key_schedule, inverted_schedule; if (argc < 2) exit_with_usage(argv[0]); @@ -31,6 +32,9 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes192_expand_key_schedule(&key, &key_schedule); + aes192_invert_key_schedule(&key_schedule, &inverted_schedule); + for (int i = 2; i < argc; ++i) { if (parse_aes_block128(&cipher, argv[i]) != 0) @@ -38,7 +42,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - plain = aes192ecb_decrypt(cipher, &key); + plain = aes192ecb_decrypt(cipher, &inverted_schedule); print_aes_block128(&plain); } diff --git a/test/aes192ecb_encrypt_block.c b/test/aes192ecb_encrypt_block.c index 9f2db50..2b4f688 100644 --- a/test/aes192ecb_encrypt_block.c +++ b/test/aes192ecb_encrypt_block.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, cipher; __declspec(align(16)) AesBlock192 key; + __declspec(align(16)) Aes192KeySchedule key_schedule; if (argc < 2) exit_with_usage(argv[0]); @@ -31,6 +32,8 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes192_expand_key_schedule(&key, &key_schedule); + for (int i = 2; i < argc; ++i) { if (parse_aes_block128(&plain, argv[i]) != 0) @@ -38,7 +41,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - cipher = aes192ecb_encrypt(plain, &key); + cipher = aes192ecb_encrypt(plain, &key_schedule); print_aes_block128(&cipher); } diff --git a/test/aes256cbc_decrypt_block.c b/test/aes256cbc_decrypt_block.c index bac98e3..bb082d5 100644 --- a/test/aes256cbc_decrypt_block.c +++ b/test/aes256cbc_decrypt_block.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, cipher, iv; __declspec(align(16)) AesBlock256 key; + __declspec(align(16)) Aes256KeySchedule key_schedule, inverted_schedule; if (argc < 3) exit_with_usage(argv[0]); @@ -37,6 +38,9 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes256_expand_key_schedule(&key, &key_schedule); + aes256_invert_key_schedule(&key_schedule, &inverted_schedule); + for (int i = 3; i < argc; ++i) { if (parse_aes_block128(&cipher, argv[i]) != 0) @@ -44,7 +48,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - plain = aes256cbc_decrypt(cipher, &key, &iv); + plain = aes256cbc_decrypt(cipher, &inverted_schedule, &iv); print_aes_block128(&plain); } diff --git a/test/aes256cbc_encrypt_block.c b/test/aes256cbc_encrypt_block.c index 08ca11b..1436020 100644 --- a/test/aes256cbc_encrypt_block.c +++ b/test/aes256cbc_encrypt_block.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, cipher, iv; __declspec(align(16)) AesBlock256 key; + __declspec(align(16)) Aes256KeySchedule key_schedule; if (argc < 3) exit_with_usage(argv[0]); @@ -37,6 +38,8 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes256_expand_key_schedule(&key, &key_schedule); + for (int i = 3; i < argc; ++i) { if (parse_aes_block128(&plain, argv[i]) != 0) @@ -44,7 +47,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - cipher = aes256cbc_encrypt(plain, &key, &iv); + cipher = aes256cbc_encrypt(plain, &key_schedule, &iv); print_aes_block128(&cipher); } diff --git a/test/aes256ecb_decrypt_block.c b/test/aes256ecb_decrypt_block.c index f3126fe..a290eed 100644 --- a/test/aes256ecb_decrypt_block.c +++ b/test/aes256ecb_decrypt_block.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, cipher; __declspec(align(16)) AesBlock256 key; + __declspec(align(16)) Aes256KeySchedule key_schedule, inverted_schedule; if (argc < 2) exit_with_usage(argv[0]); @@ -31,6 +32,9 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes256_expand_key_schedule(&key, &key_schedule); + aes256_invert_key_schedule(&key_schedule, &inverted_schedule); + for (int i = 2; i < argc; ++i) { if (parse_aes_block128(&cipher, argv[i]) != 0) @@ -38,7 +42,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - plain = aes256ecb_decrypt(cipher, &key); + plain = aes256ecb_decrypt(cipher, &inverted_schedule); print_aes_block128(&plain); } diff --git a/test/aes256ecb_encrypt_block.c b/test/aes256ecb_encrypt_block.c index 3fb979d..2a4899e 100644 --- a/test/aes256ecb_encrypt_block.c +++ b/test/aes256ecb_encrypt_block.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { __declspec(align(16)) AesBlock128 plain, cipher; __declspec(align(16)) AesBlock256 key; + __declspec(align(16)) Aes256KeySchedule key_schedule; if (argc < 2) exit_with_usage(argv[0]); @@ -31,6 +32,8 @@ int main(int argc, char** argv) exit_with_usage(argv[0]); } + aes256_expand_key_schedule(&key, &key_schedule); + for (int i = 2; i < argc; ++i) { if (parse_aes_block128(&plain, argv[i]) != 0) @@ -38,7 +41,7 @@ int main(int argc, char** argv) fprintf(stderr, "Invalid 128-bit AES block '%s'\n", argv[i]); continue; } - cipher = aes256ecb_encrypt(plain, &key); + cipher = aes256ecb_encrypt(plain, &key_schedule); print_aes_block128(&cipher); } |