char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Xuan-Son Nguyenmtmd: use sha256 for input hashing (#27274)ed1c3a20f

char/aliceai-t5-moe
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}