I have a sipHashDigest function calculating a siphash2-4 digest with this go library.As you can see, the method normalizes the key to 16 bytes, splits the randomBytes and calculates the digest.My question is, how can I test this function to understand if the siphash has been calculated correctly? There are known vectors to use ?I was using this to check the results but I'm not getting the same results with my implementation. What I'm doing wrong?
Thanks for the support.
// normalizeKey ensures the key is exactly 16 bytes long by truncating or padding with zeros if necessary.func normalizeKey(key string) []byte { const keySize = 16 if len(key) > keySize { return []byte(key[:keySize]) } if len(key) < keySize { paddedKey := make([]byte, keySize) copy(paddedKey, key) return paddedKey } return []byte(key)}
func splitKey(key []byte) (uint64, uint64) { key0 := binary.LittleEndian.Uint64(key[:8]) key1 := binary.LittleEndian.Uint64(key[8:]) return key0, key1}
func sipHashDigest(randomBytes []byte, key string) uint64 { normalizedKey := normalizeKey(key) key0, key1 := splitKey(randomBytes) return siphash.Hash(key0, key1, []byte(normalizedKey))}