Luanti
5.15.0-dev
Loading...
Searching...
No Matches
sha1.h
Go to the documentation of this file.
1
/* sha1.h
2
3
Copyright (c) 2005 Michael D. Leonhard
4
5
http://tamale.net/
6
7
Permission is hereby granted, free of charge, to any person obtaining a copy of
8
this software and associated documentation files (the "Software"), to deal in
9
the Software without restriction, including without limitation the rights to
10
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11
of the Software, and to permit persons to whom the Software is furnished to do
12
so, subject to the following conditions:
13
14
The above copyright notice and this permission notice shall be included in all
15
copies or substantial portions of the Software.
16
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
SOFTWARE.
24
25
*/
26
27
#pragma once
28
29
#if !defined(IN_HASHING_CPP) && !defined(IN_SHA1_CPP)
30
#error do not include directly
31
#endif
32
33
#include <cstdint>
34
#include <string>
35
#include <string_view>
36
37
typedef
uint32_t
Uint32
;
38
39
class
SHA1
40
{
41
private
:
42
// fields
43
Uint32
H0
= 0x67452301;
44
Uint32
H1
= 0xefcdab89;
45
Uint32
H2
= 0x98badcfe;
46
Uint32
H3
= 0x10325476;
47
Uint32
H4
= 0xc3d2e1f0;
48
unsigned
char
bytes
[64];
49
Uint32
unprocessedBytes
= 0;
50
Uint32
size
= 0;
51
void
process
();
52
53
public
:
54
SHA1
();
55
~SHA1
();
56
void
addBytes
(
const
char
*data,
Uint32
num);
57
inline
void
addBytes
(std::string_view data) {
58
addBytes
(data.data(), data.size());
59
}
60
void
getDigest
(
unsigned
char
*to);
61
inline
std::string
getDigest
() {
62
std::string ret(20,
'\000'
);
63
getDigest
(
reinterpret_cast<
unsigned
char
*
>
(ret.data()));
64
return
ret;
65
}
66
};
SHA1
Definition
sha1.h:40
SHA1::addBytes
void addBytes(const char *data, Uint32 num)
Definition
sha1.cpp:126
SHA1::H2
Uint32 H2
Definition
sha1.h:45
SHA1::H0
Uint32 H0
Definition
sha1.h:43
SHA1::H4
Uint32 H4
Definition
sha1.h:47
SHA1::unprocessedBytes
Uint32 unprocessedBytes
Definition
sha1.h:49
SHA1::~SHA1
~SHA1()
Definition
sha1.cpp:62
SHA1::getDigest
std::string getDigest()
Definition
sha1.h:61
SHA1::addBytes
void addBytes(std::string_view data)
Definition
sha1.h:57
SHA1::bytes
unsigned char bytes[64]
Definition
sha1.h:48
SHA1::process
void process()
Definition
sha1.cpp:71
SHA1::H1
Uint32 H1
Definition
sha1.h:44
SHA1::SHA1
SHA1()
Definition
sha1.cpp:55
SHA1::size
Uint32 size
Definition
sha1.h:50
SHA1::H3
Uint32 H3
Definition
sha1.h:46
Uint32
uint32_t Uint32
Definition
sha1.h:37
util
sha1.h
Generated on Fri Jan 2 2026 04:32:22 for Luanti by
1.11.0