Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmlibrhash/librhash/algorithms.h
3150 views
1
/* algorithms.h - rhash library algorithms */
2
#ifndef RHASH_ALGORITHMS_H
3
#define RHASH_ALGORITHMS_H
4
5
#include "rhash.h"
6
#include "byte_order.h"
7
#include <stddef.h>
8
9
#ifdef __cplusplus
10
extern "C" {
11
#endif
12
13
#ifndef RHASH_API
14
/* modifier for RHash library functions */
15
# define RHASH_API
16
#endif
17
18
/**
19
* Bit flag: default hash output format is base32.
20
*/
21
#define RHASH_INFO_BASE32 1
22
23
/**
24
* Information about a hash function.
25
*/
26
typedef struct rhash_info
27
{
28
/**
29
* Hash function indentifier.
30
*/
31
unsigned hash_id;
32
/**
33
* Flags bit-mask, including RHASH_INFO_BASE32 bit.
34
*/
35
unsigned flags;
36
/**
37
The size of of the raw message digest in bytes.
38
*/
39
size_t digest_size;
40
/**
41
* The hash function name.
42
*/
43
const char* name;
44
/**
45
* The corresponding paramenter name in a magnet link.
46
*/
47
const char* magnet_name;
48
} rhash_info;
49
50
typedef void (*pinit_t)(void* ctx);
51
typedef void (*pupdate_t)(void* ctx, const void* msg, size_t size);
52
typedef void (*pfinal_t)(void* ctx, unsigned char* result);
53
typedef void (*pcleanup_t)(void* ctx);
54
55
/**
56
* Information about a hash function
57
*/
58
typedef struct rhash_hash_info
59
{
60
rhash_info* info;
61
size_t context_size;
62
ptrdiff_t digest_diff;
63
pinit_t init;
64
pupdate_t update;
65
pfinal_t final;
66
pcleanup_t cleanup;
67
} rhash_hash_info;
68
69
/**
70
* Information on a hash function and its context
71
*/
72
typedef struct rhash_vector_item
73
{
74
struct rhash_hash_info* hash_info;
75
void* context;
76
} rhash_vector_item;
77
78
/**
79
* The rhash context containing contexts for several hash functions
80
*/
81
typedef struct rhash_context_ext
82
{
83
struct rhash_context rc;
84
unsigned hash_vector_size; /* number of contained hash sums */
85
unsigned flags;
86
volatile unsigned state;
87
rhash_callback_t callback;
88
void* callback_data;
89
void* bt_ctx;
90
rhash_vector_item vector[]; /* contexts of contained hash sums */
91
} rhash_context_ext;
92
93
extern rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT];
94
extern rhash_hash_info* rhash_info_table;
95
extern int rhash_info_size;
96
extern unsigned rhash_uninitialized_algorithms;
97
98
extern rhash_info info_crc32;
99
extern rhash_info info_crc32c;
100
extern rhash_info info_md4;
101
extern rhash_info info_md5;
102
extern rhash_info info_sha1;
103
extern rhash_info info_tiger;
104
extern rhash_info info_tth ;
105
extern rhash_info info_btih;
106
extern rhash_info info_ed2k;
107
extern rhash_info info_aich;
108
extern rhash_info info_whirlpool;
109
extern rhash_info info_rmd160;
110
extern rhash_info info_gost;
111
extern rhash_info info_gostpro;
112
extern rhash_info info_has160;
113
extern rhash_info info_snf128;
114
extern rhash_info info_snf256;
115
extern rhash_info info_sha224;
116
extern rhash_info info_sha256;
117
extern rhash_info info_sha384;
118
extern rhash_info info_sha512;
119
extern rhash_info info_sha3_224;
120
extern rhash_info info_sha3_256;
121
extern rhash_info info_sha3_384;
122
extern rhash_info info_sha3_512;
123
extern rhash_info info_edr256;
124
extern rhash_info info_edr512;
125
126
/* rhash_info flags */
127
#define F_BS32 1 /* default output in base32 */
128
#define F_SWAP32 2 /* big endian flag */
129
#define F_SWAP64 4
130
#define F_SPCEXP 8 /* needs special import/export logic */
131
132
/* define endianness flags */
133
#if IS_LITTLE_ENDIAN
134
#define F_LE32 0
135
#define F_LE64 0
136
#define F_BE32 F_SWAP32
137
#define F_BE64 F_SWAP64
138
#else
139
#define F_LE32 F_SWAP32
140
#define F_LE64 F_SWAP64
141
#define F_BE32 0
142
#define F_BE64 0
143
#endif
144
145
void rhash_init_algorithms(unsigned mask);
146
const rhash_info* rhash_info_by_id(unsigned hash_id); /* get hash sum info by hash id */
147
148
#if !defined(NO_IMPORT_EXPORT)
149
size_t rhash_export_alg(unsigned hash_id, const void* ctx, void* out, size_t size);
150
size_t rhash_import_alg(unsigned hash_id, void* ctx, const void* in, size_t size);
151
#endif /* !defined(NO_IMPORT_EXPORT) */
152
153
#if defined(OPENSSL_RUNTIME) && !defined(USE_OPENSSL)
154
# define USE_OPENSSL
155
#endif
156
157
#ifdef USE_OPENSSL
158
typedef struct rhash_hashing_methods
159
{
160
pinit_t init;
161
pupdate_t update;
162
pfinal_t final;
163
} rhash_hashing_methods;
164
165
enum rhash_methods_type
166
{
167
METHODS_RHASH,
168
METHODS_OPENSSL,
169
METHODS_SELECTED,
170
};
171
172
void rhash_load_sha1_methods(rhash_hashing_methods* methods, int methods_type);
173
174
#define ARE_OPENSSL_METHODS(methods) ((methods).init != (void (*)(void*))&rhash_sha1_init)
175
#endif
176
177
#ifdef __cplusplus
178
} /* extern "C" */
179
#endif /* __cplusplus */
180
181
#endif /* RHASH_ALGORITHMS_H */
182
183