CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
sha256.h
Go to the documentation of this file.
1
6// //////////////////////////////////////////////////////////
7// sha256.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 __int32 uint32_t;
22typedef unsigned __int64 uint64_t;
23#else
24// GCC
25#include <stdint.h>
26#endif
27
28// Added namespace to avoid clash with OpenSSL
29namespace hash {
30
32
44class SHA256 //: public Hash
45{
46public:
48 enum { BlockSize = 512 / 8, HashBytes = 32 };
49
52
54 std::string operator()(const void* data, size_t numBytes);
56 std::string operator()(const std::string& text);
57
59 void add(const void* data, size_t numBytes);
60
62 std::string getHash();
64 void getHash(unsigned char buffer[HashBytes]);
65
67 void reset();
68
69private:
71 void processBlock(const void* data);
73 void processBuffer();
74
76 uint64_t m_numBytes;
78 size_t m_bufferSize;
80 uint8_t m_buffer[BlockSize];
81
82 enum { HashValues = HashBytes / 4 };
84 uint32_t m_hash[HashValues];
85};
86
87} // namespace hash
long long __int64
Definition Standard.h:183
std::string getHash()
return latest hash as 64 hex characters
void getHash(unsigned char buffer[HashBytes])
return latest hash as bytes
SHA256()
same as reset()
std::string operator()(const void *data, size_t numBytes)
compute SHA256 of a memory block
std::string operator()(const std::string &text)
compute SHA256 of a string, excluding final zero
void reset()
restart
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Usage: std::string msg = "The quick brown fox jumps over the lazy dog"; std::string key = "key"; std:...
Definition crc32.h:28