Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/crypto_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ pub trait HashType {
assert!(key.len() <= self.block_len());
let block_len = self.block_len();
let hash_len = self.hash_len();
let mut ipad = [0x36u8; MAXBLOCKLEN];
let mut opad = [0x5cu8; MAXBLOCKLEN];
let mut i_pad = [0x36u8; MAXBLOCKLEN];
let mut o_pad = [0x5cu8; MAXBLOCKLEN];
for count in 0..key.len() {
ipad[count] ^= key[count];
opad[count] ^= key[count];
i_pad[count] ^= key[count];
o_pad[count] ^= key[count];
}
self.reset();
self.input(&ipad[..block_len]);
self.input(&i_pad[..block_len]);
self.input(data);
let mut inner_output = [0u8; MAXHASHLEN];
self.result(&mut inner_output);
self.reset();
self.input(&opad[..block_len]);
self.input(&o_pad[..block_len]);
self.input(&inner_output[..hash_len]);
self.result(out);
}
Expand Down
14 changes: 7 additions & 7 deletions src/handshakestate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> HandshakeState<'a> {
&mut owner.rng,
&mut owner.cipherstate,
&mut owner.hasher,
&mut owner.s, &mut owner.e,
&owner.s, &mut owner.e,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale behind this change?

&mut owner.rs[..dhlen],
&mut owner.re[..dhlen],
owner.has_s, owner.has_e, owner.has_rs, owner.has_re,
Expand Down Expand Up @@ -105,24 +105,24 @@ impl<'a> HandshakeState<'a> {
}

if let Some(_) = optional_preshared_key {
copy_memory("NoisePSK_".as_bytes(), &mut handshake_name);
copy_memory(b"NoisePSK_", &mut handshake_name);
name_len = 9;
} else {
copy_memory("Noise_".as_bytes(), &mut handshake_name);
copy_memory(b"Noise_", &mut handshake_name);
name_len = 6;
}
name_len += resolve_handshake_pattern(handshake_pattern,
&mut handshake_name[name_len..],
&mut premsg_pattern_i,
&mut premsg_pattern_r,
&mut message_patterns);
handshake_name[name_len] = '_' as u8;
handshake_name[name_len] = b'_';
name_len += 1;
name_len += s.name(&mut handshake_name[name_len..]);
handshake_name[name_len] = '_' as u8;
handshake_name[name_len] = b'_';
name_len += 1;
name_len += cipherstate.name(&mut handshake_name[name_len..]);
handshake_name[name_len] = '_' as u8;
handshake_name[name_len] = b'_';
name_len += 1;
name_len += hasher.name(&mut handshake_name[name_len..]);

Expand Down Expand Up @@ -266,7 +266,7 @@ impl<'a> HandshakeState<'a> {
pub fn read_message(&mut self,
message: &[u8],
payload: &mut [u8]) -> Result<(usize, bool), NoiseError> {
assert!(self.my_turn_to_send == false);
assert!(!self.my_turn_to_send);
assert!(message.len() <= MAXMSGLEN);

let tokens = self.message_patterns[self.message_index];
Expand Down
34 changes: 17 additions & 17 deletions src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,45 @@ pub fn resolve_handshake_pattern(
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[S], premsg_pattern_r);
copy_tokens(&[E, Dhes], &mut msg_patterns[0]);
copy_memory("N".as_bytes(), name)
copy_memory(b"N", name)
},

K => {
copy_tokens(&[S], premsg_pattern_i);
copy_tokens(&[S], premsg_pattern_r);
copy_tokens(&[E, Dhes, Dhss], &mut msg_patterns[0]);
copy_memory("K".as_bytes(), name)
copy_memory(b"K", name)
},

X => {
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[S], premsg_pattern_r);
copy_tokens(&[E, Dhes, S, Dhss], &mut msg_patterns[0]);
copy_memory("X".as_bytes(), name)
copy_memory(b"X", name)
},

NN => {
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[], premsg_pattern_r);
copy_tokens(&[E], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee], &mut msg_patterns[1]);
copy_memory("NN".as_bytes(), name)
copy_memory(b"NN", name)
},

NK => {
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[S], premsg_pattern_r);
copy_tokens(&[E, Dhes], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee], &mut msg_patterns[1]);
copy_memory("NK".as_bytes(), name)
copy_memory(b"NK", name)
},

NX => {
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[], premsg_pattern_r);
copy_tokens(&[E], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee, S, Dhse], &mut msg_patterns[1]);
copy_memory("NX".as_bytes(), name)
copy_memory(b"NX", name)
},

XN => {
Expand All @@ -72,7 +72,7 @@ pub fn resolve_handshake_pattern(
copy_tokens(&[E], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee], &mut msg_patterns[1]);
copy_tokens(&[S, Dhse], &mut msg_patterns[2]);
copy_memory("XN".as_bytes(), name)
copy_memory(b"XN", name)
},

XK => {
Expand All @@ -81,7 +81,7 @@ pub fn resolve_handshake_pattern(
copy_tokens(&[E, Dhes], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee], &mut msg_patterns[1]);
copy_tokens(&[S, Dhse], &mut msg_patterns[2]);
copy_memory("XK".as_bytes(), name)
copy_memory(b"XK", name)
},

XX => {
Expand All @@ -90,7 +90,7 @@ pub fn resolve_handshake_pattern(
copy_tokens(&[E], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee, S, Dhse], &mut msg_patterns[1]);
copy_tokens(&[S, Dhse], &mut msg_patterns[2]);
copy_memory("XX".as_bytes(), name)
copy_memory(b"XX", name)
},

XR => {
Expand All @@ -100,63 +100,63 @@ pub fn resolve_handshake_pattern(
copy_tokens(&[E, Dhee], &mut msg_patterns[1]);
copy_tokens(&[S, Dhse], &mut msg_patterns[2]);
copy_tokens(&[S, Dhse], &mut msg_patterns[3]);
copy_memory("XR".as_bytes(), name)
copy_memory(b"XR", name)
},

KN => {
copy_tokens(&[S], premsg_pattern_i);
copy_tokens(&[], premsg_pattern_r);
copy_tokens(&[E], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee, Dhes], &mut msg_patterns[1]);
copy_memory("KN".as_bytes(), name)
copy_memory(b"KN", name)
}

KK => {
copy_tokens(&[S], premsg_pattern_i);
copy_tokens(&[S], premsg_pattern_r);
copy_tokens(&[E, Dhes, Dhss], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee, Dhes], &mut msg_patterns[1]);
copy_memory("KK".as_bytes(), name)
copy_memory(b"KK", name)
}

KX => {
copy_tokens(&[S], premsg_pattern_i);
copy_tokens(&[], premsg_pattern_r);
copy_tokens(&[E], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee, Dhes, S, Dhse], &mut msg_patterns[1]);
copy_memory("KX".as_bytes(), name)
copy_memory(b"KX", name)
}

IN => {
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[], premsg_pattern_r);
copy_tokens(&[E, S], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee, Dhes], &mut msg_patterns[1]);
copy_memory("IN".as_bytes(), name)
copy_memory(b"IN", name)
}

IK => {
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[S], premsg_pattern_r);
copy_tokens(&[E, Dhes, S, Dhss], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee, Dhes], &mut msg_patterns[1]);
copy_memory("IK".as_bytes(), name)
copy_memory(b"IK", name)
}

IX => {
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[], premsg_pattern_r);
copy_tokens(&[E, S], &mut msg_patterns[0]);
copy_tokens(&[E, Dhee, Dhes, S, Dhse], &mut msg_patterns[1]);
copy_memory("IX".as_bytes(), name)
copy_memory(b"IX", name)
}

XXfallback => {
copy_tokens(&[], premsg_pattern_i);
copy_tokens(&[E], premsg_pattern_r);
copy_tokens(&[E, Dhee, S, Dhse], &mut msg_patterns[0]);
copy_tokens(&[S, Dhse], &mut msg_patterns[1]);
copy_memory("XXfallback".as_bytes(), name)
copy_memory(b"XXfallback", name)
}
}
}
26 changes: 13 additions & 13 deletions src/wrappers/crypto_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ pub struct HashBLAKE2b {
impl DhType for Dh25519 {

fn name(&self, out : &mut [u8]) -> usize {
copy_memory("25519".as_bytes(), out)
copy_memory(b"25519", out)
}

fn pub_len(&self) -> usize {
return 32;
32
}

fn set(&mut self, privkey: &[u8], pubkey: &[u8]) {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl DhType for Dh25519 {
impl CipherType for CipherAESGCM {

fn name(&self, out : &mut [u8]) -> usize {
copy_memory("AESGCM".as_bytes(), out)
copy_memory(b"AESGCM", out)
}

fn set(&mut self, key: &[u8]) {
Expand Down Expand Up @@ -119,7 +119,7 @@ impl CipherType for CipherAESGCM {
impl CipherType for CipherChaChaPoly {

fn name(&self, out : &mut [u8]) -> usize {
copy_memory("ChaChaPoly".as_bytes(), out)
copy_memory(b"ChaChaPoly", out)
}

fn set(&mut self, key: &[u8]) {
Expand Down Expand Up @@ -189,15 +189,15 @@ impl Default for HashSHA256 {
impl HashType for HashSHA256 {

fn block_len(&self) -> usize {
return 64;
64
}

fn hash_len(&self) -> usize {
return 32;
32
}

fn name(&self, out : &mut [u8]) -> usize {
copy_memory("SHA256".as_bytes(), out)
copy_memory(b"SHA256", out)
}

fn reset(&mut self) {
Expand All @@ -222,15 +222,15 @@ impl Default for HashSHA512 {
impl HashType for HashSHA512 {

fn name(&self, out: &mut [u8]) -> usize {
copy_memory("SHA512".as_bytes(), out)
copy_memory(b"SHA512", out)
}

fn block_len(&self) -> usize {
return 128;
128
}

fn hash_len(&self) -> usize {
return 64;
64
}

fn reset(&mut self) {
Expand All @@ -255,15 +255,15 @@ impl Default for HashBLAKE2b {
impl HashType for HashBLAKE2b {

fn name(&self, out : &mut [u8]) -> usize {
copy_memory("BLAKE2b".as_bytes(), out)
copy_memory(b"BLAKE2b", out)
}

fn block_len(&self) -> usize {
return 128;
128
}

fn hash_len(&self) -> usize {
return 64;
64
}

fn reset(&mut self) {
Expand Down