€•;dŒ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Œ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: ”…””}”(hjhžhhŸNh NubhŒtitle_reference”“”)”}”(hŒ`jhash`”h]”hŒjhash”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubhŒ, ”…””}”(hjhžhhŸNh Nubj)”}”(hŒ`md5_transform`”h]”hŒ md5_transform”…””}”(hj+hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubhŒ, ”…””}”hjsbj)”}”(hŒ`sha1_transform`”h]”hŒsha1_transform”…””}”(hj=hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubhŒ, and so forth.”…””}”(hjhž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.”…””}”(hjUhž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”…””}”(hjfhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjchž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:”…””}”(hjthžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h Khjchž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 Khjchž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 Khjchž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.”…””}”(hjóhž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)]; }”…””}”hjsbah}”(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.”…””}”(hjhž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”…””}”(hj6hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj3hž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.”…””}”(hjDhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h KJhj3hžhubhØ)”}”(hŒ.Linux implements the "2-4" variant of SipHash.”h]”hŒ2Linux implements the “2-4†variant of SipHash.”…””}”(hjRhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h KOhj3hž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”…””}”(hjkhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjhhž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:”…””}”(hjyhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h KThjhhž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\hjhhž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¦hjhž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 Kjhjhž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”…””}”(hjþhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhjûhŸh¶h KubhÒ)”}”(hŒ0Written by Jason A. Donenfeld ”h]”hØ)”}”(hŒ/Written by Jason A. Donenfeld ”h]”(hŒWritten by Jason A. Donenfeld <”…””}”(hjhžhhŸNh Nubhâ)”}”(hŒjason@zx2c4.com”h]”hŒjason@zx2c4.com”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:jason@zx2c4.com”uh1háhjubhŒ>”…””}”(hjhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h Kshj ubah}”(h]”h ]”h"]”h$]”h&]”uh1hÑhjûubeh}”(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 ”…””}”(hjDhžhhŸNh Nubj)”}”(hŒ`jhash`”h]”hŒjhash”…””}”(hjLhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjDubhŒ users.”…””}”(hjDhž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.”…””}”(hjdhž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 ”…””}”(hjxhžhhŸNh Nubj)”}”(hŒ`jhash`”h]”hŒjhash”…””}”(hj€hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjxubhŒG as a means of mitigating hashtable flooding denial of service attacks.”…””}”(hjxhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h Khjtubah}”(h]”h ]”h"]”h$]”h&]”uh1jrhjç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.”…””}”(hjíhž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:”…””}”(hjhž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);”…””}”hj"sbah}”(h]”h ]”h"]”h$]”h&]”j’j“uh1j‚hŸh¶h KžhjhžhubhØ)”}”(hŒAnd::”h]”hŒAnd:”…””}”(hj0hž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);”…””}”hj>sbah}”(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.”…””}”(hjLhž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”…””}”(hjehžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjbhž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)]; }”…””}”hjssbah}”(h]”h ]”h"]”h$]”h&]”j’j“uh1j‚hŸh¶h K°hjbhž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.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h K¿hjbhž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¤j0j-jejbjšj—jÐjÍjÃjÀjjýj_j\j”j‘j»j¸uŒ nametypes”}”(j؉j§‰j0‰je‰jš‰jЉjÉj‰j_‰j”‰j»‰uh}”(jÕh£j¤jcj-jªjbj3j—jhjÍjjÀjçjýjÀj\jj‘jbj¸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.