aboutsummaryrefslogtreecommitdiffstats
path: root/src/messages.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/messages.rs')
-rw-r--r--src/messages.rs79
1 files changed, 40 insertions, 39 deletions
diff --git a/src/messages.rs b/src/messages.rs
index 805de8d..340f5e0 100644
--- a/src/messages.rs
+++ b/src/messages.rs
@@ -5,21 +5,22 @@ const SIZE_TAG : usize = 16;
const SIZE_X25519_POINT : usize = 32;
const SIZE_TIMESTAMP : usize = 12;
-pub const TYPE_INITIATION : u8 = 1;
-pub const TYPE_RESPONSE : u8 = 2;
+pub const TYPE_INITIATION : u32 = 1;
+pub const TYPE_RESPONSE : u32 = 2;
-/* Wireguard handshake initiation message
+/* Wireguard handshake (noise) initiation message
* initator -> responder
*/
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Initiation {
- pub f_type : u8,
- f_reserved : [u8; 3],
- pub f_sender : u32,
- pub f_ephemeral : [u8; SIZE_X25519_POINT],
- pub f_static : [u8; SIZE_X25519_POINT + SIZE_TAG],
- pub f_timestamp : [u8; SIZE_TIMESTAMP + SIZE_TAG],
+ f_type : u32,
+ pub f_sender : u32,
+ pub f_ephemeral : [u8; SIZE_X25519_POINT],
+ pub f_static : [u8; SIZE_X25519_POINT],
+ pub f_static_tag : [u8; SIZE_TAG],
+ pub f_timestamp : [u8; SIZE_TIMESTAMP],
+ pub f_timestamp_tag : [u8; SIZE_TAG],
}
impl From<&[u8]> for Initiation {
@@ -70,12 +71,13 @@ impl fmt::Debug for Initiation {
impl Default for Initiation {
fn default() -> Self {
Self {
- f_type : TYPE_INITIATION,
- f_reserved : [0u8; 3],
- f_sender : 0,
- f_ephemeral : [0u8; SIZE_X25519_POINT],
- f_static : [0u8; SIZE_X25519_POINT + SIZE_TAG],
- f_timestamp : [0u8; SIZE_TIMESTAMP + SIZE_TAG],
+ f_type : TYPE_INITIATION,
+ f_sender : 0,
+ f_ephemeral : [0u8; SIZE_X25519_POINT],
+ f_static : [0u8; SIZE_X25519_POINT],
+ f_static_tag : [0u8; SIZE_TAG],
+ f_timestamp : [0u8; SIZE_TIMESTAMP],
+ f_timestamp_tag : [0u8; SIZE_TAG]
}
}
}
@@ -84,11 +86,12 @@ impl Default for Initiation {
impl PartialEq for Initiation {
fn eq(&self, other: &Self) -> bool {
self.f_type == other.f_type &&
- self.f_reserved == other.f_reserved &&
self.f_sender == other.f_sender &&
self.f_ephemeral[..] == other.f_ephemeral[..] &&
self.f_static[..] == other.f_static[..] &&
- self.f_timestamp[..] == other.f_timestamp
+ self.f_static_tag[..] == other.f_static_tag[..] &&
+ self.f_timestamp[..] == other.f_timestamp &&
+ self.f_timestamp_tag[..] == other.f_timestamp_tag
}
}
@@ -96,18 +99,17 @@ impl PartialEq for Initiation {
impl Eq for Initiation {}
-/* Wireguard handshake responder message
+/* Wireguard handshake (noise) responder message
* responder -> initator
*/
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Response {
- f_type : u8,
- f_reserved : [u8; 3],
- f_sender : u32,
- f_receiver : u32,
- f_ephemeral : [u8; SIZE_X25519_POINT],
- f_empty : [u8; SIZE_TAG],
+ f_type : u32,
+ pub f_sender : u32,
+ pub f_receiver : u32,
+ pub f_ephemeral : [u8; SIZE_X25519_POINT],
+ pub f_empty_tag : [u8; SIZE_TAG],
}
impl From<&[u8]> for Response {
@@ -161,11 +163,10 @@ impl fmt::Debug for Response {
impl PartialEq for Response {
fn eq(&self, other: &Self) -> bool {
self.f_type == other.f_type &&
- self.f_reserved == other.f_reserved &&
self.f_sender == other.f_sender &&
self.f_receiver == other.f_receiver &&
self.f_ephemeral == other.f_ephemeral &&
- self.f_empty == other.f_empty
+ self.f_empty_tag == other.f_empty_tag
}
}
@@ -176,10 +177,9 @@ mod tests {
#[test]
fn message_response_identity() {
let msg = Response {
- f_type : TYPE_RESPONSE,
- f_reserved : [0u8; 3],
- f_sender : 146252,
- f_receiver : 554442,
+ f_type : TYPE_RESPONSE,
+ f_sender : 146252,
+ f_receiver : 554442,
f_ephemeral : [
// ephemeral public key
0xc1, 0x66, 0x0a, 0x0c, 0xdc, 0x0f, 0x6c, 0x51,
@@ -187,7 +187,7 @@ mod tests {
0xf7, 0xf1, 0xca, 0x90, 0x86, 0x72, 0xad, 0x67,
0xea, 0x89, 0x45, 0x44, 0x13, 0x56, 0x52, 0x1f
],
- f_empty : [
+ f_empty_tag : [
// tag
0x60, 0x0e, 0x1e, 0x95, 0x41, 0x6b, 0x52, 0x05,
0xa2, 0x09, 0xe1, 0xbf, 0x40, 0x05, 0x2f, 0xde
@@ -201,9 +201,8 @@ mod tests {
#[test]
fn message_initiate_identity() {
let msg = Initiation {
- f_type : TYPE_RESPONSE,
- f_reserved : [0u8; 3],
- f_sender : 575757,
+ f_type : TYPE_RESPONSE,
+ f_sender : 575757,
f_ephemeral : [
// ephemeral public key
0xc1, 0x66, 0x0a, 0x0c, 0xdc, 0x0f, 0x6c, 0x51,
@@ -211,13 +210,14 @@ mod tests {
0xf7, 0xf1, 0xca, 0x90, 0x86, 0x72, 0xad, 0x67,
0xea, 0x89, 0x45, 0x44, 0x13, 0x56, 0x52, 0x1f
],
- f_static : [
+ f_static : [
// encrypted static public key
0xdc, 0x33, 0x90, 0x15, 0x8f, 0x82, 0x3e, 0x06,
0x44, 0xa0, 0xde, 0x4c, 0x15, 0x6c, 0x5d, 0xa4,
0x65, 0x99, 0xf6, 0x6c, 0xa1, 0x14, 0x77, 0xf9,
- 0xeb, 0x6a, 0xec, 0xc3, 0x3c, 0xda, 0x47, 0xe1,
-
+ 0xeb, 0x6a, 0xec, 0xc3, 0x3c, 0xda, 0x47, 0xe1
+ ],
+ f_static_tag : [
// tag
0x45, 0xac, 0x8d, 0x43, 0xea, 0x1b, 0x2f, 0x02,
0x45, 0x5d, 0x86, 0x37, 0xee, 0x83, 0x6b, 0x42
@@ -225,8 +225,9 @@ mod tests {
f_timestamp : [
// timestamp
0x4f, 0x1c, 0x60, 0xec, 0x0e, 0xf6, 0x36, 0xf0,
- 0x78, 0x28, 0x57, 0x42,
-
+ 0x78, 0x28, 0x57, 0x42
+ ],
+ f_timestamp_tag : [
// tag
0x60, 0x0e, 0x1e, 0x95, 0x41, 0x6b, 0x52, 0x05,
0xa2, 0x09, 0xe1, 0xbf, 0x40, 0x05, 0x2f, 0xde