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])
| 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. |
| 50 | pub 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`. |
| 59 | pub fn seal_bundle( |
no outgoing calls