-
Notifications
You must be signed in to change notification settings - Fork 80
/
sha1.hpp
57 lines (42 loc) · 1.38 KB
/
sha1.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
sha1.hpp - header of
============
SHA-1 in C++
============
100% Public Domain.
Original C Code
-- Steve Reid <[email protected]>
Small changes to fit into bglibs
-- Bruce Guenter <[email protected]>
Translation to simpler C++ Code
-- Volker Grabsch <[email protected]>
Safety fixes
-- Eugene Hopkinson <slowriot at voxelstorm dot com>
*/
#ifndef SHA1_HPP
#define SHA1_HPP
#include <iostream>
#include <string>
class SHA1
{
public:
SHA1();
void update(const std::string &s);
void update(std::istream &is);
std::string final();
static std::string from_file(const std::string &filename);
private:
typedef unsigned long int uint32; /* just needs to be at least 32bit */
typedef unsigned long long uint64; /* just needs to be at least 64bit */
static const uint DIGEST_INTS = 5; /* number of 32bit integers per SHA1 digest */
static const uint BLOCK_INTS = 16; /* number of 32bit integers per SHA1 block */
static const uint BLOCK_BYTES = BLOCK_INTS * 4;
uint32 digest[DIGEST_INTS];
std::string buffer;
uint64 transforms;
void reset();
void transform(uint32 block[BLOCK_BYTES]);
static void buffer_to_block(const std::string &buffer, uint32 block[BLOCK_INTS]);
static void read(std::istream &is, std::string &s, size_t max);
};
#endif /* SHA1_HPP */