diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-11-26 17:28:15 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-11-26 17:28:15 -0800 |
commit | 0cbb542ccd3b62e7b099ae01e5d58418c254862c (patch) | |
tree | 861c958db08d37abb141137f0de0758a080dee28 /src/lib.rs | |
parent | 82a4ce577b9da17e7eccc78b04b7e2e96b809b75 (diff) | |
download | geniza-0cbb542ccd3b62e7b099ae01e5d58418c254862c.tar.gz geniza-0cbb542ccd3b62e7b099ae01e5d58418c254862c.zip |
move make_discovery_key() to lib.rs
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -52,3 +52,21 @@ mod protocol; pub use protocol::*; pub mod network_msgs; pub mod metadata_msgs; + + +use crypto::digest::Digest; +use crypto::blake2b::Blake2b; + +/// Helper to calculate a discovery key from a public key. 'key' should be 32 bytes; the returned +/// array will also be 32 bytes long. +/// +/// dat discovery keys are calculated as a BLAKE2b "keyed hash" (using the passed key) of the string +/// "hypercore" (with no trailing null byte). +pub fn make_discovery_key(key: &[u8]) -> Vec<u8> { + let mut discovery_key = [0; 32]; + let mut hash = Blake2b::new_keyed(32, key); + hash.input(&"hypercore".as_bytes()); + hash.result(&mut discovery_key); + discovery_key.to_vec() +} + |