Coverage Report

Created: 2021-11-25 09:31

/src/botan/build/include/botan/internal/mdx_hash.h
Line
Count
Source
1
/*
2
* MDx Hash Function
3
* (C) 1999-2008 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_MDX_BASE_H_
9
#define BOTAN_MDX_BASE_H_
10
11
#include <botan/hash.h>
12
13
namespace Botan {
14
15
/**
16
* MDx Hash Function Base Class
17
*/
18
class MDx_HashFunction : public HashFunction
19
   {
20
   public:
21
      /**
22
      * @param block_length is the number of bytes per block, which must
23
      *        be a power of 2 and at least 8.
24
      * @param big_byte_endian specifies if the hash uses big-endian bytes
25
      * @param big_bit_endian specifies if the hash uses big-endian bits
26
      * @param counter_size specifies the size of the counter var in bytes
27
      */
28
      MDx_HashFunction(size_t block_length,
29
                       bool big_byte_endian,
30
                       bool big_bit_endian,
31
                       uint8_t counter_size = 8);
32
33
19.9k
      size_t hash_block_size() const override final { return m_buffer.size(); }
34
   protected:
35
      void add_data(const uint8_t input[], size_t length) override final;
36
      void final_result(uint8_t output[]) override final;
37
38
      /**
39
      * Run the hash's compression function over a set of blocks
40
      * @param blocks the input
41
      * @param block_n the number of blocks
42
      */
43
      virtual void compress_n(const uint8_t blocks[], size_t block_n) = 0;
44
45
      void clear() override;
46
47
      /**
48
      * Copy the output to the buffer
49
      * @param buffer to put the output into
50
      */
51
      virtual void copy_out(uint8_t buffer[]) = 0;
52
   private:
53
      const uint8_t m_pad_char;
54
      const uint8_t m_counter_size;
55
      const uint8_t m_block_bits;
56
      const bool m_count_big_endian;
57
58
      uint64_t m_count;
59
      secure_vector<uint8_t> m_buffer;
60
      size_t m_position;
61
   };
62
63
}
64
65
#endif