• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5910687851

19 Aug 2023 09:36AM UTC coverage: 91.711% (-0.001%) from 91.712%
5910687851

Pull #3675

github

web-flow
Merge 88c4a1ce7 into dfe17143e
Pull Request #3675: Refactor: Keccak Permutation

78576 of 85678 relevant lines covered (91.71%)

8450547.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/lib/stream/shake_cipher/shake_cipher.h
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/internal/keccak_perm.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
   protected:
22
      explicit SHAKE_Cipher(size_t keccak_capacity);
23

24
   public:
25
      /**
26
      * Seeking is not supported, this function will throw
27
      */
28
      void seek(uint64_t offset) final;
29

30
      void clear() final;
31

32
      Key_Length_Specification key_spec() const final;
33

34
      bool has_keying_material() const final { return m_has_keying_material; }
142,240✔
35

36
      size_t buffer_size() const final { return m_keccak.byte_rate(); }
101,484✔
37

38
   private:
39
      void key_schedule(const uint8_t key[], size_t key_len) final;
40
      /**
41
      * Produce more XOF output
42
      */
43
      void cipher_bytes(const uint8_t in[], uint8_t out[], size_t length) final;
44
      void generate_keystream(uint8_t out[], size_t length) override;
45

46
      void generate_keystream_internal(std::span<uint8_t> out);
47

48
      /**
49
      * IV not supported, this function will throw unless iv_len == 0
50
      */
51
      void set_iv_bytes(const uint8_t iv[], size_t iv_len) final;
52

53
   private:
54
      Keccak_Permutation m_keccak;
55
      bool m_has_keying_material;
56
      secure_vector<uint8_t> m_keystream_buffer;
57
      size_t m_bytes_generated;
58
};
59

60
class SHAKE_128_Cipher final : public SHAKE_Cipher {
×
61
   public:
62
      SHAKE_128_Cipher();
63

64
      std::string name() const override { return "SHAKE-128"; }
6,870✔
65

66
      std::unique_ptr<StreamCipher> new_object() const override { return std::make_unique<SHAKE_128_Cipher>(); }
1,145✔
67
};
68

69
class SHAKE_256_Cipher final : public SHAKE_Cipher {
×
70
   public:
71
      SHAKE_256_Cipher();
72

73
      std::string name() const override { return "SHAKE-256"; }
6,870✔
74

75
      std::unique_ptr<StreamCipher> new_object() const override { return std::make_unique<SHAKE_256_Cipher>(); }
1,145✔
76
};
77

78
}  // namespace Botan
79

80
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc