0

I'm experimenting with various Keccak implementations for java. This implementation is the most promising so far, however I'm getting strange results. The test cases are defined here (although I'm using hex strings directly, as per the test vectors). Current (and correct) test vectors are defined here in green (I'm providing the link for convenience, to save anyone from having to download the official test vector zip file from the website).

For starters, I don't understand the correlation between the 'len' and 'msg' fields in the test vectors. 'Len' is supposed to be the length of 'msg', in bits. For example, 'len' = 5, 'msg' = "48" (a hex string), I thought 2 hex digits = 1 byte, which = 8 bits. What am I missing?

I'm only getting correct digests (as per the test vectors) for the inputs of the following lengths: 16, 24, 40, 56, 64, 72, 112, and 128 (where length corresponds to the 'len' field in the test vectors, and the input is the 'msg'). The values that I'm getting for lengths: 32, 48, 80, 88, 96, 104, however, do not match the test vectors. Can anyone make an educated guess as to why this is happening? Of course, if anyone can recommend a different implementation in Java I'd be grateful.

hunter
  • 872
  • 10
  • 26
  • I've just pushed my new [Java implementation of Keccak and SHA-3 to GitHub](https://github.com/Bobulous/Cryptography) so you could give that a spin. I've been developing and testing (and rewriting) it for six weeks, and it passes 53,000 unit tests (based primarily on the KATs generated by the Keccak team) so it should be fairly sound. – Bobulous May 26 '17 at 00:26

1 Answers1

1

look at example here: LINK

or just add this method to "Keccak" class:

/**
 * @param string original string to get kekkan hash from it
 * @return hash or null
 */
public static String generateHash(String string) {
    Keccak keccak = new Keccak();
    String hex;
    try {
        hex = keccak.getHexStringByByteArray(string.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        return null;
    }
    // 576,64 is values for sha-512
    return keccak.getHash(hex, 576, 64);
}