1. souce code and algorithm
2. 算法流程 hash = SipHash(message, key)
1. 初始化 (Initialization)
1.1 初始化四个向量 v0,v1,v2,v3
uint64_t v0 = 0x736f6d6570736575ULL; //unsigned long longuint64_t v1 = 0x646f72616e646f6dULL;uint64_t v2 = 0x6c7967656e657261ULL;uint64_t v3 = 0x7465646279746573ULL;
1.2 将128位的key用little-endian(较小的字节在低位)编码为64位的k0,k1
// uint8_t key[16]; // key = [8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1] Byte = total 128-bituint64_t k0 = (*(uint64_t*)key); // 64-bituint64_t k1 = (*(uint64_t*)(key+8)) // 64-bit
1.3 用k0,k1初始化v0,v1,v2,v3
v3 ^= k1; // xorv2 ^= k0;v1 ^= k1;v0 ^= k0;
2. 压缩 (Compression)
2.1 split message
message = 'abcdefghijk', length = 11step1: msgs = {'abcdefgh', 'ijk'} // 8 Bytes and 3 Bytesstep2: msgs = {'abcdefgh', '\0\0\0\0\0ijk'} // 8 Bytes and 8 Bytesstep3: msgs = { 0x6162636465666768, 0x0000000000696a6b} // 64-bit and 64-bit
2.2 transfer
for m in msgsdo v3 ^= m SipRound v0 ^= mdone
2.4 SipRound
3. 结束 (Finalization)
v2 ^= 0xffSipRoundSipRoundfinal = v0 ^ v1 ^ v2 ^ v3