Module: crypto.hexfmt

Source: ./crypto/hexfmt.reef


Overview

crypto/hexfmt - hex formatting shared by the digest and checksum modules

C4 / ROADMAP 8.5 item 4. Before this module there were FIVE copies of the same two things:

md5_hex_digits() / sha1_hex_digits() / sha256_hex_digits()

  • three copies of the literal "0123456789abcdef" md5_state_to_hex / sha1_state_to_hex / sha256_state_to_hex
  • sha1's and sha256's were byte-identical apart from the word count; md5's differed only in walking each word's bytes the other way crc32's get_hex_digits_upper/lower + int_to_hex_upper/int_to_hex_lower
  • two more copies of the table and two copies of one loop that differed only in which table it indexed

The buffer-filling loops stay here rather than delegating to encoding.hex: encoding.hex.byte_to_hex allocates a fresh string per byte, which is a per-byte allocation in a hash's hot path. These write into one preallocated buffer.


Functions

fn hex_digits_lower(): string

fn hex_digits_upper(): string

fn state_to_hex(state: [int], words: int, big_endian: bool): string

fn int_to_hex(n: int, digits: string): string


Generated by reefc doc