Botan
1.11.15
|
00001 /* 00002 * Lion 00003 * (C) 1999-2007,2014 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_LION_H__ 00009 #define BOTAN_LION_H__ 00010 00011 #include <botan/block_cipher.h> 00012 #include <botan/stream_cipher.h> 00013 #include <botan/hash.h> 00014 00015 namespace Botan { 00016 00017 /** 00018 * Lion is a block cipher construction designed by Ross Anderson and 00019 * Eli Biham, described in "Two Practical and Provably Secure Block 00020 * Ciphers: BEAR and LION". It has a variable block size and is 00021 * designed to encrypt very large blocks (up to a megabyte) 00022 00023 * http://www.cl.cam.ac.uk/~rja14/Papers/bear-lion.pdf 00024 */ 00025 class BOTAN_DLL Lion : public BlockCipher 00026 { 00027 public: 00028 void encrypt_n(const byte in[], byte out[], size_t blocks) const override; 00029 void decrypt_n(const byte in[], byte out[], size_t blocks) const override; 00030 00031 size_t block_size() const override { return m_block_size; } 00032 00033 Key_Length_Specification key_spec() const override 00034 { 00035 return Key_Length_Specification(2, 2*m_hash->output_length(), 2); 00036 } 00037 00038 void clear() override; 00039 std::string name() const override; 00040 BlockCipher* clone() const override; 00041 00042 /** 00043 * @param hash the hash to use internally 00044 * @param cipher the stream cipher to use internally 00045 * @param block_size the size of the block to use 00046 */ 00047 Lion(HashFunction* hash, 00048 StreamCipher* cipher, 00049 size_t block_size); 00050 private: 00051 void key_schedule(const byte[], size_t); 00052 00053 size_t left_size() const { return m_hash->output_length(); } 00054 size_t right_size() const { return m_block_size - left_size(); } 00055 00056 const size_t m_block_size; 00057 std::unique_ptr<HashFunction> m_hash; 00058 std::unique_ptr<StreamCipher> m_cipher; 00059 secure_vector<byte> m_key1, m_key2; 00060 }; 00061 00062 } 00063 00064 #endif