Skip to content
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

Made Hash store a byte array, so Node can store a Hash, rather than a byte slice #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

FreddieRidell
Copy link
Contributor

🙋 feature

Key Changes:

  • Refactors crypto::hash::Hash to contain a [u8; 32], rather than Blake2bResult
  • Refactors storage::node::Node.hash to be a Hash, rather than a Vec<u8>

@@ -112,6 +140,12 @@ impl DerefMut for Hash {
}
}

impl fmt::Display for Hash {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:x?}", self.hash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for compat with the JS version we should probably use pretty-fmt here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I thought there was somewhere I'd missed that!

Related question: are we aiming for full storage API compatibility with the js version, as well as network API compatibility? If so are the JS maintainers aware that any braking change they make will also break the rust version?

@yoshuawuyts
Copy link
Contributor

Thanks heaps for this PR! Unfortunately in its current state we can't accept it, because it opens us up to timing attacks.

Keeping Blake2bResult around was a deliberate choice, as the Eq and PartialEq methods are guaranteed to be constant-time. By moving the bytes over to a regular buffer we drop that property, which isn't great. (ref)

I do really like some of the ergonomics improvements introduced here; typing .as_bytes().into() gets old fast. I wonder if perhaps we introduce some conversion traits we could achieve similar benefits without losing any (cryptographic) properties.

Thanks again so much; overall I really like this direction!

@FreddieRidell
Copy link
Contributor Author

Ahh, I should have asked before I picked a TODO to work on, is there a better place to ask in future?

It looks like like Blake2BResult uses constant_time_eq to do its equality check, it should be pretty easy to adapt this solution to use that function. If I made that change would that make this PR acceptable?

@FreddieRidell FreddieRidell force-pushed the replace-byte-slice-with-hash-blake-hash branch from 053a054 to 19dbe3d Compare May 7, 2019 17:44
@yoshuawuyts
Copy link
Contributor

Ahh, I should have asked before I picked a TODO to work on, is there a better place to ask in future?

Opening an issue is a good way to go about this! Otherwise I'm also around on Freenode and Discord for synchronous chat.

If I made that change would that make this PR acceptable?

Possibly! But looking at this patch I'm thinking that adding more conversion traits on the existing codebase could probably get us the closest to our intended goal with the fewest amount of changes required.

@FreddieRidell
Copy link
Contributor Author

Possibly!

I've switched Hash to manually implementing PartialEq and Eq using constant_time_eq, let me know what you think?

But looking at this patch I'm thinking that adding more conversion traits on the existing codebase could probably get us the closest to our intended goal with the fewest amount of changes required.

Do you mean implementing From for Hash -> Blake2bResult and stuff like that?

@bltavares
Copy link
Member

@yoshuawuyts sorry to bother, but I'm wondering how do you feel in regards of the new constant hash verification in this current PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants