Coverage Report

Created: 2023-02-22 06:14

/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
      bool has_keying_material() const override final;
48
49
   private:
50
      void key_schedule(const uint8_t key[], size_t key_len) override final;
51
52
   protected:
53
      size_t m_shake_rate;
54
55
      secure_vector<uint64_t> m_state; // internal state
56
      secure_vector<uint8_t> m_buffer; // ciphertext buffer
57
      size_t m_buf_pos; // position in m_buffer
58
   };
59
60
class SHAKE_128_Cipher final : public SHAKE_Cipher
61
   {
62
   public:
63
      SHAKE_128_Cipher();
64
65
      std::string name() const override
66
0
         { return "SHAKE-128"; }
67
68
      std::unique_ptr<StreamCipher> new_object() const override
69
0
         { return std::make_unique<SHAKE_128_Cipher>(); }
70
   };
71
72
class SHAKE_256_Cipher final : public SHAKE_Cipher
73
   {
74
   public:
75
      SHAKE_256_Cipher();
76
77
      std::string name() const override
78
0
         { return "SHAKE-256"; }
79
80
      std::unique_ptr<StreamCipher> new_object() const override
81
0
         { return std::make_unique<SHAKE_256_Cipher>(); }
82
   };
83
84
}
85
86
#endif