From b0788b62d95cf8c45ad2dca4e0a398de0a30b49d Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 20 Oct 2023 15:37:36 -0400 Subject: [PATCH] Add a 384-bit hash to V1 identity. --- src/x25519.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/x25519.rs b/src/x25519.rs index 6ae8e2f..47eafbf 100644 --- a/src/x25519.rs +++ b/src/x25519.rs @@ -20,7 +20,7 @@ use zerotier_common_utils::blob::Blob; use zerotier_common_utils::error::InvalidParameterError; use zerotier_common_utils::hex; use zerotier_common_utils::tofrombytes::ToFromBytes; -use zerotier_crypto_glue::hash::SHA512; +use zerotier_crypto_glue::hash::{SHA384, SHA512}; use zerotier_crypto_glue::salsa::Salsa; use zerotier_crypto_glue::x25519::*; @@ -175,6 +175,19 @@ impl Identity { false } } + + /// Get a SHA384 hash of all this identity's elements but with the address overwriting the first 5 bytes. + /// This is for use with CAMP and modern federated root backplanes that require all identity types to + /// have a full length 384-bit address. + pub fn address384(&self) -> [u8; 48] { + let mut a384 = SHA384::new(); + a384.update(&self.address.0); + a384.update(&self.ecdh); + a384.update(&self.eddsa); + let mut a384 = a384.finish(); + a384[..5].copy_from_slice(&self.address.0); + a384 + } } impl ToString for Identity {