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/aesni/api.h | |
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 'include/aesni/api.h')
-rw-r--r-- | include/aesni/api.h | 94 |
1 files changed, 68 insertions, 26 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); } |