2

I've tried a few. Python's pyskein; a javascript skein calculator I found online somewhere; and the skein calculator being used for xkcd's april fools' comic all give the same output for a given input.

But when I download version 1.3 of the reference C source here I get different results. Worst of all, the results I get from the C API perfectly match the "known answer test" examples that come with the source code, so I assume I'm using it right.

My C code:

#include <stdio.h>
#include <stdlib.h>
#include "SHA3api_ref.h"

int main(int argc, const char * argv[])
{
    const int BITS = 256; // length of hash in bits
    const int LENGTH = 32; // length of data in bits
    BitSequence *hashval = calloc(BITS/8, 1);
    const BitSequence content[] = {0xC1, 0xEC, 0xFD, 0xFC};

    Hash(BITS, content, LENGTH, hashval);

    for (int i = 0; i < BITS/8; i++) {
        printf("%02X", hashval[i]);
    }
    return 0;
}

result hex: 2638B1711F1346D08BF02B5D1A575CD924140A608512AF5B8E4475632599A896

Python code for the same hash on the same data:

import skein
print( skein.skein256(bytes([0xC1, 0xEC, 0xFD, 0xFC])).hexdigest() )

result hex: 07e785ce898fa5cfa22e15294481717935923985ea90f67fc65cb5b3cb718190

Note that the C answer is the expected answer according to the KAT_MCT/ShortMsgKAT_256.txt file that comes with the code. But pyskein gives results that everyone else seems to agree are correct. What am I missing?

Josh
  • 2,039
  • 3
  • 20
  • 25
  • 1
    `BitSequence *hashval = calloc(32, 1); // 256 bytes` errm, 32 bytes, 256 bits probably. – Daniel Fischer Apr 02 '13 at 15:51
  • Because I just encountered this yesterday, _make sure you have the right version of the code_. Note that the website lists 1.0, 1.1, 1.2, and 1.3, but it manages to hide the link to 1.3 pretty well. pyskein uses 1.3, for reference (as should everyone). – Xymostech Apr 02 '13 at 16:03
  • 1
    "What am I missing?"... You're missing an [SSCCE](http://sscce.org/). – autistic Apr 02 '13 at 16:05
  • Oops, that's supposed to be bits, yes. – Josh Apr 02 '13 at 16:07
  • @modifiablelvalue, yes, I am. Any "self-contained, compilable" example would have to include the entire skein implementation, and hence would not be short. So I don't see that that's an option. – Josh Apr 02 '13 at 16:12
  • I was able to get PySkein and the C code, but I don't see where you're getting the known answer from. Can you link to it? – Brendan Long Apr 02 '13 at 16:13
  • @Josh `#include ` isn't short? Show us how you're using the library, so we can answer your question! – autistic Apr 02 '13 at 16:14
  • @Josh Give us something that compiles, providing we have the skein header files and library in the right place. If you can't do this for us, then we can't answer your question. It's as simple as that. – autistic Apr 02 '13 at 16:16
  • @brendan, there's a folder called KAT_MCT distributed with the C source. – Josh Apr 02 '13 at 16:24
  • @xymostech, I'm not sure what version I had, but I just updated to 1.3 and nothing changed. You're right, the site layout is confusing! – Josh Apr 02 '13 at 16:25
  • In order to `#include ` you must first invent The Universe. That's not gonna be short or self-contained... – mgalgs Apr 03 '13 at 16:33

0 Answers0