diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 6 | ||||
| -rw-r--r-- | src/test.rs | 8 |
2 files changed, 7 insertions, 7 deletions
@@ -841,11 +841,13 @@ pub fn keyed_hash(key: &[u8; KEY_LEN], input: &[u8]) -> Hash { /// [`Hasher::finalize_xof`]: struct.Hasher.html#method.finalize_xof /// [Argon2]: https://en.wikipedia.org/wiki/Argon2 /// [`Hasher::update_with_join`]: struct.Hasher.html#method.update_with_join -pub fn derive_key(context: &str, key_material: &[u8], output: &mut [u8]) { +pub fn derive_key<const N: usize>(context: &str, key_material: &[u8]) -> [u8; N] { let context_key = hash_all_at_once(context.as_bytes(), IV, DERIVE_KEY_CONTEXT).root_hash(); let context_key_words = platform::words_from_le_bytes_32(context_key.as_bytes()); let inner_output = hash_all_at_once(key_material, &context_key_words, DERIVE_KEY_MATERIAL); - OutputReader::new(inner_output).fill(output); + let mut ret = [0; N]; + OutputReader::new(inner_output).fill(&mut ret); + ret } fn parent_node_output( diff --git a/src/test.rs b/src/test.rs index cd46091..c0f327f 100644 --- a/src/test.rs +++ b/src/test.rs @@ -326,9 +326,8 @@ fn test_compare_reference_impl() { reference_hasher.finalize(&mut expected_out); // all at once - let mut test_out = [0; OUT]; - crate::derive_key(context, input, &mut test_out); - assert_eq!(test_out[..], expected_out[..]); + let test_out = crate::derive_key(context, input); + assert_eq!(test_out, expected_out); // incremental let mut hasher = crate::Hasher::new_derive_key(context); hasher.update(input); @@ -501,8 +500,7 @@ fn test_reset() { kdf.update(&[42; 3 * CHUNK_LEN + 7]); kdf.reset(); kdf.update(&[42; CHUNK_LEN + 3]); - let mut expected = [0; crate::OUT_LEN]; - crate::derive_key(context, &[42; CHUNK_LEN + 3], &mut expected); + let expected = crate::derive_key(context, &[42; CHUNK_LEN + 3]); assert_eq!(kdf.finalize(), expected); } |
