okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-1b (033cfdd8c) into f-own-int: nothing downloads llama.cppb2de2641f

main
581 B23 linesraw
1#include "hash.h"
2
3extern "C" {
4#include "sha256/sha256.h"
5}
6
7static std::string to_hex(const unsigned char * digest, size_t len) {
8    static const char hex[] = "0123456789abcdef";
9
10    std::string out;
11    out.reserve(2*len);
12    for (size_t i = 0; i < len; ++i) {
13        out += hex[digest[i] >> 4];
14        out += hex[digest[i] & 0xf];
15    }
16    return out;
17}
18
19std::string hash_sha256_hex(const void * data, size_t len) {
20    unsigned char digest[SHA256_DIGEST_SIZE];
21    sha256_hash(digest, (const unsigned char *) data, len);
22    return to_hex(digest, SHA256_DIGEST_SIZE);
23}