Add keyed bao methods - #77
Open
cryptoquick wants to merge 3 commits into
Open
Conversation
Collaborator
|
I haven't really looked at the code yet, but what it does is definitely something that is in scope for this crate. So thank you! |
Author
|
I will be testing it out in my Carbonado v2 work, and will let you know how well it works! |
Standard and keyed modes share one IO implementation through compile time strategy types instead of Option branches. Public keyed APIs are unchanged. Adds comments and hash_strategy naming for clarity. Fixes dead_code warnings in validate only builds.
Trim comments to bao-tree style, hide strategy types from rustdoc, and add Keyed decode type aliases. Public keyed APIs unchanged.
Author
|
Unless I discover something truly egregious in my Lean proving efforts and other end to end testing, I consider this work ready for review. |
Collaborator
|
There are a few minor things I would want changed, so I am going to make a branch based on this and let you review. |
Collaborator
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds keyed BLAKE3 mode so merkle roots depend on a 32-byte key, not just the data. Same bytes with different keys produce different roots — useful when you want the tree to commit to out-of-band metadata (e.g. a Carbonado format byte) without putting that metadata in the blob itself.
The design follows BLAKE3’s own split: existing APIs are unchanged, and new keyed_* wrappers take an extra key: &[u8; 32] the same way blake3::keyed_hash relates to blake3::hash. BaoTree is unchanged; the wire format is unchanged. The key is never serialized into the encoded stream — both sides must agree on it out of band.
API surface
Core (lib.rs): keyed_hash_subtree, keyed_parent_cv
Sync I/O (io/sync.rs): keyed_outboard, keyed_outboard_post_order, keyed_encode_ranges_validated, keyed_decode_ranges, keyed_valid_ranges, plus CreateOutboard::create_keyed / create_sized_keyed / init_from_keyed
Async I/O (io/fsm.rs): async equivalents of the above
In-memory outboards (io/outboard.rs): PostOrderMemOutboard::create_keyed, PreOrderMemOutboard::create_keyed
Internally, keyed and unkeyed paths share the same helpers with an Option<&[u8; 32]> — no duplicated hash logic.
Usage
Root hashes match blake3::keyed_hash(&key, &data) for full blobs.
Tests
55 keyed_* tests (124 total passing), covering sync and FSM paths:
• Low-level primitives cross-checked against BLAKE3 hazmat
• Full and partial encode/decode roundtrips, including proptests
• Wrong-key rejection on encode and decode
• Cross-mode rejection (keyed encode + unkeyed decode, and the reverse)
• Outboard construction via every public entry point (create_keyed, create_sized_keyed, init_from_keyed, keyed_outboard, keyed_outboard_post_order)
• keyed_valid_ranges positive, wrong-key, and corrupted-outboard cases
Breaking changes
None. All existing functions and types behave as before.
Closes #76