1

I have been told to use the a Siphash key

24 64 6d 71 33 45 30 31 63 2f 6d 69 37 33 9d 19

Which I am trying to use the SipHash24_Init from OpenBSD on.

I have the following global:

const SIPHASH_KEY COMP_SIPHASH_KEY = 0x24646d7133453031632f6d6937339d19;

And is used like this:

SIPHASH_CTX ctx;
SipHash24_Init(&ctx, &COMP_SIPHASH_KEY);

I would post more but its complicated and I don't think it's relevant

However i get the following compiler error on the definition/declaration:

error: integer constant is too large for its type
error: invalid initializer
jnd
  • 754
  • 9
  • 20
  • We have no idea what library you are using that contains these types or functions. – President James K. Polk Oct 18 '15 at 03:37
  • SipHash24 in OpenBSD - my bad http://www.openbsd.org/cgi-bin/man.cgi?query=SipHash24 – jnd Oct 18 '15 at 04:18
  • 2
    You need to either use an array of 16 bytes or one of two 64 bit integers. Probably the former. There is no 128 bit integer type in most implementations of C. Something like `byte key[] = {0x24, 0x64, 0x6d, ... }`. Alternatively you can store it as hex string, and use one of the answers to [Hexadecimal String to Byte Array in C](http://stackoverflow.com/questions/3408706/hexadecimal-string-to-byte-array-in-c) to convert it to raw bytes. – CodesInChaos Oct 18 '15 at 08:32
  • 1
    @MaartenBodewes The problem is that without knowing the library I can only post some ideas, not don't know which answer is actually correct. – CodesInChaos Oct 18 '15 at 12:15

1 Answers1

2

So given my limited practice in C lately, I think you should do something like:

SIPHASH_CTX ctx;
SIPHASH_KEY key;

key.k0 = bswap_64(0x24646d7133453031);
key.k1 = bswap_64(0x632f6d6937339d19);
SipHash24_Init(&ctx, &key);

as SIPHASH_KEY seems to be defined as

typedef struct {
    uint64_t k0;
    uint64_t k1;
} SIPHASH_KEY;

I'm using a <byteswap.h> library here to reverse the bytes within the long value as k0 and k1 are supposed to be encoded as little endian values.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263