| 1 |
#ifndef SHA2_H |
| 2 |
#define SHA2_H |
| 3 |
|
| 4 |
#include <cstddef> |
| 5 |
#include <cstdint> |
| 6 |
|
| 7 |
#define CRYPT_OK 0 |
| 8 |
#define CRYPT_INVALID_ARG 1 |
| 9 |
#define CRYPT_NOP 2 |
| 10 |
#define CRYPT_HASH_OVERFLOW 3 |
| 11 |
#define CRYPT_FAIL_TESTVECTOR 4 |
| 12 |
|
| 13 |
struct sha256_state { |
| 14 |
std::uint64_t length; |
| 15 |
std::uint32_t state[8], curlen; |
| 16 |
unsigned char buf[64]; |
| 17 |
}; |
| 18 |
|
| 19 |
union hash_state { |
| 20 |
sha256_state sha256; |
| 21 |
}; |
| 22 |
|
| 23 |
int sha256_init(hash_state *md); |
| 24 |
int sha256_process(hash_state *md, const unsigned char *in, unsigned long inlen); |
| 25 |
int sha256_done(hash_state *md, unsigned char *hash); |
| 26 |
int sha256_test(); |
| 27 |
|
| 28 |
|
| 29 |
using sha256_ctx = hash_state; |
| 30 |
#define sha256_begin(ctx) sha256_init(ctx) |
| 31 |
#define sha256_hash(data, len, ctx) sha256_process((ctx), (data), (len)) |
| 32 |
#define sha256_end(hval, ctx) sha256_done((ctx), (hval)) |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
void sha256_ez(char *hash, const char *data, std::size_t data_len); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
void sha256_datasrc(char *hash, class CVmDataSource *src, unsigned long len); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
void sha256_ezf(char *hash, const char *fmt, ...); |
| 54 |
|
| 55 |
#endif |