-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsha256.h
More file actions
28 lines (22 loc) · 832 Bytes
/
Copy pathsha256.h
File metadata and controls
28 lines (22 loc) · 832 Bytes
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
26
27
28
// SHA-256 (FIPS 180-4). Streaming, because the handshake transcript hash
// absorbs messages as they cross the wire; no message is ever buffered
// whole for hashing.
#ifndef CH_SHA256_H
#define CH_SHA256_H
#include <stddef.h>
#include <stdint.h>
#define SHA256_LEN 32
#define SHA256_BLOCK 64
typedef struct {
uint32_t h[8];
uint64_t total_bytes; // total message bytes absorbed
uint8_t block[SHA256_BLOCK];
size_t fill; // bytes pending in block
} sha256;
void sha256_init(sha256 *s);
void sha256_update(sha256 *s, const uint8_t *in, size_t n);
// Finalizes into out[32]. s is spent; re-init to reuse. Does not wipe —
// callers hashing secrets wipe the context themselves.
void sha256_final(sha256 *s, uint8_t out[SHA256_LEN]);
void sha256_of(const uint8_t *in, size_t n, uint8_t out[SHA256_LEN]);
#endif