According to https://www.online-convert.com/result/952ea2f0-6d2a-4027-aebf-8309b3888ffb the hash of "test" generated by the Whirlpool hash function is:
B913D5BBB8E461C2C5961CBE0EDCDADFD29F068225CEB37DA6DEFCF89849368F8C6C2EB6A4C4AC75775D032A0ECFDFE8550573062B653FE92FC7B8FB3B7BE8D6
Now, in the following lines of code I try to achieve the same thing in Java:
import gnu.crypto.hash.HashFactory;
import gnu.crypto.hash.IMessageDigest;
import gnu.crypto.util.Util;
import java.nio.charset.Charset;
public class Main {
public static void main(String[] args) {
byte[] input = "test".getBytes(Charset.forName("UTF-8"));
IMessageDigest md = HashFactory.getInstance("whirlpool");
md.update(input, 0, input.length);
byte[] digest = md.digest();
System.out.println("expected: B913D5BBB8E461C2C5961CBE0EDCDADFD29F068225CEB37DA6DEFCF89849368F8C6C2EB6A4C4AC75775D032A0ECFDFE8550573062B653FE92FC7B8FB3B7BE8D6");
System.out.println("real: " + Util.toString(digest));
}
}
The output is as follows:
expected: B913D5BBB8E461C2C5961CBE0EDCDADFD29F068225CEB37DA6DEFCF89849368F8C6C2EB6A4C4AC75775D032A0ECFDFE8550573062B653FE92FC7B8FB3B7BE8D6
real: E6B4AA087751B4428171777F1893BA585404C7E0171787720EBA0D8BCCD710DC2C42F874C572BFAE4CEDABF50F2C80BF923805D4E31C504B86CA3BC59265E7DD
With the empty string (similar to the selfTest) it returns the expected string. I'm using the gnu crypto library 2.0.1 from https://www.gnu.org/software/gnu-crypto/.
Does anyone have a hint why the real hash does not match the expected one?