-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wangjiahan
committed
Apr 28, 2024
1 parent
29621cc
commit a4d20c4
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
fn main() { | ||
let hash1 = blake3::hash(b"foobarbaz"); | ||
|
||
let mut hasher = blake3::Hasher::new(); | ||
hasher.update(b"foo"); | ||
hasher.update(b"bar"); | ||
hasher.update(b"baz"); | ||
let hash2 = hasher.finalize(); | ||
assert_eq!(hash1, hash2); | ||
|
||
let mut output = [0; 1000]; | ||
let mut output_reader = hasher.finalize_xof(); | ||
output_reader.fill(&mut output); | ||
assert_eq!(hash1, output[..32]); | ||
|
||
println!("{}", hash1); | ||
|
||
let example_key = [42u8; 32]; | ||
let mac1 = blake3::keyed_hash(&example_key, b"foobarbaz"); | ||
|
||
let mut hasher = blake3::Hasher::new_keyed(&example_key); | ||
hasher.update(b"foobarbaz"); | ||
let mac2 = hasher.finalize(); | ||
assert_eq!(mac1, mac2); | ||
println!("{}", mac1); | ||
|
||
const EMAIL_CONTEXT: &str = "BLAKE3 example 2020-01-07 17:10:44 email key"; | ||
const API_CONTEXT: &str = "BLAKE3 example 2020-01-07 17:11:21 API key"; | ||
let email_key = blake3::derive_key(EMAIL_CONTEXT, &example_key); | ||
let api_key = blake3::derive_key(API_CONTEXT, &example_key); | ||
assert_ne!(email_key, api_key); | ||
} |