From 0f5d49402a260201fcb3980fa7c90efe105fa437 Mon Sep 17 00:00:00 2001 From: sinuio <> Date: Thu, 7 Jul 2022 15:42:19 -0700 Subject: [PATCH] relocate hs msgs --- tls-2pc-core/src/handshake/master.rs | 55 +----------- tls-2pc-core/src/handshake/mod.rs | 30 +------ tls-2pc-core/src/handshake/slave.rs | 53 +---------- tls-2pc-core/src/lib.rs | 1 + tls-2pc-core/src/msgs/handshake.rs | 127 +++++++++++++++++++++++++++ tls-2pc-core/src/msgs/mod.rs | 2 + 6 files changed, 133 insertions(+), 135 deletions(-) create mode 100644 tls-2pc-core/src/msgs/handshake.rs create mode 100644 tls-2pc-core/src/msgs/mod.rs diff --git a/tls-2pc-core/src/handshake/master.rs b/tls-2pc-core/src/handshake/master.rs index a9b44358f..2dfd70938 100644 --- a/tls-2pc-core/src/handshake/master.rs +++ b/tls-2pc-core/src/handshake/master.rs @@ -2,60 +2,7 @@ use super::sha::finalize_sha256_digest; use super::utils::{seed_cf, seed_ke, seed_ms, seed_sf}; use super::HandshakeMessage; use super::{errors::*, MasterCore}; - -#[derive(Copy, Clone)] -pub struct MasterMs1 { - /// H((pms xor ipad) || seed) - pub inner_hash: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct MasterMs2 { - /// H((pms xor ipad) || a1) - pub inner_hash: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct MasterMs3 { - /// H((pms xor ipad) || a2) - pub inner_hash: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct MasterKe1 { - /// H((ms xor ipad) || seed) - pub inner_hash: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct MasterKe2 { - /// H((ms xor ipad) || a1) - pub inner_hash: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct MasterCf1 { - /// H((ms xor ipad) || seed) - pub inner_hash: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct MasterCf2 { - /// H((ms xor ipad) || a1 || seed) - pub inner_hash: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct MasterSf1 { - /// H((ms xor ipad) || seed) - pub inner_hash: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct MasterSf2 { - /// H((ms xor ipad) || a1 || seed) - pub inner_hash: [u8; 32], -} +use crate::msgs::handshake::*; #[derive(PartialEq, Copy, Clone)] enum State { diff --git a/tls-2pc-core/src/handshake/mod.rs b/tls-2pc-core/src/handshake/mod.rs index 2c7478ea3..f3ccb8fcd 100644 --- a/tls-2pc-core/src/handshake/mod.rs +++ b/tls-2pc-core/src/handshake/mod.rs @@ -4,38 +4,10 @@ mod sha; pub mod slave; mod utils; +pub use crate::msgs::handshake::HandshakeMessage; use errors::*; pub use master::HandshakeMaster; -use master::{ - MasterCf1, MasterCf2, MasterKe1, MasterKe2, MasterMs1, MasterMs2, MasterMs3, MasterSf1, - MasterSf2, -}; pub use slave::HandshakeSlave; -use slave::{ - SlaveCf1, SlaveCf2, SlaveKe1, SlaveKe2, SlaveMs1, SlaveMs2, SlaveMs3, SlaveSf1, SlaveSf2, -}; - -#[derive(Copy, Clone)] -pub enum HandshakeMessage { - MasterMs1(MasterMs1), - SlaveMs1(SlaveMs1), - MasterMs2(MasterMs2), - SlaveMs2(SlaveMs2), - MasterMs3(MasterMs3), - SlaveMs3(SlaveMs3), - MasterKe1(MasterKe1), - SlaveKe1(SlaveKe1), - MasterKe2(MasterKe2), - SlaveKe2(SlaveKe2), - MasterCf1(MasterCf1), - SlaveCf1(SlaveCf1), - MasterCf2(MasterCf2), - SlaveCf2(SlaveCf2), - MasterSf1(MasterSf1), - SlaveSf1(SlaveSf1), - MasterSf2(MasterSf2), - SlaveSf2(SlaveSf2), -} pub trait MasterCore { /// The first method that should be called after instantiation. Performs diff --git a/tls-2pc-core/src/handshake/slave.rs b/tls-2pc-core/src/handshake/slave.rs index 135d63ef4..192f4c35f 100644 --- a/tls-2pc-core/src/handshake/slave.rs +++ b/tls-2pc-core/src/handshake/slave.rs @@ -1,58 +1,7 @@ use super::sha::finalize_sha256_digest; use super::HandshakeMessage; use super::{errors::*, SlaveCore}; - -#[derive(Copy, Clone)] -pub struct SlaveMs1 { - /// H((pms xor opad) || H((pms xor ipad) || seed)) - pub a1: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct SlaveMs2 { - /// H((pms xor opad) || H((pms xor ipad) || a1)) - pub a2: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct SlaveMs3 { - /// H((pms xor opad) || H((pms xor ipad) || a2 || seed)) - pub p2: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct SlaveKe1 { - /// H((ms xor opad) || H((ms xor ipad) || seed)) - pub a1: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct SlaveKe2 { - /// H((ms xor opad) || H((ms xor ipad) || a1)) - pub a2: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct SlaveCf1 { - /// H((ms xor opad) || H((ms xor ipad) || seed)) - pub a1: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct SlaveCf2 { - pub verify_data: [u8; 12], -} - -#[derive(Copy, Clone)] -pub struct SlaveSf1 { - /// H((ms xor opad) || H((ms xor ipad) || seed)) - pub a1: [u8; 32], -} - -#[derive(Copy, Clone)] -pub struct SlaveSf2 { - pub verify_data: [u8; 12], -} +use crate::msgs::handshake::*; #[derive(PartialEq, Copy, Clone)] enum State { diff --git a/tls-2pc-core/src/lib.rs b/tls-2pc-core/src/lib.rs index 4d4bf6f25..45ccf3de1 100644 --- a/tls-2pc-core/src/lib.rs +++ b/tls-2pc-core/src/lib.rs @@ -2,3 +2,4 @@ pub mod ghash; #[cfg(feature = "handshake")] pub mod handshake; +pub mod msgs; diff --git a/tls-2pc-core/src/msgs/handshake.rs b/tls-2pc-core/src/msgs/handshake.rs new file mode 100644 index 000000000..d5defa57c --- /dev/null +++ b/tls-2pc-core/src/msgs/handshake.rs @@ -0,0 +1,127 @@ +#[derive(Copy, Clone)] +pub enum HandshakeMessage { + MasterMs1(MasterMs1), + SlaveMs1(SlaveMs1), + MasterMs2(MasterMs2), + SlaveMs2(SlaveMs2), + MasterMs3(MasterMs3), + SlaveMs3(SlaveMs3), + MasterKe1(MasterKe1), + SlaveKe1(SlaveKe1), + MasterKe2(MasterKe2), + SlaveKe2(SlaveKe2), + MasterCf1(MasterCf1), + SlaveCf1(SlaveCf1), + MasterCf2(MasterCf2), + SlaveCf2(SlaveCf2), + MasterSf1(MasterSf1), + SlaveSf1(SlaveSf1), + MasterSf2(MasterSf2), + SlaveSf2(SlaveSf2), +} + +#[derive(Copy, Clone)] +pub struct MasterMs1 { + /// H((pms xor ipad) || seed) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct MasterMs2 { + /// H((pms xor ipad) || a1) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct MasterMs3 { + /// H((pms xor ipad) || a2) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct MasterKe1 { + /// H((ms xor ipad) || seed) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct MasterKe2 { + /// H((ms xor ipad) || a1) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct MasterCf1 { + /// H((ms xor ipad) || seed) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct MasterCf2 { + /// H((ms xor ipad) || a1 || seed) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct MasterSf1 { + /// H((ms xor ipad) || seed) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct MasterSf2 { + /// H((ms xor ipad) || a1 || seed) + pub inner_hash: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct SlaveMs1 { + /// H((pms xor opad) || H((pms xor ipad) || seed)) + pub a1: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct SlaveMs2 { + /// H((pms xor opad) || H((pms xor ipad) || a1)) + pub a2: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct SlaveMs3 { + /// H((pms xor opad) || H((pms xor ipad) || a2 || seed)) + pub p2: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct SlaveKe1 { + /// H((ms xor opad) || H((ms xor ipad) || seed)) + pub a1: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct SlaveKe2 { + /// H((ms xor opad) || H((ms xor ipad) || a1)) + pub a2: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct SlaveCf1 { + /// H((ms xor opad) || H((ms xor ipad) || seed)) + pub a1: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct SlaveCf2 { + pub verify_data: [u8; 12], +} + +#[derive(Copy, Clone)] +pub struct SlaveSf1 { + /// H((ms xor opad) || H((ms xor ipad) || seed)) + pub a1: [u8; 32], +} + +#[derive(Copy, Clone)] +pub struct SlaveSf2 { + pub verify_data: [u8; 12], +} diff --git a/tls-2pc-core/src/msgs/mod.rs b/tls-2pc-core/src/msgs/mod.rs new file mode 100644 index 000000000..3e716210c --- /dev/null +++ b/tls-2pc-core/src/msgs/mod.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "handshake")] +pub mod handshake;