git clone https://garage44.eu/jeroen/pinnacle.gitcartopolis-agent · 2026-11-30T14:44:06Z
style(crypto,wifi): rustfmt
crypto/src/aes.rs | 1 -
crypto/src/tests.rs | 35 +++++++++++++++++++++++++++-------
wifi/src/wpa.rs | 55 +++++++++++++++++++++++++++++++++++++++++++----------
3 files changed, 73 insertions(+), 18 deletions(-)
diff --git a/crypto/src/aes.rs b/crypto/src/aes.rs
index b089d78..91837bc 100644
--- a/crypto/src/aes.rs
+++ b/crypto/src/aes.rs
@@ -289,7 +289,6 @@ pub fn unwrap(kek: &[u8], wrapped: &[u8], out: &mut [u8]) -> bool {
true
}
-
fn add(state: &mut [u8; 16], key: &[u8; 16]) {
for (s, k) in state.iter_mut().zip(key) {
*s ^= k;
diff --git a/crypto/src/tests.rs b/crypto/src/tests.rs
index dcb8bc0..9a7e895 100644
--- a/crypto/src/tests.rs
+++ b/crypto/src/tests.rs
@@ -542,14 +542,20 @@ fn aes_siv_rfc5297() {
#[test]
fn sha1_hmac_and_wpa2s_password_key() {
- assert_eq!(sha1::Sha1::digest(b"abc").to_vec(), hex("a9993e364706816aba3e25717850c26c9cd0d89d"));
+ assert_eq!(
+ sha1::Sha1::digest(b"abc").to_vec(),
+ hex("a9993e364706816aba3e25717850c26c9cd0d89d")
+ );
let long = [b'a'; 1000];
let mut h = sha1::Sha1::new();
for _ in 0..1000 {
h.update(&long);
}
// FIPS 180's million a's.
- assert_eq!(h.finish().to_vec(), hex("34aa973cd4c4daa4f61eeb2bdbad27316534016f"));
+ assert_eq!(
+ h.finish().to_vec(),
+ hex("34aa973cd4c4daa4f61eeb2bdbad27316534016f")
+ );
// RFC 2202, case 1.
assert_eq!(
sha1::hmac(&[0x0b; 20], &[b"Hi There"]).to_vec(),
@@ -558,11 +564,20 @@ fn sha1_hmac_and_wpa2s_password_key() {
// IEEE 802.11-2020, J.4.2: a network's key from its password and name.
let mut psk = [0u8; 32];
sha1::pbkdf2_sha1(b"password", b"IEEE", 4096, &mut psk);
- assert_eq!(psk.to_vec(), hex("f42c6fc52df0ebef9ebb4b90b38a5f902e83fe1b135a70e23aed762e9710a12e"));
+ assert_eq!(
+ psk.to_vec(),
+ hex("f42c6fc52df0ebef9ebb4b90b38a5f902e83fe1b135a70e23aed762e9710a12e")
+ );
sha1::pbkdf2_sha1(b"ThisIsAPassword", b"ThisIsASSID", 4096, &mut psk);
- assert_eq!(psk.to_vec(), hex("0dc0d6eb90555ed6419756b9a15ec3e3209b63df707dd508d14581f8982721af"));
+ assert_eq!(
+ psk.to_vec(),
+ hex("0dc0d6eb90555ed6419756b9a15ec3e3209b63df707dd508d14581f8982721af")
+ );
sha1::pbkdf2_sha256(b"password", b"salt", 2, &mut psk);
- assert_eq!(psk.to_vec(), hex("ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43"));
+ assert_eq!(
+ psk.to_vec(),
+ hex("ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43")
+ );
}
#[test]
@@ -573,7 +588,10 @@ fn aes_decrypts_and_wraps_keys() {
let mut block = hex("69c4e0d86a7b0430d8cdb78070b4c55a");
a.decrypt_blocks(&mut block);
assert_eq!(block, hex("00112233445566778899aabbccddeeff"));
- let a = aes::Aes::new(&hex("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")).unwrap();
+ let a = aes::Aes::new(&hex(
+ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
+ ))
+ .unwrap();
let mut block = hex("8ea2b7ca516745bfeafc49904b496089");
a.decrypt_blocks(&mut block);
assert_eq!(block, hex("00112233445566778899aabbccddeeff"));
@@ -582,7 +600,10 @@ fn aes_decrypts_and_wraps_keys() {
let key = hex("00112233445566778899aabbccddeeff");
let mut wrapped = [0u8; 24];
assert!(aes::wrap(&kek, &key, &mut wrapped));
- assert_eq!(wrapped.to_vec(), hex("1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5"));
+ assert_eq!(
+ wrapped.to_vec(),
+ hex("1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5")
+ );
let mut back = [0u8; 16];
assert!(aes::unwrap(&kek, &wrapped, &mut back));
assert_eq!(back.to_vec(), key);
diff --git a/wifi/src/wpa.rs b/wifi/src/wpa.rs
index 2c105f4..c2e5b69 100644
--- a/wifi/src/wpa.rs
+++ b/wifi/src/wpa.rs
@@ -86,7 +86,10 @@ impl Rsn {
};
let group = suite(body, at);
at += 4;
- let count = |b: &[u8], at: usize| b.get(at..at + 2).map(|c| usize::from(u16::from_le_bytes([c[0], c[1]])));
+ let count = |b: &[u8], at: usize| {
+ b.get(at..at + 2)
+ .map(|c| usize::from(u16::from_le_bytes([c[0], c[1]])))
+ };
let n = count(body, at)?;
at += 2;
let pairwise: Vec<Option<u8>> = (0..n).map(|i| suite(body, at + 4 * i)).collect();
@@ -200,7 +203,14 @@ impl Supplicant {
/// For joining the access point at `ap` from `own` with the network's
/// key `pmk` ([`psk`]); `theirs` the RSN element its beacon carried;
/// `snonce` 32 random bytes.
- pub fn new(pmk: [u8; 32], akm: Akm, own: [u8; 6], ap: [u8; 6], theirs: &[u8], snonce: [u8; 32]) -> Supplicant {
+ pub fn new(
+ pmk: [u8; 32],
+ akm: Akm,
+ own: [u8; 6],
+ ap: [u8; 6],
+ theirs: &[u8],
+ snonce: [u8; 32],
+ ) -> Supplicant {
Supplicant {
pmk,
akm,
@@ -296,7 +306,11 @@ impl Supplicant {
/// The PTK from the PMK, both addresses and both nonces (12.7.1.3).
fn derive(&self, anonce: &[u8; 32]) -> Ptk {
- let (a1, a2) = if self.own < self.ap { (self.own, self.ap) } else { (self.ap, self.own) };
+ let (a1, a2) = if self.own < self.ap {
+ (self.own, self.ap)
+ } else {
+ (self.ap, self.own)
+ };
let (n1, n2) = if self.snonce[..] < anonce[..] {
(self.snonce, *anonce)
} else {
@@ -495,7 +509,12 @@ mod tests {
let mut data = rsn.to_vec();
data.extend_from_slice(&[0xdd, 22, 0x00, 0x0f, 0xac, 1, 0x01, 0]);
data.extend_from_slice(>K);
- self.frame(PAIRWISE | ACK | MIC | INSTALL | SECURE | ENCRYPTED, replay, &ANONCE, &data)
+ self.frame(
+ PAIRWISE | ACK | MIC | INSTALL | SECURE | ENCRYPTED,
+ replay,
+ &ANONCE,
+ &data,
+ )
}
fn checks(&self, frame: &[u8]) -> bool {
@@ -513,12 +532,23 @@ mod tests {
fn the_4_way_handshake() {
let ap = Authenticator::new("password");
let mut s = supplicant("password");
- let Ok(actions) = s.receive(&ap.message1()) else { panic!() };
- let [Action::Send(message2)] = actions.as_slice() else { panic!("{actions:?}") };
+ let Ok(actions) = s.receive(&ap.message1()) else {
+ panic!()
+ };
+ let [Action::Send(message2)] = actions.as_slice() else {
+ panic!("{actions:?}")
+ };
// Its MIC as Python's hmac and hashlib make it, for these inputs.
- assert_eq!(message2[MIC_AT..MIC_AT + 16], hex("688787e519a79f7230dac64e7f72e155"));
+ assert_eq!(
+ message2[MIC_AT..MIC_AT + 16],
+ hex("688787e519a79f7230dac64e7f72e155")
+ );
assert!(ap.checks(message2));
- assert_eq!(&message2[DATA..], theirs().as_slice(), "our RSN element in message 2");
+ assert_eq!(
+ &message2[DATA..],
+ theirs().as_slice(),
+ "our RSN element in message 2"
+ );
let actions = s.receive(&ap.message3(2, &theirs())).unwrap();
let tk = hex("5b88694a8268c05bfe4c53de87b97d81");
@@ -532,9 +562,14 @@ mod tests {
}
);
assert_eq!(actions[3], Action::Connected);
- let Action::Send(message4) = &actions[0] else { panic!() };
+ let Action::Send(message4) = &actions[0] else {
+ panic!()
+ };
assert!(ap.checks(message4));
- assert_eq!(u16::from_be_bytes([message4[INFO], message4[INFO + 1]]), PAIRWISE | MIC | SECURE | 2);
+ assert_eq!(
+ u16::from_be_bytes([message4[INFO], message4[INFO + 1]]),
+ PAIRWISE | MIC | SECURE | 2
+ );
assert!(s.connected());
// A new group key, later.