1

I am studying at night graduate school.

While studying the cryptographic hash function, I found information that the speed of the SHA3 hash function is faster than the speed of the SHA2 hash function.

So, using JMH benchmarking in actual JAVA, I tried to compare the performance of SHA512/256 of SHA2 and SHAKE256 of SHA3 series, but there doesn't seem to be much difference than I thought.

The library I used and the source code I wrote are as follows.

  1. SHA512-256
import java.security.MessageDigest;

public static byte[] digest(byte[] data) throws NoSuchAlgorithmException 
{

    CryptoProvider.setupIfNeeded();

    java.security.MessageDigest digest = java.security.MessageDigest.getInstance("SHA512/256");
    digest.update(Arrays.copyOf(data, data.length));
    return digest.digest();

}
  1. SHAKE256 (use 2 methods)
import org.bouncycastle.crypto.digests.SHAKEDigest;

public static byte[] shakeDigest(byte[] data, int returnLength) throws NoSuchAlgorithmException 
{

    CryptoProvider.setupIfNeeded();

    SHAKEDigest digest = new SHAKEDigest(256);
    byte[] hashBytes = new byte[returnLength];

    digest.update(data, 0, data.length);
    digest.doFinal(hashBytes, 0);
    digest.reset();

    return Arrays.copyOf(hashBytes, returnLength);

}

import com.github.aelstad.keccakj.fips202.Shake256;

public static byte[] shakeDigest2(byte[] data, int returnLength) throws Exception 
{

    CryptoProvider.setupIfNeeded();

    Shake256 digest = new Shake256();
    digest.getAbsorbStream().write(data);

    byte[] hashBytes = new byte[returnLength];
    digest.getSqueezeStream().read(hashBytes);
    digest.reset();

    return Arrays.copyOf(hashBytes, returnLength);

}

I'm wondering if I'm missing something, or if there exists a SHAKE256 library that's closer to perfection than the one I used.

Please help. Thank you.

President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
Luffy Choi
  • 31
  • 2

0 Answers0