Hash function
lastmod 2025-01-15created 2016-08-227 edits
A hash function is an algorithm that maps data of arbitrary length to data of fixed length. The value obtained by a hash function is called a hash value, hash code, checksum, or hash. A hash function must operate deterministically, so if two hash values differ, the original data for those hash values must also differ. (The converse does not hold.) The quality of a hash function is determined by the probability of hash collisions over the input domain; the higher the probability of hash collisions, the harder it becomes to distinguish different data and the higher the cost of searching.
Hash functions are often divided into cryptographic hash functions (Cryptographic Hash Function) and non-cryptographic hash functions.
Cryptographic hash functions include MD5 and the SHA family of hash functions, while non-cryptographic hash functions include CRC32, among others.
Cryptographic hash functions must be secure against pre-image (pre-image), second pre-image (2nd preimage), and collision (collision) attacks, and are used for authentication. Cryptographic hash functions accept input of arbitrary length, but since length information is included during MD Strength Padding, there is a limit on the maximum length. For example, if the length information is written into the lower 8 bits during padding, the maximum hashable length is 0xFF, or 255 bytes. (The actual length information may differ depending on the padding scheme.)
Categories
What is a hash function?
A hash function H transforms a variable-size input m into a fixed-size string called the hash value h. Hash functions with this characteristic are used in a variety of general computations. When used in cryptography, however, hash functions generally have a few additional characteristics.
The basic requirements of a cryptographic hash function are as follows.
- The input can be of any length.
- The output has a fixed length.
- H(x) is relatively easy to compute for any given x.
- H(x) is one-way (one-way).
- H(x) is collision-free (collision).
A hash function H is called one-way if it is hard to invert. Here, "hard to invert" means that, given a hash value h, it is computationally infeasible to find an x such that H(x)=h. If, for a given message x, it is computationally infeasible to find messages x, y such that H(x)=H(y), H is called a weakly collision-free hash function. A strongly collision-free hash function H is one for which it is computationally infeasible to find two messages x and y such that H(x)=H(y). A hash value concisely represents a long message or computerized document. It can be thought of as a message digest, like a "digital fingerprint" of a long document. Well-known examples of hash functions are MD2, MD5, and SHA. Perhaps the main role of cryptographic hash functions is in preparing digital signatures. Since hash functions are generally faster than digital signature algorithms, it is standard to compute the digital signature of a document by computing a signature on the document's hash value, which is small compared to the document itself. In addition, a digest can be made public without revealing the contents of the document it was derived from. This is important for digital timestamping. Here, by using a hash function, a document can be timestamped without revealing its contents to the timestamping service.
It is an algorithm that generates a message digest (message digest), a new compressed representation of a message, and is also called:
- Cryptographic checksum (cryptographic checksum).
- Cryptographic compression (cryptographic compression) algorithm.
- Message digest (message digest).
Each has slight differences in meaning depending on the context of use, but they are almost the same as a hash function.
Hash collision (Hash collision)
In computer science, a hash collision is a situation in which a hash function produces the same output for two different inputs. Every hash function, however well designed, carries the potential for collisions. Hash collisions should occur relatively rarely or be relatively hard to find. In specific applications where the number of possible inputs is known in advance and is small, it is possible to create a perfect hash function that maps every input to a non-colliding output. However, most hash functions, including cryptographic hash functions, produce outputs in a fixed range from fairly long inputs. Therefore, since such designs accept a far larger range of inputs than the range of hash outputs, collisions always occur.
Double hashing (Double hashing)
Double hashing is a method for resolving hash collisions. A hash collision occurs when two different values have the same hash key. If colliding items are placed in other address spaces of the hash table instead of being managed separately, the question arises of where to place them. Double hashing hashes the value with a different hash function and adds that value to the current address to get a new address. Since the step size on collision then varies with the value, clustering at a single hash value is reduced. It also solves the problem where, with bad luck, collisions keep occurring and search takes a very long time.
See also
- Authentication
- Cryptographic hash function (Cryptographic hash function)
- HashMap
- Information Security
- Secure Coding (Key store)
- C++:SecureProgramming (C++)
- Hopscotch hashing
Favorite site
- Wikipedia (en) Hash function
- Wikipedia (ko) description of hash functions
- Description of general-purpose hash functions and API download 1
Guide
- (Data structures) Implementing a chaining hash table (Chaining Hash Table) -C/C++
- Hash algorithm (Hash Algorithm) summary and test code
- Data structures :: Hash table (Hash Table)
- Understanding and implementing a Hashtable #1
- Performance comparison of map and unordered_map with string keys
implementation
- Github - A C++ implementation of a fast hash map and hash set using hopscotch hashing
- Github - A fast, memory efficient hash map for C++
- Github - arthurs97/HashMap
- Github - aozturk/HashMap.h
References
-
Www.partow.net.zip ↩
- Authentication
- Awk
- Bash
- C++:SecureProgramming
- Cat
- Computer Language
- Cryptographic hash function
- Cryptography
- Cut
- Data Structures
- Diff
- Electronic signature
- GNU
- Grep
- HashMap
- HTTP:Authentication
- Information security
- Java.util.HashSet
- Linux
- Linux:UsefulCommandLines
- Message-Digest algorithm
- Rev
- Secure Coding
- Secure Socket Layer
- Security token
- Sed
- Session
- SolutionStack:FullStackDeveloper:Curriculum
- Stdbuf
- Tee
- Unix
- Xargs