rpc: switch GlobalId mac to KMAC.
This commit is contained in:
parent
66a72370d1
commit
de423f6a36
|
@ -36,7 +36,7 @@ rand = "0.8"
|
||||||
serde = { version = "1.0.103", features = ["derive"] }
|
serde = { version = "1.0.103", features = ["derive"] }
|
||||||
serde_json = "1.0.50"
|
serde_json = "1.0.50"
|
||||||
thiserror = "1"
|
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-async-utils = { path = "../tor-async-utils", version = "0.1.1" }
|
||||||
tor-bytes = { path = "../tor-bytes", version = "0.7.1" }
|
tor-bytes = { path = "../tor-bytes", version = "0.7.1" }
|
||||||
tor-error = { path = "../tor-error", version = "0.5.1" }
|
tor-error = { path = "../tor-error", version = "0.5.1" }
|
||||||
|
|
|
@ -64,20 +64,10 @@ impl MacKey {
|
||||||
///
|
///
|
||||||
/// The current construction allows `out` to be any length.
|
/// The current construction allows `out` to be any length.
|
||||||
fn mac(&self, inp: &[u8], out: &mut [u8]) {
|
fn mac(&self, inp: &[u8], out: &mut [u8]) {
|
||||||
use tiny_keccak::{Hasher as _, KangarooTwelve as K12};
|
use tiny_keccak::{Hasher as _, Kmac};
|
||||||
// This is the HopMAC construction from draft-irtf-cfrg-kangarootwelve-10:
|
let mut mac = Kmac::v128(&self.key[..], b"artirpc globalid");
|
||||||
//
|
mac.update(inp);
|
||||||
// HopMAC(Key, M, C, L) = K12(Key, K12(M, C, 32), L)
|
mac.finalize(out);
|
||||||
//
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue