CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
keccak.h
Go to the documentation of this file.
1
6// //////////////////////////////////////////////////////////
7// keccak.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 Keccak //: public Hash
44{
45public:
47 enum Bits { Keccak224 = 224, Keccak256 = 256, Keccak384 = 384, Keccak512 = 512 };
48
50 explicit Keccak(Bits bits = Keccak256);
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
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition keccak.cpp:181
std::string operator()(const void *data, size_t numBytes)
compute hash of a memory block
Definition keccak.cpp:284
std::string getHash()
return latest hash as hex characters
Definition keccak.cpp:245
Keccak(Bits bits=Keccak256)
same as reset()
Definition keccak.cpp:25
void reset()
restart
Definition keccak.cpp:34
Bits
algorithm variants
Definition keccak.h:47
Usage: std::string msg = "The quick brown fox jumps over the lazy dog"; std::string key = "key"; std:...
Definition crc32.h:28