majek/csiphash

invalid code, casting a void pointer to an uint64_t pointer

doko42 opened this issue · 5 comments

siphash24 casts a void pointer to an uint64_t pointer, which has more strict alignment requirements on some targets, leading to a bus error. that's not valid code.

seen in the siphash24 copy in Python: http://bugs.python.org/issue28055

The proposed solution is to use a memcpy for all little endian targets.

majek commented

"on some targets" can you be more precise?

I see this problem on Solaris Sparc and fixed it in this kind:

@@ -75,7 +90,9 @@
uint64_t
uint64_t siphash24(const void *src, unsigned long src_sz, const char key[16]) {
{

  • const uint64_t *_key = (uint64_t *)key;
  • uint64_t _key[2];
  • bcopy(key, _key, 16);
  • uint64_t k0 = _le64toh(_key[0]);
    uint64_t k1 = _le64toh(_key[1]);
    uint64_t b = (uint64_t)src_sz << 56;

the original target was ARM32, using a 64bit AArch64 kernel

mcqtom commented

+1

siphash24(...) fails to run on ARM Cortex M0+ (STM32L0) due to this cast.

Passed in key has to be manually aligned in order to work.
unsigned char __attribute__ ((aligned (16))) secret_key[16] = {...};

majek commented