23 if (!ki || !fixed || !out || out_len == 0)
29 memset(k, 0,
sizeof(k));
36 memcpy(k, ki, ki_len);
38 uint8_t ipad[64], opad[64];
39 for (
int i = 0; i < 64; i++)
41 ipad[i] = (uint8_t)(k[i] ^ 0x36u);
42 opad[i] = (uint8_t)(k[i] ^ 0x5cu);
47 for (uint32_t counter = 1; done < out_len; counter++)
63 size_t take = (out_len - done < 32) ? out_len - done : 32;
64 memcpy(out + done, block, take);
Per-translation-unit optimization override for hot, pure-integer crypto.
Fixed-width integer serializers into a raw uint8_t* buffer - one source of truth.
size_t pc_wr32be(uint8_t *p, uint32_t v)
Write v big-endian at p.
PC_CRYPTO_HOT bool pc_kdf_ctr_hmac_sha256(const uint8_t *ki, size_t ki_len, const uint8_t *fixed, size_t fixed_len, uint8_t *out, size_t out_len)
SP800-108 KDF in counter mode with HMAC-SHA256 as the PRF (NIST SP800-108 ยง5.1; r = 32-bit counter pl...
SP800-108 counter-mode key derivation (HMAC-SHA256 PRF).
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).
SHA-256 (FIPS 180-4) - streaming context and one-shot API.
Streaming SHA-256 context.