Botan  1.10.9
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 
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 
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
bool valid_keylength(size_t key_len) const
Definition: cts.h:63
std::string name() const
Definition: cts.h:57
bool valid_iv_length(size_t iv_len) const
Definition: cts.h:66
unsigned char byte
Definition: types.h:22
RC4_KEY state
Definition: ossl_arc4.cpp:39
std::string name() const
Definition: cts.h:22
void set_key(const SymmetricKey &key)
Definition: cts.h:61
EVP_CIPHER_CTX decrypt
Definition: ossl_bc.cpp:43
EVP_CIPHER_CTX encrypt
Definition: ossl_bc.cpp:43
bool valid_iv_length(size_t iv_len) const
Definition: cts.h:31
bool valid_keylength(size_t key_len) const
Definition: cts.h:28
void set_key(const SymmetricKey &key)
Definition: cts.h:26