test: hygiene check sees arcanum's own features; A-15 binding goes through session_prk

This commit is contained in:
2026-11-25 07:40:57 +01:00
parent 89b5329f06
commit 6233c8244e
3 changed files with 51 additions and 29 deletions
+27 -16
View File
@@ -5,8 +5,10 @@
use sha3::{Digest, Sha3_256};
use crate::schedule::{ALL_LABELS, session_prk_raw};
use crate::schedule::{ALL_LABELS, Transcript, session_prk};
use crate::xwing::{CIPHERTEXT_LEN, Ciphertext, PUBLIC_KEY_LEN, PublicKey, SecretKey, SharedSecret};
use crate::xwing::{SHARED_SECRET_LEN, combiner};
use zeroize::Zeroizing;
const SS_M: [u8; 32] = [0xa1; 32];
const SS_X: [u8; 32] = [0xb2; 32];
@@ -58,19 +60,32 @@ fn every_bit_of_each_component_reaches_the_output() {
}
}
/// The binding survives the key schedule: a zeroed component of either direction's X-Wing
/// secret gives a different session key.
fn ss(b: [u8; 32]) -> SharedSecret {
SharedSecret(Zeroizing::new(b))
}
/// The binding survives the key schedule, through the real `session_prk`: a zeroed component of
/// the first direction's X-Wing secret, or a missing second direction, gives a different session.
/// The last case is QA A-15: an attacker who impersonates the initiator knows ss_IR (she made it)
/// and the whole transcript, but not ss_RI; every guess of hers that reuses known values fails.
#[test]
fn zeroed_components_give_a_different_session() {
let th = [0x5a; 32];
fn zeroed_components_and_a_missing_direction_give_a_different_session() {
let pk_i = SecretKey::from_bytes(&[1u8; 32]).unwrap().public_key().clone();
let pk_r = SecretKey::from_bytes(&[2u8; 32]).unwrap().public_key().clone();
let ct_ir = Ciphertext::from_bytes(&[3u8; CIPHERTEXT_LEN]).unwrap();
let ct_ri = Ciphertext::from_bytes(&[4u8; CIPHERTEXT_LEN]).unwrap();
let t = Transcript { initiator: &pk_i, responder: &pk_r, ct_ir: &ct_ir, ct_ri: &ct_ri, context: b"ctx" };
let ss_ir = combiner(&SS_M, &SS_X, &CT_X, &PK_X);
let ss_ri = combiner(&[0x01; 32], &[0x02; 32], &CT_X, &PK_X);
let honest = session_prk_raw(&combiner(&SS_M, &SS_X, &CT_X, &PK_X), &ss_ri, &th);
let no_m = session_prk_raw(&combiner(&ZERO, &SS_X, &CT_X, &PK_X), &ss_ri, &th);
let no_x = session_prk_raw(&combiner(&SS_M, &ZERO, &CT_X, &PK_X), &ss_ri, &th);
let no_ri = session_prk_raw(&combiner(&SS_M, &SS_X, &CT_X, &PK_X), &ZERO, &th);
assert_ne!(*honest, *no_m);
assert_ne!(*honest, *no_x);
assert_ne!(*honest, *no_ri);
let honest = *session_prk(&ss(ss_ir), &ss(ss_ri), &t);
let no_m = *session_prk(&ss(combiner(&ZERO, &SS_X, &CT_X, &PK_X)), &ss(ss_ri), &t);
let no_x = *session_prk(&ss(combiner(&SS_M, &ZERO, &CT_X, &PK_X)), &ss(ss_ri), &t);
assert_ne!(honest, no_m);
assert_ne!(honest, no_x);
for guess in [ZERO, ss_ir, [0xff; 32]] {
assert_ne!(*session_prk(&ss(ss_ir), &ss(guess), &t), honest, "PSK computable without ss_RI");
}
}
/// QA A-02: recomputed independently, the combiner is SHA3-256(ss_M || ss_X || ct_X || pk_X ||
@@ -103,10 +118,6 @@ fn labels_are_versioned_and_prefix_free() {
/// key-schedule binding from what X-Wing itself hashes.
#[test]
fn the_schedule_binds_the_full_transcript() {
use crate::schedule::{Transcript, session_prk};
use crate::xwing::{CIPHERTEXT_LEN, Ciphertext, PUBLIC_KEY_LEN, PublicKey, SecretKey, SharedSecret};
use zeroize::Zeroizing;
let ss_ir = SharedSecret(Zeroizing::new([7u8; 32]));
let ss_ri = SharedSecret(Zeroizing::new([8u8; 32]));
let pk_i = SecretKey::from_bytes(&[1u8; 32]).unwrap().public_key().clone();
-6
View File
@@ -85,12 +85,6 @@ pub(crate) fn session_prk(ss_ir: &SharedSecret, ss_ri: &SharedSecret, t: &Transc
extract(&[ss_ir.as_bytes(), ss_ri.as_bytes()], &t.hash())
}
/// The same derivation on raw component values, for the in-crate binding tests.
#[cfg(test)]
pub(crate) fn session_prk_raw(ss_ir: &[u8; 32], ss_ri: &[u8; 32], th: &[u8; 32]) -> Prk {
extract(&[ss_ir, ss_ri], th)
}
/// The PRK of one sealed box: the X-Wing secret, the recipient key, the ciphertext and the aad.
pub(crate) fn seal_prk(ss: &SharedSecret, recipient: &PublicKey, ct: &Ciphertext, aad: &[u8]) -> Prk {
let mut h = Sha256::new();