OXYGENHUB
◆ main openmsx / src / utils / tiger.hh
2.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
/**
2
 * The implementation of the tiger() function is based on the corresponding
3
 * function in the tigertree project:
4
 *    https://sourceforge.net/projects/tigertree/
5
 * Which in turn states that the code is almost a literal copy from the
6
 * original Tiger authors code. It can be found at:
7
 *    http://www.cs.technion.ac.il/~biham/Reports/Tiger
8
 *
9
 * The functions tiger_int() and tiger_leaf() are implemented by me. These are
10
 * built on top of the (internal) tiger_compress() function. These 2 functions
11
 * are faster than the generic tiger() function for the specific case of
12
 * tiger-tree calculations.
13
 */
14
15
#ifndef TIGER_HH
16
#define TIGER_HH
17
18
#include <array>
19
#include <cstdint>
20
#include <span>
21
#include <string>
22
23
namespace openmsx {
24
25
/** This struct represents the result of a tiger-hash.
26
 * This is a 192-bit value. It can be formatted as a 39-char base32-encoded
27
 * string. Similar to the output of the unix 'tthsum' tool.
28
 */
29
struct TigerHash
30
{
31
	[[nodiscard]] std::string toString() const;
32
	union {
33
		std::array<uint64_t, 3> h64;
34
		std::array<uint8_t, 24> h8;
35
	};
36
};
37
38
/** Generic function to calculate a tiger-hash.
39
 * input: start-address and size of the block
40
 * output: 192-bit hash value
41
 * The result is endianness-neutral (on big-endian systems the result is
42
 * converted so that, when interpreted as a byte-array, it is identical to
43
 * the result obtained on a little-endian system).
44
 */
45
void tiger(std::span<const uint8_t> input, TigerHash& result);
46
47
/** Use for tiger-tree internal node hash calculations.
48
 * Combine two earlier calculated tiger hash values in a specific way (add
49
 * marker/padding/length bytes before/after) and calculate a new hash value.
50
 * This function is not reentrant.
51
 */
52
void tiger_int(const TigerHash& h0, const TigerHash& h1, TigerHash& result);
53
54
/** Use for tiger-tree leaf node hash calculations.
55
 * Take a 1+1024-byte input block, add some marker/padding/length bytes
56
 * before/after and calculate a tiger-hash.
57
 * This function is not reentrant.
58
 * This function requires that data[0] can be (temporarily) overridden (so
59
 * after the function returns the data buffer is unchanged, but temporarily
60
 * it is changed, hence the parameter cannot be const).
61
 */
62
void tiger_leaf(std::span</*const*/uint8_t> data, TigerHash& result);
63
64
} // namespace openmsx
65
66
#endif