Botan  2.4.0
Crypto and TLS for C++11
shake_cipher.h
Go to the documentation of this file.
1 /*
2 * SHAKE-128 as a stream cipher
3 * (C) 2016 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_SHAKE128_CIPHER_H_
9 #define BOTAN_SHAKE128_CIPHER_H_
10 
11 #include <botan/stream_cipher.h>
12 #include <botan/secmem.h>
13 
14 namespace Botan {
15 
16 /**
17 * SHAKE-128 XOF presented as a stream cipher
18 */
20  {
21  public:
23 
24  /**
25  * Produce more XOF output
26  */
27  void cipher(const uint8_t in[], uint8_t out[], size_t length) override;
28 
29  /**
30  * Seeking is not supported, this function will throw
31  */
32  void seek(uint64_t offset) override;
33 
34  /**
35  * IV not supported, this function will throw unless iv_len == 0
36  */
37  void set_iv(const uint8_t iv[], size_t iv_len) override;
38 
39  bool valid_iv_length(size_t iv_len) const override { return (iv_len == 0); }
40 
41  /**
42  * In principle SHAKE can accept arbitrary length inputs, but this
43  * does not seem required for a stream cipher.
44  */
46  {
47  return Key_Length_Specification(16, 160, 8);
48  }
49 
50  void clear() override;
51  std::string name() const override { return "SHAKE-128"; }
52  StreamCipher* clone() const override { return new SHAKE_128_Cipher; }
53 
54  private:
55  void key_schedule(const uint8_t key[], size_t key_len) override;
56 
57  secure_vector<uint64_t> m_state; // internal state
58  secure_vector<uint8_t> m_buffer; // ciphertext buffer
59  size_t m_buf_pos; // position in m_buffer
60  };
61 
62 }
63 
64 #endif
Key_Length_Specification key_spec() const override
Definition: shake_cipher.h:45
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
bool valid_iv_length(size_t iv_len) const override
Definition: shake_cipher.h:39
StreamCipher * clone() const override
Definition: shake_cipher.h:52
Definition: alg_id.cpp:13
std::string name() const override
Definition: shake_cipher.h:51
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88