···7788extern crate alloc;
991010-/// Version of Strobe that this crate implements.
1111-pub static STROBE_VERSION: &str = "1.0.2";
1010+/// Version of WHARRGARBL that this crate implements.
1211pub static WHARRGHARBL_PROTO: &str = "WGBL-v0.0-STv1.0.2";
1212+1313+pub mod utils {
1414+ pub use wharrgarbl_utils::BufferSlice;
1515+}
···6677use aead::consts::{U16, U65};
88use hybrid_array::Array;
99-use wharrgarbl_core::Role;
1091111-use crate::{StrobeSecurity, keccakf::KECCAK_BUFFER_SIZE, strobe::StrobeState};
1010+use crate::{StrobeRole, StrobeSecurity, keccakf::KECCAK_BUFFER_SIZE, strobe::StrobeState};
12111312extern crate std;
14131514#[test]
1615fn test_init_128() {
1717- let s = StrobeState::new(b"", StrobeSecurity::B128, Role::Sender);
1616+ let s = StrobeState::new(b"", StrobeSecurity::B128, StrobeRole::Sender);
18171918 let expected_st: [u8; KECCAK_BUFFER_SIZE] = [
2019 0x9c, 0x7f, 0x16, 0x8f, 0xf8, 0xfd, 0x55, 0xda, 0x2a, 0xa7, 0x3c, 0x23, 0x55, 0x65, 0x35,
···38373938#[test]
4039fn test_init_256() {
4141- let s = StrobeState::new(b"", StrobeSecurity::B256, Role::Sender);
4040+ let s = StrobeState::new(b"", StrobeSecurity::B256, StrobeRole::Sender);
42414342 let expected_st: [u8; KECCAK_BUFFER_SIZE] = [
4443 0x37, 0xc1, 0x15, 0x06, 0xed, 0x61, 0xe7, 0xda, 0x7c, 0x1a, 0x2f, 0x2c, 0x1f, 0x49, 0x74,
···6362#[test]
6463fn test_metadata() {
6564 // We will accumulate output over 3 operations and 3 meta-operations
6666- let mut s = StrobeState::new(b"metadatatest", StrobeSecurity::B256, Role::Sender);
6565+ let mut s = StrobeState::new(b"metadatatest", StrobeSecurity::B256, StrobeRole::Sender);
6766 let mut output = std::vec::Vec::new();
68676968 let buf = b"meta1";
···117116118117#[test]
119118fn test_seq() {
120120- let mut s = StrobeState::new(b"seqtest", StrobeSecurity::B256, Role::Sender);
119119+ let mut s = StrobeState::new(b"seqtest", StrobeSecurity::B256, StrobeRole::Sender);
121120122121 let mut buf = [0u8; 10];
123122 s.prf(&mut buf[..]);
···173172#[test]
174173fn test_enc_correctness() {
175174 let orig_msg = b"Hello there";
176176- let mut tx = StrobeState::new(b"enccorrectnesstest", StrobeSecurity::B256, Role::Sender);
177177- let mut rx = StrobeState::new(b"enccorrectnesstest", StrobeSecurity::B256, Role::Receiver);
175175+ let mut tx = StrobeState::new(
176176+ b"enccorrectnesstest",
177177+ StrobeSecurity::B256,
178178+ StrobeRole::Sender,
179179+ );
180180+ let mut rx = StrobeState::new(
181181+ b"enccorrectnesstest",
182182+ StrobeSecurity::B256,
183183+ StrobeRole::Receiver,
184184+ );
178185179186 tx.key(b"the-combination-on-my-luggage");
180187 rx.key(b"the-combination-on-my-luggage");
···189196190197#[test]
191198fn test_mac_correctness_and_soundness() {
192192- let mut tx = StrobeState::new(b"mactest", StrobeSecurity::B256, Role::Sender);
193193- let mut rx = StrobeState::new(b"mactest", StrobeSecurity::B256, Role::Receiver);
199199+ let mut tx = StrobeState::new(b"mactest", StrobeSecurity::B256, StrobeRole::Sender);
200200+ let mut rx = StrobeState::new(b"mactest", StrobeSecurity::B256, StrobeRole::Receiver);
194201195202 // Just do some stuff with the state
196203···218225219226#[test]
220227fn test_long_inputs() {
221221- let mut s = StrobeState::new(b"bigtest", StrobeSecurity::B256, Role::Sender);
228228+ let mut s = StrobeState::new(b"bigtest", StrobeSecurity::B256, StrobeRole::Sender);
222229 const BIG_N: usize = 9823;
223230 const SMALL_N: usize = 65;
224231 let big_data = [0x34u8; BIG_N];
···275282fn test_streaming_correctness() {
276283 // Compute a few things without breaking up their inputs
277284 let one_shot_st: std::vec::Vec<u8> = {
278278- let mut s = StrobeState::new(b"streamingtest", StrobeSecurity::B256, Role::Receiver);
285285+ let mut s = StrobeState::new(b"streamingtest", StrobeSecurity::B256, StrobeRole::Receiver);
279286280287 s.ad(b"mynonce");
281288···291298 };
292299 // Now do the same thing but stream the inputs
293300 let streamed_st: std::vec::Vec<u8> = {
294294- let mut s = StrobeState::new(b"streamingtest", StrobeSecurity::B256, Role::Receiver);
301301+ let mut s = StrobeState::new(b"streamingtest", StrobeSecurity::B256, StrobeRole::Receiver);
295302296303 s.ad(b"my");
297304 s.ad(b"nonce");
+2-3
wharrgarbl-strobe/src/herding_kats/harness.rs
···4455use aead::consts::U14;
66use serde::{Deserialize, Deserializer, de};
77-use wharrgarbl_core::Role;
8799-use crate::{StrobeSecurity, strobe::StrobeState};
88+use crate::{StrobeRole, StrobeSecurity, strobe::StrobeState};
1091110/// The harness we will put on our KATs so we can herd them and make them do tests.
1211/// (This is the top-level structure of the JSON we find in the test vectors)
···115114 operations,
116115 } = serde_json::from_reader(file).unwrap();
117116118118- let mut strobe = StrobeState::new(proto_string.as_bytes(), security, Role::Sender);
117117+ let mut strobe = StrobeState::new(proto_string.as_bytes(), security, StrobeRole::Sender);
119118120119 operations.into_iter().for_each(
121120 |KatOperation {
+17
wharrgarbl-strobe/src/lib.rs
···88#[cfg(test)]
99mod herding_kats;
10101111+use core::ops::BitXor;
1212+1113pub use strobe::StrobeState;
12141315/// Version of Strobe that this crate implements.
···2931 (self as u16).to_le_bytes()
3032 }
3133}
3434+3535+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3636+#[repr(u8)]
3737+pub enum StrobeRole {
3838+ Sender = 0,
3939+ Receiver = 1,
4040+}
4141+4242+impl BitXor for StrobeRole {
4343+ fn bitxor(self, rhs: Self) -> Self::Output {
4444+ (self as u8) ^ (rhs as u8)
4545+ }
4646+4747+ type Output = u8;
4848+}
+3-4
wharrgarbl-strobe/src/strobe.rs
···11use ctutils::{Choice, CtAssign, CtEq, CtLt, CtSelect};
22use hybrid_array::{Array, ArraySize};
33-use wharrgarbl_core::Role;
43use zeroize::Zeroize;
5465use crate::{
77- STROBE_VERSION, StrobeSecurity,
66+ STROBE_VERSION, StrobeRole, StrobeSecurity,
87 keccakf::{KECCAK_BUFFER_SIZE, KeccakF1600},
98 opflags::OpFlags,
109 ops,
···110109111110impl StrobeState {
112111 /// Makes a new `StrobeState` object with a given protocol byte string and security parameter.
113113- pub fn new(protocol: &[u8], sec: StrobeSecurity, role: Role) -> Self {
112112+ pub fn new(protocol: &[u8], sec: StrobeSecurity, role: StrobeRole) -> Self {
114113 let rate = KECCAK_BUFFER_SIZE - (sec as usize) / 4 - 2;
115114 assert!((1..254).contains(&rate));
116115···458457459458 #[test]
460459 fn version_formatting() {
461461- let s = StrobeState::new(b"", StrobeSecurity::B128, Role::Sender);
460460+ let s = StrobeState::new(b"", StrobeSecurity::B128, StrobeRole::Sender);
462461463462 let display = std::format!("{s}");
464463 let debug = std::format!("{s:?}");