sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
sha1.h
Go to the documentation of this file.
1
5// //////////////////////////////////////////////////////////
6// sha1.h
7// Copyright (c) 2014,2015 Stephan Brumme. All rights reserved.
8// see http://create.stephan-brumme.com/disclaimer.html
9//
10
11#pragma once
12
13//#include "hash.h"
14#include <string>
15
16// define fixed size integer types
17#ifdef _MSC_VER
18// Windows
19typedef unsigned __int8 uint8_t;
20typedef unsigned __int32 uint32_t;
21typedef unsigned __int64 uint64_t;
22#else
23// GCC
24#include <stdint.h>
25#endif
26
27
29
41class SHA1 //: public Hash
42{
43public:
45 enum { BlockSize = 512 / 8, HashBytes = 20 };
46
48 SHA1();
49
51 std::string operator()(const void* data, size_t numBytes);
53 std::string operator()(const std::string& text);
54
56 void add(const void* data, size_t numBytes);
57
59 std::string getHash();
61 void getHash(unsigned char buffer[HashBytes]);
62
64 void reset();
65
66private:
68 void processBlock(const void* data);
70 void processBuffer();
71
73 uint64_t m_numBytes;
75 size_t m_bufferSize;
77 uint8_t m_buffer[BlockSize];
78
79 enum { HashValues = HashBytes / 4 };
81 uint32_t m_hash[HashValues];
82};
void getHash(unsigned char buffer[HashBytes])
return latest hash as bytes
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition sha1.cpp:158
std::string operator()(const void *data, size_t numBytes)
compute SHA1 of a memory block
Definition sha1.cpp:314
std::string getHash()
return latest hash as 40 hex characters
Definition sha1.cpp:268
void reset()
restart
Definition sha1.cpp:25
SHA1()
same as reset()
Definition sha1.cpp:18