hash_functions.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Harry Storbacka
27 ** Magnus Norddahl
28 */
29
30
31 #pragma once
32
33 #include "../System/cl_platform.h"
34 #include "../Crypto/sha1.h"
35 #include "../Crypto/md5.h"
36 #include "../Crypto/sha224.h"
37 #include "../Crypto/sha256.h"
38 #include "../Crypto/sha384.h"
39 #include "../Crypto/sha512.h"
40 #include "../Crypto/sha512_224.h"
41 #include "../Crypto/sha512_256.h"
42
43 namespace clan
44 {
47
49 class HashFunctions
50 {
53
54 public:
55
59
60 public:
61
65
66 public:
68 static uint32_t crc32(const void *data, int size, uint32_t running_crc=0);
69
71 static uint32_t adler32(const void *data, int size, uint32_t running_adler32=0);
72
74 static std::string sha1(const void *data, int size, bool uppercase = false);
75
82 static std::string sha1(const std::string &data, bool uppercase = false);
83
90 static std::string sha1(const DataBuffer &data, bool uppercase = false);
91
97 static void sha1(const void *data, int size, unsigned char out_hash[20]);
98
103 static void sha1(const std::string &data, unsigned char out_hash[20]);
104
109 static void sha1(const DataBuffer &data, unsigned char out_hash[20]);
110
112 static std::string md5(const void *data, int size, bool uppercase = false);
113
120 static std::string md5(const std::string &data, bool uppercase = false);
121
128 static std::string md5(const DataBuffer &data, bool uppercase = false);
129
135 static void md5(const void *data, int size, unsigned char out_hash[16]);
136
141 static void md5(const std::string &data, unsigned char out_hash[16]);
142
147 static void md5(const DataBuffer &data, unsigned char out_hash[16]);
148
150 static std::string sha224(const void *data, int size, bool uppercase = false);
151
158 static std::string sha224(const std::string &data, bool uppercase = false);
159
166 static std::string sha224(const DataBuffer &data, bool uppercase = false);
167
173 static void sha224(const void *data, int size, unsigned char out_hash[28]);
174
179 static void sha224(const std::string &data, unsigned char out_hash[28]);
180
185 static void sha224(const DataBuffer &data, unsigned char out_hash[28]);
186
187
189 static std::string sha256(const void *data, int size, bool uppercase = false);
190
197 static std::string sha256(const std::string &data, bool uppercase = false);
198
205 static std::string sha256(const DataBuffer &data, bool uppercase = false);
206
212 static void sha256(const void *data, int size, unsigned char out_hash[32]);
213
218 static void sha256(const std::string &data, unsigned char out_hash[32]);
219
224 static void sha256(const DataBuffer &data, unsigned char out_hash[32]);
225
227 static std::string sha384(const void *data, int size, bool uppercase = false);
228
235 static std::string sha384(const std::string &data, bool uppercase = false);
236
243 static std::string sha384(const DataBuffer &data, bool uppercase = false);
244
250 static void sha384(const void *data, int size, unsigned char out_hash[48]);
251
256 static void sha384(const std::string &data, unsigned char out_hash[48]);
257
262 static void sha384(const DataBuffer &data, unsigned char out_hash[48]);
263
265 static std::string sha512(const void *data, int size, bool uppercase = false);
266
273 static std::string sha512(const std::string &data, bool uppercase = false);
274
281 static std::string sha512(const DataBuffer &data, bool uppercase = false);
282
288 static void sha512(const void *data, int size, unsigned char out_hash[64]);
289
294 static void sha512(const std::string &data, unsigned char out_hash[64]);
295
300 static void sha512(const DataBuffer &data, unsigned char out_hash[64]);
301
303 static std::string sha512_224(const void *data, int size, bool uppercase = false);
304
311 static std::string sha512_224(const std::string &data, bool uppercase = false);
312
319 static std::string sha512_224(const DataBuffer &data, bool uppercase = false);
320
326 static void sha512_224(const void *data, int size, unsigned char out_hash[28]);
327
332 static void sha512_224(const std::string &data, unsigned char out_hash[28]);
333
338 static void sha512_224(const DataBuffer &data, unsigned char out_hash[28]);
339
340
342 static std::string sha512_256(const void *data, int size, bool uppercase = false);
343
350 static std::string sha512_256(const std::string &data, bool uppercase = false);
351
358 static std::string sha512_256(const DataBuffer &data, bool uppercase = false);
359
365 static void sha512_256(const void *data, int size, unsigned char out_hash[32]);
366
371 static void sha512_256(const std::string &data, unsigned char out_hash[32]);
372
377 static void sha512_256(const DataBuffer &data, unsigned char out_hash[32]);
378
382
383 private:
385 };
386
387 }
388
clan::HashFunctions::crc32
static uint32_t crc32(const void *data, int size, uint32_t running_crc=0)
Calculate a CRC32 checksum on the data.
clan
Definition: clanapp.h:35
clan::StyleTokenType::string
@ keyword
clan::HashFunctions::sha512_224
static std::string sha512_224(const void *data, int size, bool uppercase=false)
Generate SHA-512_224 hash from data.
clan::HashFunctions::sha256
static std::string sha256(const void *data, int size, bool uppercase=false)
Generate SHA-256 hash from data.
clan::HashFunctions::sha1
static std::string sha1(const void *data, int size, bool uppercase=false)
Generate SHA-1 hash from data.
clan::HashFunctions::adler32
static uint32_t adler32(const void *data, int size, uint32_t running_adler32=0)
Calculate a CRC32 checksum on the data.
clan::HashFunctions::md5
static std::string md5(const void *data, int size, bool uppercase=false)
Generate SHA-1 hash from data.
clan::HashFunctions::sha512
static std::string sha512(const void *data, int size, bool uppercase=false)
Generate SHA-512 hash from data.
clan::HashFunctions::sha384
static std::string sha384(const void *data, int size, bool uppercase=false)
Generate SHA-384 hash from data.
clan::HashFunctions::sha224
static std::string sha224(const void *data, int size, bool uppercase=false)
Generate SHA-224 hash from data.
clan::HashFunctions
A Collection of checksum functions.
Definition: hash_functions.h:49
clan::DataBuffer
General purpose data buffer.
Definition: databuffer.h:42
clan::HashFunctions::sha512_256
static std::string sha512_256(const void *data, int size, bool uppercase=false)
Generate SHA-512_256 hash from data.