DDraceNetwork Documentation
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1#ifndef BASE_HASH_H
2#define BASE_HASH_H
3
4#include <cstddef> // size_t
5
6enum
7{
12};
13
15{
16 unsigned char data[SHA256_DIGEST_LENGTH];
17};
18
20{
21 unsigned char data[MD5_DIGEST_LENGTH];
22};
23
24SHA256_DIGEST sha256(const void *message, size_t message_len);
25void sha256_str(SHA256_DIGEST digest, char *str, size_t max_len);
26int sha256_from_str(SHA256_DIGEST *out, const char *str);
27int sha256_comp(SHA256_DIGEST digest1, SHA256_DIGEST digest2);
28
29MD5_DIGEST md5(const void *message, size_t message_len);
30void md5_str(MD5_DIGEST digest, char *str, size_t max_len);
31int md5_from_str(MD5_DIGEST *out, const char *str);
32int md5_comp(MD5_DIGEST digest1, MD5_DIGEST digest2);
33
34inline bool operator==(const SHA256_DIGEST &that, const SHA256_DIGEST &other)
35{
36 return sha256_comp(that, other) == 0;
37}
38inline bool operator!=(const SHA256_DIGEST &that, const SHA256_DIGEST &other)
39{
40 return !(that == other);
41}
42inline bool operator==(const MD5_DIGEST &that, const MD5_DIGEST &other)
43{
44 return md5_comp(that, other) == 0;
45}
46inline bool operator!=(const MD5_DIGEST &that, const MD5_DIGEST &other)
47{
48 return !(that == other);
49}
50
51#endif // BASE_HASH_H
MD5_DIGEST md5(const void *message, size_t message_len)
Definition hash.cpp:52
bool operator==(const SHA256_DIGEST &that, const SHA256_DIGEST &other)
Definition hash.h:34
int sha256_from_str(SHA256_DIGEST *out, const char *str)
Definition hash.cpp:42
int md5_comp(MD5_DIGEST digest1, MD5_DIGEST digest2)
Definition hash.cpp:70
SHA256_DIGEST sha256(const void *message, size_t message_len)
Definition hash.cpp:29
bool operator!=(const SHA256_DIGEST &that, const SHA256_DIGEST &other)
Definition hash.h:38
void sha256_str(SHA256_DIGEST digest, char *str, size_t max_len)
Definition hash.cpp:37
int md5_from_str(MD5_DIGEST *out, const char *str)
Definition hash.cpp:65
@ MD5_MAXSTRSIZE
Definition hash.h:11
@ SHA256_MAXSTRSIZE
Definition hash.h:9
@ SHA256_DIGEST_LENGTH
Definition hash.h:8
@ MD5_DIGEST_LENGTH
Definition hash.h:10
void md5_str(MD5_DIGEST digest, char *str, size_t max_len)
Definition hash.cpp:60
int sha256_comp(SHA256_DIGEST digest1, SHA256_DIGEST digest2)
Definition hash.cpp:47
Definition hash.h:20
unsigned char data[MD5_DIGEST_LENGTH]
Definition hash.h:21
Definition hash.h:15
unsigned char data[SHA256_DIGEST_LENGTH]
Definition hash.h:16