Coverage Report

Created: 2020-02-14 15:38

/src/botan/src/lib/hash/keccak/keccak.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Keccak
3
* (C) 2010,2016 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/keccak.h>
9
#include <botan/sha3.h>
10
#include <botan/exceptn.h>
11
#include <botan/loadstor.h>
12
13
namespace Botan {
14
15
std::unique_ptr<HashFunction> Keccak_1600::copy_state() const
16
0
   {
17
0
   return std::unique_ptr<HashFunction>(new Keccak_1600(*this));
18
0
   }
19
20
Keccak_1600::Keccak_1600(size_t output_bits) :
21
   m_output_bits(output_bits),
22
   m_bitrate(1600 - 2*output_bits),
23
   m_S(25),
24
   m_S_pos(0)
25
0
   {
26
0
   // We only support the parameters for the SHA-3 proposal
27
0
28
0
   if(output_bits != 224 && output_bits != 256 &&
29
0
      output_bits != 384 && output_bits != 512)
30
0
      throw Invalid_Argument("Keccak_1600: Invalid output length " +
31
0
                             std::to_string(output_bits));
32
0
   }
33
34
std::string Keccak_1600::name() const
35
0
   {
36
0
   return "Keccak-1600(" + std::to_string(m_output_bits) + ")";
37
0
   }
38
39
HashFunction* Keccak_1600::clone() const
40
0
   {
41
0
   return new Keccak_1600(m_output_bits);
42
0
   }
43
44
void Keccak_1600::clear()
45
0
   {
46
0
   zeroise(m_S);
47
0
   m_S_pos = 0;
48
0
   }
49
50
void Keccak_1600::add_data(const uint8_t input[], size_t length)
51
0
   {
52
0
   m_S_pos = SHA_3::absorb(m_bitrate, m_S, m_S_pos, input, length);
53
0
   }
54
55
void Keccak_1600::final_result(uint8_t output[])
56
0
   {
57
0
   SHA_3::finish(m_bitrate, m_S, m_S_pos, 0x01, 0x80);
58
0
59
0
   /*
60
0
   * We never have to run the permutation again because we only support
61
0
   * limited output lengths
62
0
   */
63
0
   copy_out_vec_le(output, m_output_bits/8, m_S);
64
0
65
0
   clear();
66
0
   }
67
68
}