csiphash icon indicating copy to clipboard operation
csiphash copied to clipboard

invalid code, casting a void pointer to an uint64_t pointer

Open doko42 opened this issue 9 years ago • 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.

doko42 avatar Sep 10 '16 09:09 doko42

"on some targets" can you be more precise?

majek avatar Sep 20 '16 08:09 majek

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;

cgrzemba avatar Oct 05 '17 12:10 cgrzemba

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

doko42 avatar Oct 07 '17 00:10 doko42

+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] = {...};

mcqtom avatar Aug 15 '23 08:08 mcqtom

@mcqtom PR?

majek avatar Aug 15 '23 08:08 majek