1.2. The PQXDH protocol
1.2.1. Overview
PQXDH has three phases:
-
Bob publishes his elliptic curve identity key, elliptic curve prekeys, and pqkem prekeys to a server.
-
Alice fetches a "prekey bundle" from the server, and uses it to send an initial message to Bob src/session.rs:181-275 where Alice processes those keys.
-
Bob receives and processes Alice's initial messagesrc/session_management.rs:176-188.
The following sections explain these phases.
1.2.2. Publishing keys
Bob generates a sequence of 64-byte random values ZSPK, ZPQSPK, Z1, Z2, … and publishes a set of keys to the server containing:
-
Bob's curve identity key IKB in example: tests/pqxdh.rs:26, support/mod.rs:226
-
Bob's signed curve prekey and its identifier (SPKB, IdEC(SPKB)) tests/pqxdh.rs:31 in example, and support/mod.rs:271-293 in tests
-
Bob's signature on the curve prekey Sig(IKB, EncodeEC(SPKB), ZSPK) support/mod.rs:286 in test
-
Bob's signed last-resort pqkem prekey and its identifier (PQSPKB, IdKEM(PQSPKB)) note in section 2.5
-
Bob's signature on the pqkem prekey Sig(IKB, EncodeKEM(PQSPKB), ZPQSPK)
-
A set of Bob's one-time curve prekeys (OPKB1, OPKB2, OPKB3, …) along with their identifiers (IdEC(OPKB1), IdEC(OPKB2), IdEC(OPKB3), …)
-
A set of Bob's signed one-time pqkem prekeys (PQOPKB1, PQOPKB2, PQOPKB3, …) along with their identifiers (IdKEM(PQOPKB1), IdKEM(PQOPKB2), IdKEM(PQOPKB3), …) in example: tests/pqxdh.rs:32, support/mod.rs:308
-
The set of Bob's signatures on the signed one-time pqkem prekeys (Sig(IKB, EncodeKEM(PQOPKB1), Z1), Sig(IKB, EncodeKEM(PQOPKB2), Z2), Sig(IKB, EncodeKEM(PQOPKB3), Z3), …)support/mod.rs:310
Bob only needs to upload his identity key to the server once. However, Bob may upload new one-time prekeys at other times (e.g. when the server informs Bob that the server's store of one-time prekeys is getting low).
For both the signed curve prekey and the signed last-resort pqkem prekey, Bob will upload a new prekey along with its signature using IKB at some interval (e.g. once a week or once a month). The new signed prekey and its signatures will replace the previous values.
After uploading a new pair of signed curve and signed last-resort pqkem prekeys, Bob may keep the private key corresponding to the previous pair around for some period of time to handle messages using it that may have been delayed in transit. Eventually, Bob should delete this private key for forward secrecy (one-time prekey private keys will be deleted as Bob receives messages using them; see Section 3.4).
1.2.3. Sending the initial message
To perform a PQXDH key agreement with Bob, Alice contacts the server and fetches a "prekey bundle" containing the following values:
-
Bob's curve identity key IKB
-
Bob's signed curve prekey with its identifier (SPKB, IdEC(SPKB))
-
Bob's signature on the curve prekey Sig(IKB, EncodeEC(SPKB), ZSPK)
-
One of either Bob's signed one-time pqkem prekey PQOPKBn or Bob's last-resort signed pqkem prekey PQSPKB if no signed one-time pqkem prekey remains. Call this key PQPKB. The bundle also contains IdKEM(PQPKB)
-
Bob's signature on the pqkem prekey Sig(IKB, EncodeKEM(PQPKB), ZPQPK)
-
(Optionally) Bob's one-time curve prekey OPKBn and its identifier IdEC(OPKBn)
The server should provide one of Bob's curve one-time prekeys if one exists and then delete it. If all of Bob's curve one-time prekeys on the server have been deleted, the bundle will not contain a one-time curve prekey element.
The server should prefer to provide one of Bob's pqkem one-time signed prekeys PQOPKBn if one exists and then delete it. If all of Bob's pqkem one-time signed prekeys on the server have been deleted, the bundle will instead contain Bob's pqkem last-resort signed prekey PQSPKB.
Alice processes the prekey_bundle they receive from the server src/session.rs:181-275 and Alice verifies the signatures on the prekeyssrc/session.rs:201-206, src/session.rs:208-213 and checks that Bob's address and key are trusted src/session.rs:192-199. If any signature check fails, Alice aborts the protocol. Otherwise, if all signature checks pass, Alice then generates an ephemeral curve key pair with public key EKAsrc/session.rs:220. Alice additionally generates a pqkem encapsulated shared secretAlice's side: src/pqxdh.rs:226-230; Bob's side: src/pqxdh.rs:368-373.:
(CT, SS) = PQKEM-ENC(PQPKB)
shared secret SS
ciphertext CT
If the bundle does not contain a curve one-time prekey, she calculates:
DH1 = DH(IKA, SPKB) [Alice's side and Bob's side] DH2 = DH(EKA, IKB) [Alice's side and Bob's side] DH3 = DH(EKA, SPKB) [Alice's side and Bob's side] SK = KDF(DH1 || DH2 || DH3 || SS)[see 1, 2]
If the bundle does contain a curve one-time prekey, the calculation is modified to include an additional DH:
DH4 = DH(EKA, OPKB)[Alice's side and Bob's side] SK = KDF(DH1 || DH2 || DH3 || DH4 || SS)[see 1, 2]
After calculating SK, Alice deletes her ephemeral private key, the DH outputs and the shared secret SS.
Alice then calculates an "associated data" byte sequence AD that contains identity information for both parties:
AD = EncodeEC(IKA) || EncodeEC(IKB)
If pqkem does not incorporate PQPKB into the ciphertext, Alice must also append EncodeKEM(PQPKB) to AD (see the discussion in Section 4.12). Alice may optionally append additional information to AD, such as Alice and Bob's usernames, certificates, or other identifying information.
Alice then sends Bob an initial message containingsrc/session_management.rs:101-110:
-
Alice's identity key IKA
-
Alice's ephemeral key EKA
-
The pqkem ciphertext CT encapsulating SS for PQPKB
-
Identifiers stating which of Bob's prekeys Alice used
-
An initial ciphertext encrypted with some AEAD encryption scheme [5] using AD as associated data and using an encryption key which is either SK or the output from some cryptographic PRF keyed by SK.
The initial ciphertext is typically the first message in some post-PQXDH communication protocol. In other words, this ciphertext typically has two roles, serving as the first message within some post-PQXDH protocol, and as part of Alice's PQXDH initial message.
The initial message must be encoded in an unambiguous format to avoid confusion of the message items by the recipientsrc/protocol.rs:25-30.
After sending this, Alice deletes the ciphertext CT and may continue using SK or keys derived from SK within the post-PQXDH protocol for communication with Bob, subject to the security considerations discussed in Section 4.
1.2.4. Receiving the initial message
Upon receiving Alice's initial message, Bob retrieves Alice's identity key and ephemeral key from the messagesrc/session_management.rs:219-229. Bob also loads his identity private key and uses the key identifiers to load the private key(s) corresponding to the signed prekeys, one-time prekeys, and KEM key Alice used.
Using these keys, Bob calculates PQKEM-DEC(PQPKB, CT) as the shared secret SSsrc/pqxdh.rs:368-373 and repeats the DH and KDF calculations from the previous section to derive SKsrc/pqxdh.rs:375, and then deletes the DH values and SS values.
Bob then constructs the AD byte sequence using IKA and IKB as described in the previous section. Finally, Bob attempts to decrypt the initial ciphertext using SK and ADsrc/session_management.rs:249-256. If the initial ciphertext fails to decrypt, then Bob aborts the protocol and deletes SK.
If the initial ciphertext decrypts successfully, the protocol is complete for Bob. For forward secrecy, Bob deletes the ciphertext and any one-time prekey private key that was used. Bob may then continue using SK or keys derived from SK within the post-PQXDH protocol for communication with Alice subject to the security considerations discussed in Section 4.