Skip to main content

Module pake

Module pake 

Source
Expand description

CPace over X25519 with SHA-512, as Sendspin’s code-based pairing uses it.

The suite is CPACE-X25519-SHA512 from draft-irtf-cfrg-cpace-21: group G_X25519, hash SHA-512, mutual confirmation flow. This module implements the primitives that flow is built from - the generator, the verified scalar multiplication, the transcript hashing, the intermediate session key and the key-confirmation tags - and pins them to the draft’s vectors in tests/pake_vectors.rs. The message flow itself belongs to the session layer, which knows when a share or a tag crosses the wire.

§What the generator is

generator_string is lv_cat(DSI, PRS, zero_bytes(len_zpad), CI, sid) with the zero padding sized so that the first SHA-512 block holds exactly the encoded DSI and PRS (§8.1, Appendix A.2). The first 32 bytes of its SHA-512 digest are decoded as a u-coordinate (decodeUCoordinate(_, 255) from [RFC 7748]) and mapped with Elligator 2. The associated data ADa/ADb is not an input: it enters the transcript that the confirmation flow hashes, not the generator.

§The transcript and the key confirmation

Sendspin fixes CPace’s initiator-responder mode, so the transcript is transcript_ir: lv_cat(Ya, ADa) || lv_cat(Yb, ADb). intermediate_session_key hashes lv_cat(G.DSI_ISK, sid, K) followed by that transcript. The explicit key confirmation of §10.4 derives mac_key = H(b"CPaceMac" || sid || ISK) and authenticates the sender’s own lv_cat(share, associated data) with HMAC-SHA-512, which is key_confirmation_tag. transcript_oc is the parallel-execution form: Sendspin does not use it, but the draft’s vectors cover it and keeping it proves the two forms differ only in the ordering step.

§Representative convention

CPace hands the map an arbitrary field element. elligator2::from_representative instead expects a representative, a value below (p-1)/2, and masks bits 254 and 255 of its input. The draft’s field element can have bit 254 set, and then passing it straight in changes the point: for the §B.1.1 vector the raw call returns 97ef2dc8...cd72fe23 instead of the draft’s d04bf6d4...2f05a73f. representative closes the gap exactly: Elligator 2 uses only r^2, so r and -r map to the same point, and negating a value with bit 254 set yields one the crate accepts. The §B.1.1 generator matches only with that normalisation.

§Secret handling

PRS, the scalar, the shared point, ISK and the tags derive from the pairing code or from a scalar. This module returns them as bytes, exactly as super::wrap does, and never formats them: no Debug, no Display, no error string carries a value. key_confirmation_tag and verify_key_confirmation_tag are branch-free over the secret-derived tag.

§Not reviewed

Neither this module nor elligator2 0.1 has had an external cryptographic review. The draft vectors pin the arithmetic, not the review.

Constants§

ISK_LEN
Length of the intermediate session key in bytes: one SHA-512 output.
SHARE_LEN
Length of a CPace public share in bytes.
TAG_LEN
Length of a key-confirmation tag in bytes: one HMAC-SHA-512 output.

Functions§

generator
Derives the CPace generator for this PRS, CI and sid.
intermediate_session_key
Derives ISK = H(lv_cat(G.DSI_ISK, sid, K) || transcript) (§7.2).
key_confirmation_tag
Computes the explicit key-confirmation tag of the sender’s own message (§10.4).
lv_cat
Concatenates each part with its LEB128 length prepended (lv_cat from §6.3).
public_share
Computes a public share Y = G.scalar_mult(scalar, generator).
scalar_mult_vfy
Computes G_X25519.scalar_mult_vfy(scalar, u), the verified scalar multiplication.
transcript_ir
Builds the initiator-responder transcript lv_cat(Ya, ADa) || lv_cat(Yb, ADb) (§6.3).
transcript_oc
Builds the parallel-execution transcript o_cat(lv_cat(Ya, ADa), lv_cat(Yb, ADb)) (§6.3).
verify_key_confirmation_tag
Returns whether a received tag equals the one this side derived.