libMVRgdtf 40bc00a
A library for GDTF and MVR
Loading...
Searching...
No Matches
sha256.h
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////
2// sha256.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
15typedef unsigned __int8 uint8_t;
16typedef unsigned __int32 uint32_t;
17typedef unsigned __int64 uint64_t;
18#else
19// GCC
20#include <stdint.h>
21#endif
22
23
25
37class SHA256 //: public Hash
38{
39public:
41 enum { BlockSize = 512 / 8, HashBytes = 32 };
42
44 SHA256();
45
47 std::string operator()(const void* data, size_t numBytes);
49 std::string operator()(const std::string& text);
50
52 void add(const void* data, size_t numBytes);
53
55 std::string getHash();
57 void getHash(unsigned char buffer[HashBytes]);
58
60 void reset();
61
62private:
64 void processBlock(const void* data);
66 void processBuffer();
67
69 uint64_t m_numBytes;
71 size_t m_bufferSize;
73 uint8_t m_buffer[BlockSize];
74
75 enum { HashValues = HashBytes / 4 };
77 uint32_t m_hash[HashValues];
78};
compute SHA256 hash
Definition sha256.h:38
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition sha256.cpp:241
std::string operator()(const void *data, size_t numBytes)
compute SHA256 of a memory block
Definition sha256.cpp:397
SHA256()
same as reset()
Definition sha256.cpp:16
void getHash(unsigned char buffer[HashBytes])
return latest hash as bytes
void reset()
restart
Definition sha256.cpp:23
@ BlockSize
Definition sha256.h:41
@ HashBytes
Definition sha256.h:41
std::string getHash()
return latest hash as 64 hex characters
Definition sha256.cpp:351