Botan
1.11.15
|
00001 /* 00002 * CTR-BE Mode 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_CTR_BE_H__ 00009 #define BOTAN_CTR_BE_H__ 00010 00011 #include <botan/block_cipher.h> 00012 #include <botan/stream_cipher.h> 00013 00014 namespace Botan { 00015 00016 /** 00017 * CTR-BE (Counter mode, big-endian) 00018 */ 00019 class BOTAN_DLL CTR_BE : public StreamCipher 00020 { 00021 public: 00022 void cipher(const byte in[], byte out[], size_t length); 00023 00024 void set_iv(const byte iv[], size_t iv_len); 00025 00026 bool valid_iv_length(size_t iv_len) const 00027 { return (iv_len <= m_cipher->block_size()); } 00028 00029 Key_Length_Specification key_spec() const 00030 { 00031 return m_cipher->key_spec(); 00032 } 00033 00034 std::string name() const; 00035 00036 CTR_BE* clone() const 00037 { return new CTR_BE(m_cipher->clone()); } 00038 00039 void clear(); 00040 00041 static CTR_BE* make(const Spec& spec); 00042 00043 /** 00044 * @param cipher the underlying block cipher to use 00045 */ 00046 CTR_BE(BlockCipher* cipher); 00047 private: 00048 void key_schedule(const byte key[], size_t key_len); 00049 void increment_counter(); 00050 00051 std::unique_ptr<BlockCipher> m_cipher; 00052 secure_vector<byte> m_counter, m_pad; 00053 size_t m_pad_pos; 00054 }; 00055 00056 } 00057 00058 #endif