-
Notifications
You must be signed in to change notification settings - Fork 354
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
Hash struct lacks an Ord implementation #202
Comments
Interesting question. My instinct is that for most applications where constant-time ordering isn't an issue, the easiest thing is to convert to |
For what it's worth, I've often thought about splitting out the |
My understanding is not all of const-generics have landed, and RustCrypto need more than currently offered even by nightly. |
@oconnor663 Hi, is there any work done on that? I am trying to use |
I haven't done any work on this myself, no. It looks like the right way to do it will be to replace our dependency on In the meantime, you might want to convert |
Shouldn't #203 be merged before eventually finding a better alternative? Also why is a constant-time After thinking a bit about how it could be done when comparing 2 Hash I realised that having a constant-time implementation for this would require to always go through the whole byte array. This would be the equivalent of the worst case scenario of the default implementation which stops the comparison whenever the bytes aren't equal, so I don't see why that would make sense. |
Same reason Anyway, I'm glad there's already an issue open here with something of a plan, I'll take a look at |
Basically whenever Blake3 is used as an HMAC you really really want CT comparison https://threatpost.com/timing-attack-google-keyczar-library-060209/72738/ I'd also say that I doubt this could be a bottleneck anywhere, it's 4 words xoring them instead of branching over them might even be faster |
One issue to keep in mind here is that, even if
Even if comparing individual MACs is constant time, the tree structure itself still has a timing leak. If I query it with a MAC that's less than We could probably come up with some way to fix the tree. We could add a requirement that all the leaves are at the same depth, and we could design some sort of "empty node" concept to make that work. I'm sure someone somewhere has done this before, but it's a very exotic problem to be solving, and no ordinary tree-map implementation is going to do anything like this. So one worry I have about a constant-time |
I agree with that concern. Even in a non-MAC scenario it could be a problem - if you can fetch data based on it's hash, the time until cache miss could reveal blocks that are present in the cache.
I don't think I have an actual use case for a constant-time |
This #267 (comment) seems relevant over here.
So the recommendation for types that want an |
Yeah if you need to sort hashes or something like that, my instinct is to convert them to |
@oconnor663 One mild annoyance with using |
Yeah, in practice I make my own wrapper around In particular I'm finding this issue not a big deal because I also am adding implementations for serialization and other nonsense that doesn't belong in the blake3 crate, and there's no |
Without an
Ord
implementation (or even aHash
implementation)blake3::Hash
values cannot be used as keys inBTreeMap
s orHashMap
s, among many other valid uses for (vartime) orderings.To be safe; these implementations ought to be constant-time. Either way, the subtle crate provides traits which are explicitly intended for constant time equality and ordering.
As a workaround, I'm using the newtype pattern to implement these traits on my own
OrdHash
type.If a PR would be welcome for this addition, should the implementation be constant time or variable?
The text was updated successfully, but these errors were encountered: