Coverage Report

Created: 2021-05-04 09:02

/src/botan/build/include/botan/internal/sha3.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* SHA-3
3
* (C) 2010,2016 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_SHA3_H_
9
#define BOTAN_SHA3_H_
10
11
#include <botan/hash.h>
12
#include <botan/secmem.h>
13
#include <string>
14
15
namespace Botan {
16
17
/**
18
* SHA-3
19
*/
20
class SHA_3 : public HashFunction
21
   {
22
   public:
23
24
      /**
25
      * @param output_bits the size of the hash output; must be one of
26
      *                    224, 256, 384, or 512
27
      */
28
      explicit SHA_3(size_t output_bits);
29
30
0
      size_t hash_block_size() const override { return m_bitrate / 8; }
31
0
      size_t output_length() const override { return m_output_bits / 8; }
32
33
      std::unique_ptr<HashFunction> new_object() const override;
34
      std::unique_ptr<HashFunction> copy_state() const override;
35
      std::string name() const override;
36
      void clear() override;
37
      std::string provider() const override;
38
39
      // Static functions for internal usage
40
41
      /**
42
      * Absorb data into the provided state
43
      * @param bitrate the bitrate to absorb into the sponge
44
      * @param S the sponge state
45
      * @param S_pos where to begin absorbing into S
46
      * @param input the input data
47
      * @param length size of input in bytes
48
      */
49
      static size_t absorb(size_t bitrate,
50
                           secure_vector<uint64_t>& S, size_t S_pos,
51
                           const uint8_t input[], size_t length);
52
53
      /**
54
      * Add final padding and permute. The padding is assumed to be
55
      * init_pad || 00... || fini_pad
56
      *
57
      * @param bitrate the bitrate to absorb into the sponge
58
      * @param S the sponge state
59
      * @param S_pos where to begin absorbing into S
60
      * @param init_pad the leading pad bits
61
      * @param fini_pad the final pad bits
62
      */
63
      static void finish(size_t bitrate,
64
                         secure_vector<uint64_t>& S, size_t S_pos,
65
                         uint8_t init_pad, uint8_t fini_pad);
66
67
      /**
68
      * Expand from provided state
69
      * @param bitrate sponge parameter
70
      * @param S the state
71
      * @param output the output buffer
72
      * @param output_length the size of output in bytes
73
      */
74
      static void expand(size_t bitrate,
75
                         secure_vector<uint64_t>& S,
76
                         uint8_t output[], size_t output_length);
77
78
      /**
79
      * The bare Keccak-1600 permutation
80
      */
81
      static void permute(uint64_t A[25]);
82
83
   private:
84
      void add_data(const uint8_t input[], size_t length) override;
85
      void final_result(uint8_t out[]) override;
86
87
#if defined(BOTAN_HAS_SHA3_BMI2)
88
      static void permute_bmi2(uint64_t A[25]);
89
#endif
90
91
      size_t m_output_bits, m_bitrate;
92
      secure_vector<uint64_t> m_S;
93
      size_t m_S_pos;
94
   };
95
96
/**
97
* SHA-3-224
98
*/
99
class SHA_3_224 final : public SHA_3
100
   {
101
   public:
102
0
      SHA_3_224() : SHA_3(224) {}
103
   };
104
105
/**
106
* SHA-3-256
107
*/
108
class SHA_3_256 final : public SHA_3
109
   {
110
   public:
111
0
      SHA_3_256() : SHA_3(256) {}
112
   };
113
114
/**
115
* SHA-3-384
116
*/
117
class SHA_3_384 final : public SHA_3
118
   {
119
   public:
120
0
      SHA_3_384() : SHA_3(384) {}
121
   };
122
123
/**
124
* SHA-3-512
125
*/
126
class SHA_3_512 final : public SHA_3
127
   {
128
   public:
129
0
      SHA_3_512() : SHA_3(512) {}
130
   };
131
132
}
133
134
#endif