hash_functions.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 "../api_core.h"
34 #include "../System/cl_platform.h"
35 #include "../Crypto/sha1.h"
36 #include "../Crypto/md5.h"
37 #include "../Crypto/sha224.h"
38 #include "../Crypto/sha256.h"
39 #include "../Crypto/sha384.h"
40 #include "../Crypto/sha512.h"
41 #include "../Crypto/sha512_224.h"
42 #include "../Crypto/sha512_256.h"
43 
44 namespace clan
45 {
48 
50 class CL_API_CORE HashFunctions
51 {
54 
55 public:
56 
60 
61 public:
62 
66 
67 public:
69  static ubyte32 crc32(const void *data, int size, ubyte32 running_crc=0);
70 
72  static ubyte32 adler32(const void *data, int size, ubyte32 running_adler32=0);
73 
75  static std::string sha1(const void *data, int size, bool uppercase = false);
76 
83  static std::string sha1(const std::string &data, bool uppercase = false);
84 
91  static std::string sha1(const DataBuffer &data, bool uppercase = false);
92 
98  static void sha1(const void *data, int size, unsigned char out_hash[20]);
99 
104  static void sha1(const std::string &data, unsigned char out_hash[20]);
105 
110  static void sha1(const DataBuffer &data, unsigned char out_hash[20]);
111 
113  static std::string md5(const void *data, int size, bool uppercase = false);
114 
121  static std::string md5(const std::string &data, bool uppercase = false);
122 
129  static std::string md5(const DataBuffer &data, bool uppercase = false);
130 
136  static void md5(const void *data, int size, unsigned char out_hash[16]);
137 
142  static void md5(const std::string &data, unsigned char out_hash[16]);
143 
148  static void md5(const DataBuffer &data, unsigned char out_hash[16]);
149 
151  static std::string sha224(const void *data, int size, bool uppercase = false);
152 
159  static std::string sha224(const std::string &data, bool uppercase = false);
160 
167  static std::string sha224(const DataBuffer &data, bool uppercase = false);
168 
174  static void sha224(const void *data, int size, unsigned char out_hash[28]);
175 
180  static void sha224(const std::string &data, unsigned char out_hash[28]);
181 
186  static void sha224(const DataBuffer &data, unsigned char out_hash[28]);
187 
188 
190  static std::string sha256(const void *data, int size, bool uppercase = false);
191 
198  static std::string sha256(const std::string &data, bool uppercase = false);
199 
206  static std::string sha256(const DataBuffer &data, bool uppercase = false);
207 
213  static void sha256(const void *data, int size, unsigned char out_hash[32]);
214 
219  static void sha256(const std::string &data, unsigned char out_hash[32]);
220 
225  static void sha256(const DataBuffer &data, unsigned char out_hash[32]);
226 
228  static std::string sha384(const void *data, int size, bool uppercase = false);
229 
236  static std::string sha384(const std::string &data, bool uppercase = false);
237 
244  static std::string sha384(const DataBuffer &data, bool uppercase = false);
245 
251  static void sha384(const void *data, int size, unsigned char out_hash[48]);
252 
257  static void sha384(const std::string &data, unsigned char out_hash[48]);
258 
263  static void sha384(const DataBuffer &data, unsigned char out_hash[48]);
264 
266  static std::string sha512(const void *data, int size, bool uppercase = false);
267 
274  static std::string sha512(const std::string &data, bool uppercase = false);
275 
282  static std::string sha512(const DataBuffer &data, bool uppercase = false);
283 
289  static void sha512(const void *data, int size, unsigned char out_hash[64]);
290 
295  static void sha512(const std::string &data, unsigned char out_hash[64]);
296 
301  static void sha512(const DataBuffer &data, unsigned char out_hash[64]);
302 
304  static std::string sha512_224(const void *data, int size, bool uppercase = false);
305 
312  static std::string sha512_224(const std::string &data, bool uppercase = false);
313 
320  static std::string sha512_224(const DataBuffer &data, bool uppercase = false);
321 
327  static void sha512_224(const void *data, int size, unsigned char out_hash[28]);
328 
333  static void sha512_224(const std::string &data, unsigned char out_hash[28]);
334 
339  static void sha512_224(const DataBuffer &data, unsigned char out_hash[28]);
340 
341 
343  static std::string sha512_256(const void *data, int size, bool uppercase = false);
344 
351  static std::string sha512_256(const std::string &data, bool uppercase = false);
352 
359  static std::string sha512_256(const DataBuffer &data, bool uppercase = false);
360 
366  static void sha512_256(const void *data, int size, unsigned char out_hash[32]);
367 
372  static void sha512_256(const std::string &data, unsigned char out_hash[32]);
373 
378  static void sha512_256(const DataBuffer &data, unsigned char out_hash[32]);
379 
383 
384 private:
386 };
387 
388 }
389 
A Collection of checksum functions.
Definition: hash_functions.h:50
General purpose data buffer.
Definition: databuffer.h:43
unsigned int ubyte32
Definition: cl_platform.h:64