Debian Codegraph @

terps/tads/tads3/sha2.h

raw symbols SCIP
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 /* Compatibility with Brian Gladman's SHA-256. */
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 /* TADS-specific functions */
35
36 /*
37 * Generate a printable version of a hash for a given buffer. 'hash' is an
38 * array of at least 65 characters to receive the hash string. It's fine
39 * to pass in the same buffer for both 'hash' and 'data', as long as it's
40 * big enough (>=65 characters). [mjr]
41 */
42 void sha256_ez(char *hash, const char *data, std::size_t data_len);
43
44 /*
45 * Generate a printable version of a hash for a given data source. [mjr]
46 */
47 void sha256_datasrc(char *hash, class CVmDataSource *src, unsigned long len);
48
49 /*
50 * printf-style hash construction: format the string given by 'fmt' and the
51 * subsequent arguments, and hash the result
52 */
53 void sha256_ezf(char *hash, const char *fmt, ...);
54
55 #endif