Botan  2.9.0
Crypto and TLS for C++11
mdx_hash.h
Go to the documentation of this file.
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 */
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  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 
53  /**
54  * Write the count, if used, to this spot
55  * @param out where to write the counter to
56  */
57  virtual void write_count(uint8_t out[]);
58  private:
59  const uint8_t m_pad_char;
60  const uint8_t m_counter_size;
61  const uint8_t m_block_bits;
62  const bool m_count_big_endian;
63 
64  uint64_t m_count;
65  secure_vector<uint8_t> m_buffer;
66  size_t m_position;
67  };
68 
69 }
70 
71 #endif
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
size_t hash_block_size() const override final
Definition: mdx_hash.h:33
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65