use slither::packet::{Channel, suite::ReferenceSuite};
#[test]
fn reference_suite_protocol_name() {
assert_eq!(
<ReferenceSuite as Channel>::PROTOCOL_NAME,
"Noise_IK_P256_ChaChaPoly_BLAKE2b"
);
}
#[test]
fn reference_suite_sizes_are_the_spec_values() {
assert_eq!(<ReferenceSuite as Channel>::MSG1_LEN, 174);
assert_eq!(<ReferenceSuite as Channel>::MSG2_LEN, 81);
assert_eq!(<ReferenceSuite as Channel>::INIT_PACKET_LEN, 196);
assert_eq!(<ReferenceSuite as Channel>::RESP_PACKET_LEN, 107);
assert_eq!(
<ReferenceSuite as Channel>::MSG1_LEN,
slither::constants::IK_MSG1_LEN
);
assert_eq!(
<ReferenceSuite as Channel>::MSG2_LEN,
slither::constants::IK_MSG2_LEN
);
assert_eq!(
<ReferenceSuite as Channel>::INIT_PACKET_LEN,
slither::constants::INIT_PACKET_LEN
);
assert_eq!(
<ReferenceSuite as Channel>::RESP_PACKET_LEN,
slither::constants::RESP_PACKET_LEN
);
}
mod second_suite {
slither::channel! {
pub Second<hiss::curve::p256::P256, hiss::noise::cipher::ChaChaPoly, hiss::noise::hash::Sha256>;
}
}
#[test]
fn two_suites_coexist_in_one_crate() {
use second_suite::Second;
assert_ne!(
<Second as Channel>::PROTOCOL_NAME,
<ReferenceSuite as Channel>::PROTOCOL_NAME
);
assert_eq!(
<ReferenceSuite as Channel>::PROTOCOL_NAME,
"Noise_IK_P256_ChaChaPoly_BLAKE2b"
);
}
mod third_suite {
slither::channel! {
pub Third<hiss::curve::x25519::X25519, hiss::noise::cipher::ChaChaPoly, hiss::noise::hash::Blake2b>;
}
}
#[test]
fn a_second_curve_derives_different_sizes() {
use third_suite::Third;
assert_eq!(<Third as Channel>::STATIC_PUBLIC_LEN, 32);
assert_ne!(
<Third as Channel>::STATIC_PUBLIC_LEN,
<ReferenceSuite as Channel>::STATIC_PUBLIC_LEN
);
assert_ne!(
<Third as Channel>::MSG1_LEN,
<ReferenceSuite as Channel>::MSG1_LEN
);
assert_ne!(
<Third as Channel>::MSG2_LEN,
<ReferenceSuite as Channel>::MSG2_LEN
);
assert_ne!(
<Third as Channel>::INIT_PACKET_LEN,
<ReferenceSuite as Channel>::INIT_PACKET_LEN
);
assert_ne!(
<Third as Channel>::RESP_PACKET_LEN,
<ReferenceSuite as Channel>::RESP_PACKET_LEN
);
let pk = <Third as Channel>::STATIC_PUBLIC_LEN;
let tag = <Third as Channel>::AEAD_TAG_LEN;
assert_eq!(
tag,
slither::constants::AEAD_TAG_LEN,
"TAG is suite-independent per §2.3"
);
let expected_msg1 = pk + (pk + tag) + (slither::constants::MSG1_PAYLOAD_LEN + tag);
let expected_msg2 = pk + tag;
let expected_init =
slither::constants::INIT_HEADER_LEN + expected_msg1 + slither::constants::MAC1_LEN;
let expected_resp =
slither::constants::RESP_HEADER_LEN + expected_msg2 + slither::constants::MAC1_LEN;
assert_eq!(<Third as Channel>::MSG1_LEN, expected_msg1);
assert_eq!(<Third as Channel>::MSG2_LEN, expected_msg2);
assert_eq!(<Third as Channel>::INIT_PACKET_LEN, expected_init);
assert_eq!(<Third as Channel>::RESP_PACKET_LEN, expected_resp);
assert_eq!(<Third as Channel>::MSG1_LEN, 108);
assert_eq!(<Third as Channel>::MSG2_LEN, 48);
assert_eq!(<Third as Channel>::INIT_PACKET_LEN, 130);
assert_eq!(<Third as Channel>::RESP_PACKET_LEN, 74);
}
mod aes_suite {
slither::channel! {
pub OfferedAes<hiss::curve::p256::P256, hiss::noise::cipher::AesGcm, hiss::noise::hash::Blake2b>;
}
}
#[test]
fn the_offered_aes_suite_is_pinned_and_length_identical() {
use aes_suite::OfferedAes;
assert_eq!(
<OfferedAes as Channel>::PROTOCOL_NAME,
"Noise_IK_P256_AESGCM_BLAKE2b"
);
assert_ne!(
<OfferedAes as Channel>::PROTOCOL_NAME,
<ReferenceSuite as Channel>::PROTOCOL_NAME
);
assert_eq!(<OfferedAes as Channel>::STATIC_PUBLIC_LEN, 65);
assert_eq!(<OfferedAes as Channel>::AEAD_TAG_LEN, 16);
assert_eq!(<OfferedAes as Channel>::MSG1_LEN, 174);
assert_eq!(<OfferedAes as Channel>::MSG2_LEN, 81);
assert_eq!(<OfferedAes as Channel>::INIT_PACKET_LEN, 196);
assert_eq!(<OfferedAes as Channel>::RESP_PACKET_LEN, 107);
assert_eq!(
<OfferedAes as Channel>::MSG1_LEN,
<ReferenceSuite as Channel>::MSG1_LEN
);
assert_eq!(
<OfferedAes as Channel>::MSG2_LEN,
<ReferenceSuite as Channel>::MSG2_LEN
);
assert_eq!(
<OfferedAes as Channel>::INIT_PACKET_LEN,
<ReferenceSuite as Channel>::INIT_PACKET_LEN
);
assert_eq!(
<OfferedAes as Channel>::RESP_PACKET_LEN,
<ReferenceSuite as Channel>::RESP_PACKET_LEN
);
}