Belle II Software  release-08-01-10
Hash.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <vector>
12 
14 struct KeccakHashInstance;
15 
16 namespace Belle2 {
23  class SHA3Hash {
24  public:
26  enum EHashMode {
27  c_SHA3_224 = 224 / 8,
28  c_SHA3_256 = 256 / 8,
29  c_SHA3_384 = 384 / 8,
30  c_SHA3_512 = 512 / 8
31  };
33  explicit SHA3Hash(EHashMode length);
35  SHA3Hash(const SHA3Hash&) = delete;
37  ~SHA3Hash();
39  void clear();
41  void update(int n, unsigned char* buff);
46  void getHash(unsigned char* buff);
48  std::vector<unsigned char> getHash();
49  private:
54  };
55 
58  class ShakeHash {
59  public:
61  enum EHashMode {
64  };
66  explicit ShakeHash(EHashMode mode);
68  ShakeHash(const ShakeHash&) = delete;
70  ~ShakeHash();
72  void clear();
74  void update(int n, unsigned char* buff);
76  void getHash(int n, unsigned char* buff);
77  private:
82  };
84 } //Belle2 namespace
Simple interface to calculate SHA3 hash sum (FIPS 202 draft) with fixed size from given data inputs.
Definition: Hash.h:23
EHashMode m_mode
chosen hash mode
Definition: Hash.h:53
SHA3Hash(const SHA3Hash &)=delete
No copying.
KeccakHashInstance * m_instance
memory structure to calculate the hash value
Definition: Hash.h:51
EHashMode
Available hash modes according to FIPS 202 draft.
Definition: Hash.h:26
@ c_SHA3_512
384bit output size
Definition: Hash.h:30
@ c_SHA3_384
256bit output size
Definition: Hash.h:29
@ c_SHA3_256
224bit output size
Definition: Hash.h:28
Simple interface to calculate SHAKE256 hash sum (FIPS 202 draft) with variable size from given data i...
Definition: Hash.h:58
EHashMode m_mode
chosen hash mode
Definition: Hash.h:81
KeccakHashInstance * m_instance
memory structure to calculate the hash value
Definition: Hash.h:79
EHashMode
Available hash modes according to FIPS 202 draft.
Definition: Hash.h:61
@ c_SHAKE128
variable hash size with up to 128 bit collision resistance
Definition: Hash.h:62
@ c_SHAKE256
variable hash size with up to 256 bit collision resistance
Definition: Hash.h:63
ShakeHash(const ShakeHash &)=delete
No copying.
~SHA3Hash()
destructor freeing the memory
Definition: Hash.cc:31
void update(int n, unsigned char *buff)
update the internal state by adding n bytes of data from buff
Definition: Hash.cc:57
void getHash(int n, unsigned char *buff)
obtain the hash value with a length of n bytes into buff
Definition: Hash.cc:105
SHA3Hash(EHashMode length)
Constructor initializing the hash structure with a given output size.
Definition: Hash.cc:25
~ShakeHash()
destructor freeing the memory
Definition: Hash.cc:80
void clear()
reinit the hash structure to create a new hash sum
Definition: Hash.cc:36
std::vector< unsigned char > getHash()
obtain the hash value as a vector of unsigned char
Definition: Hash.cc:67
ShakeHash(EHashMode mode)
constructor initializing the hash structure
Definition: Hash.cc:74
Abstract base class for different kinds of events.
Since we cannot forward declare the memory structure directly due to some typedeffing we inherit from...
Definition: Hash.cc:17