hash_functions.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore 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 <cstdint>
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 
42 namespace uicore
43 {
46  {
47  public:
49  static uint32_t crc32(const void *data, int size, uint32_t running_crc = 0);
50 
52  static uint32_t adler32(const void *data, int size, uint32_t running_adler32 = 0);
53 
55  static std::string sha1(const void *data, int size, bool uppercase = false);
56 
63  static std::string sha1(const std::string &data, bool uppercase = false);
64 
71  static std::string sha1(const DataBufferPtr &data, bool uppercase = false);
72 
78  static void sha1(const void *data, int size, unsigned char out_hash[20]);
79 
84  static void sha1(const std::string &data, unsigned char out_hash[20]);
85 
90  static void sha1(const DataBufferPtr &data, unsigned char out_hash[20]);
91 
93  static std::string md5(const void *data, int size, bool uppercase = false);
94 
101  static std::string md5(const std::string &data, bool uppercase = false);
102 
109  static std::string md5(const DataBufferPtr &data, bool uppercase = false);
110 
116  static void md5(const void *data, int size, unsigned char out_hash[16]);
117 
122  static void md5(const std::string &data, unsigned char out_hash[16]);
123 
128  static void md5(const DataBufferPtr &data, unsigned char out_hash[16]);
129 
131  static std::string sha224(const void *data, int size, bool uppercase = false);
132 
139  static std::string sha224(const std::string &data, bool uppercase = false);
140 
147  static std::string sha224(const DataBufferPtr &data, bool uppercase = false);
148 
154  static void sha224(const void *data, int size, unsigned char out_hash[28]);
155 
160  static void sha224(const std::string &data, unsigned char out_hash[28]);
161 
166  static void sha224(const DataBufferPtr &data, unsigned char out_hash[28]);
167 
168 
170  static std::string sha256(const void *data, int size, bool uppercase = false);
171 
178  static std::string sha256(const std::string &data, bool uppercase = false);
179 
186  static std::string sha256(const DataBufferPtr &data, bool uppercase = false);
187 
193  static void sha256(const void *data, int size, unsigned char out_hash[32]);
194 
199  static void sha256(const std::string &data, unsigned char out_hash[32]);
200 
205  static void sha256(const DataBufferPtr &data, unsigned char out_hash[32]);
206 
208  static std::string sha384(const void *data, int size, bool uppercase = false);
209 
216  static std::string sha384(const std::string &data, bool uppercase = false);
217 
224  static std::string sha384(const DataBufferPtr &data, bool uppercase = false);
225 
231  static void sha384(const void *data, int size, unsigned char out_hash[48]);
232 
237  static void sha384(const std::string &data, unsigned char out_hash[48]);
238 
243  static void sha384(const DataBufferPtr &data, unsigned char out_hash[48]);
244 
246  static std::string sha512(const void *data, int size, bool uppercase = false);
247 
254  static std::string sha512(const std::string &data, bool uppercase = false);
255 
262  static std::string sha512(const DataBufferPtr &data, bool uppercase = false);
263 
269  static void sha512(const void *data, int size, unsigned char out_hash[64]);
270 
275  static void sha512(const std::string &data, unsigned char out_hash[64]);
276 
281  static void sha512(const DataBufferPtr &data, unsigned char out_hash[64]);
282 
284  static std::string sha512_224(const void *data, int size, bool uppercase = false);
285 
292  static std::string sha512_224(const std::string &data, bool uppercase = false);
293 
300  static std::string sha512_224(const DataBufferPtr &data, bool uppercase = false);
301 
307  static void sha512_224(const void *data, int size, unsigned char out_hash[28]);
308 
313  static void sha512_224(const std::string &data, unsigned char out_hash[28]);
314 
319  static void sha512_224(const DataBufferPtr &data, unsigned char out_hash[28]);
320 
321 
323  static std::string sha512_256(const void *data, int size, bool uppercase = false);
324 
331  static std::string sha512_256(const std::string &data, bool uppercase = false);
332 
339  static std::string sha512_256(const DataBufferPtr &data, bool uppercase = false);
340 
346  static void sha512_256(const void *data, int size, unsigned char out_hash[32]);
347 
352  static void sha512_256(const std::string &data, unsigned char out_hash[32]);
353 
358  static void sha512_256(const DataBufferPtr &data, unsigned char out_hash[32]);
359  };
360 }
static std::string sha1(const void *data, int size, bool uppercase=false)
Generate SHA-1 hash from data.
static std::string sha512(const void *data, int size, bool uppercase=false)
Generate SHA-512 hash from data.
static std::string sha384(const void *data, int size, bool uppercase=false)
Generate SHA-384 hash from data.
static std::string sha224(const void *data, int size, bool uppercase=false)
Generate SHA-224 hash from data.
static std::string md5(const void *data, int size, bool uppercase=false)
Generate SHA-1 hash from data.
A Collection of checksum functions.
Definition: hash_functions.h:45
static uint32_t crc32(const void *data, int size, uint32_t running_crc=0)
Calculate a CRC32 checksum on the data.
std::shared_ptr< DataBuffer > DataBufferPtr
Definition: databuffer.h:66
static std::string sha512_224(const void *data, int size, bool uppercase=false)
Generate SHA-512_224 hash from data.
static std::string sha512_256(const void *data, int size, bool uppercase=false)
Generate SHA-512_256 hash from data.
Definition: Application/application.h:35
static std::string sha256(const void *data, int size, bool uppercase=false)
Generate SHA-256 hash from data.
static uint32_t adler32(const void *data, int size, uint32_t running_adler32=0)
Calculate a CRC32 checksum on the data.