[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

Kristof Beyls via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jun 5 00:53:23 PDT 2024


================
@@ -58,21 +38,15 @@
     v2 = ROTL(v2, 32);                                                         \
   } while (0)
 
-/*
-    Computes a SipHash value
-    *in: pointer to input data (read-only)
-    inlen: input data length in bytes (any size_t value)
-    *k: pointer to the key data (read-only), must be 16 bytes
-    *out: pointer to output data (write-only), outlen bytes must be allocated
-    outlen: length of the output in bytes, must be 8 or 16
-*/
-int siphash(const void *in, const size_t inlen, const void *k, uint8_t *out,
-            const size_t outlen) {
+template <int cROUNDS, int dROUNDS, class ResultTy>
+static inline ResultTy siphash(const unsigned char *in, uint64_t inlen,
+                               const unsigned char (&k)[16]) {
 
   const unsigned char *ni = (const unsigned char *)in;
   const unsigned char *kk = (const unsigned char *)k;
 
-  assert((outlen == 8) || (outlen == 16));
----------------
kbeyls wrote:

I guess that adding
```
const size_t outlen = sizeof(ResultTy);
```
above this might result in fewer local modification needed in the rest of this function implementation?
Not sure if it's worth it. It might make it somewhat easier to update the implementation to a later "upstream" version if that would ever be needed. But I guess that's it's unlikely we'd ever need to update the implementation to a later upstream version....

https://github.com/llvm/llvm-project/pull/94394


More information about the llvm-branch-commits mailing list