Coverage Report

Created: 2023-01-25 06:35

/src/botan/build/include/botan/internal/shake_cipher.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * SHAKE-128 and SHAKE-256 as a stream ciphers
3
 * (C) 2016 Jack Lloyd
4
 *     2022 René Meusel, Michael Boric - Rohde & Schwarz Cybersecurity
5
 *
6
 * Botan is released under the Simplified BSD License (see license.txt)
7
 */
8
9
#ifndef BOTAN_SHAKE_CIPHER_H_
10
#define BOTAN_SHAKE_CIPHER_H_
11
12
#include <botan/stream_cipher.h>
13
#include <botan/secmem.h>
14
15
namespace Botan {
16
17
/**
18
* Base class for SHAKE-based XOFs presented as a stream cipher
19
*/
20
class SHAKE_Cipher : public StreamCipher
21
   {
22
   protected:
23
      explicit SHAKE_Cipher(size_t shake_rate);
24
25
   public:
26
      /**
27
      * Produce more XOF output
28
      */
29
      void cipher(const uint8_t in[], uint8_t out[], size_t length) override final;
30
31
      void write_keystream(uint8_t out[], size_t length) override;
32
33
      /**
34
      * Seeking is not supported, this function will throw
35
      */
36
      void seek(uint64_t offset) override final;
37
38
      /**
39
      * IV not supported, this function will throw unless iv_len == 0
40
      */
41
      void set_iv(const uint8_t iv[], size_t iv_len) override final;
42
43
      void clear() override final;
44
45
      Key_Length_Specification key_spec() const override final;
46
47
   private:
48
      void key_schedule(const uint8_t key[], size_t key_len) override final;
49
50
   protected:
51
      size_t m_shake_rate;
52
53
      secure_vector<uint64_t> m_state; // internal state
54
      secure_vector<uint8_t> m_buffer; // ciphertext buffer
55
      size_t m_buf_pos; // position in m_buffer
56
   };
57
58
class SHAKE_128_Cipher final : public SHAKE_Cipher
59
   {
60
   public:
61
      SHAKE_128_Cipher();
62
63
      std::string name() const override
64
0
         { return "SHAKE-128"; }
65
66
      std::unique_ptr<StreamCipher> new_object() const override
67
0
         { return std::make_unique<SHAKE_128_Cipher>(); }
68
   };
69
70
class SHAKE_256_Cipher final : public SHAKE_Cipher
71
   {
72
   public:
73
      SHAKE_256_Cipher();
74
75
      std::string name() const override
76
0
         { return "SHAKE-256"; }
77
78
      std::unique_ptr<StreamCipher> new_object() const override
79
0
         { return std::make_unique<SHAKE_256_Cipher>(); }
80
   };
81
82
}
83
84
#endif