CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
sha3.h
Go to the documentation of this file.
1
6// //////////////////////////////////////////////////////////
7// sha3.h
8// Copyright (c) 2014,2015 Stephan Brumme. All rights reserved.
9// see http://create.stephan-brumme.com/disclaimer.html
10//
11
12#pragma once
13
14//#include "hash.h"
15#include <string>
16
17// define fixed size integer types
18#ifdef _MSC_VER
19// Windows
20typedef unsigned __int8 uint8_t;
21typedef unsigned __int64 uint64_t;
22#else
23// GCC
24#include <stdint.h>
25#endif
26
27// Added namespace to avoid clash with OpenSSL
28namespace hash {
29
31
43class SHA3 //: public Hash
44{
45public:
47 enum Bits { Bits224 = 224, Bits256 = 256, Bits384 = 384, Bits512 = 512 };
48
50 explicit SHA3(Bits bits = Bits256);
51
53 std::string operator()(const void* data, size_t numBytes);
55 std::string operator()(const std::string& text);
56
58 void add(const void* data, size_t numBytes);
59
61 std::string getHash();
62
64 void reset();
65
66private:
68 void processBlock(const void* data);
70 void processBuffer();
71
73 enum { StateSize = 1600 / (8 * 8),
74 MaxBlockSize = 200 - 2 * (224 / 8) };
75
77 uint64_t m_hash[StateSize];
79 uint64_t m_numBytes;
81 size_t m_blockSize;
83 size_t m_bufferSize;
85 uint8_t m_buffer[MaxBlockSize];
87 Bits m_bits;
88};
89
90} // namespace hash
long long __int64
Definition Standard.h:183
SHA3(Bits bits=Bits256)
same as reset()
Definition sha3.cpp:25
Bits
algorithm variants
Definition sha3.h:47
@ Bits384
Definition sha3.h:47
@ Bits512
Definition sha3.h:47
@ Bits224
Definition sha3.h:47
@ Bits256
Definition sha3.h:47
void reset()
restart
Definition sha3.cpp:34
std::string getHash()
return latest hash as hex characters
Definition sha3.cpp:244
std::string operator()(const void *data, size_t numBytes)
compute hash of a memory block
Definition sha3.cpp:284
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition sha3.cpp:181
Usage: std::string msg = "The quick brown fox jumps over the lazy dog"; std::string key = "key"; std:...
Definition crc32.h:28