-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsha256.h
More file actions
33 lines (26 loc) · 935 Bytes
/
sha256.h
File metadata and controls
33 lines (26 loc) · 935 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
29
30
31
32
33
#ifndef SHA256_H
#define SHA256_H
#include <stddef.h>
#include <stdint.h>
#define SHA256_HEX_SIZE (64 + 1)
#define SHA256_BYTES_SIZE 32
/*
* Compute the SHA-256 checksum of a memory region given a pointer and
* the size of that memory region.
* The output is a hexadecimal string of 65 characters.
* The last character will be the null-character.
*/
void sha256_hex(const void *src, size_t n_bytes, char *dst_hex65);
void sha256_bytes(const void *src, size_t n_bytes, void *dst_bytes32);
typedef struct sha256 {
uint32_t state[8];
uint8_t buffer[64];
uint64_t n_bits;
uint8_t buffer_counter;
} sha256;
/* Functions to compute streaming SHA-256 checksums. */
void sha256_init(struct sha256 *sha);
void sha256_append(struct sha256 *sha, const void *data, size_t n_bytes);
void sha256_finalize_hex(struct sha256 *sha, char *dst_hex65);
void sha256_finalize_bytes(struct sha256 *sha, void *dst_bytes32);
#endif