rpc: switch GlobalId mac to KMAC.

This commit is contained in:
Nick Mathewson 2023-06-06 15:35:24 -04:00
parent 66a72370d1
commit de423f6a36
2 changed files with 5 additions and 15 deletions

View File

@ -36,7 +36,7 @@ rand = "0.8"
serde = { version = "1.0.103", features = ["derive"] }
serde_json = "1.0.50"
thiserror = "1"
tiny-keccak = { version = "2", features = ["k12"] }
tiny-keccak = { version = "2", features = ["kmac"] }
tor-async-utils = { path = "../tor-async-utils", version = "0.1.1" }
tor-bytes = { path = "../tor-bytes", version = "0.7.1" }
tor-error = { path = "../tor-error", version = "0.5.1" }

View File

@ -64,20 +64,10 @@ impl MacKey {
///
/// The current construction allows `out` to be any length.
fn mac(&self, inp: &[u8], out: &mut [u8]) {
use tiny_keccak::{Hasher as _, KangarooTwelve as K12};
// This is the HopMAC construction from draft-irtf-cfrg-kangarootwelve-10:
//
// HopMAC(Key, M, C, L) = K12(Key, K12(M, C, 32), L)
//
// TODO RPC: Just use KMAC or something.
let mut inner = K12::new(b"artirpc globalid");
let mut hash = [0_u8; 32];
inner.update(inp);
inner.finalize(&mut hash);
let mut outer = K12::new(hash);
outer.update(&self.key[..]);
outer.finalize(out);
use tiny_keccak::{Hasher as _, Kmac};
let mut mac = Kmac::v128(&self.key[..], b"artirpc globalid");
mac.update(inp);
mac.finalize(out);
}
}