ReviewOS

home-lang/home

CryptoHasher: match Bun binary input and HMAC key semantics

#585
Closed chris opened this 10 days ago ·
10 days ago

Scope

Port Bun CryptoHasher input normalization and keyed digest behavior into the native corpus runtime without fixture rewrites or delegated Bun execution.

The complete js/bun/util corpus currently reaches 852 passes and first fails in js/bun/util/bun-cryptohasher.test.ts at HMAC sha1 with a String key. The harness accepts the string but stores plain byte arrays; the digest path later feeds an Array slice to TextDecoder, whose native contract requires an ArrayBuffer or view.

Required parity

  • Normalize string, Buffer, ArrayBuffer, SharedArrayBuffer, ArrayBufferView, and Blob inputs into stable byte views with Bun-compatible offsets/lengths.
  • Preserve Bun.file rejection behavior.
  • Match keyed HMAC vectors, copy/digest lifecycle, algorithm aliases, encodings, and post-digest errors.
  • Keep all upstream corpus files unchanged.

Acceptance

  • packages/runtime/test/bun-corpus/js/bun/util/bun-cryptohasher.test.ts passes in the native Home runner.
  • Neighboring hash/crypto and full js/bun/util tranches have no regressions.
  • Commit and test evidence are linked back to #66.
10 days ago

Completed in 37215a5 (fix(runtime): implement native CryptoHasher HMAC).

Implemented real keyed BoringSSL HMAC for Bun and Node crypto shims; added real BLAKE2s, SHAKE, MD4, RIPEMD-160, SHA-512/224, SHA-512/256, and md5-sha1 digest routing; normalized binary inputs; removed both fixed HMAC vector tables and the fixture-specific shortcut; matched the Bun sha128 alias and keyed BLAKE2s/SHAKE rejection; and made the native bridge GC-safe by filling a caller-owned output view.

Validation:

  • bun-cryptohasher.test.ts: 397 pass / 0 fail
  • hash.test.js: 20 / 20
  • crypto.hmac.test.ts: 74 / 74
  • crypto-hmac-algorithm.test.ts: 5 / 5
  • mixed 16,000-call native digest stress probe: pass
  • arbitrary HMAC keys/messages match pinned Bun byte-for-byte
  • full js/bun/util: 1,249 pass / 23 fail / 1 unsupported / 2 TODO, up from 852 pass / 24 fail; the first remaining failure is unrelated

The broader js/node/crypto/crypto.test.ts now passes its hash assertions and reaches the separate SHA-224 signing gap.

Sign in to comment on this issue.