Maximum SHA-1 Hash Performance Tips in Java

I am writing a Java library that should compute SHA-1 hashes. During a common task, the JVM spends about 70% of its time at sun.security.provider.SHA.implCompress, 10% at java.util.zip.Inflater.inflateand 2% at sun.security.provider.ByteArrayAccess.b2iBig64. (According to the NetBeans Profiler.)

I can’t find the right Google search keywords to get relevant results. I am not very good at SHA-1 hashing algorithm. How can I get maximum performance from SHA-1 MessageDigest? Is there a specific piece size that I have to digest, or several values ​​of certain sizes that I should try?

To answer some of the questions you are thinking about, ask:

  • Yes, I digest when I read files ( MessageDigest.update), so bytes only digest once.
  • SHA-1 collections are used as checksums, usually for files that must be zlib / inflated.
  • No, I can’t use another hash.
  • Yes, I know that zlib already uses checksums, but external requirements determine the use of SHA-1 hashes on top of this. I can’t come up with a good reason why (+1, if possible) :-)
+5
source share
3 answers

SHA-1 has a block size of 64 bytes, so concise ones are probably best; otherwise, the implementation will have to copy the partial blocks to the buffers.

? zlib SHA-1 , - java.util.concurrent.SynchronousQueue, 64- . , , ​​ .

( BlockingQueue, , , . , , zlib , , , SynchronousQueue.)

, , -, -? , , , , , . , , readahead, .

, - - ; , . , .: -)

+1

, , C. SHA1.

+1

? , , , IO NIO.

0

All Articles