Botan 1.10.17
cbc.h
Go to the documentation of this file.
1/*
2* CBC Mode
3* (C) 1999-2007 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#ifndef BOTAN_CBC_H__
9#define BOTAN_CBC_H__
10
11#include <botan/block_cipher.h>
12#include <botan/key_filt.h>
13#include <botan/mode_pad.h>
14#include <botan/buf_filt.h>
15
16namespace Botan {
17
18/**
19* CBC Encryption
20*/
21class BOTAN_DLL CBC_Encryption : public Keyed_Filter,
22 private Buffered_Filter
23 {
24 public:
25 std::string name() const;
26
27 void set_iv(const InitializationVector& iv);
28
29 void set_key(const SymmetricKey& key) { cipher->set_key(key); }
30
31 bool valid_keylength(size_t key_len) const
32 { return cipher->valid_keylength(key_len); }
33
34 bool valid_iv_length(size_t iv_len) const
35 { return (iv_len == cipher->block_size()); }
36
39
42 const SymmetricKey& key,
43 const InitializationVector& iv);
44
45 ~CBC_Encryption() { delete cipher; delete padder; }
46 private:
47 void buffered_block(const byte input[], size_t input_length);
48 void buffered_final(const byte input[], size_t input_length);
49
50 void write(const byte input[], size_t input_length);
51 void end_msg();
52
53 BlockCipher* cipher;
54 const BlockCipherModePaddingMethod* padder;
56 };
57
58/**
59* CBC Decryption
60*/
61class BOTAN_DLL CBC_Decryption : public Keyed_Filter,
62 private Buffered_Filter
63 {
64 public:
65 std::string name() const;
66
67 void set_iv(const InitializationVector& iv);
68
69 void set_key(const SymmetricKey& key) { cipher->set_key(key); }
70
71 bool valid_keylength(size_t key_len) const
72 { return cipher->valid_keylength(key_len); }
73
74 bool valid_iv_length(size_t iv_len) const
75 { return (iv_len == cipher->block_size()); }
76
79
82 const SymmetricKey& key,
83 const InitializationVector& iv);
84
85 ~CBC_Decryption() { delete cipher; delete padder; }
86 private:
87 void buffered_block(const byte input[], size_t input_length);
88 void buffered_final(const byte input[], size_t input_length);
89
90 void write(const byte[], size_t);
91 void end_msg();
92
93 BlockCipher* cipher;
94 const BlockCipherModePaddingMethod* padder;
95 SecureVector<byte> state, temp;
96 };
97
98}
99
100#endif
Buffered_Filter(size_t block_size, size_t final_minimum)
Definition buf_filt.cpp:18
void set_iv(const InitializationVector &iv)
Definition cbc.cpp:150
std::string name() const
Definition cbc.cpp:231
void set_key(const SymmetricKey &key)
Definition cbc.h:69
bool valid_iv_length(size_t iv_len) const
Definition cbc.h:74
CBC_Decryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
Definition cbc.cpp:115
bool valid_keylength(size_t key_len) const
Definition cbc.h:71
void set_iv(const InitializationVector &iv)
Definition cbc.cpp:50
CBC_Encryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
Definition cbc.cpp:17
bool valid_iv_length(size_t iv_len) const
Definition cbc.h:34
bool valid_keylength(size_t key_len) const
Definition cbc.h:31
void set_key(const SymmetricKey &key)
Definition cbc.h:29
std::string name() const
Definition cbc.cpp:107
OctetString SymmetricKey
Definition symkey.h:147
OctetString InitializationVector
Definition symkey.h:152