Hash function
between keys "John Smith" and "Sandra Dee". A hash function is any function that can be used to map data of arbitrary size to fixed-size values, though there are some hash functions that support variable-length output. The values returned by a hash function are called hash values, hash codes, (hash/message) digests, or simply hashes. The values are usually used to index a fixed-size table called a hash table. Use of a hash function to index a hash table is called hashing or scatter-storage addressing. Hash functions and their associated hash tables are used in data storage and retrieval applications to access data in a small and nearly constant time per retrieval. They require an amount of storage space only fractionally greater than the total space required for the data or records themselves. Hashing is a way to access data quickly and efficiently. Unlike lists or trees, it provides near-constant access time. It also uses much less storage than trying to store all possible keys...
between keys "John Smith" and "Sandra Dee". A hash function is any function that can be used to map data of arbitrary size to fixed-size values, though there are some hash functions that support variable-length output. The values returned by a hash function are called hash values, hash codes, (hash/message) digests, or simply hashes. The values are usually used to index a fixed-size table called a hash table. Use of a hash function to index a hash table is called hashing or scatter-storage addressing. Hash functions and their associated hash tables are used in data storage and retrieval applications to access data in a small and nearly constant time per retrieval. They require an amount of storage space only fractionally greater than the total space required for the data or records themselves. Hashing is a way to access data quickly and efficiently. Unlike lists or trees, it provides near-constant access time. It also uses much less storage than trying to store all possible keys directly, especially when keys are large or variable in length. Use of hash functions relies on statistical properties of key and function interaction: worst-case behavior is intolerably bad but rare, and average-case behavior can be nearly optimal (minimal collision). Hash functions are related to (and often confused with) checksums, check digits, fingerprints, lossy compression, randomization functions, error-correcting codes, and ciphers. Although the concepts overlap to some extent, each one has its own uses and requirements and is designed and optimized differently. The hash function differs from these concepts mainly in terms of data integrity. Hash tables may use non-cryptographic hash functions, while cryptographic hash functions are used in cybersecurity to secure sensitive data such as passwords. \frac{m}{n}{\sum_{j=1}^m b_j^2} - n where is the number of keys, is the number of buckets, and is the number of items in bucket . A ratio within one confidence interval (such as 0.95 to 1.05) is indicative that the hash function evaluated has an expected uniform distribution. Hash functions can have some technical properties that make it more likely that they will have a uniform distribution when applied. One is the strict avalanche criterion: whenever a single input bit is complemented, each of the output bits changes with a 50% probability. The reason for this property is that selected subsets of the keyspace may have low variability. For the output to be uniformly distributed, a low amount of variability, even one bit, should translate into a high amount of variability (i.e. distribution over the tablespace) in the output. Each bit should change with a probability of 50% because, if some bits are reluctant to change, then the keys become clustered around those values. If the bits want to change too readily, then the mapping is approaching a fixed XOR function of a single bit. Standard tests for this property have been described in the literature. The relevance of the criterion to a multiplicative hash function is assessed here. ===Applicability=== A hash function that allows only certain table sizes or strings only up to a certain length, or cannot accept a seed (i.e. allow double hashing) is less useful than one that does. A hash function is applicable in a variety of situations. Particularly within cryptography, notable applications include: Integrity checking: Identical hash values for different files imply equality, providing a reliable means to detect file modifications. Key derivation: Minor input changes result in a random-looking output alteration, known as the diffusion property. Thus, hash functions are valuable for key derivation functions. Message authentication codes (MACs): Through the integration of a confidential key with the input data, hash functions can generate MACs ensuring the genuineness of the data, such as in HMACs. Password storage: The password's hash value does not expose any password details, emphasizing the importance of securely storing hashed passwords on the server. Signatures: Message hashes are signed rather than the whole message. ==Hashing integer data types== There are several common algorithms for hashing integers. The method giving the best distribution is data-dependent. One of the simplest and most common methods in practice is the modulo division method. Other types of data can also use this hashing scheme. For example, when mapping character strings between upper and lower case, one can use the binary encoding of each character, interpreted as an integer, to index a table that gives the alternative form of that character ("A" for "a", "8" for "8", etc.). If each character is stored in 8 bits (as in extended ASCII or ISO Latin 1), the table has only 2 8 = 256 entries; in the case of Unicode characters, the table would have 17 × 2 16 = entries. The same technique can be used to map two-letter country codes like "us" or "za" to country names (26 2 = 676 table entries), 5-digit ZIP codes like 13083 to city names ( entries), etc. Invalid data values (such as the country code "xx" or the ZIP code 00000) may be left undefined in the table or mapped to some appropriate "null" value. Define P(x)=\prod_{j\in S}(x-\alpha^j) where and where the coefficients of are computed in this field. Then the degree of . Since is a root of whenever is a root, it follows that the coefficients of satisfy , so they are all 0 or 1. If is any nonzero polynomial modulo 2 with at most nonzero coefficients, then is not a multiple of modulo 2. If follows that the corresponding hash function will map keys with fewer than bits in common to unique indices. The usual outcome is that either will get large, or will get large, or both, for the scheme to be computationally feasible. Therefore, it is more suited to hardware or microcode implementation. unsigned hash(unsigned K) { return (a * K) >> (w - m); } and for fixed and this translates into a single integer multiplication and right-shift, making it one of the fastest hash functions to compute. Multiplicative hashing is susceptible to a "common mistake" that leads to poor diffusion—higher-value input bits do not affect lower-value output bits. A transmutation on the input which shifts the span of retained top bits down and XORs or ADDs them to the key before the multiplication step corrects for this. The resulting function looks like: unsigned hash(unsigned K) { K ^= K >> (w - m); return (a * K) >> (w - m); } 16: a = 9E37 16 = 10 32: a = 16 = 10 48: a = 16 = 10 64: a = 16 = 10 The multiplier should be odd, so the least significant bit of the output is invertible modulo . The last two values given above are rounded (up and down, respectively) by more than 1/2 of a least-significant bit to achieve this. The most familiar algorithm of this type is Rabin-Karp with best and average case performance and worst case (in all fairness, the worst case here is gravely pathological: both the text string and substring are composed of a repeated single character, such as ="AAAAAAAAAAA", and ="AAA"). The hash function used for the algorithm is usually the Rabin fingerprint, designed to avoid collisions in 8-bit character strings, but other suitable hash functions are also used.
References
- ^ Aggarwal, Kirti; Verma, Harsh K. (March 19, 2015). Hash_RC6 — Variable length Hash algorithm using RC6 . 2015 International Conference on Advances in Computer Engineering and Applications (ICACEA). doi : 10.1109/ICACEA.2015.7164747 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Wagner, Urs; Lugrin, Thomas (2023), "Hash Functions", in Mulder, Valentin; Mermoud, Alain; Lenders, Vincent; Tellenbach, Bernhard (eds.), Trends in Data Protection and Encryption Technologies , Cham: Springer Nature Switzerland, pp. 21– 24, doi : 10.1007/978-3-031-33386-6_5 , ISBN 978-3-031-33386-6 Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ "3. Data model — Python 3.6.1 documentation" . docs.python.org . Retrieved 2017-03-24 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1490310000.0
- ^ Plain ASCII is a 7-bit character encoding, although it is often stored in 8-bit bytes with the highest-order bit always clear (zero). Therefore, for plain ASCII, the bytes have only 2 7 = 128 valid values, and the character translation table has only this many entries. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ For example, for n=15, k=4, t=6, S={1,2,3,4,5,6,8,10,12,9} [Knuth] Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Knuth conveniently leaves the proof of this to the reader. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Dolev, Shlomi; Lahiani, Limor; Haviv, Yinnon (2013). "Unique permutation hashing" . Theoretical Computer Science . 475 : 59– 65. doi : 10.1016/j.tcs.2012.12.047 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ "CS 3110 Lecture 21: Hash functions" . Section "Multiplicative hashing". Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Unisys large systems. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ "hash digest" . Computer Security Resource Center - Glossary . NIST . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Zobrist, Albert L. (April 1970), A New Hashing Method with Application for Game Playing (PDF) , Tech. Rep. 88, Madison, Wisconsin: Computer Sciences Department, University of Wisconsin . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Aho, A. ; Sethi, R. ; Ullman, J. D. (1986). Compilers: Principles, Techniques and Tools . Reading, MA: Addison-Wesley . p. 435. ISBN 0-201-10088-6 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Ramakrishna, M. V.; Zobel, Justin (1997). "Performance in Practice of String Hashing Functions". Database Systems for Advanced Applications '97 . DASFAA 1997. pp. 215– 224. doi : 10.1142/9789812819536_0023 . ISBN 981-02-3107-5 . S2CID 8250194 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Singh, N. B. A Handbook of Algorithms . N.B. Singh. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ "Lecture 14: Hash Tables" . www.cs.cornell.edu . Retrieved 2026-10-03 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1790982000.0
- ^ Knuth, Donald E. (1975). The Art of Computer Programming, Vol. 3, Sorting and Searching . Reading, MA: Addison-Wesley . p. 540. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Gonnet, G. (1978). Expected Length of the Longest Probe Sequence in Hash Code Searching (Technical report). Ontario, Canada: University of Waterloo . CS-RR-78-46. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ This is useful in cases where keys are devised by a malicious agent, for example in pursuit of a DOS attack. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Stokes, Jon (2002-07-08). "Understanding CPU caching and performance" . Ars Technica . Retrieved 2022-02-06 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1644102000.0
- ^ "About the explanation of testing and measurement of hash functions at Wikipedia" . Cross Validated. July 9, 2026. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Castro, Julio Cesar Hernandez; et al. (3 February 2005). "The strict avalanche criterion randomness test". Mathematics and Computers in Simulation . 68 (1). Elsevier : 1– 7. doi : 10.1016/j.matcom.2004.09.001 . S2CID 18086276 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Pagani, Fabio; Dell'Amico, Matteo; Balzarotti, Davide (2018-03-13). "Beyond Precision and Recall" (PDF) . Proceedings of the Eighth ACM Conference on Data and Application Security and Privacy . New York, NY, USA: ACM. pp. 354– 365. doi : 10.1145/3176258.3176306 . ISBN 9781450356329 . Retrieved December 12, 2022 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Sarantinos, Nikolaos; Benzaïd, Chafika; Arabiat, Omar (2016). "Forensic Malware Analysis: The Value of Fuzzy Hashing Algorithms in Identifying Similarities" . 2016 IEEE Trustcom/BigDataSE/ISPA (PDF) . pp. 1782– 1787. doi : 10.1109/TrustCom.2016.0274 . ISBN 978-1-5090-3205-1 . S2CID 32568938 . 10.1109/TrustCom.2016.0274. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Breitinger, Frank (May 2014). "NIST Special Publication 800-168" (PDF) . NIST Publications . doi : 10.6028/NIST.SP.800-168 . Retrieved January 11, 2023 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Kornblum, Jesse (2006). "Identifying almost identical files using context triggered piecewise hashing" . Digital Investigation . 3, Supplement (September 2006): 91– 97. doi : 10.1016/j.diin.2006.06.015 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Oliver, Jonathan; Cheng, Chun; Chen, Yanggui (2013). "TLSH -- A Locality Sensitive Hash" (PDF) . 2013 Fourth Cybercrime and Trustworthy Computing Workshop . IEEE. pp. 7– 13. doi : 10.1109/ctc.2013.9 . ISBN 978-1-4799-3076-0 . Retrieved December 12, 2022 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Buldas, Ahto; Kroonmaa, Andres; Laanoja, Risto (2013). "Keyless Signatures' Infrastructure: How to Build Global Distributed Hash-Trees". In Riis, Nielson H.; Gollmann, D. (eds.). Secure IT Systems. NordSec 2013 . Lecture Notes in Computer Science. Vol. 8208. Berlin, Heidelberg: Springer. doi : 10.1007/978-3-642-41488-6_21 . ISBN 978-3-642-41487-9 . Keyless Signatures Infrastructure (KSI) is a globally distributed system for providing time-stamping and server-supported digital signature services. Global per-second hash trees are created and their root hash values published. We discuss some service quality issues that arise in practical implementation of the service and present solutions for avoiding single points of failure and guaranteeing a service with reasonable and stable delay. Guardtime AS has been operating a KSI Infrastructure for 5 years. We summarize how the KSI Infrastructure is built, and the lessons learned during the operational period of the service. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Klinger, Evan; Starkweather, David. "pHash.org: Home of pHash, the open source perceptual hash library" . pHash.org . Retrieved 2018-07-05 . pHash is an open source software library released under the GPLv3 license that implements several perceptual hashing algorithms, and provides a C-like API to use those functions in your own programs. pHash itself is written in C++. Wikipedia revision 1378286790, retrieved 2026-11-21 · 1530745200.0
- ^ a b Sedgewick, Robert (2002). "14. Hashing". Algorithms in Java (3 ed.). Addison Wesley. ISBN 978-0-201-36120-9 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ a b Sharupke, Malte (16 June 2018). "Fibonacci Hashing: The Optimization that the World Forgot" . Probably Dance . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ Menezes, Alfred J.; van Oorschot, Paul C.; Vanstone, Scott A (1996). Handbook of Applied Cryptography . CRC Press. ISBN 978-0-8493-8523-0 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ a b c d Knuth, Donald E. (1973). The Art of Computer Programming, Vol. 3, Sorting and Searching . Reading, MA., United States: Addison-Wesley . Bibcode : 1973acp..book.....K . ISBN 978-0-201-03803-3 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- ^ a b Knuth, Donald E. (2000). The Art of Computer Programming, Vol. 3, Sorting and Searching (2. ed., 6. printing, newly updated and rev. ed.). Boston [u.a.]: Addison-Wesley. ISBN 978-0-201-89685-5 . Wikipedia revision 1378286790, retrieved 2026-11-21 · 1795215600.0
- hash digest . Computer Security Resource Center - Glossary . · 1790982000.0
- Singh, N. B. A Handbook of Algorithms . N.B. Singh . · 1790982000.0
- Lecture 14: Hash Tables . www.cs.cornell.edu . retrieved 2026-10-03 · 1790982000.0
- Understanding CPU caching and performance . · 1790982000.0
- Menezes, Alfred J. Handbook of Applied Cryptography . CRC Press . 1996. · 1790982000.0
- About the explanation of testing and measurement of hash functions at Wikipedia . Cross Validated . July 9, 2026. · 1790982000.0
- Sharupke, Malte. Fibonacci Hashing: The Optimization that the World Forgot . · 1790982000.0
- 3. Data model — Python 3.6.1 documentation . docs.python.org . retrieved 2017-03-24 · 1490310000.0
- CS 3110 Lecture 21: Hash functions . · 1790982000.0
- A New Hashing Method with Application for Game Playing . · 1790982000.0
Cite this
"Hash function". 1791053295. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1378286790