From 87eb124551aa45d3b9275b9ec54671ec5c4ca769 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Tue, 14 Mar 2023 18:16:21 -0400 Subject: [PATCH] ran cargo fmt --- zssp/src/proto.rs | 10 ++++------ zssp/src/zssp.rs | 48 ++++++++++++----------------------------------- 2 files changed, 16 insertions(+), 42 deletions(-) diff --git a/zssp/src/proto.rs b/zssp/src/proto.rs index 2913928a5..826371983 100644 --- a/zssp/src/proto.rs +++ b/zssp/src/proto.rs @@ -27,14 +27,12 @@ pub const MAX_INIT_PAYLOAD_SIZE: usize = MAX_NOISE_HANDSHAKE_SIZE - ALICE_NOISE_ /// Initial value of 'h' /// echo -n 'Noise_XKpsk3_P384_AESGCM_SHA512_hybridKyber1024' | shasum -a 512 -pub(crate) const INITIAL_H: [u8; SHA512_HASH_SIZE] = hex!( - "12ae70954e8d93bf7f73d0fe48d487155666f541e532f9461af5ef52ab90c8fd9259ef9e48f5adcf9af63f869805a570004ae095655dcaddbc226a50623b2b25" -); +pub(crate) const INITIAL_H: [u8; SHA512_HASH_SIZE] = + hex!("12ae70954e8d93bf7f73d0fe48d487155666f541e532f9461af5ef52ab90c8fd9259ef9e48f5adcf9af63f869805a570004ae095655dcaddbc226a50623b2b25"); /// Initial value of 'h' /// echo -n 'Noise_KKpsk0_P384_AESGCM_SHA512' | shasum -a 512 -pub(crate) const INITIAL_H_REKEY: [u8; SHA512_HASH_SIZE] = hex!( - "daeedd651ac9c5173f2eaaff996beebac6f3f1bfe9a70bb1cc54fa1fb2bf46260d71a3c4fb4d4ee36f654c31773a8a15e5d5be974a0668dc7db70f4e13ed172e" -); +pub(crate) const INITIAL_H_REKEY: [u8; SHA512_HASH_SIZE] = + hex!("daeedd651ac9c5173f2eaaff996beebac6f3f1bfe9a70bb1cc54fa1fb2bf46260d71a3c4fb4d4ee36f654c31773a8a15e5d5be974a0668dc7db70f4e13ed172e"); /// Version 0: Noise_XK with NIST P-384 plus Kyber1024 hybrid exchange on session init. pub(crate) const SESSION_PROTOCOL_VERSION: u8 = 0x00; diff --git a/zssp/src/zssp.rs b/zssp/src/zssp.rs index e397565e1..4af147e81 100644 --- a/zssp/src/zssp.rs +++ b/zssp/src/zssp.rs @@ -15,7 +15,7 @@ use std::sync::atomic::{AtomicI64, AtomicU64, AtomicUsize, Ordering}; use std::sync::{Arc, Mutex, MutexGuard, RwLock, Weak}; use zerotier_crypto::aes::{Aes, AesGcm}; -use zerotier_crypto::hash::{SHA512, hmac_sha512_secret, hmac_sha512_secret256}; +use zerotier_crypto::hash::{hmac_sha512_secret, hmac_sha512_secret256, SHA512}; use zerotier_crypto::p384::{P384KeyPair, P384PublicKey}; use zerotier_crypto::secret::Secret; use zerotier_crypto::{random, secure_eq}; @@ -935,9 +935,10 @@ impl Context { let mut enc_start = ack_len; ack_len = append_to_slice(&mut ack, ack_len, alice_s_public_blob)?; - let mut gcm = AesGcm::new(&kbkdf256::( - &hmac_sha512_secret(noise_ck_es_ee.as_bytes(), hk.as_bytes()), - )); + let mut gcm = AesGcm::new(&kbkdf256::(&hmac_sha512_secret( + noise_ck_es_ee.as_bytes(), + hk.as_bytes(), + ))); gcm.reset_init_gcm(&reply_message_nonce); gcm.aad(&noise_h_next); gcm.crypt_in_place(&mut ack[enc_start..ack_len]); @@ -953,9 +954,7 @@ impl Context { enc_start = ack_len; ack_len = append_to_slice(&mut ack, ack_len, metadata)?; - let mut gcm = AesGcm::new(&kbkdf256::( - &noise_ck_es_ee_se_hk_psk, - )); + let mut gcm = AesGcm::new(&kbkdf256::(&noise_ck_es_ee_se_hk_psk)); gcm.reset_init_gcm(&reply_message_nonce); gcm.aad(&noise_h_next); gcm.crypt_in_place(&mut ack[enc_start..ack_len]); @@ -1041,9 +1040,10 @@ impl Context { let alice_static_public_blob = r.read_decrypt_auth( alice_static_public_blob_size, - kbkdf256::( - &hmac_sha512_secret(incoming.noise_ck_es_ee.as_bytes(), incoming.hk.as_bytes()), - ), + kbkdf256::(&hmac_sha512_secret( + incoming.noise_ck_es_ee.as_bytes(), + incoming.hk.as_bytes(), + )), &incoming.noise_h, &incoming_message_nonce, )?; @@ -1706,34 +1706,10 @@ fn mix_hash(h: &[u8; NOISE_HASHLEN], m: &[u8]) -> [u8; NOISE_HASHLEN] { /// These are the values we have assigned to the 5 variables involved in https://csrc.nist.gov/publications/detail/sp/800-108/final: /// K_in = key, i = 1u8, Label = b'Z'||b'T'||LABEL, Context = 0u8, L = 512u16 or 256u16 fn kbkdf512(key: &Secret) -> Secret { - hmac_sha512_secret( - key.as_bytes(), - &[ - 1, - b'Z', - b'T', - LABEL, - 0x00, - 0, - 2u8, - 0u8, - ], - ) + hmac_sha512_secret(key.as_bytes(), &[1, b'Z', b'T', LABEL, 0x00, 0, 2u8, 0u8]) } fn kbkdf256(key: &Secret) -> Secret<32> { - hmac_sha512_secret256( - key.as_bytes(), - &[ - 1, - b'Z', - b'T', - LABEL, - 0x00, - 0, - 1u8, - 0u8, - ], - ) + hmac_sha512_secret256(key.as_bytes(), &[1, b'Z', b'T', LABEL, 0x00, 0, 1u8, 0u8]) } fn prng32(mut x: u32) -> u32 {