Hash and symmetric implementation research, 2026-10-25

Implementation scope is algo/hash, algo/symmetric and their benchmark adapters. The SDK and neighboring repositories are read-only inputs. No cryptographic algorithm or protocol construction is invented here.

Reused sources

The SHA-256 unrolled rolling schedule and special 0/32/33/64-byte paths come from /srv/shared/code/motoko_experiments/plugins/plugins/sha256/runtime/src/lib.rs, SHA-256 981af382272002639ada6ed997248b4e41be79bc5a7760c70b6a3233e09ea6de. SHA-512 borrowed batching follows its runtime (SHA-256 4aa226a8e29ac2d77384ec4365f8403030838c4d2b1afb4af9e37d95292e491e). Prepared HMAC follows its current inner/outer-state design (SHA-256 d2b680ce0b6169a516cbd7f6b108bfa501af2055ffaa26b1aa9adcad75d82c2a). These inputs preserve Apache-2.0 WITH LLVM-exception and extraction provenance at Motoko commit 7b95f5589d75e2eb8277ca8579415fe5063a104a.

Motoko serialized carriers are not copied. Direct contexts borrow full input blocks, retain one partial block and finalize with that block. SHA-512/HMAC retain pinned RustCrypto compression: earlier unrolling trials were rejected for modest instruction gains and larger Wasm. HMAC setup caches the exact standard ipad/opad chaining values; HKDF composes those standard operations.

BLAKE3 1.8.7 is copied from Showtime's vendor. The existing patch only enables its upstream Wasm SIMD backend on wasm64 and selects the corresponding intrinsics. Added constructors explicitly select Platform::Portable, giving honest portable and SIMD controls in one feature-unified artifact. Update, parent merging, reset and derive-context hashing preserve the selected platform. The exact original and new hashes are in the hash vendor receipts. Original licenses are retained.

Other symmetric controls use the pinned RustCrypto package versions documented by each crate. Scalar ChaCha is a direct fixed-round adaptation, not a new cipher. Its prepared words and bounded one-block scratch are a candidate against the existing RustCrypto stream wrapper. AES preserves fixslicing; GHASH/POLYVAL preserve constant-time software multiplication. No secret-indexed lookup table or variable-time key operation is introduced.

Final Ascon comes from the official CC0 reference at commit 446347f21b209f3921c65ece70027c366cbe1693. It uses final little-endian encoding, IVs and standard hash/customization domains. An explicitly named permutation unrolling candidate changes call shape only. Both variants use the same pinned official KATs. CXOF customization is limited to 256 bytes as in SP 800-232.

Current upstream versions and specifications

Source review on this date verified newer releases than these qualified local controls: SHA2 0.11.0, HMAC 0.13.0, HKDF 0.13.0, ChaCha20 0.10.2, ChaCha20Poly1305 0.11.0, Poly1305 0.9.1, AES 0.9.3, AES-GCM 0.11.1, AES-GCM-SIV 0.12.1, and BLAKE2 0.11.0. BLAKE3 1.8.7 is current. These version facts do not establish performance or qualification for replacing the selected local pins.

Normative algorithm/vector sources are FIPS 180-4, FIPS 197, SP 800-38D, RFC 4231, RFC 5869, RFC 7693, RFC 8439, RFC 8452, and SP 800-232 final. HChaCha/XChaCha follow the established expired IETF draft and interoperable implementation vectors; they are not described as a finalized IETF RFC.

Measurement and qualification contract

Fixture preparation derives public keys/nonces/input bytes, allocates bounded buffers and computes expected outputs. Timed calls allocate no heap buffers; they black-box complete inputs/outputs and retain all outputs for checks after timing. Prepared contexts are allocated before the setup call commits, so the later measured message still pays its actual page-access charges. Reusing a Rust context does not mean warm IC pages across messages.

Fresh/prepared MAC, HKDF Expand, AES schedules and AEAD keys are separate cases. Whole hash and raw compression are separate cases. BLAKE3 portable and selected controls use identical one-update Hasher semantics. In-place symmetric calls include input restoration; the copy-only control exposes that cost. Repeated-key batches share one retained prepared context; distinct-key batches retain one context per key. This keeps the declared key population reflected in the physical prepared-state footprint. Hash fixture metadata boxes each native prepared-state variant, so an absent state does not reserve the largest native context in every raw-hash item. This corrects the measurement layout; it is not a cryptographic-kernel improvement. Existing AEAD cases perform exact fixture replay, including repeated tuples within distinct=false cohorts. Separate *-records seal cases use one key, vary input/AAD by record, and advance a unique 96-bit nonce prefix using the driver's cohort number and record index. Their reference encryption is checked outside timing. Ascon loop and unrolled record candidates share this workload. Valid/invalid/mixed verification/open checks retain expected status and enforce zeroed failure output. Poly1305 prepared-key repetition is public test work, never a production one-time-key policy.

Qualification requires native tests, matching-target compilation and installed Wasm vectors, then exact-source PocketIC instructions, complete endpoint costs, page traces and Wasm size. Historical Showtime SIMD measurements concern their original artifacts and are not new results for this source relocation. At implementation handoff, shared Cargo tests/builds are delegated to the root build owner to avoid target/cache races; this file makes no fresh pass or performance claim before those results exist.

Detached AEAD boundary correction

Primary-source review of SP 800-38D 5.2.1.1/5.2.2 and RFC 8439/8452 section 6 requires the same body bound for seal and detached open. aes-gcm 0.10.3 allows 2^36 plaintext bytes, exceeding the standard's 2^36-32; its detached open also applies the combined-output C_MAX to a body whose tag is separate. The wrapper now preflights both directions at 2^36-32 bytes. Its supported AAD bound remains the backend's documented 2^36 bytes, below the standard maximum floor((2^64-1)/8). GCM-SIV instead correctly permits 2^36 body/AAD bytes; its detached open receives no extra 16-byte tag allowance.

chacha20poly1305 0.10.1 seeks to block counter 1, then uses an infallible apply_keystream. The pinned chacha20 0.9.1 backend reports only u32::MAX-current_counter remaining blocks. Consequently its safe AEAD window is (2^32-2)*64 = 274877906816 bytes, 64 bytes below RFC 8439's body maximum. The old AEAD division guard admitted 63 additional bytes before a panic. Both ChaCha and XChaCha wrappers now reject them explicitly, while documenting the backend restriction rather than changing the standard's claimed maximum. AAD remains bounded by its unsigned 64-bit byte-length field. Pure u128-length tests cover these boundaries without allocation; small seeks near the stream end probe the actual backend capacity with 64/65-byte buffers.

Length failures return before any body mutation; authentication failures still wipe the complete body. There is no per-nonce state change in these wrappers.