Feature #13017 ยป 0001switchSipHashfromSipHash24toSipHash13variant.patch
random.c  

1457  1457 
} 
1458  1458  
1459  1459 
#define SIP_HASH_STREAMING 0 
1460 
#define sip_hash24 ruby_sip_hash24


1460 
#define sip_hash13 ruby_sip_hash13


1461  1461 
#if !defined _WIN32 && !defined BYTE_ORDER 
1462  1462 
# ifdef WORDS_BIGENDIAN 
1463  1463 
# define BYTE_ORDER BIG_ENDIAN 
...  ...  
1501  1501 
st_index_t 
1502  1502 
rb_memhash(const void *ptr, long len) 
1503  1503 
{ 
1504 
sip_uint64_t h = sip_hash24(seed.key.sip, ptr, len);


1504 
sip_uint64_t h = sip_hash13(seed.key.sip, ptr, len);


1505  1505 
#ifdef HAVE_UINT64_T 
1506  1506 
return (st_index_t)h; 
1507  1507 
#else 
siphash.c  

386  386 
} 
387  387 
#endif /* SIP_HASH_STREAMING */ 
388  388  
389 
#define SIP_2_ROUND(m, v0, v1, v2, v3) \


389 
#define SIP_ROUND(m, v0, v1, v2, v3) \ 

390  390 
do { \ 
391  391 
XOR64_TO((v3), (m)); \ 
392  392 
SIP_COMPRESS(v0, v1, v2, v3); \ 
393 
SIP_COMPRESS(v0, v1, v2, v3); \ 

394  393 
XOR64_TO((v0), (m)); \ 
395  394 
} while (0) 
396  395  
397  396 
uint64_t 
398 
sip_hash24(const uint8_t key[16], const uint8_t *data, size_t len)


397 
sip_hash13(const uint8_t key[16], const uint8_t *data, size_t len)


399  398 
{ 
400  399 
uint64_t k0, k1; 
401  400 
uint64_t v0, v1, v2, v3; 
...  ...  
415  414 
uint64_t *data64 = (uint64_t *)data; 
416  415 
while (data64 != (uint64_t *) end) { 
417  416 
m = *data64++; 
418 
SIP_2_ROUND(m, v0, v1, v2, v3);


417 
SIP_ROUND(m, v0, v1, v2, v3); 

419  418 
} 
420  419 
} 
421  420 
#else 
422  421 
for (; data != end; data += sizeof(uint64_t)) { 
423  422 
m = U8TO64_LE(data); 
424 
SIP_2_ROUND(m, v0, v1, v2, v3);


423 
SIP_ROUND(m, v0, v1, v2, v3); 

425  424 
} 
426  425 
#endif 
427  426  
...  ...  
468  467 
break; 
469  468 
} 
470  469  
471 
SIP_2_ROUND(last, v0, v1, v2, v3);


470 
SIP_ROUND(last, v0, v1, v2, v3); 

472  471  
473  472 
XOR64_INT(v2, 0xff); 
474  473  
475  474 
SIP_COMPRESS(v0, v1, v2, v3); 
476  475 
SIP_COMPRESS(v0, v1, v2, v3); 
477  476 
SIP_COMPRESS(v0, v1, v2, v3); 
478 
SIP_COMPRESS(v0, v1, v2, v3); 

479  477  
480  478 
XOR64_TO(v0, v1); 
481  479 
XOR64_TO(v0, v2); 
siphash.h  

43  43 
void sip_hash_free(sip_hash *h); 
44  44 
void sip_hash_dump(sip_hash *h); 
45  45  
46 
uint64_t sip_hash24(const uint8_t key[16], const uint8_t *data, size_t len);


46 
uint64_t sip_hash13(const uint8_t key[16], const uint8_t *data, size_t len);


47  47  
48  48 
#endif 
49 
 