Module: crypto.hmac
Source: ./crypto/hmac.reef
Overview
crypto/hmac - HMAC (Hash-based Message Authentication Code)
Implements HMAC (RFC 2104) for MD5, SHA-1, and SHA-256. HMAC provides message authentication using a secret key.
Usage: import crypto.hmac let mac = hmac_sha256("key", "message") let mac = hmac_md5("key", "message") let mac = hmac_sha1("key", "message")
Functions
fn hmac_hex_nibble(c: int): int
C16 note (reef-lang#53): the return 0 below is NOT a failure sentinel and
this function is deliberately NOT Option-returning. It is private to this
module, and every argument it can ever receive is a character of a hex string
this library itself just produced -- md5.md5_bytes / sha1.sha1_bytes /
sha256.sha256_bytes are the only feeds (see hmac_hex_to_byte_array's four
call sites). The non-hex branch is unreachable over that closed domain, so
converting it would cascade Option through hmac_hex_to_byte_array and all
three public hmac_* entry points to defend against an input that cannot occur.
fn hmac_str_to_bytes(s: string): [uint8]
Copy a string's bytes into a [byte] buffer (up to str.length — the string API boundary; all binary intermediates below stay in [byte]).
fn hmac_hex_to_byte_array(hex: string): [uint8]
Decode a hex string to its raw bytes. Binary-safe: the result may legally contain 0x00 bytes (that is the whole point of this fix).
fn hmac_pad_key_bytes(kb: [uint8], block_size: int): [uint8]
Zero-padded key block of exactly block_size bytes.
fn hmac_xor_block(block: [uint8], pad_byte: int): [uint8]
XOR every byte of a block with pad_byte, returning a new block.
fn hmac_concat_bytes(a: [uint8], b: [uint8]): [uint8]
Concatenate two byte buffers (length-delimited, NUL-safe).
fn hmac_md5(key: string, message: string): string
fn hmac_sha1(key: string, message: string): string
fn hmac_sha256(key: string, message: string): string
Generated by reefc doc