hash_functions.h Source File - ClanLib SDK
Description: hash_functions.h Source File

hash_functions.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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** Mark Page
27*/
28
29
30#pragma once
31
32#include "../System/cl_platform.h"
33#include "../Crypto/sha1.h"
34#include "../Crypto/md5.h"
35#include "../Crypto/sha224.h"
36#include "../Crypto/sha256.h"
37#include "../Crypto/sha384.h"
38#include "../Crypto/sha512.h"
39#include "../Crypto/sha512_224.h"
40#include "../Crypto/sha512_256.h"
41
42namespace clan
43{
46
48 class HashFunctions
49 {
50 public:
52 static uint32_t crc32(const void *data, int size, uint32_t running_crc = 0);
53
55 static uint32_t adler32(const void *data, int size, uint32_t running_adler32 = 0);
56
58 static std::string sha1(const void *data, int size, bool uppercase = false);
59
66 static std::string sha1(const std::string &data, bool uppercase = false);
67
74 static std::string sha1(const DataBuffer &data, bool uppercase = false);
75
81 static void sha1(const void *data, int size, unsigned char out_hash[20]);
82
87 static void sha1(const std::string &data, unsigned char out_hash[20]);
88
93 static void sha1(const DataBuffer &data, unsigned char out_hash[20]);
94
96 static std::string md5(const void *data, int size, bool uppercase = false);
97
104 static std::string md5(const std::string &data, bool uppercase = false);
105
112 static std::string md5(const DataBuffer &data, bool uppercase = false);
113
119 static void md5(const void *data, int size, unsigned char out_hash[16]);
120
125 static void md5(const std::string &data, unsigned char out_hash[16]);
126
131 static void md5(const DataBuffer &data, unsigned char out_hash[16]);
132
134 static std::string sha224(const void *data, int size, bool uppercase = false);
135
142 static std::string sha224(const std::string &data, bool uppercase = false);
143
150 static std::string sha224(const DataBuffer &data, bool uppercase = false);
151
157 static void sha224(const void *data, int size, unsigned char out_hash[28]);
158
163 static void sha224(const std::string &data, unsigned char out_hash[28]);
164
169 static void sha224(const DataBuffer &data, unsigned char out_hash[28]);
170
171
173 static std::string sha256(const void *data, int size, bool uppercase = false);
174
181 static std::string sha256(const std::string &data, bool uppercase = false);
182
189 static std::string sha256(const DataBuffer &data, bool uppercase = false);
190
196 static void sha256(const void *data, int size, unsigned char out_hash[32]);
197
202 static void sha256(const std::string &data, unsigned char out_hash[32]);
203
208 static void sha256(const DataBuffer &data, unsigned char out_hash[32]);
209
211 static std::string sha384(const void *data, int size, bool uppercase = false);
212
219 static std::string sha384(const std::string &data, bool uppercase = false);
220
227 static std::string sha384(const DataBuffer &data, bool uppercase = false);
228
234 static void sha384(const void *data, int size, unsigned char out_hash[48]);
235
240 static void sha384(const std::string &data, unsigned char out_hash[48]);
241
246 static void sha384(const DataBuffer &data, unsigned char out_hash[48]);
247
249 static std::string sha512(const void *data, int size, bool uppercase = false);
250
257 static std::string sha512(const std::string &data, bool uppercase = false);
258
265 static std::string sha512(const DataBuffer &data, bool uppercase = false);
266
272 static void sha512(const void *data, int size, unsigned char out_hash[64]);
273
278 static void sha512(const std::string &data, unsigned char out_hash[64]);
279
284 static void sha512(const DataBuffer &data, unsigned char out_hash[64]);
285
287 static std::string sha512_224(const void *data, int size, bool uppercase = false);
288
295 static std::string sha512_224(const std::string &data, bool uppercase = false);
296
303 static std::string sha512_224(const DataBuffer &data, bool uppercase = false);
304
310 static void sha512_224(const void *data, int size, unsigned char out_hash[28]);
311
316 static void sha512_224(const std::string &data, unsigned char out_hash[28]);
317
322 static void sha512_224(const DataBuffer &data, unsigned char out_hash[28]);
323
324
326 static std::string sha512_256(const void *data, int size, bool uppercase = false);
327
334 static std::string sha512_256(const std::string &data, bool uppercase = false);
335
342 static std::string sha512_256(const DataBuffer &data, bool uppercase = false);
343
349 static void sha512_256(const void *data, int size, unsigned char out_hash[32]);
350
355 static void sha512_256(const std::string &data, unsigned char out_hash[32]);
356
361 static void sha512_256(const DataBuffer &data, unsigned char out_hash[32]);
362 };
363
365}
clan::DataBuffer
General purpose data buffer.
Definition databuffer.h:42
clan::HashFunctions
A Collection of checksum functions.
Definition hash_functions.h:49
clan::HashFunctions::md5
static std::string md5(const void *data, int size, bool uppercase=false)
Generate SHA-1 hash from data.
clan::HashFunctions::md5
static std::string md5(const DataBuffer &data, bool uppercase=false)
MD5.
clan::HashFunctions::sha512
static std::string sha512(const DataBuffer &data, bool uppercase=false)
SHA512.
clan::HashFunctions::sha512_224
static void sha512_224(const void *data, int size, unsigned char out_hash[28])
SHA512_224.
clan::HashFunctions::sha224
static void sha224(const void *data, int size, unsigned char out_hash[28])
SHA224.
clan::HashFunctions::sha512_256
static std::string sha512_256(const std::string &data, bool uppercase=false)
SHA512_256.
clan::HashFunctions::sha384
static std::string sha384(const std::string &data, bool uppercase=false)
SHA384.
clan::HashFunctions::sha1
static std::string sha1(const DataBuffer &data, bool uppercase=false)
SHA1.
clan::HashFunctions::sha256
static void sha256(const void *data, int size, unsigned char out_hash[32])
SHA256.
clan::HashFunctions::sha256
static void sha256(const std::string &data, unsigned char out_hash[32])
SHA256.
clan::HashFunctions::sha224
static void sha224(const DataBuffer &data, unsigned char out_hash[28])
SHA224.
clan::HashFunctions::sha256
static void sha256(const DataBuffer &data, unsigned char out_hash[32])
SHA256.
clan::HashFunctions::sha1
static std::string sha1(const std::string &data, bool uppercase=false)
SHA1.
clan::HashFunctions::sha1
static std::string sha1(const void *data, int size, bool uppercase=false)
Generate SHA-1 hash from data.
clan::HashFunctions::sha384
static void sha384(const DataBuffer &data, unsigned char out_hash[48])
SHA384.
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::sha512_256
static void sha512_256(const DataBuffer &data, unsigned char out_hash[32])
SHA512_256.
clan::HashFunctions::sha256
static std::string sha256(const DataBuffer &data, bool uppercase=false)
SHA256.
clan::HashFunctions::md5
static void md5(const void *data, int size, unsigned char out_hash[16])
MD5.
clan::HashFunctions::md5
static void md5(const DataBuffer &data, unsigned char out_hash[16])
MD5.
clan::HashFunctions::sha384
static void sha384(const void *data, int size, unsigned char out_hash[48])
SHA384.
clan::HashFunctions::sha384
static std::string sha384(const DataBuffer &data, bool uppercase=false)
SHA384.
clan::HashFunctions::sha512_256
static void sha512_256(const void *data, int size, unsigned char out_hash[32])
SHA512_256.
clan::HashFunctions::sha512_224
static void sha512_224(const DataBuffer &data, unsigned char out_hash[28])
SHA512_224.
clan::HashFunctions::md5
static void md5(const std::string &data, unsigned char out_hash[16])
MD5.
clan::HashFunctions::sha1
static void sha1(const void *data, int size, unsigned char out_hash[20])
SHA1.
clan::HashFunctions::sha384
static std::string sha384(const void *data, int size, bool uppercase=false)
Generate SHA-384 hash from data.
clan::HashFunctions::sha512_256
static std::string sha512_256(const DataBuffer &data, bool uppercase=false)
SHA512_256.
clan::HashFunctions::sha224
static std::string sha224(const DataBuffer &data, bool uppercase=false)
SHA224.
clan::HashFunctions::sha512_256
static void sha512_256(const std::string &data, unsigned char out_hash[32])
SHA512_256.
clan::HashFunctions::sha1
static void sha1(const std::string &data, unsigned char out_hash[20])
SHA1.
clan::HashFunctions::sha512_224
static void sha512_224(const std::string &data, unsigned char out_hash[28])
SHA512_224.
clan::HashFunctions::md5
static std::string md5(const std::string &data, bool uppercase=false)
MD5.
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::HashFunctions::sha512
static std::string sha512(const void *data, int size, bool uppercase=false)
Generate SHA-512 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::sha224
static std::string sha224(const void *data, int size, bool uppercase=false)
Generate SHA-224 hash from data.
clan::HashFunctions::sha512
static void sha512(const void *data, int size, unsigned char out_hash[64])
SHA512.
clan::HashFunctions::sha512
static void sha512(const std::string &data, unsigned char out_hash[64])
SHA512.
clan::HashFunctions::sha384
static void sha384(const std::string &data, unsigned char out_hash[48])
SHA384.
clan::HashFunctions::sha512
static void sha512(const DataBuffer &data, unsigned char out_hash[64])
SHA512.
clan::HashFunctions::sha1
static void sha1(const DataBuffer &data, unsigned char out_hash[20])
SHA1.
clan::HashFunctions::sha512_224
static std::string sha512_224(const std::string &data, bool uppercase=false)
SHA512_224.
clan::HashFunctions::sha512_256
static std::string sha512_256(const void *data, int size, bool uppercase=false)
Generate SHA-512_256 hash from data.
clan::HashFunctions::sha256
static std::string sha256(const std::string &data, bool uppercase=false)
SHA256.
clan::HashFunctions::sha224
static std::string sha224(const std::string &data, bool uppercase=false)
SHA224.
clan::HashFunctions::sha512
static std::string sha512(const std::string &data, bool uppercase=false)
SHA512.
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::sha224
static void sha224(const std::string &data, unsigned char out_hash[28])
SHA224.
clan::HashFunctions::sha512_224
static std::string sha512_224(const DataBuffer &data, bool uppercase=false)
SHA512_224.
clan
Definition clanapp.h:36