Jenkins Hash Function
   HOME

TheInfoList



OR:

The Jenkins hash functions are a collection of (non-
cryptographic Cryptography, or cryptology (from grc, , translit=kryptós "hidden, secret"; and ''graphein'', "to write", or '' -logia'', "study", respectively), is the practice and study of techniques for secure communication in the presence of adve ...
)
hash functions A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called ''hash values'', ''hash codes'', ''digests'', or simply ''hashes''. The values are usually u ...
for multi-
byte The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit ...
keys designed by
Bob Jenkins Robert F. Jenkins (September 4, 1947 – August 9, 2021) was an American television and radio sports announcer, primarily calling Indy car and NASCAR telecasts for ESPN/ABC and later Versus/NBCSN. Jenkins was the radio "Voice of the Indianapoli ...
. The first one was formally published in 1997.


The hash functions


one_at_a_time

Jenkins's one_at_a_time hash is adapted here from a WWW page by Bob Jenkins, which is an expanded version of his ''
Dr. Dobb's ''Dr. Dobb's Journal'' (''DDJ'') was a monthly magazine published in the United States by UBM Technology Group, part of UBM. It covered topics aimed at computer programmers. When launched in 1976, DDJ was the first regular periodical focused on m ...
'' article. It was originally created to fulfill certain requirements described by Colin Plumb, a cryptographer, but was ultimately not put to use. uint32_t jenkins_one_at_a_time_hash(const uint8_t* key, size_t length) Sample hash values for one_at_a_time hash function. one_at_a_time("a", 1) 0xca2e9442 one_at_a_time("The quick brown fox jumps over the lazy dog", 43) 0x519e91f5 The
avalanche An avalanche is a rapid flow of snow down a slope, such as a hill or mountain. Avalanches can be set off spontaneously, by such factors as increased precipitation or snowpack weakening, or by external means such as humans, animals, and earth ...
behavior of this hash is shown on the right. Each of the 24 rows corresponds to a single bit in the 3-byte input key, and each of the 32 columns corresponds to a bit in the output hash. Colors are chosen by how well the input key bit affects the given output hash bit: a green square indicates good mixing behavior, a yellow square weak mixing behavior, and red would indicate no mixing. Only a few bits in the last byte of the input key are weakly mixed to a minority of bits in the output hash. Standard implementations of the
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
programming language prior to version 5.28 included Jenkins's one-at-a-time hash or a hardened variant of it, which was used by default.


lookup2

The lookup2 function was an interim successor to one-at-a-time. It is the function referred to as "My Hash" in the 1997 Dr. Dobbs journal article, though it has been obsoleted by subsequent functions that Jenkins has released. Applications of this hash function are found in: * the
SPIN model checker SPIN is a general tool for verifying the correctness of concurrent software models in a rigorous and mostly automated fashion. It was written by Gerard J. Holzmann and others in the original Unix group of the Computing Sciences Research Center ...
, for probabilistic error detection. In a paper about this program, researchers Dillinger and Manolios note that lookup2 is "a popular choice among implementers of hash tables and
Bloom filter A Bloom filter is a space-efficient probabilistic data structure, conceived by Burton Howard Bloom in 1970, that is used to test whether an element is a member of a set. False positive matches are possible, but false negatives are not – in ...
s". They study lookup2 and a simple extension of it that produces 96-bit rather than 32-bit hash values. * The
Netfilter Netfilter is a framework provided by the Linux kernel that allows various networking-related operations to be implemented in the form of customized handlers. Netfilter offers various functions and operations for packet filtering, network addre ...
firewall component of
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
, where it replaced an earlier hash function that was too sensitive to collisions. The resulting system, however, was shown to still be sensitive to
hash flooding In cryptography, a collision attack on a cryptographic hash tries to find two inputs producing the same hash value, i.e. a hash collision. This is in contrast to a preimage attack where a specific target hash value is specified. There are roughl ...
attacks, even when the Jenkins hash is randomized using a secret key. * The program that solved the game of
kalah Kalah is a modern variation in the ancient Mancala family of games, the oldest known version having been found carved into a stone tablet in the 16th-century BCE pyramid of Cheops. The Kalah variation was developed in the United States by Willia ...
used the Jenkins hash function, instead of the
Zobrist hashing Zobrist hashing (also referred to as Zobrist keys or Zobrist signatures Bruce Moreland/ref>) is a hash function construction used in computer programs that play abstract board games, such as chess and Go, to implement transposition tables, a speci ...
technique more commonly used for this type of problem; the reasons for this choice were the speed of Jenkins' function on the small representations of kalah boards, as well as the fact that the basic rule of kalah can radically alter the board, negating the benefit of Zobrist's incremental computation of hash functions.


lookup3

The lookup3 function consumes input in 12 byte (96 bit) chunks. It may be appropriate when speed is more important than simplicity. Note, though, that any speed improvement from the use of this hash is only likely to be useful for large keys, and that the increased complexity may also have speed consequences such as preventing an optimizing compiler from inlining the hash function.


SpookyHash

In 2011 Jenkins released a new 128-bit hash function called SpookyHash. SpookyHash is significantly faster than lookup3. Example for V2 (little-endian x64): The short method for less than 192 bytes (43 bytes): Hash128("The quick brown fox jumps over the lazy dog") 2b12e846aa0693c71d367e742407341b The standard method for more than 191 bytes (219 bytes): Hash128("The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog") f1b71c6ac5af39e7b69363a60dd29c49


See also

*
Non-cryptographic hash functions This is a list of hash functions, including cyclic redundancy checks, checksum functions, and cryptographic hash functions. Cyclic redundancy checks Adler-32 is often mistaken for a CRC, but it is not: it is a checksum. Checksums Universa ...


References

{{Reflist, 30em Hash function (non-cryptographic)