test: the six mandatory tests, pinned KAT vectors, fuzz target and cargo-deny config (written before the code)
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
//! Mandatory test 3, at the combiner: replacing either component secret by zeros must change the
|
||||
//! output, so both halves are bound. These are unit tests because the combiner is crate-private
|
||||
//! (exposing it would invite misuse).
|
||||
|
||||
use crate::schedule::session_prk;
|
||||
use crate::xwing::{SHARED_SECRET_LEN, combiner};
|
||||
|
||||
const SS_M: [u8; 32] = [0xa1; 32];
|
||||
const SS_X: [u8; 32] = [0xb2; 32];
|
||||
const CT_X: [u8; 32] = [0xc3; 32];
|
||||
const PK_X: [u8; 32] = [0xd4; 32];
|
||||
const ZERO: [u8; SHARED_SECRET_LEN] = [0; SHARED_SECRET_LEN];
|
||||
|
||||
#[test]
|
||||
fn zeroing_the_ml_kem_secret_changes_the_output() {
|
||||
let honest = combiner(&SS_M, &SS_X, &CT_X, &PK_X);
|
||||
assert_ne!(combiner(&ZERO, &SS_X, &CT_X, &PK_X), honest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zeroing_the_x25519_secret_changes_the_output() {
|
||||
let honest = combiner(&SS_M, &SS_X, &CT_X, &PK_X);
|
||||
assert_ne!(combiner(&SS_M, &ZERO, &CT_X, &PK_X), honest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zeroing_both_differs_from_zeroing_either() {
|
||||
let only_m = combiner(&ZERO, &SS_X, &CT_X, &PK_X);
|
||||
let only_x = combiner(&SS_M, &ZERO, &CT_X, &PK_X);
|
||||
let both = combiner(&ZERO, &ZERO, &CT_X, &PK_X);
|
||||
assert_ne!(only_m, only_x);
|
||||
assert_ne!(both, only_m);
|
||||
assert_ne!(both, only_x);
|
||||
}
|
||||
|
||||
/// Swapping the two secrets must not give the same output: the positions are bound, not just the set.
|
||||
#[test]
|
||||
fn the_two_halves_are_not_interchangeable() {
|
||||
assert_ne!(combiner(&SS_M, &SS_X, &CT_X, &PK_X), combiner(&SS_X, &SS_M, &CT_X, &PK_X));
|
||||
}
|
||||
|
||||
/// Every single bit of either component secret reaches the output.
|
||||
#[test]
|
||||
fn every_bit_of_each_component_reaches_the_output() {
|
||||
let honest = combiner(&SS_M, &SS_X, &CT_X, &PK_X);
|
||||
for byte in 0..32 {
|
||||
for bit in 0..8 {
|
||||
let mut m = SS_M;
|
||||
m[byte] ^= 1 << bit;
|
||||
assert_ne!(combiner(&m, &SS_X, &CT_X, &PK_X), honest, "ss_M byte {byte} bit {bit}");
|
||||
let mut x = SS_X;
|
||||
x[byte] ^= 1 << bit;
|
||||
assert_ne!(combiner(&SS_M, &x, &CT_X, &PK_X), honest, "ss_X byte {byte} bit {bit}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The binding survives the key schedule: a zeroed component gives a different session key too.
|
||||
#[test]
|
||||
fn zeroed_components_give_a_different_session() {
|
||||
let pk = [0x5a; crate::xwing::PUBLIC_KEY_LEN];
|
||||
let ct = [0x6b; crate::xwing::CIPHERTEXT_LEN];
|
||||
let honest = session_prk(&combiner(&SS_M, &SS_X, &CT_X, &PK_X), &pk, &ct, b"ctx");
|
||||
let no_m = session_prk(&combiner(&ZERO, &SS_X, &CT_X, &PK_X), &pk, &ct, b"ctx");
|
||||
let no_x = session_prk(&combiner(&SS_M, &ZERO, &CT_X, &PK_X), &pk, &ct, b"ctx");
|
||||
assert_ne!(*honest, *no_m);
|
||||
assert_ne!(*honest, *no_x);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user