Blockchain for Test Engineers: Hashing (2024)

Photo by Pan Yunbo on Unsplash.

This is the first blog post in the “Blockchain for Test Engineers” series.

When you start to study blockchain, the odds are pretty high that you will hear about hashing and hash functions.
But what is hashing? Why is it a critical concept in cryptography? Which hashing algorithms are used for different blockchains? And even more interesting - how can we test a cryptographic hash function (and should we do it at all)?

What is hashing?

Hashing can be imagined as a “box” with one input and one output. You can provide any data as an input and get a result of the fixed length.

Blockchain for Test Engineers: Hashing (1)

In the case of the SHA-256 hash function - the result will always be a 256-bit sequence. The most exciting thing in hashing is - that even the minimal change to the input changes the output - significantly.

As an example, let’s get the SHA-256 hash of the text “Test Engineering Notes”.
The result will be - “dc3101f57c983aa68499306de0e60cb7266e3b1ae2235a84aa0d727f0f07b18f”.

But “Test Engineering note” will have completely different hash: “16d164f46c6a29518420d0cdda6394969692cc82145b46eb89fe32af4a8b996e”.

Properties of hash functions

The two main properties of the hash function are ease of computation and determinism (the same input data should always result in the same hash).

Besides that, a good hashing function should withstand cryptographic attacks.
So it should have the following properties:

  • Pre-image resistance. The hash function should be a “one-way”: Given a hash value h, it should be difficult to find any message m such that h = hash(m).
  • Second pre-image resistance. Given an input m1, it should be difficult to find a different input m2 such that hash(m1) = hash(m2).
  • Collision resistance. It should be difficult to find two different messages m1 and m2, such that hash(m1) = hash(m2). Such two messages are called a hash collision.

Why does hashing exist?

There are multiple applications of the hashing in the world of computers:

  • With hashing, you can check the integrity of the data;
  • Instead of storing user passwords as plain text in a database - it is better to keep its hashes;
  • You can use hashing in the digital signatures;
  • Datatypes, such as Hash Tables and Hash Maps;
  • Blockchains :);

Different hash functions

The most famous are MD5, SHA-1, RIPEMD-160, BLAKE, Whirlpool, SHA-2, and SHA-3. E.g., Bitcoin (and its forks) uses SHA-256 cryptographic function, Ethereum - SHA-3 (Keccak), Cardano - BLAKE2b-224.

Those algorithms are based on some sequence of rounds with bit operations: shifts, AND, XOR operations, and others).

Blockchain for Test Engineers: Hashing (2)

Lane Wagner’s blog post provides an excellent step-by-step explanation of the SHA-2 hash function. You can also try to hash something online.

It is a vast mathematical task to create new hash functions and prove their properties. National Institute of Standards and Technologyis reponsible for testing hash functions. The chosen one are added to the family of secure hash algorithms and recommeded by NIST. The last known standard algorithm (Keccak) was chosen at the NIST hash functions competition. Hash functions were evaluated by their performance, security, analysis, and diversity.

How to test hash functions?

One of the leading indicators of the quality of hash functions is the probability of getting hash collisions. So one test is to check collisions at the massive input data.

Usually, the distribution of hash values ​​is uniform and is tested using the Chi-square test. The actual distribution of elements is compared with the expected (uniform) distribution. The ratio within the confidence interval should be in the range of 0.95 - 1.05.

Also, there is an additional test for uniformity of distribution of hashes. It is based on strict avalanche criteria - when each input bit changes with a probability of 50% in the output sequence.

Will you test hashing function as a blockchain test engineer?

As always - it depends. Many blockchains use well-known standards and rarely implement hash functions from scratch.

Suppose you will be a part of the core engineering team responsible for developing the whole blockchain from scratch. In that case, you may need to verify that hashing algorithm works as expected within the context of the system.

If you test only blockchain-based applications based on smart contracts - you don’t need to verify the hashing function in isolation. You should trust other security specialists and mathematicians who tested these functions for you. But you definitely need to know how such functions are used in your system.

  • ← Previous Post
  • Next Post →
Blockchain for Test Engineers: Hashing (2024)

FAQs

How many rounds does SHA512Crypt have? ›

Expert-Verified Answer. SHA512Crypt ($6$) uses 5000 rounds by default. SHA512Crypt ($6$) is a variant of the SHA-2 cryptographic hash function that is commonly used for password hashing.

Does Blockchain use hashing? ›

A Blockchain hash is created when a new block of information or data is added to the chain. The information contained in the block is hashed, and then the hash value is further added to the end of the chain. Any time the data contained in the block is altered or changed in any way, the hash value will also change.

What is the best hashing algorithm for Blockchain? ›

SHA-256 stands for Secure Hash Algorithm that generates a 256-bit digest of a message. This is one of the most renowned hashing algorithms used by several cryptocurrencies. Another popular application of this algorithm is Digital Signing Verification.

Is hashing more secure than encryption? ›

For example, a piece of plain text (a password, for example) can be turned into a hashed value, making it very hard to decipher. Hashing is a one-way process that can't be directly reversed (as opposed to encryption, which can be decrypted if you have the appropriate decryption key).

How long is a SHA-256 hash? ›

The SHA-256 algorithm generates an almost unique, fixed-size 256-bit (32-byte) hash.

What is the difference between SHA-256 and SHA-512? ›

The primary difference between SHA-256 and SHA-512 is the word size; SHA-256 uses 32-byte words whereas SHA-512 uses 64-byte words. There are also modified versions of each standard, known as SHA-224, SHA-384, SHA-512/224, and SHA-512/256.

How long is a blockchain hash? ›

Blockchain Hash Function. A hash function takes an input string (numbers, alphabets, media files) of any length and transforms it into a fixed length. The fixed bit length can vary (like 32-bit or 64-bit or 128-bit or 256-bit) depending on the hash function which is being used. The fixed-length output is called a hash.

How is hash calculated in blockchain? ›

The Bitcoin blockchain uses the SHA-256 hashing algorithm to calculate hashes. When a computer puts a string through this algorithm, the algorithm will turn it into a long hex code unique to the string. If the same string is re-hashed, the result should always be the same.

Is blockchain encrypted or hashed? ›

Private Key and Digital Signatures

Hash Functions have a lot of importance in public key cryptography within the blockchain. Public keys and digital signatures are generated through hash functions and provide a secure way for participants to verify their ownership of assets.

What is the strongest hashing algorithm? ›

What's the Most Secure Hashing Algorithm? SHA-256. SHA-256 (secure hash algorithm) is an algorithm that takes an input of any length and uses it to create a 256-bit fixed-length hash value.

What are the 4 hashing algorithms? ›

Some common hashing algorithms include MD5, SHA-1, SHA-2, NTLM, and LANMAN.

What are the 3 hashing algorithm? ›

The SHA-3 family consists of six hash functions with digests (hash values) that are 128, 224, 256, 384 or 512 bits: SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128, SHAKE256. Currently, this library supports all of the algorithms mentioned above.

What is the safest hashing algorithm? ›

Common attacks like brute force attacks can take years or even decades to crack the hash digest, so SHA-2 is considered the most secure hash algorithm.

Can you decrypt a hash? ›

Since encryption is two-way, the data can be decrypted so it is readable again. Hashing, on the other hand, is one-way, meaning the plaintext is scrambled into a unique digest, through the use of a salt, that cannot be decrypted.

Can a hashed password be reversed? ›

You can't "reverse" password hashes. You can't "unhash" or "dehash" passwords. You can't "reverse" or "invert" MD5, SHA256, bcrypt, SHA1, or similar hashes, salted or unsalted. You (usually) can't "decode" passwords, "decrypt" password hashes or "reverse" or "unscramble" password hashes at all.

How many chars is SHA512? ›

SHA-2 output is always fixed. SHA-512 will always produce a message digest of 512 bits – hence its name – and is practically represented using 64 binary bytes, or 128 chars when HEX-encoding the message digest. It does not matter how long or short your input is.

What is the default round of SHA512 crypt? ›

The value 0 means that the system will choose the default number of rounds for the crypt method (5000). A minimal value of 1000 and a maximal value of 999,999,999 will be enforced. You can only use this option with the SHA256 or SHA512 crypt method.

What is the default round of SHA 512? ›

The maximum password length for crypt_sha512 is 255 characters. Specifies the number of rounds of SHA-512 to use in generation of the salt; the default number of rounds is 5000. Negative values have no effect and are ignored. The minimum number of rounds cannot be below 1000.

What is the round function of SHA 512? ›

SHA 512 consists of 8 words of 64 bits each. The standard hashing algorithm will run individual round for 80 times and the generates 512 bits output. This 512 bits will act as input to the following message block.

Top Articles
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 5782

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.