00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BOTAN_CBC_H__
00009 #define BOTAN_CBC_H__
00010
00011 #include <botan/block_cipher.h>
00012 #include <botan/key_filt.h>
00013 #include <botan/mode_pad.h>
00014 #include <botan/buf_filt.h>
00015
00016 namespace Botan {
00017
00018
00019
00020
00021 class BOTAN_DLL CBC_Encryption : public Keyed_Filter,
00022 private Buffered_Filter
00023 {
00024 public:
00025 std::string name() const;
00026
00027 void set_iv(const InitializationVector& iv);
00028
00029 void set_key(const SymmetricKey& key) { cipher->set_key(key); }
00030
00031 bool valid_keylength(u32bit key_len) const
00032 { return cipher->valid_keylength(key_len); }
00033
00034 bool valid_iv_length(u32bit iv_len) const
00035 { return (iv_len == cipher->BLOCK_SIZE); }
00036
00037 CBC_Encryption(BlockCipher* cipher,
00038 BlockCipherModePaddingMethod* padding);
00039
00040 CBC_Encryption(BlockCipher* cipher,
00041 BlockCipherModePaddingMethod* padding,
00042 const SymmetricKey& key,
00043 const InitializationVector& iv);
00044
00045 ~CBC_Encryption() { delete cipher; delete padder; }
00046 private:
00047 void buffered_block(const byte input[], u32bit input_length);
00048 void buffered_final(const byte input[], u32bit input_length);
00049
00050 void write(const byte input[], u32bit input_length);
00051 void end_msg();
00052
00053 BlockCipher* cipher;
00054 const BlockCipherModePaddingMethod* padder;
00055 SecureVector<byte> state;
00056 };
00057
00058
00059
00060
00061 class BOTAN_DLL CBC_Decryption : public Keyed_Filter,
00062 private Buffered_Filter
00063 {
00064 public:
00065 std::string name() const;
00066
00067 void set_iv(const InitializationVector& iv);
00068
00069 void set_key(const SymmetricKey& key) { cipher->set_key(key); }
00070
00071 bool valid_keylength(u32bit key_len) const
00072 { return cipher->valid_keylength(key_len); }
00073
00074 bool valid_iv_length(u32bit iv_len) const
00075 { return (iv_len == cipher->BLOCK_SIZE); }
00076
00077 CBC_Decryption(BlockCipher* cipher,
00078 BlockCipherModePaddingMethod* padding);
00079
00080 CBC_Decryption(BlockCipher* cipher,
00081 BlockCipherModePaddingMethod* padding,
00082 const SymmetricKey& key,
00083 const InitializationVector& iv);
00084
00085 ~CBC_Decryption() { delete cipher; delete padder; }
00086 private:
00087 void buffered_block(const byte input[], u32bit input_length);
00088 void buffered_final(const byte input[], u32bit input_length);
00089
00090 void write(const byte[], u32bit);
00091 void end_msg();
00092
00093 BlockCipher* cipher;
00094 const BlockCipherModePaddingMethod* padder;
00095 SecureVector<byte> state, temp;
00096 };
00097
00098 }
00099
00100 #endif