**One-way hash function, a fingerprint to get message**

Fingerprints, also known as ‘human identity cards’, everyone has but different. The message processed in the computer also has its unique fingerprint. By comparing you can know whether the two messages are the same, and the **one-way hash function** is used to generate the fingerprint in computer.

One way operations are called that because they are not reversible. Most typical operations like addition and multiplication can be reversed while modulo division can not be reversed. Why is that important? Because you want to provide a output value which 1) is difficult to duplicate without the original inputs and 2) provides no way to figure out the inputs from the output.

A one-way hash function, also known as a message digest, fingerprint or compression function, is a mathematical function which takes a variable-length input string and converts it into a fixed-length binary sequence. Furthermore, a one-way hash function is designed in such a way that it is hard to reverse the process, that is, to find a string that hashes to a given value (hence the name one-way.) A good hash function also makes it hard to find two strings that would produce the same hash value.

One-way hash function is a kind of file fingerprint technology, its generated hash value is equivalent to the message ‘fingerprint’. One-way hash function can calculate the hash value according to the content of the message. For any message, the one-way hash function treats it as a pure bit sequence. Just as everyone has a different fingerprint, each message has a different hash value that can be used to check the consistency or integrity of the message.

Besides, there are several methods to use a block cipher to build a cryptographic hash function, specifically a one-way compression function. The methods resemble the block cipher modes of operation usually used for encryption. Many well-known hash functions, including MD4, MD5, SHA-1 and SHA-2 are built from block-cipher-like components designed for the purpose, with feedback to ensure that the resulting function is not invertible. SHA-3 finalists included functions with block-cipher-like components (e.g., Skein, BLAKE) though the function finally selected, Keccak, was built on a cryptographic sponge instead.

One-way hash function must have the following properties:

(1) Messages of any length can calculate short and fixed-length hash values;

(2) Hash values can be calculated quickly according to messages;

(3) Different messages output different hash values;

Here’s a very simple example. Assume that I’m a beginning cryptographer and I create a hash function that does the following:

Now here’s the test. *SimpleHash(specialFile)* is 0. What was my original file?

Obviously, there’s no way to know (although you could likely discover pretty easily that my hash is based on file length). There is no way to “reconstitute” my file based on the hash because the hash doesn’t contain everything that my file did.

Besides, there are many places where one-way hash functions are used in bitcoin. Bitcoin transactions are done through bitcoin addresses, which are generated by hash values of the public key.

The blockchain structured as follows: a block consists of several transactions and a block header, in which the hash value of the previous block and the all transactions overall hash value in the block are stored.

In the following figure, the hash value H2 in block header 2 is calculated based on block header 1; the hash value T2 is calculated based on all transaction data in block 2. If a transaction in block 1 is tampered, the corresponding hash value T1 needs to be recalculated, and the hash value H2 in the corresponding block header 2 changes, making it more difficult to tamper with the data on the block chain.

To add a new block to the blockchain, the miner needs to generate a legal block header, which specifies the format of the ‘the previous block hash value’. While Using the PoW workload proves, the miner needs to constantly change the nouce to try until the hash values of the previous bits are all zeros to meet the requirements.

One-way hash functions are also used in the digital signature techniques used to create transactions. The hash value of the message is first computed by a one-way hash function, and then a digital signature is applied to the hash value.

In addition to digital cryptocurrency, one-way hash functions are often used in real life. For example, detecting whether the software has been tampered with, constructing message authentication codes to detect and prevent errors, tampering, and masquerading in the communication process, performing digital signatures, and constructing pseudo-random number generators. The one-time password is used to authenticate the client and so on.

# Official Channels

Telegram(Official): https://t.me/TriasOfficial

Telegram(English):https://t.me/triaslab

Twitter: https://twitter.com/triaslab

Medium: https://medium.com/@Triaslab