Coverage Report

Created: 2020-08-01 06:18

/src/botan/build/include/botan/shake.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* SHAKE hash functions
3
* (C) 2010,2016 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_SHAKE_HASH_H_
9
#define BOTAN_SHAKE_HASH_H_
10
11
#include <botan/hash.h>
12
#include <botan/secmem.h>
13
#include <string>
14
15
BOTAN_FUTURE_INTERNAL_HEADER(shake.h)
16
17
namespace Botan {
18
19
/**
20
* SHAKE-128
21
*/
22
class BOTAN_PUBLIC_API(2,0) SHAKE_128 final : public HashFunction
23
   {
24
   public:
25
26
      /**
27
      * @param output_bits the desired output size in bits
28
      * must be a multiple of 8
29
      */
30
      explicit SHAKE_128(size_t output_bits);
31
32
0
      size_t hash_block_size() const override { return SHAKE_128_BITRATE / 8; }
33
0
      size_t output_length() const override { return m_output_bits / 8; }
34
35
      HashFunction* clone() const override;
36
      std::unique_ptr<HashFunction> copy_state() const override;
37
      std::string name() const override;
38
      void clear() override;
39
40
   private:
41
      void add_data(const uint8_t input[], size_t length) override;
42
      void final_result(uint8_t out[]) override;
43
44
      static const size_t SHAKE_128_BITRATE = 1600 - 256;
45
46
      size_t m_output_bits;
47
      secure_vector<uint64_t> m_S;
48
      size_t m_S_pos;
49
   };
50
51
/**
52
* SHAKE-256
53
*/
54
class BOTAN_PUBLIC_API(2,0) SHAKE_256 final : public HashFunction
55
   {
56
   public:
57
58
      /**
59
      * @param output_bits the desired output size in bits
60
      * must be a multiple of 8
61
      */
62
      explicit SHAKE_256(size_t output_bits);
63
64
0
      size_t hash_block_size() const override { return SHAKE_256_BITRATE / 8; }
65
0
      size_t output_length() const override { return m_output_bits / 8; }
66
67
      HashFunction* clone() const override;
68
      std::unique_ptr<HashFunction> copy_state() const override;
69
      std::string name() const override;
70
      void clear() override;
71
72
   private:
73
      void add_data(const uint8_t input[], size_t length) override;
74
      void final_result(uint8_t out[]) override;
75
76
      static const size_t SHAKE_256_BITRATE = 1600 - 512;
77
78
      size_t m_output_bits;
79
      secure_vector<uint64_t> m_S;
80
      size_t m_S_pos;
81
   };
82
83
}
84
85
#endif