48 "HmacWork outgrew PC_WORK_HMAC_SHA256 - raise it in protocore_config.h, which derives "
49 "PC_SECURE_ARENA_SIZE from it");
53void build_key_block(
const uint8_t *key,
size_t key_len, uint8_t block[64], uint8_t pad_byte, uint8_t scratch[64])
55 memset(scratch, 0, 64);
62 for (
size_t i = 0; i < key_len; i++)
67 for (
int i = 0; i < 64; i++)
69 block[i] = scratch[i] ^ pad_byte;
82 HmacWork *w =
reinterpret_cast<HmacWork *
>(ws.
buf);
83 build_key_block(key, key_len, w->ipad, 0x36u, w->opad);
84 build_key_block(key, key_len, ctx->
okey, 0x5cu, w->opad);
103 HmacWork *w =
reinterpret_cast<HmacWork *
>(ws.
buf);
113void pc_hmac_sha256(
const uint8_t *key,
size_t key_len,
const uint8_t *data,
size_t len,
124 HmacWork *w =
reinterpret_cast<HmacWork *
>(ws.
buf);
125 build_key_block(key, key_len, w->ipad, 0x36u, w->opad);
131 build_key_block(key, key_len, w->opad, 0x5cu, w->ipad);
A secure borrow whose acquire and release are one call each.
const pc_span & span() const
The borrowed region; empty if the pool could not satisfy it.
Per-translation-unit optimization override for hot, pure-integer crypto.
void pc_hmac_sha256(const uint8_t *key, size_t key_len, const uint8_t *data, size_t len, uint8_t mac[PC_HMAC_SHA256_LEN])
Compute HMAC-SHA2-256 over a single contiguous buffer.
void pc_hmac_sha256_update(pc_hmac_sha256_ctx *ctx, const uint8_t *data, size_t len)
Feed len bytes into the running HMAC.
void pc_hmac_sha256_init(pc_hmac_sha256_ctx *ctx, const uint8_t *key, size_t key_len)
Initialize a streaming HMAC-SHA2-256 context.
void pc_hmac_sha256_final(pc_hmac_sha256_ctx *ctx, uint8_t mac[PC_HMAC_SHA256_LEN])
Finalize and write the 32-byte MAC.
HMAC-SHA2-256 (RFC 2104 + FIPS 198-1) - streaming context and one-shot API.
#define PC_HMAC_SHA256_LEN
HMAC-SHA2-256 output length in bytes.
void build_key_block(const uint8_t *key, size_t key_len, uint8_t block[64], uint8_t pad_byte, uint8_t scratch[64])
#define PC_WORK_HMAC_SHA256
Secure pool accessor - borrows that hold key material.
PC_CRYPTO_HOT void pc_sha256_init(pc_sha256_ctx *ctx)
Initialize a streaming SHA-256 context (ctx must not be NULL).
void pc_sha256_final(pc_sha256_ctx *ctx, uint8_t digest[PC_SHA256_DIGEST_LEN])
Finalize the hash and write the 32-byte digest. The context is undefined afterwards; call init() agai...
void pc_sha256_update(pc_sha256_ctx *ctx, const uint8_t *data, size_t len)
Feed len bytes of data into the running hash.
void pc_sha256(const uint8_t *data, size_t len, uint8_t digest[PC_SHA256_DIGEST_LEN])
One-shot SHA-256: hash len bytes of data into digest (32 bytes).
#define PC_SHA256_DIGEST_LEN
SHA-256 digest length in bytes.
bool pc_span_ok(const pc_span &s)
True when the span refers to real storage and every write so far has fit.
pc_sha256_ctx hash
transient hash: one-shot inner then outer; streaming final outer
Streaming HMAC-SHA2-256 context.
uint8_t okey[64]
Outer key block (key XOR opad), stored for the final step.
pc_sha256_ctx inner
Inner hash context (key XOR ipad prepended).
Streaming SHA-256 context.
A writable byte region: the storage, the capacity that belongs to it, and what has been produced into...
uint8_t * buf
first byte, or nullptr when the region could not be obtained