aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hash/comb4p/comb4p.h
blob: d2e9587c28c766b873250d23bdeeb2ac66ec3fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Comb4P hash combiner
* (C) 2010 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#ifndef BOTAN_COMB4P_H__
#define BOTAN_COMB4P_H__

#include <botan/hash.h>

namespace Botan {

/**
* Combines two hash functions using a Feistel scheme. Described in
* "On the Security of Hash Function Combiners", Anja Lehmann
*/
class BOTAN_DLL Comb4P : public HashFunction
   {
   public:
      /**
      * @param h1 the first hash
      * @param h2 the second hash
      */
      Comb4P(HashFunction* h1, HashFunction* h2);

      size_t hash_block_size() const;

      size_t output_length() const
         {
         return m_hash1->output_length() + m_hash2->output_length();
         }

      static Comb4P* make(const Spec& spec);
      
      HashFunction* clone() const
         {
         return new Comb4P(m_hash1->clone(), m_hash2->clone());
         }

      std::string name() const
         {
         return "Comb4P(" + m_hash1->name() + "," + m_hash2->name() + ")";
         }

      void clear();
   private:
      void add_data(const byte input[], size_t length);
      void final_result(byte out[]);

      std::unique_ptr<HashFunction> m_hash1, m_hash2;
   };

}

#endif