CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
sha1.h
Go to the documentation of this file.
1
6// //////////////////////////////////////////////////////////
7// sha1.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 SHA1 //: public Hash
45{
46public:
48 enum { BlockSize = 512 / 8, HashBytes = 20 };
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();
63
65 std::string getHashRaw();
66
68 void getHash(unsigned char buffer[HashBytes]);
69
71 void reset();
72
73private:
75 void processBlock(const void* data);
77 void processBuffer();
78
80 uint64_t m_numBytes;
82 size_t m_bufferSize;
84 uint8_t m_buffer[BlockSize];
85
86 enum { HashValues = HashBytes / 4 };
88 uint32_t m_hash[HashValues];
89};
90
91} // namespace hash
long long __int64
Definition Standard.h:183
std::string operator()(const std::string &text)
compute SHA1 of a string, excluding final zero
std::string getHashRaw()
return latest hash as raw characters
void getHash(unsigned char buffer[HashBytes])
return latest hash as bytes
SHA1()
same as reset()
void reset()
restart
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
std::string operator()(const void *data, size_t numBytes)
compute SHA1 of a memory block
@ HashBytes
Definition sha1.h:48
@ BlockSize
Definition sha1.h:48
std::string getHash()
return latest hash as 40 hex characters
Usage: std::string msg = "The quick brown fox jumps over the lazy dog"; std::string key = "key"; std:...
Definition crc32.h:28