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

A way to get a HashFunction backed by a MessageDigest algorithm #5990

Open
kevinb9n opened this issue Mar 28, 2022 · 11 comments
Open

A way to get a HashFunction backed by a MessageDigest algorithm #5990

kevinb9n opened this issue Mar 28, 2022 · 11 comments

Comments

@kevinb9n
Copy link
Contributor

Another way to satisfy #3960

@ritikBhandari
Copy link

Is MessageDigest the same as MD5 algo?

@lowasser
Copy link
Contributor

MessageDigest includes, but is not limited to, MD5.

@ritikBhandari
Copy link

mdalgo

Among these, which MD algo do we have to back HashFunction with? and which one are we currently using?

@lowasser
Copy link
Contributor

HashFunction is an interface with many implementations, including those three (Hashing.md5(), Hashing.sha1(), Hashing.sha256()). Those three are backed by MessageDigest; the others are not.

@lowasser
Copy link
Contributor

The point is that we don't expose a utility in general to allow any MessageDigest algorithm to be used as a HashFunction.

@ritikBhandari
Copy link

HashFunction is an interface with many implementations, including those three (Hashing.md5(), Hashing.sha1(), Hashing.sha256()). Those three are backed by MessageDigest; the others are not.

So now do we have to back the other ones as well according to the issue raised?

@lowasser
Copy link
Contributor

No, there's no plan to change other implementations of HashFunction. This issue is just about whether or not we should expose a way to make a HashFunction from any MessageDigest.

@ritikBhandari
Copy link

Okay! Got it.
Thank you :)

@cpovirk cpovirk added the P3 no SLO label Mar 29, 2022
@nkkolluru
Copy link

@cpovirk Is there any documentation as to what label P3 means?

@nkkolluru
Copy link

hello! Is the decision to add new API method(s) to Hashing, to support creating a HashFunction from any MessageDigest algorithm taken? Would there be a design process?

@google google deleted a comment from smartdengjie Oct 18, 2022
@vorburger
Copy link
Member

Just FTR for anyone else looking for this in the future, perhaps this analysis could be useful background:

I've poked around this space while wondering whether to add support for more hash functions here e.g. for this (related to the multihash tagged lines of this table, based on jbenet/random-ideas#1) e.g. for the MessageDigest that Guava does not "expose" (intentionally), but which are available at least in the Java 21+ JDK:

I ultimately concluded that, at least for my current application, there was really no need for wanting or needing to do this... but YMMV, of course. It probably boils down to whether you (externally) "have" to support certain hash functions, or whether your application can "choose" which one it wants to support.

In the former case, it could be "handy" to implement was this FR suggests. But in the latter (and my) case, I've opted to not support SHA-224, SHA-384, SHA-512/224, SHA-512/256 and stick to SHA-256 & SHA-512, only. (BTW all those are sometimes called SHA-2 sha2-224, sha2-384, sha2-512-224, sha2-512-256 elsewhere; it took at least me a while to dig this!)

As for SHA3-* (and #3960), after reading "sha3 not being a very good choice" here, and noticing https://developers.google.com/tink/protect-data-from-tampering#java (currently) "recommend[ing] the HMAC_SHA256" (=sha2-256), I didn't see any interest in supporting that either by writing a custom Guava HashFunction for it.

Just recording this here in case it could be of interest to other Guava users who are investigating how to add more JDK MessageDigest-based HashFunction implementations in the future - you may or may not actually need & want to do that.

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

No branches or pull requests

6 participants