summaryrefslogtreecommitdiffstats
path: root/src/handshake/noise.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-26 15:00:14 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-26 15:00:14 +0200
commit5f3c4d2e276792b99449cba6a04520ee1d324bbf (patch)
treee8dee95e8e2db3724372e75a0d4f095770aed7a6 /src/handshake/noise.rs
parentMove to hjul crate (diff)
downloadwireguard-rs-5f3c4d2e276792b99449cba6a04520ee1d324bbf.tar.xz
wireguard-rs-5f3c4d2e276792b99449cba6a04520ee1d324bbf.zip
Update the blake2 crate to fix bug upstream
Included basic sanity check for the HKDF macroes, to avoid regression in future.
Diffstat (limited to '')
-rw-r--r--src/handshake/noise.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/handshake/noise.rs b/src/handshake/noise.rs
index 6a1eb6d..2f8f67e 100644
--- a/src/handshake/noise.rs
+++ b/src/handshake/noise.rs
@@ -157,15 +157,81 @@ mod tests {
const IDENTIFIER: &[u8] = b"WireGuard v1 zx2c4 Jason@zx2c4.com";
const CONSTRUCTION: &[u8] = b"Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s";
+ /* Sanity check precomputed initial chain key
+ */
#[test]
fn precomputed_chain_key() {
assert_eq!(INITIAL_CK[..], HASH!(CONSTRUCTION)[..]);
}
+ /* Sanity check precomputed initial hash transcript
+ */
#[test]
fn precomputed_hash() {
assert_eq!(INITIAL_HS[..], HASH!(INITIAL_CK, IDENTIFIER)[..]);
}
+
+ /* Sanity check the HKDF macro
+ *
+ * Test vectors generated using WireGuard-Go
+ */
+ #[test]
+ fn hkdf() {
+ let tests: Vec<(Vec<u8>, Vec<u8>, [u8; 32], [u8; 32], [u8; 32])> = vec![
+ (
+ vec![],
+ vec![],
+ [
+ 0x83, 0x87, 0xb4, 0x6b, 0xf4, 0x3e, 0xcc, 0xfc, 0xf3, 0x49, 0x55, 0x2a, 0x09,
+ 0x5d, 0x83, 0x15, 0x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x87, 0x92, 0x1d, 0xac, 0x53, 0xce, 0x6d, 0xb4, 0xb4, 0xe1,
+ 0x21, 0x92, 0xf2, 0x63, 0xc4, 0xc4,
+ ],
+ ),
+ ];
+
+ for (key, input, t0, t1, t2) in &tests {
+ let tt0 = KDF1!(key, input);
+ debug_assert_eq!(tt0[..], t0[..]);
+
+ let (tt0, tt1) = KDF2!(key, input);
+ debug_assert_eq!(tt0[..], t0[..]);
+ debug_assert_eq!(tt1[..], t1[..]);
+
+ let (tt0, tt1, tt2) = KDF3!(key, input);
+ debug_assert_eq!(tt0[..], t0[..]);
+ debug_assert_eq!(tt1[..], t1[..]);
+ debug_assert_eq!(tt2[..], t2[..]);
+ }
+ }
}
pub fn create_initiation<T: Copy, R: RngCore + CryptoRng>(