Botan 1.10.17

cts.h
Go to the documentation of this file.
1 /*
2 * CTS Mode
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_CTS_H__
9 #define BOTAN_CTS_H__
10
11 #include <botan/block_cipher.h>
12 #include <botan/key_filt.h>
13
14 namespace Botan {
15
16 /**
17 * CBC encryption with ciphertext stealing
18 */
19 class BOTAN_DLL CTS_Encryption : public Keyed_Filter
20 {
21 public:
22 std::string name() const { return cipher->name() + "/CTS"; }
23
24 void set_iv(const InitializationVector&);
25
26 void set_key(const SymmetricKey& key) { cipher->set_key(key); }
27
28 bool valid_keylength(size_t key_len) const
29 { return cipher->valid_keylength(key_len); }
30
31 bool valid_iv_length(size_t iv_len) const
32 { return (iv_len == cipher->block_size()); }
33
34 CTS_Encryption(BlockCipher* cipher);
35
36 CTS_Encryption(BlockCipher* cipher,
37 const SymmetricKey& key,
38 const InitializationVector& iv);
39
40 ~CTS_Encryption() { delete cipher; }
41 private:
42 void write(const byte[], size_t);
43 void end_msg();
44 void encrypt(const byte[]);
45
46 BlockCipher* cipher;
47 SecureVector<byte> buffer, state;
48 size_t position;
49 };
50
51 /**
52 * CBC decryption with ciphertext stealing
53 */
54 class BOTAN_DLL CTS_Decryption : public Keyed_Filter
55 {
56 public:
57 std::string name() const { return cipher->name() + "/CTS"; }
58
59 void set_iv(const InitializationVector&);
60
61 void set_key(const SymmetricKey& key) { cipher->set_key(key); }
62
63 bool valid_keylength(size_t key_len) const
64 { return cipher->valid_keylength(key_len); }
65
66 bool valid_iv_length(size_t iv_len) const
67 { return (iv_len == cipher->block_size()); }
68
69 CTS_Decryption(BlockCipher* cipher);
70
71 CTS_Decryption(BlockCipher* cipher,
72 const SymmetricKey& key,
73 const InitializationVector& iv);
74
75 ~CTS_Decryption() { delete cipher; }
76 private:
77 void write(const byte[], size_t);
78 void end_msg();
79 void decrypt(const byte[]);
80
81 BlockCipher* cipher;
82 SecureVector<byte> buffer, state, temp;
83 size_t position;
84 };
85
86 }
87
88 #endif
Botan::OctetString
Definition: symkey.h:19
Botan::Keyed_Filter
Definition: key_filt.h:20
Botan::CTS_Decryption::valid_keylength
bool valid_keylength(size_t key_len) const
Definition: cts.h:63
Botan::CTS_Decryption
Definition: cts.h:54
Botan::CTS_Encryption
Definition: cts.h:19
Botan::CTS_Decryption::~CTS_Decryption
~CTS_Decryption()
Definition: cts.h:75
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::CTS_Decryption::set_key
void set_key(const SymmetricKey &key)
Definition: cts.h:61
Botan::CTS_Encryption::name
std::string name() const
Definition: cts.h:22
Botan::CTS_Encryption::valid_iv_length
bool valid_iv_length(size_t iv_len) const
Definition: cts.h:31
Botan
Definition: algo_base.h:14
Botan::CTS_Encryption::valid_keylength
bool valid_keylength(size_t key_len) const
Definition: cts.h:28
Botan::CTS_Decryption::valid_iv_length
bool valid_iv_length(size_t iv_len) const
Definition: cts.h:66
Botan::SecureVector< byte >
Botan::CTS_Decryption::name
std::string name() const
Definition: cts.h:57
Botan::CTS_Encryption::~CTS_Encryption
~CTS_Encryption()
Definition: cts.h:40
Botan::BlockCipher
Definition: block_cipher.h:18
Botan::CTS_Encryption::set_key
void set_key(const SymmetricKey &key)
Definition: cts.h:26