skip to content
==> include/mesh/ref/sha256d.h <==
1/* @ajax/mesh-ref-sha256d: programs/sha256d's CPU reference (mesh-ref sha.rs): SHA-256 (FIPS 180-4,
2 * plainly), double SHA-256, a header hashed at a nonce and time, and Bitcoin's little-endian 256-bit
3 * targets. Freestanding (no libc). */
4#ifndef MESH_REF_SHA256D_H
5#define MESH_REF_SHA256D_H
6
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10
11#define MESH_SHA_GENESIS_NONCE 2083236893u
12#define MESH_SHA_GENESIS_HASH "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
13
14void mesh_sha256(const void *msg, size_t len, uint8_t out[32]);
15void mesh_sha256d(const void *msg, size_t len, uint8_t out[32]);
16/* The hash of hdr with `ntime` at bytes 68..72 and `nonce` at 76..80 (little-endian). */
17void mesh_sha_hash_at(const uint8_t hdr[80], uint32_t nonce, uint32_t ntime, uint8_t out[32]);
18/* Little-endian 256-bit a < b (byte 31 the most significant). */
19bool mesh_sha_le_lt(const uint8_t a[32], const uint8_t b[32]);
20/* Leading zero bits of a hash as a little-endian 256-bit number. */
21uint32_t mesh_sha_zbits(const uint8_t h[32]);
22/* The target whose top z bits are zero (every other bit set). */
23void mesh_sha_zbits_target(uint32_t z, uint8_t out[32]);
24/* Bytes in reverse order as lowercase hex (Bitcoin's display): out holds 65 bytes. */
25void mesh_sha_display(const uint8_t h[32], char out[65]);
26/* Bytes in order as lowercase hex: out holds 2n + 1 bytes. */
27void mesh_sha_hex(const uint8_t *b, size_t n, char *out);
28
29#endif