NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sha3.h
1 // //////////////////////////////////////////////////////////
2 // sha3.h
3 // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved.
4 // see http://create.stephan-brumme.com/disclaimer.html
5 //
6 
7 #pragma once
8 
9 //#include "hash.h"
10 #include <string>
11 
12 // define fixed size integer types
13 #ifdef _MSC_VER
14 // Windows
15 typedef unsigned __int8 uint8_t;
16 typedef unsigned __int64 uint64_t;
17 #else
18 // GCC
19 #include <stdint.h>
20 #endif
21 
22 namespace hash_lib
23 {
24 
26 
38 class SHA3 //: public Hash
39 {
40 public:
42  enum Bits { Bits224 = 224, Bits256 = 256, Bits384 = 384, Bits512 = 512 };
43 
45  explicit SHA3(Bits bits = Bits256);
46 
48  std::string operator()(const void* data, size_t numBytes);
50  std::string operator()(const std::string& text);
51 
53  void add(const void* data, size_t numBytes);
54 
56  std::string getHash();
57 
59  void reset();
60 
61 private:
63  void processBlock(const void* data);
65  void processBuffer();
66 
68  enum { StateSize = 1600 / (8 * 8),
69  MaxBlockSize = 200 - 2 * (224 / 8) };
70 
72  uint64_t m_hash[StateSize];
74  uint64_t m_numBytes;
76  size_t m_blockSize;
78  size_t m_bufferSize;
80  uint8_t m_buffer[MaxBlockSize];
82  Bits m_bits;
83 };
84 
85 }
compute SHA3 hash
Definition: sha3.h:38
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition: sha3.cpp:174
std::string getHash()
return latest hash as hex characters
Definition: sha3.cpp:237
std::string operator()(const void *data, size_t numBytes)
compute hash of a memory block
Definition: sha3.cpp:277
SHA3(Bits bits=Bits256)
same as reset()
Definition: sha3.cpp:18
void reset()
restart
Definition: sha3.cpp:27
Bits
algorithm variants
Definition: sha3.h:42