MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / derive_mac_key

Function derive_mac_key

nodedb-cluster/src/auth/bundle.rs:50–56  ·  view source on GitHub ↗

Derive the MAC key as `cluster_secret XOR token_hash`. Both inputs are exactly 32 bytes. The XOR ensures neither value alone is sufficient to forge a MAC — an attacker who has the cluster secret but not the token (or vice versa) cannot produce a valid MAC.

(cluster_secret: &[u8; 32], token_hash: &[u8; 32])

Source from the content-addressed store, hash-verified

48/// is sufficient to forge a MAC — an attacker who has the cluster secret
49/// but not the token (or vice versa) cannot produce a valid MAC.
50pub fn derive_mac_key(cluster_secret: &[u8; 32], token_hash: &[u8; 32]) -> [u8; 32] {
51 let mut key = [0u8; 32];
52 for i in 0..32 {
53 key[i] = cluster_secret[i] ^ token_hash[i];
54 }
55 key
56}
57
58/// Wrap `bundle_bytes` in an `AuthenticatedJoinBundle`.
59pub fn seal_bundle(

Callers 3

seal_bundleFunction · 0.85
open_bundleFunction · 0.85

Calls

no outgoing calls

Tested by 1