aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-07-25 21:43:25 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-07-25 21:43:25 +0200
commit27f8fd8e3496ed1189ff826b382e04a492dcf1a4 (patch)
treedbbfb02e466b81922fe6866c5bc5072f3f4fa9da
parentAdded opaque identity to output (diff)
downloadwireguard-rs-27f8fd8e3496ed1189ff826b382e04a492dcf1a4.tar.xz
wireguard-rs-27f8fd8e3496ed1189ff826b382e04a492dcf1a4.zip
Fixed GenericArray version
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml2
-rw-r--r--src/noise.rs51
3 files changed, 24 insertions, 39 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 85e6cec..0b4d902 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -57,7 +57,7 @@ name = "crypto-mac"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -78,7 +78,7 @@ name = "digest"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -93,7 +93,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "generic-array"
-version = "0.12.0"
+version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -305,7 +305,7 @@ name = "wg-handshake"
version = "0.1.0"
dependencies = [
"blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -357,7 +357,7 @@ dependencies = [
"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c"
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
-"checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592"
+"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
"checksum hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695"
"checksum libc 0.2.59 (registry+https://github.com/rust-lang/crates.io-index)" = "3262021842bf00fe07dbd6cf34ff25c99d7a7ebef8deea84db72be3ea3bb0aff"
diff --git a/Cargo.toml b/Cargo.toml
index de66caa..2ccb719 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@ rand = "0.6.5"
blake2 = "0.8.0"
hmac = "0.7.1"
rust-crypto = "^0.2"
-generic-array = "0.12"
+generic-array = "0.12.3"
[dependencies.x25519-dalek]
version = "^0.5"
diff --git a/src/noise.rs b/src/noise.rs
index d5495b8..6327776 100644
--- a/src/noise.rs
+++ b/src/noise.rs
@@ -14,7 +14,7 @@ use crypto::aead::{AeadEncryptor,AeadDecryptor};
use rand::rngs::OsRng;
-use generic_array::typenum::U32;
+use generic_array::typenum::*;
use generic_array::GenericArray;
use crate::types::*;
@@ -184,11 +184,11 @@ mod tests {
}
}
-pub fn create_initiation<T>(
+pub fn create_initiation<T : Copy>(
device : &Device<T>,
peer : &Peer<T>,
sender : u32
-) -> Result<Vec<u8>, HandshakeError> where T : Copy {
+) -> Result<Vec<u8>, HandshakeError> {
let mut rng = OsRng::new().unwrap();
let mut msg : Initiation = Default::default();
@@ -263,10 +263,10 @@ pub fn create_initiation<T>(
Ok(Initiation::into(msg))
}
-pub fn consume_initiation<'a, T>(
+pub fn consume_initiation<'a, T : Copy>(
device : &'a Device<T>,
msg : &[u8]
-) -> Result<(&'a Peer<T>, TemporaryState), HandshakeError> where T : Copy {
+) -> Result<(&'a Peer<T>, TemporaryState), HandshakeError> {
// parse message
@@ -341,11 +341,11 @@ pub fn consume_initiation<'a, T>(
Ok((peer, (msg.f_sender, eph_r_pk, hs, ck)))
}
-pub fn create_response<T>(
+pub fn create_response<T : Copy>(
peer : &Peer<T>,
sender : u32, // sending identifier
state : TemporaryState // state from "consume_initiation"
-) -> Result<Output<T>, HandshakeError> where T : Copy {
+) -> Result<Output<T>, HandshakeError> {
let mut rng = OsRng::new().unwrap();
let mut msg : Response = Default::default();
@@ -399,20 +399,14 @@ pub fn create_response<T>(
);
/* not strictly needed
- // H := Hash(H || msg.empty)
- let hs = HASH!(&hs, &msg.f_empty_tag);
- */
+ * // H := Hash(H || msg.empty)
+ * let hs = HASH!(&hs, &msg.f_empty_tag);
+ */
// derive key-pair
// (verbose code, due to GenericArray -> [u8; 32] conversion)
- let (key_recv, key_send) = {
- let (k1, k2) = KDF2!(&ck, &[]);
- let (mut d1, mut d2) = ([0u8; 32], [0u8; 32]);
- d1.clone_from_slice(&k1);
- d2.clone_from_slice(&k2);
- (d1, d2)
- };
+ let (key_recv, key_send) = KDF2!(&ck, &[]);
// return response and unconfirmed key-pair
@@ -423,20 +417,17 @@ pub fn create_response<T>(
confirmed : false,
send : Key{
id : sender,
- key : key_send
+ key : key_send.into()
},
recv : Key{
id : receiver,
- key : key_recv
+ key : key_recv.into()
}
})
))
}
-pub fn consume_response<T>(
- device : &Device<T>,
- msg : &[u8]
-) -> Result<Output<T>, HandshakeError> where T : Copy {
+pub fn consume_response<T : Copy>(device : &Device<T>, msg : &[u8]) -> Result<Output<T>, HandshakeError> {
// parse message
@@ -487,15 +478,9 @@ pub fn consume_response<T>(
// derive key-pair
- let (key_send, key_recv) = {
- let (k1, k2) = KDF2!(&ck, &[]);
- let (mut d1, mut d2) = ([0u8; 32], [0u8; 32]);
- d1.clone_from_slice(&k1);
- d2.clone_from_slice(&k2);
- (d1, d2)
- };
+ let (key_send, key_recv) = KDF2!(&ck, &[]);
- // return response and unconfirmed key-pair
+ // return confirmed key-pair
Ok((
peer.identifier,
@@ -504,11 +489,11 @@ pub fn consume_response<T>(
confirmed : true,
send : Key{
id : sender,
- key : key_send
+ key : key_send.into()
},
recv : Key{
id : msg.f_sender,
- key : key_recv
+ key : key_recv.into()
}
})
))