€• eŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ$/translations/zh_CN/security/siphash”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ$/translations/zh_TW/security/siphash”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ$/translations/it_IT/security/siphash”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ$/translations/ja_JP/security/siphash”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ$/translations/ko_KR/security/siphash”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ$/translations/pt_BR/security/siphash”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ$/translations/sp_SP/security/siphash”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒSipHash - a short input PRF”h]”hŒSipHash - a short input PRF”…””}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³Œ>/var/lib/git/docbuild/linux/Documentation/security/siphash.rst”h´KubhŒ field_list”“”)”}”(hhh]”hŒfield”“”)”}”(hhh]”(hŒ field_name”“”)”}”(hŒAuthor”h]”hŒAuthor”…””}”(hh×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÕhhÒh³hÊh´KubhŒ field_body”“”)”}”(hŒ0Written by Jason A. Donenfeld ”h]”hŒ paragraph”“”)”}”(hŒ/Written by Jason A. Donenfeld ”h]”(hŒWritten by Jason A. Donenfeld <”…””}”(hhíh²hh³Nh´NubhŒ reference”“”)”}”(hŒjason@zx2c4.com”h]”hŒjason@zx2c4.com”…””}”(hh÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:jason@zx2c4.com”uh1hõhhíubhŒ>”…””}”(hhíh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khhçubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhÒubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÐh³hÊh´KhhÍh²hubah}”(h]”h ]”h"]”h$]”h&]”uh1hËhh·h²hh³hÊh´Kubhì)”}”(hX=SipHash is a cryptographically secure PRF -- a keyed hash function -- that performs very well for short inputs, hence the name. It was designed by cryptographers Daniel J. Bernstein and Jean-Philippe Aumasson. It is intended as a replacement for some uses of: `jhash`, `md5_transform`, `sha1_transform`, and so forth.”h]”(hXSipHash is a cryptographically secure PRF -- a keyed hash function -- that performs very well for short inputs, hence the name. It was designed by cryptographers Daniel J. Bernstein and Jean-Philippe Aumasson. It is intended as a replacement for some uses of: ”…””}”(hj#h²hh³Nh´NubhŒtitle_reference”“”)”}”(hŒ`jhash`”h]”hŒjhash”…””}”(hj-h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j+hj#ubhŒ, ”…””}”(hj#h²hh³Nh´Nubj,)”}”(hŒ`md5_transform`”h]”hŒ md5_transform”…””}”(hj?h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j+hj#ubhŒ, ”…””}”hj#sbj,)”}”(hŒ`sha1_transform`”h]”hŒsha1_transform”…””}”(hjQh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j+hj#ubhŒ, and so forth.”…””}”(hj#h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khh·h²hubhì)”}”(hX0SipHash takes a secret key filled with randomly generated numbers and either an input buffer or several input integers. It spits out an integer that is indistinguishable from random. You may then use that integer as part of secure sequence numbers, secure cookies, or mask it off for use in a hash table.”h]”hX0SipHash takes a secret key filled with randomly generated numbers and either an input buffer or several input integers. It spits out an integer that is indistinguishable from random. You may then use that integer as part of secure sequence numbers, secure cookies, or mask it off for use in a hash table.”…””}”(hjih²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K hh·h²hubh¶)”}”(hhh]”(h»)”}”(hŒGenerating a key”h]”hŒGenerating a key”…””}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjwh²hh³hÊh´Kubhì)”}”(hŒŒKeys should always be generated from a cryptographically secure source of random numbers, either using get_random_bytes or get_random_once::”h]”hŒ‹Keys should always be generated from a cryptographically secure source of random numbers, either using get_random_bytes or get_random_once:”…””}”(hjˆh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khjwh²hubhŒ literal_block”“”)”}”(hŒ7siphash_key_t key; get_random_bytes(&key, sizeof(key));”h]”hŒ7siphash_key_t key; get_random_bytes(&key, sizeof(key));”…””}”hj˜sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1j–h³hÊh´Khjwh²hubhì)”}”(hŒAIf you're not deriving your key from here, you're doing it wrong.”h]”hŒEIf you’re not deriving your key from here, you’re doing it wrong.”…””}”(hj¨h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khjwh²hubeh}”(h]”Œgenerating-a-key”ah ]”h"]”Œgenerating a key”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒUsing the functions”h]”hŒUsing the functions”…””}”(hjÁh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj¾h²hh³hÊh´Kubhì)”}”(hŒhThere are two variants of the function, one that takes a list of integers, and one that takes a buffer::”h]”hŒgThere are two variants of the function, one that takes a list of integers, and one that takes a buffer:”…””}”(hjÏh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K hj¾h²hubj—)”}”(hŒDu64 siphash(const void *data, size_t len, const siphash_key_t *key);”h]”hŒDu64 siphash(const void *data, size_t len, const siphash_key_t *key);”…””}”hjÝsbah}”(h]”h ]”h"]”h$]”h&]”j¦j§uh1j–h³hÊh´K#hj¾h²hubhì)”}”(hŒAnd::”h]”hŒAnd:”…””}”(hjëh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K%hj¾h²hubj—)”}”(hXÃu64 siphash_1u64(u64, const siphash_key_t *key); u64 siphash_2u64(u64, u64, const siphash_key_t *key); u64 siphash_3u64(u64, u64, u64, const siphash_key_t *key); u64 siphash_4u64(u64, u64, u64, u64, const siphash_key_t *key); u64 siphash_1u32(u32, const siphash_key_t *key); u64 siphash_2u32(u32, u32, const siphash_key_t *key); u64 siphash_3u32(u32, u32, u32, const siphash_key_t *key); u64 siphash_4u32(u32, u32, u32, u32, const siphash_key_t *key);”h]”hXÃu64 siphash_1u64(u64, const siphash_key_t *key); u64 siphash_2u64(u64, u64, const siphash_key_t *key); u64 siphash_3u64(u64, u64, u64, const siphash_key_t *key); u64 siphash_4u64(u64, u64, u64, u64, const siphash_key_t *key); u64 siphash_1u32(u32, const siphash_key_t *key); u64 siphash_2u32(u32, u32, const siphash_key_t *key); u64 siphash_3u32(u32, u32, u32, const siphash_key_t *key); u64 siphash_4u32(u32, u32, u32, u32, const siphash_key_t *key);”…””}”hjùsbah}”(h]”h ]”h"]”h$]”h&]”j¦j§uh1j–h³hÊh´K'hj¾h²hubhì)”}”(hŒ§If you pass the generic siphash function something of a constant length, it will constant fold at compile-time and automatically choose one of the optimized functions.”h]”hŒ§If you pass the generic siphash function something of a constant length, it will constant fold at compile-time and automatically choose one of the optimized functions.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K0hj¾h²hubhì)”}”(hŒHashtable key function usage::”h]”hŒHashtable key function usage:”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K4hj¾h²hubj—)”}”(hX·struct some_hashtable { DECLARE_HASHTABLE(hashtable, 8); siphash_key_t key; }; void init_hashtable(struct some_hashtable *table) { get_random_bytes(&table->key, sizeof(table->key)); } static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input) { return &table->hashtable[siphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)]; }”h]”hX·struct some_hashtable { DECLARE_HASHTABLE(hashtable, 8); siphash_key_t key; }; void init_hashtable(struct some_hashtable *table) { get_random_bytes(&table->key, sizeof(table->key)); } static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input) { return &table->hashtable[siphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)]; }”…””}”hj#sbah}”(h]”h ]”h"]”h$]”h&]”j¦j§uh1j–h³hÊh´K6hj¾h²hubhì)”}”(hŒ>You may then iterate like usual over the returned hash bucket.”h]”hŒ>You may then iterate like usual over the returned hash bucket.”…””}”(hj1h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KEhj¾h²hubeh}”(h]”Œusing-the-functions”ah ]”h"]”Œusing the functions”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒSecurity”h]”hŒSecurity”…””}”(hjJh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjGh²hh³hÊh´KHubhì)”}”(hŒøSipHash has a very high security margin, with its 128-bit key. So long as the key is kept secret, it is impossible for an attacker to guess the outputs of the function, even if being able to observe many outputs, since 2^128 outputs is significant.”h]”hŒøSipHash has a very high security margin, with its 128-bit key. So long as the key is kept secret, it is impossible for an attacker to guess the outputs of the function, even if being able to observe many outputs, since 2^128 outputs is significant.”…””}”(hjXh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KJhjGh²hubhì)”}”(hŒ.Linux implements the "2-4" variant of SipHash.”h]”hŒ2Linux implements the “2-4†variant of SipHash.”…””}”(hjfh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KOhjGh²hubeh}”(h]”Œsecurity”ah ]”h"]”Œsecurity”ah$]”h&]”uh1hµhh·h²hh³hÊh´KHubh¶)”}”(hhh]”(h»)”}”(hŒStruct-passing Pitfalls”h]”hŒStruct-passing Pitfalls”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj|h²hh³hÊh´KRubhì)”}”(hXóOften times the XuY functions will not be large enough, and instead you'll want to pass a pre-filled struct to siphash. When doing this, it's important to always ensure the struct has no padding holes. The easiest way to do this is to simply arrange the members of the struct in descending order of size, and to use offsetofend() instead of sizeof() for getting the size. For performance reasons, if possible, it's probably a good thing to align the struct to the right boundary. Here's an example::”h]”hXúOften times the XuY functions will not be large enough, and instead you’ll want to pass a pre-filled struct to siphash. When doing this, it’s important to always ensure the struct has no padding holes. The easiest way to do this is to simply arrange the members of the struct in descending order of size, and to use offsetofend() instead of sizeof() for getting the size. For performance reasons, if possible, it’s probably a good thing to align the struct to the right boundary. Here’s an example:”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KThj|h²hubj—)”}”(hX.const struct { struct in6_addr saddr; u32 counter; u16 dport; } __aligned(SIPHASH_ALIGNMENT) combined = { .saddr = *(struct in6_addr *)saddr, .counter = counter, .dport = dport }; u64 h = siphash(&combined, offsetofend(typeof(combined), dport), &secret);”h]”hX.const struct { struct in6_addr saddr; u32 counter; u16 dport; } __aligned(SIPHASH_ALIGNMENT) combined = { .saddr = *(struct in6_addr *)saddr, .counter = counter, .dport = dport }; u64 h = siphash(&combined, offsetofend(typeof(combined), dport), &secret);”…””}”hj›sbah}”(h]”h ]”h"]”h$]”h&]”j¦j§uh1j–h³hÊh´K\hj|h²hubeh}”(h]”Œstruct-passing-pitfalls”ah ]”h"]”Œstruct-passing pitfalls”ah$]”h&]”uh1hµhh·h²hh³hÊh´KRubh¶)”}”(hhh]”(h»)”}”(hŒ Resources”h]”hŒ Resources”…””}”(hj´h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj±h²hh³hÊh´Khubhì)”}”(hŒdRead the SipHash paper if you're interested in learning more: https://131002.net/siphash/siphash.pdf”h]”(hŒ@Read the SipHash paper if you’re interested in learning more: ”…””}”(hjÂh²hh³Nh´Nubhö)”}”(hŒ&https://131002.net/siphash/siphash.pdf”h]”hŒ&https://131002.net/siphash/siphash.pdf”…””}”(hjÊh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jÌuh1hõhjÂubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kjhj±h²hubeh}”(h]”Œ resources”ah ]”h"]”Œ resources”ah$]”h&]”uh1hµhh·h²hh³hÊh´Khubeh}”(h]”Œsiphash-a-short-input-prf”ah ]”h"]”Œsiphash - a short input prf”ah$]”h&]”uh1hµhhh²hh³hÊh´KubhŒ transition”“”)”}”(hŒO-------------------------------------------------------------------------------”h]”h}”(h]”h ]”h"]”h$]”h&]”uh1jïh³hÊh´Kmhhh²hubh¶)”}”(hhh]”(h»)”}”(hŒ/HalfSipHash - SipHash's insecure younger cousin”h]”hŒ1HalfSipHash - SipHash’s insecure younger cousin”…””}”(hjþh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjûh²hh³hÊh´KqubhÌ)”}”(hhh]”hÑ)”}”(hhh]”(hÖ)”}”(hŒAuthor”h]”hŒAuthor”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÕhjh³hÊh´Kubhæ)”}”(hŒ0Written by Jason A. Donenfeld ”h]”hì)”}”(hŒ/Written by Jason A. Donenfeld ”h]”(hŒWritten by Jason A. Donenfeld <”…””}”(hj$h²hh³Nh´Nubhö)”}”(hŒjason@zx2c4.com”h]”hŒjason@zx2c4.com”…””}”(hj,h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:jason@zx2c4.com”uh1hõhj$ubhŒ>”…””}”(hj$h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kshj ubah}”(h]”h ]”h"]”h$]”h&]”uh1håhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÐh³hÊh´Kshj h²hubah}”(h]”h ]”h"]”h$]”h&]”uh1hËhjûh²hh³hÊh´Ksubhì)”}”(hX“On the off-chance that SipHash is not fast enough for your needs, you might be able to justify using HalfSipHash, a terrifying but potentially useful possibility. HalfSipHash cuts SipHash's rounds down from "2-4" to "1-3" and, even scarier, uses an easily brute-forcable 64-bit key (with a 32-bit output) instead of SipHash's 128-bit key. However, this may appeal to some high-performance `jhash` users.”h]”(hX‘On the off-chance that SipHash is not fast enough for your needs, you might be able to justify using HalfSipHash, a terrifying but potentially useful possibility. HalfSipHash cuts SipHash’s rounds down from “2-4†to “1-3†and, even scarier, uses an easily brute-forcable 64-bit key (with a 32-bit output) instead of SipHash’s 128-bit key. However, this may appeal to some high-performance ”…””}”(hjXh²hh³Nh´Nubj,)”}”(hŒ`jhash`”h]”hŒjhash”…””}”(hj`h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j+hjXubhŒ users.”…””}”(hjXh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kuhjûh²hubhì)”}”(hŒKHalfSipHash support is provided through the "hsiphash" family of functions.”h]”hŒOHalfSipHash support is provided through the “hsiphash†family of functions.”…””}”(hjxh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K|hjûh²hubhŒwarning”“”)”}”(hX.Do not ever use the hsiphash functions except for as a hashtable key function, and only then when you can be absolutely certain that the outputs will never be transmitted out of the kernel. This is only remotely useful over `jhash` as a means of mitigating hashtable flooding denial of service attacks.”h]”hì)”}”(hX.Do not ever use the hsiphash functions except for as a hashtable key function, and only then when you can be absolutely certain that the outputs will never be transmitted out of the kernel. This is only remotely useful over `jhash` as a means of mitigating hashtable flooding denial of service attacks.”h]”(hŒàDo not ever use the hsiphash functions except for as a hashtable key function, and only then when you can be absolutely certain that the outputs will never be transmitted out of the kernel. This is only remotely useful over ”…””}”(hjŒh²hh³Nh´Nubj,)”}”(hŒ`jhash`”h]”hŒjhash”…””}”(hj”h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j+hjŒubhŒG as a means of mitigating hashtable flooding denial of service attacks.”…””}”(hjŒh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khjˆubah}”(h]”h ]”h"]”h$]”h&]”uh1j†hjûh²hh³hÊh´Nubhì)”}”(hXÝOn 64-bit kernels, the hsiphash functions actually implement SipHash-1-3, a reduced-round variant of SipHash, instead of HalfSipHash-1-3. This is because in 64-bit code, SipHash-1-3 is no slower than HalfSipHash-1-3, and can be faster. Note, this does *not* mean that in 64-bit kernels the hsiphash functions are the same as the siphash ones, or that they are secure; the hsiphash functions still use a less secure reduced-round algorithm and truncate their outputs to 32 bits.”h]”(hŒüOn 64-bit kernels, the hsiphash functions actually implement SipHash-1-3, a reduced-round variant of SipHash, instead of HalfSipHash-1-3. This is because in 64-bit code, SipHash-1-3 is no slower than HalfSipHash-1-3, and can be faster. Note, this does ”…””}”(hj²h²hh³Nh´NubhŒemphasis”“”)”}”(hŒ*not*”h]”hŒnot”…””}”(hj¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jºhj²ubhŒÜ mean that in 64-bit kernels the hsiphash functions are the same as the siphash ones, or that they are secure; the hsiphash functions still use a less secure reduced-round algorithm and truncate their outputs to 32 bits.”…””}”(hj²h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K…hjûh²hubh¶)”}”(hhh]”(h»)”}”(hŒGenerating a hsiphash key”h]”hŒGenerating a hsiphash key”…””}”(hj×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÔh²hh³hÊh´KŽubhì)”}”(hŒŒKeys should always be generated from a cryptographically secure source of random numbers, either using get_random_bytes or get_random_once::”h]”hŒ‹Keys should always be generated from a cryptographically secure source of random numbers, either using get_random_bytes or get_random_once:”…””}”(hjåh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KhjÔh²hubj—)”}”(hŒ8hsiphash_key_t key; get_random_bytes(&key, sizeof(key));”h]”hŒ8hsiphash_key_t key; get_random_bytes(&key, sizeof(key));”…””}”hjósbah}”(h]”h ]”h"]”h$]”h&]”j¦j§uh1j–h³hÊh´K“hjÔh²hubhì)”}”(hŒAIf you're not deriving your key from here, you're doing it wrong.”h]”hŒEIf you’re not deriving your key from here, you’re doing it wrong.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K–hjÔh²hubeh}”(h]”Œgenerating-a-hsiphash-key”ah ]”h"]”Œgenerating a hsiphash key”ah$]”h&]”uh1hµhjûh²hh³hÊh´KŽubh¶)”}”(hhh]”(h»)”}”(hŒUsing the hsiphash functions”h]”hŒUsing the hsiphash functions”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´K™ubhì)”}”(hŒhThere are two variants of the function, one that takes a list of integers, and one that takes a buffer::”h]”hŒgThere are two variants of the function, one that takes a list of integers, and one that takes a buffer:”…””}”(hj(h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K›hjh²hubj—)”}”(hŒFu32 hsiphash(const void *data, size_t len, const hsiphash_key_t *key);”h]”hŒFu32 hsiphash(const void *data, size_t len, const hsiphash_key_t *key);”…””}”hj6sbah}”(h]”h ]”h"]”h$]”h&]”j¦j§uh1j–h³hÊh´Kžhjh²hubhì)”}”(hŒAnd::”h]”hŒAnd:”…””}”(hjDh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K hjh²hubj—)”}”(hŒéu32 hsiphash_1u32(u32, const hsiphash_key_t *key); u32 hsiphash_2u32(u32, u32, const hsiphash_key_t *key); u32 hsiphash_3u32(u32, u32, u32, const hsiphash_key_t *key); u32 hsiphash_4u32(u32, u32, u32, u32, const hsiphash_key_t *key);”h]”hŒéu32 hsiphash_1u32(u32, const hsiphash_key_t *key); u32 hsiphash_2u32(u32, u32, const hsiphash_key_t *key); u32 hsiphash_3u32(u32, u32, u32, const hsiphash_key_t *key); u32 hsiphash_4u32(u32, u32, u32, u32, const hsiphash_key_t *key);”…””}”hjRsbah}”(h]”h ]”h"]”h$]”h&]”j¦j§uh1j–h³hÊh´K¢hjh²hubhì)”}”(hŒ¨If you pass the generic hsiphash function something of a constant length, it will constant fold at compile-time and automatically choose one of the optimized functions.”h]”hŒ¨If you pass the generic hsiphash function something of a constant length, it will constant fold at compile-time and automatically choose one of the optimized functions.”…””}”(hj`h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K§hjh²hubeh}”(h]”Œusing-the-hsiphash-functions”ah ]”h"]”Œusing the hsiphash functions”ah$]”h&]”uh1hµhjûh²hh³hÊh´K™ubh¶)”}”(hhh]”(h»)”}”(hŒHashtable key function usage”h]”hŒHashtable key function usage”…””}”(hjyh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjvh²hh³hÊh´K¬ubj—)”}”(hX¹struct some_hashtable { DECLARE_HASHTABLE(hashtable, 8); hsiphash_key_t key; }; void init_hashtable(struct some_hashtable *table) { get_random_bytes(&table->key, sizeof(table->key)); } static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input) { return &table->hashtable[hsiphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)]; }”h]”hX¹struct some_hashtable { DECLARE_HASHTABLE(hashtable, 8); hsiphash_key_t key; }; void init_hashtable(struct some_hashtable *table) { get_random_bytes(&table->key, sizeof(table->key)); } static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input) { return &table->hashtable[hsiphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)]; }”…””}”hj‡sbah}”(h]”h ]”h"]”h$]”h&]”j¦j§uh1j–h³hÊh´K°hjvh²hubhì)”}”(hŒ>You may then iterate like usual over the returned hash bucket.”h]”hŒ>You may then iterate like usual over the returned hash bucket.”…””}”(hj•h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K¿hjvh²hubeh}”(h]”Œhashtable-key-function-usage”ah ]”h"]”Œhashtable key function usage”ah$]”h&]”uh1hµhjûh²hh³hÊh´K¬ubh¶)”}”(hhh]”(h»)”}”(hŒ Performance”h]”hŒ Performance”…””}”(hj®h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj«h²hh³hÊh´KÂubhì)”}”(hXhsiphash() is roughly 3 times slower than jhash(). For many replacements, this will not be a problem, as the hashtable lookup isn't the bottleneck. And in general, this is probably a good sacrifice to make for the security and DoS resistance of hsiphash().”h]”hXhsiphash() is roughly 3 times slower than jhash(). For many replacements, this will not be a problem, as the hashtable lookup isn’t the bottleneck. And in general, this is probably a good sacrifice to make for the security and DoS resistance of hsiphash().”…””}”(hj¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÄhj«h²hubeh}”(h]”Œ performance”ah ]”h"]”Œ performance”ah$]”h&]”uh1hµhjûh²hh³hÊh´KÂubeh}”(h]”Œ-halfsiphash-siphash-s-insecure-younger-cousin”ah ]”h"]”Œ/halfsiphash - siphash's insecure younger cousin”ah$]”h&]”uh1hµhhh²hh³hÊh´Kqubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÊuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hºNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jýŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÊŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jìjéj»j¸jDjAjyjvj®j«jäjáj×jÔjjjsjpj¨j¥jÏjÌuŒ nametypes”}”(jì‰j»‰jD‰jy‰j®‰jä‰j׉j‰js‰j¨‰jωuh}”(jéh·j¸jwjAj¾jvjGj«j|jáj±jÔjûjjÔjpjj¥jvjÌj«uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.