blob: cc86df67744fde7b004f5d382e84dc13322b5647 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include "sha2.hpp"
#include "hex.hpp"
#include "../base/macros.hpp"
#include <tomcrypt.h>
namespace sha2
{
string digest256(char const * data, size_t dataSize, bool returnAsHexString)
{
hash_state md;
unsigned char out[256/8] = { 0 };
if (CRYPT_OK == sha256_init(&md)
&& CRYPT_OK == sha256_process(&md, reinterpret_cast<unsigned char const *>(data), dataSize)
&& CRYPT_OK == sha256_done(&md, out))
{
if (returnAsHexString)
return ToHex(string(reinterpret_cast<char const *>(out), ARRAY_SIZE(out)));
else
return string(reinterpret_cast<char const *>(out), ARRAY_SIZE(out));
}
return string();
}
}
|