0

I am trying to run Keccak 224 with this official library. Unfortunately I get a wrong hash from the function. I doubt that it is the fault of the library, rather I do something wrong.

This is what I am trying:

unsigned char input[] = "abc", output[168];
const unsigned long long int inputByteLen = sizeof(input);

FIPS202_SHA3_224(input, inputByteLen, output);

std::stringstream stream;
for (unsigned int i = 0; i < sizeof(output); i++) {
    stream << std::hex << static_cast<short>(output[i]);
}
cout << stream.str() << endl;

The correct hash for "abc" with SHA-3-224 (Keccak) should be:

e642824c3f8cf24a d09234ee7d3c766f c9a3a5168d0c94ad 73b46fdf

But I only get nonsense from this way of calling the library. What am I doing wrong? A small example would be great which explains me how I can achieve the expected result and what I was doing wrong.

Peter Winzer
  • 165
  • 7
  • Are you trying to use Keccak 224 or SHA3 224? They're very slightly different. – David Schwartz Mar 27 '16 at 22:43
  • SHA3 224. Is the output hash different from each other? – Peter Winzer Mar 27 '16 at 22:52
  • Yes, they use slightly different constants. – David Schwartz Mar 27 '16 at 23:24
  • O.k. I wasn't aware of that. Do you know if my library is calculating the SHA3 or Keccak of the input string? Both is mentioned in the code so I am not sure. Anyway the output I get doesn't fit both of them :/ – Peter Winzer Mar 27 '16 at 23:47
  • Given the name of the function, I'd assume it's SHA3. FIPS202 specified the final version. – David Schwartz Mar 28 '16 at 00:03
  • It looks like that: void FIPS202_SHA3_224(const u8 *in, u64 inLen, u8 *out) { Keccak(1152, 448, in, inLen, 0x06, out, 28); } The whole (small) code is here: https://github.com/gvanas/KeccakCodePackage/blob/master/Standalone/CompactFIPS202/Keccak-more-compact.c – Peter Winzer Mar 28 '16 at 00:15

1 Answers1

1

Have you taken into consideration the null character at the end?

const unsigned long long int inputByteLen = sizeof(input) - 1;

Slaiyer
  • 444
  • 8
  • 22