From 6b31d793706f8422e06b5148e366644074a48b5d Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 26 Jul 2015 00:44:16 +0300 Subject: examples: merge to block utils --- cxx/include/aesnixx/aes.hpp | 86 ++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 48 deletions(-) (limited to 'cxx/include/aesnixx') diff --git a/cxx/include/aesnixx/aes.hpp b/cxx/include/aesnixx/aes.hpp index 1273c56..231e223 100644 --- a/cxx/include/aesnixx/aes.hpp +++ b/cxx/include/aesnixx/aes.hpp @@ -462,138 +462,128 @@ namespace aesni }; template - class Encrypt; + struct Encrypt; template - class Encrypt + struct Encrypt { - public: Encrypt(const typename Types::KeyT& key, const typename Types::BlockT& iv) { - expand_key(key, m_encryption_keys); - derive_decryption_keys(m_encryption_keys, m_decryption_keys); + expand_key(key, encryption_keys); + derive_decryption_keys(encryption_keys, decryption_keys); } inline typename Types::BlockT encrypt(const typename Types::BlockT& plaintext) { - return encrypt_ecb(plaintext, m_encryption_keys); + return encrypt_ecb(plaintext, encryption_keys); } inline typename Types::BlockT decrypt(const typename Types::BlockT& ciphertext) { - return decrypt_ecb(ciphertext, m_decryption_keys); + return decrypt_ecb(ciphertext, decryption_keys); } - private: - typename Types::RoundKeysT m_encryption_keys; - typename Types::RoundKeysT m_decryption_keys; + typename Types::RoundKeysT encryption_keys; + typename Types::RoundKeysT decryption_keys; }; template - class Encrypt + struct Encrypt { - public: Encrypt(const typename Types::KeyT& key, const typename Types::BlockT& iv) - : m_iv(iv) + : iv(iv) { - expand_key(key, m_encryption_keys); - derive_decryption_keys(m_encryption_keys, m_decryption_keys); + expand_key(key, encryption_keys); + derive_decryption_keys(encryption_keys, decryption_keys); } inline typename Types::BlockT encrypt(const typename Types::BlockT& plaintext) { - return encrypt_cbc(plaintext, m_encryption_keys, m_iv, m_iv); + return encrypt_cbc(plaintext, encryption_keys, iv, iv); } inline typename Types::BlockT decrypt(const typename Types::BlockT& ciphertext) { - return decrypt_cbc(ciphertext, m_decryption_keys, m_iv, m_iv); + return decrypt_cbc(ciphertext, decryption_keys, iv, iv); } - private: - typename Types::BlockT m_iv; - typename Types::RoundKeysT m_encryption_keys; - typename Types::RoundKeysT m_decryption_keys; + typename Types::BlockT iv; + typename Types::RoundKeysT encryption_keys; + typename Types::RoundKeysT decryption_keys; }; template - class Encrypt + struct Encrypt { - public: Encrypt(const typename Types::KeyT& key, const typename Types::BlockT& iv) - : m_iv(iv) + : iv(iv) { - expand_key(key, m_encryption_keys); + expand_key(key, encryption_keys); } inline typename Types::BlockT encrypt(const typename Types::BlockT& plaintext) { - return encrypt_cfb(plaintext, m_encryption_keys, m_iv, m_iv); + return encrypt_cfb(plaintext, encryption_keys, iv, iv); } inline typename Types::BlockT decrypt(const typename Types::BlockT& ciphertext) { - return decrypt_cfb(ciphertext, m_encryption_keys, m_iv, m_iv); + return decrypt_cfb(ciphertext, encryption_keys, iv, iv); } - private: - typename Types::BlockT m_iv; - typename Types::RoundKeysT m_encryption_keys; + typename Types::BlockT iv; + typename Types::RoundKeysT encryption_keys; }; template - class Encrypt + struct Encrypt { - public: Encrypt(const typename Types::KeyT& key, const typename Types::BlockT& iv) - : m_iv(iv) + : iv(iv) { - expand_key(key, m_encryption_keys); + expand_key(key, encryption_keys); } inline typename Types::BlockT encrypt(const typename Types::BlockT& plaintext) { - return encrypt_ofb(plaintext, m_encryption_keys, m_iv, m_iv); + return encrypt_ofb(plaintext, encryption_keys, iv, iv); } inline typename Types::BlockT decrypt(const typename Types::BlockT& ciphertext) { - return decrypt_ofb(ciphertext, m_encryption_keys, m_iv, m_iv); + return decrypt_ofb(ciphertext, encryption_keys, iv, iv); } - private: - typename Types::BlockT m_iv; - typename Types::RoundKeysT m_encryption_keys; + typename Types::BlockT iv; + typename Types::RoundKeysT encryption_keys; }; template - class Encrypt + struct Encrypt { - public: Encrypt(const typename Types::KeyT& key, const typename Types::BlockT& iv) - : m_iv(iv) + : iv(iv) { - expand_key(key, m_encryption_keys); + expand_key(key, encryption_keys); } inline typename Types::BlockT encrypt(const typename Types::BlockT& plaintext) { - return encrypt_ctr(plaintext, m_encryption_keys, m_iv, m_iv); + return encrypt_ctr(plaintext, encryption_keys, iv, iv); } inline typename Types::BlockT decrypt(const typename Types::BlockT& ciphertext) { - return decrypt_ctr(ciphertext, m_encryption_keys, m_iv, m_iv); + return decrypt_ctr(ciphertext, encryption_keys, iv, iv); } - private: - typename Types::RoundKeysT m_encryption_keys; - typename Types::BlockT m_iv; + typename Types::RoundKeysT encryption_keys; + typename Types::BlockT iv; }; } } -- cgit v1.2.3