diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-30 05:13:44 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-30 05:13:44 +0300 |
commit | 1109190cc2edd86f12cdd16847f3e80e48dccc50 (patch) | |
tree | a688b89f7e4ede0defaeb79ffb8e8a99ece5a395 /include | |
parent | support AES-{128,192}-cbc (diff) | |
download | aes-tools-1109190cc2edd86f12cdd16847f3e80e48dccc50.tar.gz aes-tools-1109190cc2edd86f12cdd16847f3e80e48dccc50.zip |
detach key expansion routines
Block encryption/decryption routines now don't expand key schedules on
each call.
Diffstat (limited to '')
-rw-r--r-- | include/aesni/api.h | 94 | ||||
-rw-r--r-- | include/aesni/data.h | 19 | ||||
-rw-r--r-- | include/aesni/raw.h | 53 |
3 files changed, 121 insertions, 45 deletions
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); |