Repository navigation
Conversation
…>_keyed) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
|
I don't really understand what this is for, it sounds like maybe you want an update_and_finalize operation? |
|
It's close to that. Measured on the Impl branch (
The long rows are unchanged, within noise. An My preference is to keep Generated by Claude Code |
|
I guess I don't understand what the semantics of _keyed are, or how it maps to a Rust API. |
|
Here are the exact semantics and the Rust mapping. Semantics (
What it does: it writes Both states are Equivalently, it does the same as this sequence, in one verified call:
Rust mapping (on
If Generated by Claude Code |
|
What you're describining sounds identical to update and finalize, so I don't even know what the difference is. |
|
You're right. It is
Almost all of the gain on hmac-sha256/64 comes from the Rust side, not from a new primitive:
That change alone is −9.5% to −12.4% at 32–64 B, with no new spec. I suggest closing this PR and opening that Rust-only change instead. It's ready on Generated by Claude Code |
|
yes |
Spec change (trusted). This PR adds one contract and Api to
Spec/Hmac/Generic.lean. It changes no existing contract, adds no TCB, and adds no implementation.What it specifies
vg_hmac_<hash>_keyed(inner: *const [u8; S], outer: *const [u8; S], msg: *const u8, len: usize, out: *mut [u8; D]):innerandouterare the two streaming states thatvg_hmac_<hash>_initleaves, representingK₀ ⊕ ipadandK₀ ⊕ opad.HMAC(K₀, msg)toout, for every block-size keyK₀that the states represent.Contract (
keyedPost), stated withfinalizePost's quantifier: for allk0, ifk0.length = blockSize,k0.length + len < 2⁶⁴,Repr m inner (xorPad k0 ipad)andRepr m outer (xorPad k0 opad), thenbytesAt m' out D = hmacBlockKey H k0 (bytesAt m msg len).lenare public. The states and the message are secret.Api:
Instance.keyedApi, generic likeinitandfinalize, so it covers every HMAC instance: SHA-256, SHA-384, and the rest.Why
TLS 1.3's key schedule (HKDF-Expand-Label) runs many short HMACs under a few keys, about 60 per resumed handshake pair. Today each one is several Rust-driven calls:
update;finalize;Locally (Emerald Rapids, SHA-NI, rdtsc minimums), a 32–50 B HMAC-SHA256 that way costs about 340 TSC cycles, of which the two compressions are about 190. That is about 150 cycles of overhead per HMAC. With one verified call per HMAC, I project 50–65 cycles saved per short HMAC.
HKDF-Expand with one output block is
HMAC(PRK, info ‖ 0x01), so it is one_keyedcall with no further Spec.Next
The implementation PR comes after this merges. It will be generic over SHA backends on each target (
Generic/MdHash/<Target>/), so it gets every variant: x86-64 scalar, SHA-NI and AVX2; the AArch64 SHA extensions; x86; and ARM. It will add the RustHmac::mac_keyed.Generated by Claude Code