-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add function to efficiently hash entire non-root subtrees to guts #329
base: master
Are you sure you want to change the base?
Changes from 1 commit
c8b199b
c85017d
ac6fb22
3c658bf
3e897f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,6 +409,18 @@ impl Output { | |
Hash(platform::le_bytes_from_words_32(&cv)) | ||
} | ||
|
||
fn hash(&self, is_root: bool) -> Hash { | ||
// debug_assert_eq!(self.counter, 0); | ||
let mut cv = self.input_chaining_value; | ||
let mut flags = self.flags; | ||
if is_root { | ||
flags |= ROOT; | ||
} | ||
self.platform | ||
.compress_in_place(&mut cv, &self.block, self.block_len, 0, flags); | ||
Hash(platform::le_bytes_from_words_32(&cv)) | ||
} | ||
|
||
fn root_output_block(&self) -> [u8; 2 * OUT_LEN] { | ||
self.platform.compress_xof( | ||
&self.input_chaining_value, | ||
|
@@ -977,6 +989,15 @@ impl Hasher { | |
Self::new_internal(IV, 0) | ||
} | ||
|
||
/// Construct a new `Hasher` with a start chunk | ||
fn new_with_start_chunk(start_chunk: u64) -> Self { | ||
Self { | ||
key: *IV, | ||
chunk_state: ChunkState::new(IV, start_chunk, 0, Platform::detect()), | ||
cv_stack: ArrayVec::new(), | ||
} | ||
} | ||
|
||
/// Construct a new `Hasher` for the keyed hash function. See | ||
/// [`keyed_hash`]. | ||
/// | ||
|
@@ -1246,7 +1267,7 @@ impl Hasher { | |
// also. Convert it directly into an Output. Otherwise, we need to | ||
// merge subtrees below. | ||
if self.cv_stack.is_empty() { | ||
debug_assert_eq!(self.chunk_state.chunk_counter, 0); | ||
// debug_assert_eq!(self.chunk_state.chunk_counter, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This must be disabled because the chunk counter can be set to a non zero value in the constructor now. |
||
return self.chunk_state.output(); | ||
} | ||
|
||
|
@@ -1265,11 +1286,11 @@ impl Hasher { | |
let mut output: Output; | ||
let mut num_cvs_remaining = self.cv_stack.len(); | ||
if self.chunk_state.len() > 0 { | ||
debug_assert_eq!( | ||
self.cv_stack.len(), | ||
self.chunk_state.chunk_counter.count_ones() as usize, | ||
"cv stack does not need a merge" | ||
); | ||
// debug_assert_eq!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This must be disabled since because the chunk counter does not necessarily start at 0, it's current value is no longer equivalent to the number of chunks. I don't think there is a way to reenable this except by adding an additional value to the state that tracks the start chunk. |
||
// self.cv_stack.len(), | ||
// self.chunk_state.chunk_counter.count_ones() as usize, | ||
// "cv stack does not need a merge" | ||
// ); | ||
output = self.chunk_state.output(); | ||
} else { | ||
debug_assert!(self.cv_stack.len() >= 2); | ||
|
@@ -1304,6 +1325,11 @@ impl Hasher { | |
self.final_output().root_hash() | ||
} | ||
|
||
fn finalize_node(&self, is_root: bool) -> Hash { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just exposes a way to create non root hashes |
||
let output = self.final_output(); | ||
output.hash(is_root) | ||
} | ||
|
||
/// Finalize the hash state and return an [`OutputReader`], which can | ||
/// supply any number of output bytes. | ||
/// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just exposes a way to create non root hashes