From e3280086e0139e4545c8484a92fd4643e7d8b644 Mon Sep 17 00:00:00 2001 From: Sachymetsu Date: Mon, 15 Jun 2026 11:34:07 +0200 Subject: [PATCH] Fix should_panic tests & add omit ops test case --- wharrgarbl-neko/src/kats.rs | 47 +++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/wharrgarbl-neko/src/kats.rs b/wharrgarbl-neko/src/kats.rs index 3fa3680..23c3da1 100644 --- a/wharrgarbl-neko/src/kats.rs +++ b/wharrgarbl-neko/src/kats.rs @@ -328,9 +328,10 @@ In scelerisque, ex et porta varius, orci risus malesuada nibh, convallis euismod let tag = neko.create_mac(); + #[rustfmt::skip] let expected_tag: [u8; 16] = [ - 0x1f, 0x8a, 0x99, 0x86, 0x30, 0x96, 0xf9, 0xc2, 0x6b, 0x70, 0x21, 0xb8, 0x01, 0x11, 0xe5, - 0x0b, + 0x1f, 0x8a, 0x99, 0x86, 0x30, 0x96, 0xf9, 0xc2, + 0x6b, 0x70, 0x21, 0xb8, 0x01, 0x11, 0xe5, 0x0b, ]; assert_eq!(&tag, &expected_tag); @@ -356,8 +357,8 @@ fn mac_correctly_fails_when_it_doesnt_match() { #[rustfmt::skip] let expected_tag = [ - 0xc7, 0xd3, 0xa9, 0x29, 0x61, 0x4a, 0x95, 0xdb, - 0x39, 0xc3, 0xe2, 0x3f, 0x7e, 0xe1, 0x2e, 0x9f, + 0x1b, 0x93, 0x12, 0xb5, 0x12, 0xdf, 0xe4, 0x7f, + 0x08, 0x64, 0xca, 0x7f, 0xcb, 0x72, 0x0f, 0xd2, ]; assert_eq!(&tag, &expected_tag); @@ -372,7 +373,7 @@ fn mac_correctly_fails_when_it_doesnt_match() { #[test] #[should_panic] -fn mac_correctly_fails_when_state_doesnt_match() { +fn mac_correctly_fails_when_message_length_doesnt_match() { let key = Array([1u8; 32]); let cleartext = b"MESSAGE ENCRYPT."; @@ -390,8 +391,8 @@ fn mac_correctly_fails_when_state_doesnt_match() { #[rustfmt::skip] let expected_tag = [ - 0xc7, 0xd3, 0xa9, 0x29, 0x61, 0x4a, 0x95, 0xdb, - 0x39, 0xc3, 0xe2, 0x3f, 0x7e, 0xe1, 0x2e, 0x9f, + 0x1b, 0x93, 0x12, 0xb5, 0x12, 0xdf, 0xe4, 0x7f, + 0x08, 0x64, 0xca, 0x7f, 0xcb, 0x72, 0x0f, 0xd2, ]; message.extend_from_slice(&[0, 0, 0]); @@ -402,3 +403,35 @@ fn mac_correctly_fails_when_state_doesnt_match() { let verification = rx.verify_mac(&tag); assert!(verification.is_ok()); } + +#[test] +#[should_panic] +fn omitting_ops_with_empty_data_should_fail() { + let key = Array([1u8; 32]); + + let cleartext = b"MESSAGE ENCRYPT."; + + let mut message = cleartext.to_vec(); + + let mut tx = NekoState::::new(b"test"); + let mut rx = NekoState::::new(b"test"); + + tx.key(&key); + tx.ad(b""); + rx.key(&key); + + tx.encrypt(&mut message); + let tag = tx.create_mac(); + + #[rustfmt::skip] + let expected_tag = [ + 0x2b, 0xfb, 0xc9, 0x35, 0xc1, 0x46, 0x3b, 0x63, + 0xfb, 0xce, 0x91, 0x29, 0xe3, 0xc5, 0x03, 0xcd, + ]; + + assert_eq!(&tag, &expected_tag); + // Omit the AD op, even with empty data, and go straight to decrypt + rx.decrypt(&mut message); + let verification = rx.verify_mac(&tag); + assert!(verification.is_ok()); +} -- 2.51.2