24using namespace support;
26#define DEBUG_TYPE "llvm-siphash"
32#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))
61template <
int cROUNDS,
int dROUNDS,
size_t outlen>
62void siphash(
const unsigned char *in,
uint64_t inlen,
63 const unsigned char (&k)[16],
unsigned char (&out)[outlen]) {
65 const unsigned char *ni = (
const unsigned char *)in;
66 const unsigned char *kk = (
const unsigned char *)k;
68 static_assert(outlen == 8 || outlen == 16,
"result should be 8 or 16 bytes");
70 uint64_t v0 = UINT64_C(0x736f6d6570736575);
71 uint64_t v1 = UINT64_C(0x646f72616e646f6d);
72 uint64_t v2 = UINT64_C(0x6c7967656e657261);
73 uint64_t v3 = UINT64_C(0x7465646279746573);
78 const unsigned char *end = ni + inlen - (inlen %
sizeof(
uint64_t));
79 const int left = inlen & 7;
89 for (; ni != end; ni += 8) {
93 for (i = 0; i < cROUNDS; ++i)
127 for (i = 0; i < cROUNDS; ++i)
137 for (i = 0; i < dROUNDS; ++i)
140 b = v0 ^ v1 ^ v2 ^ v3;
148 for (i = 0; i < dROUNDS; ++i)
151 b = v0 ^ v1 ^ v2 ^ v3;
159 siphash<2, 4>(In.data(), In.size(), K, Out);
163 uint8_t (&Out)[16]) {
164 siphash<2, 4>(In.data(), In.size(), K, Out);
169 static const uint8_t K[16] = {0xb5, 0xd4, 0xc9, 0xeb, 0x79, 0x10, 0x4a, 0x79,
170 0x6f, 0xec, 0x8b, 0x1b, 0x42, 0x87, 0x81, 0xd4};
172 uint8_t RawHashBytes[8];
177 uint16_t Discriminator = (RawHash % 0xFFFF) + 1;
179 dbgs() <<
"ptrauth stable hash discriminator: " << utostr(Discriminator)
181 << utohexstr(Discriminator,
false, 4)
183 <<
" of: " << Str <<
"\n");
184 return Discriminator;
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef - Represent a constant reference to a string, i.e.
uint64_t read64le(const void *P)
void write64le(void *P, uint64_t V)
This is an optimization pass for GlobalISel generic memory operations.
void getSipHash_2_4_64(ArrayRef< uint8_t > In, const uint8_t(&K)[16], uint8_t(&Out)[8])
Computes a SipHash-2-4 64-bit result.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint16_t getPointerAuthStableSipHash(StringRef S)
Compute a stable non-zero 16-bit hash of the given string.
void getSipHash_2_4_128(ArrayRef< uint8_t > In, const uint8_t(&K)[16], uint8_t(&Out)[16])
Computes a SipHash-2-4 128-bit result.