diff options
| author | Egor Tensin <egor@tensin.name> | 2026-07-22 18:31:50 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-07-22 21:07:53 +0200 |
| commit | 4720b5ac21163936fb47f524037a6f12ce6e6ce2 (patch) | |
| tree | 7b1f3f7f0e4047134048bb9b9967498b6f8ead12 /aesxx/include | |
| parent | minor refactoring (diff) | |
| download | aes-tools-4720b5ac21163936fb47f524037a6f12ce6e6ce2.tar.gz aes-tools-4720b5ac21163936fb47f524037a6f12ce6e6ce2.zip | |
rewrite: the beginning
This a giant fuck-you to myself while I have nothing (actually, tons of
things) to do in a hospital.
* The giant screens of preprocessor code are gone, they always sucked,
fuck them.
* Switched everything to the "boxes" interface as the only one
remaining.
* Restuctured things in aes/ so that the files they're in make at least
a little bit of sense.
* Removed a bunch of cruft and prematurely generic code.
* This is half-baked at best: I just made sure that the tests pass. A
lot of cleanup awaits.
Diffstat (limited to 'aesxx/include')
| -rw-r--r-- | aesxx/include/aesxx/aes.hpp | 230 | ||||
| -rw-r--r-- | aesxx/include/aesxx/all.hpp | 2 | ||||
| -rw-r--r-- | aesxx/include/aesxx/api.hpp | 136 | ||||
| -rw-r--r-- | aesxx/include/aesxx/box.hpp | 71 | ||||
| -rw-r--r-- | aesxx/include/aesxx/data.hpp | 58 | ||||
| -rw-r--r-- | aesxx/include/aesxx/mode.hpp | 120 |
6 files changed, 70 insertions, 547 deletions
diff --git a/aesxx/include/aesxx/aes.hpp b/aesxx/include/aesxx/aes.hpp deleted file mode 100644 index 38d98fa..0000000 --- a/aesxx/include/aesxx/aes.hpp +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com> -// This file is part of the "AES tools" project. -// For details, see https://github.com/egor-tensin/aes-tools. -// Distributed under the MIT License. - -#pragma once - -#include "algorithm.hpp" -#include "api.hpp" -#include "error.hpp" -#include "mode.hpp" - -#include <aes/all.h> - -#include <cstddef> -#include <string> -#include <string_view> - -namespace aes { -namespace aes128 { - -typedef AES_Block Block; -typedef AES128_RoundKeys RoundKeys; -typedef AES128_Key Key; - -} // namespace aes128 - -template <> -struct Types<AES_AES128> { - typedef aes128::Block Block; - typedef aes128::RoundKeys RoundKeys; - typedef aes128::Key Key; -}; - -template <> -inline void from_string<AES_AES128>(aes128::Block& dest, std::string_view src) { - aes_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); -} - -template <> -inline std::string to_string<AES_AES128>(const aes128::Block& src) { - AES_BlockString str; - aes_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline std::string to_matrix_string<AES_AES128>(const aes128::Block& src) { - AES_BlockMatrixString str; - aes_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline void from_string<AES_AES128>(aes128::Key& dest, std::string_view src) { - aes128_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); -} - -template <> -inline std::string to_string<AES_AES128>(const aes128::Key& src) { - AES128_KeyString str; - aes128_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline void expand_key<AES_AES128>(const aes128::Key& key, aes128::RoundKeys& encryption_keys) { - aes128_expand_key(&key, &encryption_keys); -} - -template <> -inline void derive_decryption_keys<AES_AES128>( - const aes128::RoundKeys& encryption_keys, - aes128::RoundKeys& decryption_keys -) { - aes128_derive_decryption_keys(&encryption_keys, &decryption_keys); -} - -AESXX_ENCRYPT_BLOCK_ECB(128); -AESXX_DECRYPT_BLOCK_ECB(128); -AESXX_ENCRYPT_BLOCK_CBC(128); -AESXX_DECRYPT_BLOCK_CBC(128); -AESXX_ENCRYPT_BLOCK_CFB(128); -AESXX_DECRYPT_BLOCK_CFB(128); -AESXX_ENCRYPT_BLOCK_OFB(128); -AESXX_DECRYPT_BLOCK_OFB(128); -AESXX_ENCRYPT_BLOCK_CTR(128); -AESXX_DECRYPT_BLOCK_CTR(128); - -namespace aes192 { - -typedef AES_Block Block; -typedef AES192_RoundKeys RoundKeys; -typedef AES192_Key Key; - -} // namespace aes192 - -template <> -struct Types<AES_AES192> { - typedef aes192::Block Block; - typedef aes192::RoundKeys RoundKeys; - typedef aes192::Key Key; -}; - -template <> -inline void from_string<AES_AES192>(aes192::Block& dest, std::string_view src) { - aes_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); -} - -template <> -inline std::string to_string<AES_AES192>(const aes192::Block& src) { - AES_BlockString str; - aes_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline std::string to_matrix_string<AES_AES192>(const aes192::Block& src) { - AES_BlockMatrixString str; - aes_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline void from_string<AES_AES192>(aes192::Key& dest, std::string_view src) { - aes192_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); -} - -template <> -inline std::string to_string<AES_AES192>(const aes192::Key& src) { - AES192_KeyString str; - aes192_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline void expand_key<AES_AES192>(const aes192::Key& key, aes192::RoundKeys& encryption_keys) { - aes192_expand_key(&key, &encryption_keys); -} - -template <> -inline void derive_decryption_keys<AES_AES192>( - const aes192::RoundKeys& encryption_keys, - aes192::RoundKeys& decryption_keys -) { - aes192_derive_decryption_keys(&encryption_keys, &decryption_keys); -} - -AESXX_ENCRYPT_BLOCK_ECB(192); -AESXX_DECRYPT_BLOCK_ECB(192); -AESXX_ENCRYPT_BLOCK_CBC(192); -AESXX_DECRYPT_BLOCK_CBC(192); -AESXX_ENCRYPT_BLOCK_CFB(192); -AESXX_DECRYPT_BLOCK_CFB(192); -AESXX_ENCRYPT_BLOCK_OFB(192); -AESXX_DECRYPT_BLOCK_OFB(192); -AESXX_ENCRYPT_BLOCK_CTR(192); -AESXX_DECRYPT_BLOCK_CTR(192); - -namespace aes256 { - -typedef AES_Block Block; -typedef AES256_RoundKeys RoundKeys; -typedef AES256_Key Key; - -} // namespace aes256 - -template <> -struct Types<AES_AES256> { - typedef aes256::Block Block; - typedef aes256::RoundKeys RoundKeys; - typedef aes256::Key Key; -}; - -template <> -inline void from_string<AES_AES256>(aes256::Block& dest, std::string_view src) { - aes_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); -} - -template <> -inline std::string to_string<AES_AES256>(const aes256::Block& src) { - AES_BlockString str; - aes_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline std::string to_matrix_string<AES_AES256>(const aes256::Block& src) { - AES_BlockMatrixString str; - aes_format_block_as_matrix(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline void from_string<AES_AES256>(aes256::Key& dest, std::string_view src) { - aes256_parse_key(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); -} - -template <> -inline std::string to_string<AES_AES256>(const aes256::Key& src) { - AES256_KeyString str; - aes256_format_key(&str, &src, ErrorDetailsThrowsInDestructor{}); - return {str.str}; -} - -template <> -inline void expand_key<AES_AES256>(const aes256::Key& key, aes256::RoundKeys& encryption_keys) { - aes256_expand_key(&key, &encryption_keys); -} - -template <> -inline void derive_decryption_keys<AES_AES256>( - const aes256::RoundKeys& encryption_keys, - aes256::RoundKeys& decryption_keys -) { - aes256_derive_decryption_keys(&encryption_keys, &decryption_keys); -} - -AESXX_ENCRYPT_BLOCK_ECB(256); -AESXX_DECRYPT_BLOCK_ECB(256); -AESXX_ENCRYPT_BLOCK_CBC(256); -AESXX_DECRYPT_BLOCK_CBC(256); -AESXX_ENCRYPT_BLOCK_CFB(256); -AESXX_DECRYPT_BLOCK_CFB(256); -AESXX_ENCRYPT_BLOCK_OFB(256); -AESXX_DECRYPT_BLOCK_OFB(256); -AESXX_ENCRYPT_BLOCK_CTR(256); -AESXX_DECRYPT_BLOCK_CTR(256); - -} // namespace aes diff --git a/aesxx/include/aesxx/all.hpp b/aesxx/include/aesxx/all.hpp index 99202a7..acea406 100644 --- a/aesxx/include/aesxx/all.hpp +++ b/aesxx/include/aesxx/all.hpp @@ -5,9 +5,7 @@ #pragma once -#include "aes.hpp" #include "algorithm.hpp" -#include "api.hpp" #include "box.hpp" #include "data.hpp" #include "debug.hpp" diff --git a/aesxx/include/aesxx/api.hpp b/aesxx/include/aesxx/api.hpp deleted file mode 100644 index 131e5e5..0000000 --- a/aesxx/include/aesxx/api.hpp +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com> -// This file is part of the "AES tools" project. -// For details, see https://github.com/egor-tensin/aes-tools. -// Distributed under the MIT License. - -#pragma once - -#include "algorithm.hpp" -#include "mode.hpp" - -#include <cstddef> -#include <string> -#include <string_view> -#include <type_traits> - -namespace aes { - -template <Algorithm algorithm> -struct Types; - -template <Algorithm algorithm> -std::size_t get_number_of_rounds() { - if constexpr (algorithm == AES_AES128) - return 11; - if constexpr (algorithm == AES_AES192) - return 13; - if constexpr (algorithm == AES_AES256) - return 15; - static_assert("Unrecognized algorithm"); -} - -template <Algorithm algorithm> -void from_string(typename Types<algorithm>::Block&, std::string_view); - -template <Algorithm algorithm> -std::string to_string(const typename Types<algorithm>::Block&); - -template <Algorithm algorithm> -std::string to_matrix_string(const typename Types<algorithm>::Block&); - -template <Algorithm algorithm> -void from_string(typename Types<algorithm>::Key&, std::string_view); - -template <Algorithm algorithm> -std::string to_string(const typename Types<algorithm>::Key&); - -template <Algorithm algorithm> -void expand_key( - const typename Types<algorithm>::Key& key, - typename Types<algorithm>::RoundKeys& encryption_keys -); - -template <Algorithm algorithm> -void derive_decryption_keys( - const typename Types<algorithm>::RoundKeys& encryption_keys, - typename Types<algorithm>::RoundKeys& decryption_keys -); - -template <Algorithm algorithm, Mode mode> -void encrypt_block( - const typename Types<algorithm>::Block& plaintext, - const typename Types<algorithm>::RoundKeys& round_keys, - typename Types<algorithm>::Block& iv, - typename Types<algorithm>::Block& ciphertext -) { - if constexpr (mode_requires_init_vector(mode)) { - encrypt_block(plaintext, round_keys, iv, ciphertext); - } else { - encrypt_block(plaintext, round_keys, ciphertext); - } -} - -template <Algorithm algorithm, Mode mode> -void decrypt_block( - const typename Types<algorithm>::Block& ciphertext, - const typename Types<algorithm>::RoundKeys& round_keys, - typename Types<algorithm>::Block& iv, - typename Types<algorithm>::Block& plaintext -) { - if constexpr (mode_requires_init_vector(mode)) { - encrypt_block(plaintext, round_keys, iv, ciphertext); - } else { - encrypt_block(plaintext, round_keys, ciphertext); - } -} - -template <Algorithm algorithm, Mode mode> -struct EncryptWrapper { - EncryptWrapper( - const typename Types<algorithm>::Key& key, - const typename Types<algorithm>::Block& iv - ) - : iv{iv} { - expand_key<algorithm>(key, encryption_keys); - } - - void encrypt_block( - const typename Types<algorithm>::Block& plaintext, - typename Types<algorithm>::Block& ciphertext - ) { - aes::encrypt_block<algorithm, mode>(plaintext, encryption_keys, iv, ciphertext); - } - - typename Types<algorithm>::Block iv; - typename Types<algorithm>::RoundKeys encryption_keys; -}; - -template <Algorithm algorithm, Mode mode> -struct DecryptWrapper { - DecryptWrapper( - const typename Types<algorithm>::Key& key, - const typename Types<algorithm>::Block& iv - ) - : iv{iv} { - typename Types<algorithm>::RoundKeys encryption_keys; - expand_key<algorithm>(key, encryption_keys); - - if constexpr (mode_uses_encryption_keys_only(mode)) { - decryption_keys = encryption_keys; - } else { - derive_decryption_keys<algorithm>(encryption_keys, decryption_keys); - } - } - - void decrypt_block( - const typename Types<algorithm>::Block& ciphertext, - typename Types<algorithm>::Block& plaintext - ) { - aes::decrypt_block<algorithm, mode>(ciphertext, decryption_keys, iv, plaintext); - } - - typename Types<algorithm>::Block iv; - typename Types<algorithm>::RoundKeys decryption_keys; -}; - -} // namespace aes diff --git a/aesxx/include/aesxx/box.hpp b/aesxx/include/aesxx/box.hpp index 870b3a7..c2ea6c9 100644 --- a/aesxx/include/aesxx/box.hpp +++ b/aesxx/include/aesxx/box.hpp @@ -6,12 +6,14 @@ #pragma once #include "algorithm.hpp" +#include "data.hpp" #include "error.hpp" #include "mode.hpp" #include <aes/all.h> #include <cstddef> +#include <iostream> #include <string> #include <string_view> #include <vector> @@ -20,43 +22,48 @@ namespace aes { class Box { public: - typedef AES_Block Block; - typedef AES_BoxKey Key; + using Key = AES_Key; + /* static std::string format_key(const Key& src, Algorithm algorithm) { - AES_BoxKeyString str; - aes_box_format_key(&str, algorithm, &src, ErrorDetailsThrowsInDestructor{}); + AES_KeyString str; + aes_format_key(&str, algorithm, &src, ErrorDetailsThrowsInDestructor{}); return reinterpret_cast<const char*>(&str); } + */ - static std::string format_block(const Block& src) { - AES_BlockString str; - aes_format_block(&str, &src, ErrorDetailsThrowsInDestructor{}); - return reinterpret_cast<const char*>(&str); - } - - static void parse_block(Block& dest, std::string_view src) { - aes_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); + static void parse_key(Key& dest, Algorithm algorithm, std::string_view src) { + aes_parse_key(algorithm, &dest, src.data(), ErrorDetailsThrowsInDestructor{}); } - static void parse_key(Key& dest, Algorithm algorithm, std::string_view src) { - aes_box_parse_key(&dest, algorithm, src.data(), ErrorDetailsThrowsInDestructor{}); + Box(Algorithm algorithm, const Key& key, Mode mode, const std::optional<Block>& iv) { + aes_box_init( + &impl, algorithm, &key, mode, iv ? iv->ptr() : NULL, ErrorDetailsThrowsInDestructor{} + ); } - Box(Algorithm algorithm, const Key& key) { - aes_box_init(&impl, algorithm, &key, AES_ECB, nullptr, ErrorDetailsThrowsInDestructor{}); + Algorithm get_algorithm() const { + return impl.algorithm; } - Box(Algorithm algorithm, const Key& key, Mode mode, const Block& iv) { - aes_box_init(&impl, algorithm, &key, mode, &iv, ErrorDetailsThrowsInDestructor{}); + Mode get_mode() const { + return impl.mode; } void encrypt_block(const Block& plaintext, Block& ciphertext) { - aes_box_encrypt_block(&impl, &plaintext, &ciphertext, ErrorDetailsThrowsInDestructor{}); + dump_block("Plaintext", plaintext); + aes_box_encrypt_block( + &impl, plaintext.ptr(), ciphertext.ptr(), ErrorDetailsThrowsInDestructor{} + ); + dump_block("Ciphertext", ciphertext); } void decrypt_block(const Block& ciphertext, Block& plaintext) { - aes_box_decrypt_block(&impl, &ciphertext, &plaintext, ErrorDetailsThrowsInDestructor{}); + dump_block("Ciphertext", ciphertext); + aes_box_decrypt_block( + &impl, ciphertext.ptr(), plaintext.ptr(), ErrorDetailsThrowsInDestructor{} + ); + dump_block("Plaintext", plaintext); } std::vector<unsigned char> encrypt_buffer(const void* src_buf, std::size_t src_size) { @@ -105,26 +112,16 @@ public: return dest_buf; } - std::string format_key(const Key& src) { - return format_key(src, get_algorithm()); - } - - void parse_key(Key& dest, std::string_view src) { - parse_key(dest, get_algorithm(), src); - } - - Algorithm get_algorithm() const { - return impl.algorithm; - } - - Mode get_mode() const { - return impl.mode; - } - private: - Key key; + void dump_block(std::string_view header, const Block& block) { + if (verbose > 0) + std::cout << std::format("{}: {}\n", header, block.to_string()); + if (verbose > 1) + std::cout << std::format("{}\n", block.to_matrix_string()); + } AES_Box impl; + int verbose = 0; }; } // namespace aes diff --git a/aesxx/include/aesxx/data.hpp b/aesxx/include/aesxx/data.hpp index 8e4691d..7500913 100644 --- a/aesxx/include/aesxx/data.hpp +++ b/aesxx/include/aesxx/data.hpp @@ -5,40 +5,54 @@ #pragma once +#include "algorithm.hpp" #include "error.hpp" #include <aes/all.h> +#include <string> +#include <string_view> + namespace aes { -typedef AES_Block Block128; +class Block { +public: + static Block parse(std::string_view src) { + return Block{src}; + } + + explicit Block(AES_Block impl) : impl{impl} {} + + Block(int hi3, int hi2, int lo1, int lo0) : impl{aes_make_block(hi3, hi2, lo1, lo0)} {} -inline void make_block(Block128& dest, int hi3, int hi2, int lo1, int lo0) { - dest = aes_make_block(hi3, hi2, lo1, lo0); -} + Block() : Block{0, 0, 0, 0} {} -inline void load_block(Block128& dest, const void* src) { - dest = aes_load_block(src); -} + explicit Block(std::string_view src) { + aes_parse_block(&impl, src.data(), ErrorDetailsThrowsInDestructor{}); + } -inline void load_block_aligned(Block128& dest, const void* src) { - dest = aes_load_block_aligned(src); -} + AES_Block* ptr() { + return &impl; + } -inline void store_block(void* dest, Block128& src) { - aes_store_block(dest, src); -} + const AES_Block* ptr() const { + return &impl; + } -inline void store_block_aligned(void* dest, Block128& src) { - aes_store_block_aligned(dest, src); -} + std::string to_string() const { + AES_BlockString str; + aes_format_block(&str, &impl, ErrorDetailsThrowsInDestructor{}); + return str.str; + } -inline Block128 xor_blocks(Block128& a, Block128& b) { - return aes_xor_blocks(a, b); -} + std::string to_matrix_string() const { + AES_BlockMatrixString str; + aes_format_block_as_matrix(&str, &impl, ErrorDetailsThrowsInDestructor{}); + return str.str; + } -inline Block128 inc_block(Block128& block) { - return aes_inc_block(block); -} +private: + AES_Block impl; +}; } // namespace aes diff --git a/aesxx/include/aesxx/mode.hpp b/aesxx/include/aesxx/mode.hpp index d6f282a..a0b279f 100644 --- a/aesxx/include/aesxx/mode.hpp +++ b/aesxx/include/aesxx/mode.hpp @@ -7,128 +7,8 @@ #include <aes/all.h> -#include <type_traits> - namespace aes { typedef AES_Mode Mode; -inline constexpr bool mode_requires_init_vector(Mode mode) { - return mode != AES_ECB; -} - -inline constexpr bool mode_uses_encryption_keys_only(Mode mode) { - return mode != AES_ECB && mode != AES_CBC; -} - -#define AESXX_ENCRYPT_BLOCK_ECB(version) \ - template <> \ - inline void encrypt_block<AES_AES##version, AES_ECB>( \ - const typename Types<AES_AES##version>::Block& plaintext, \ - const typename Types<AES_AES##version>::RoundKeys& encryption_keys, \ - typename Types<AES_AES##version>::Block&, \ - typename Types<AES_AES##version>::Block& ciphertext \ - ) { \ - ciphertext = aes##version##_encrypt_block_ECB(plaintext, &encryption_keys); \ - } - -#define AESXX_DECRYPT_BLOCK_ECB(version) \ - template <> \ - inline void decrypt_block<AES_AES##version, AES_ECB>( \ - const typename Types<AES_AES##version>::Block& ciphertext, \ - const typename Types<AES_AES##version>::RoundKeys& decryption_keys, \ - typename Types<AES_AES##version>::Block&, \ - typename Types<AES_AES##version>::Block& plaintext \ - ) { \ - plaintext = aes##version##_decrypt_block_ECB(ciphertext, &decryption_keys); \ - } - -#define AESXX_ENCRYPT_BLOCK_CBC(version) \ - template <> \ - inline void encrypt_block<AES_AES##version, AES_CBC>( \ - const typename Types<AES_AES##version>::Block& plaintext, \ - const typename Types<AES_AES##version>::RoundKeys& encryption_keys, \ - typename Types<AES_AES##version>::Block& iv, \ - typename Types<AES_AES##version>::Block& ciphertext \ - ) { \ - ciphertext = aes##version##_encrypt_block_CBC(plaintext, &encryption_keys, iv, &iv); \ - } - -#define AESXX_DECRYPT_BLOCK_CBC(version) \ - template <> \ - inline void decrypt_block<AES_AES##version, AES_CBC>( \ - const typename Types<AES_AES##version>::Block& ciphertext, \ - const typename Types<AES_AES##version>::RoundKeys& decryption_keys, \ - typename Types<AES_AES##version>::Block& iv, \ - typename Types<AES_AES##version>::Block& plaintext \ - ) { \ - plaintext = aes##version##_decrypt_block_CBC(ciphertext, &decryption_keys, iv, &iv); \ - } - -#define AESXX_ENCRYPT_BLOCK_CFB(version) \ - template <> \ - inline void encrypt_block<AES_AES##version, AES_CFB>( \ - const typename Types<AES_AES##version>::Block& plaintext, \ - const typename Types<AES_AES##version>::RoundKeys& encryption_keys, \ - typename Types<AES_AES##version>::Block& iv, \ - typename Types<AES_AES##version>::Block& ciphertext \ - ) { \ - ciphertext = aes##version##_encrypt_block_CFB(plaintext, &encryption_keys, iv, &iv); \ - } - -#define AESXX_DECRYPT_BLOCK_CFB(version) \ - template <> \ - inline void decrypt_block<AES_AES##version, AES_CFB>( \ - const typename Types<AES_AES##version>::Block& ciphertext, \ - const typename Types<AES_AES##version>::RoundKeys& encryption_keys, \ - typename Types<AES_AES##version>::Block& iv, \ - typename Types<AES_AES##version>::Block& plaintext \ - ) { \ - plaintext = aes##version##_decrypt_block_CFB(ciphertext, &encryption_keys, iv, &iv); \ - } - -#define AESXX_ENCRYPT_BLOCK_OFB(version) \ - template <> \ - inline void encrypt_block<AES_AES##version, AES_OFB>( \ - const typename Types<AES_AES##version>::Block& plaintext, \ - const typename Types<AES_AES##version>::RoundKeys& encryption_keys, \ - typename Types<AES_AES##version>::Block& iv, \ - typename Types<AES_AES##version>::Block& ciphertext \ - ) { \ - ciphertext = aes##version##_encrypt_block_OFB(plaintext, &encryption_keys, iv, &iv); \ - } - -#define AESXX_DECRYPT_BLOCK_OFB(version) \ - template <> \ - inline void decrypt_block<AES_AES##version, AES_OFB>( \ - const typename Types<AES_AES##version>::Block& ciphertext, \ - const typename Types<AES_AES##version>::RoundKeys& encryption_keys, \ - typename Types<AES_AES##version>::Block& iv, \ - typename Types<AES_AES##version>::Block& plaintext \ - ) { \ - plaintext = aes##version##_decrypt_block_OFB(ciphertext, &encryption_keys, iv, &iv); \ - } - -#define AESXX_ENCRYPT_BLOCK_CTR(version) \ - template <> \ - inline void encrypt_block<AES_AES##version, AES_CTR>( \ - const typename Types<AES_AES##version>::Block& plaintext, \ - const typename Types<AES_AES##version>::RoundKeys& encryption_keys, \ - typename Types<AES_AES##version>::Block& iv, \ - typename Types<AES_AES##version>::Block& ciphertext \ - ) { \ - ciphertext = aes##version##_encrypt_block_CTR(plaintext, &encryption_keys, iv, &iv); \ - } - -#define AESXX_DECRYPT_BLOCK_CTR(version) \ - template <> \ - inline void decrypt_block<AES_AES##version, AES_CTR>( \ - const typename Types<AES_AES##version>::Block& ciphertext, \ - const typename Types<AES_AES##version>::RoundKeys& encryption_keys, \ - typename Types<AES_AES##version>::Block& iv, \ - typename Types<AES_AES##version>::Block& plaintext \ - ) { \ - plaintext = aes##version##_decrypt_block_CTR(ciphertext, &encryption_keys, iv, &iv); \ - } - } // namespace aes |
