-
Notifications
You must be signed in to change notification settings - Fork 1
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
feature: hasher -> update -> finalize paradigm #18
Comments
the following equality should hold: hasher = Message::new("some data") should be the same digest as: Hash("some data" + "more data") |
Check out this exact version of what we need from kangaroo12: // Hash an input incrementally.
let mut hasher = kangarootwelve_xkcp::Hasher::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
assert_eq!(hasher.finalize(), kangarootwelve_xkcp::hash(b"foobarbaz")); |
the other change that needs to happen is that |
Actually now that I think about it, the sponge is fine where it is. What we need to do instead is actually just update In
pub trait UpdateFinalize {
// it returns nothing and simply appends the write data into self.data, thats it
fn update(self, write_data: &[u8]);
// internally it calls compute_sha3_hash, passing in self.data and returns the result
fn finalize(self) -> Vec<u8>;
} in
impl UpdateFinalize for Message {
fn update();
fn finalize();
} This is far simpler to carry out this way and aligns well with the rest of how the library is constructed. Some notes: |
What does this do and why is it useful?this will eventually give us this syntax: let m = Message::new("Initial data");
m.update("More data")
m.update("Even more data") And then when we finalize, we essentially get the hash result of This is useful for all sorts of applications in cryptography when we dont necessarily know the entire message that we need to process before hand. When we fix this will effectively solve our issue of having to store the entire key which is equal to the length of the message into the heap |
I am just wondering if the signature of the |
I notice that in the comments for |
When we are testing the Are we trying to make this line of code work? let mut m = Message::new();
m.update("foo");
m.update("bar");
m.update("baz");
assert_eq!(m.finalize(), vec!["foobarbaz"].compute_hash_sha3(&SecParam::D256)); |
KangarooTwelve uses a function signature of I will use a similar arguments for this |
I see that |
When we are testing the Are we trying to make this line of code work? let mut m = Message::new();
m.update("foo");
m.update("bar");
m.update("baz");
assert_eq!(m.finalize(), vec!["foobarbaz"].compute_hash_sha3(&SecParam::D256)); When a new |
Thats a great question. For this issue, when the message is first created, lets assume that the user will set the security parameter themselves beforehand. So add this extra line: let mut m = Message::new();
m.d = &D256; // or similar
m.update("foo");
m.update("bar");
m.update("baz");
assert_eq!(m.finalize(), vec!["foobarbaz"].compute_hash_sha3(&SecParam::D256)); You can assume this for any other |
Thank you. |
Hi there, I added a fix feature for the above finalize paradigm under #fix/issue18. |
Hey right on thank you! Can you please open a pull request for this? We have #55 open still, but it has been some time since we have worked on that, you might find it easier to start with a fresh PR. Let me know if you have any questions! |
Similar to openSSL, the Message type should have traits that produce digests only when specifically asked. For instance, the Message should be able to absorb new data at any time, and produce a sha3 digest only when called.
Ex:
or something similar
The text was updated successfully, but these errors were encountered: