I'm writing a Java library that needs to compute SHA-1 hashes. During a common task, the JVM spends about 70% of its time in sun.security.provider.SHA.implCompress
, 10% in java.util.zip.Inflater.inflate
, and 2% in sun.security.provider.ByteArrayAccess.b2iBig64
. (According to NetBeans profiler.)
I can't seem to get the Google search keywords right to get relevant results. I'm not very familiar with the SHA-1 hash algorithm. How can I get the most performance out of an SHA-1 MessageDigest
? Is there a certain chunk size I should be digesting, or multiples of certain sizes I should try?
To answer some questions you're thinking about asking:
MessageDigest.update
), so bytes are only digested once.According to SHA-1 standard, a message digest is evaluated utilizing padded message. The evaluation utilizes two buffers, each comprises of five 32 bit words and a sequence of eighty 32 bit words.
While the speed of SHA1 is slow in comparison of MD5's speed.
SHA-256 is 15.5% slower than SHA-1 for short strings and 23.4% for longer strings. SHA-512 is 51.7% slower that SHA-1 for short strings and 20% for longer.
The hash size for the SHA1 algorithm is 160 bits.
Maybe you can call out to native code written in C. There must be a ton of super optimized SHA1 libraries available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With