What is SHA256

What is SHA256

A Simple Breakdown of Blockchain Security

To better understand this post, please refer to my last post ‘What is Blockchain?’ if you haven't.

Before delving into the topic, you must first understand two basics: Cryptography and Consensus Mechanisms..

Cryptography: These are formulae or procedures used to secure information and communication through the use of scrambled words and codes achieved with mathematical calculations known as algorithms. Cryptography is used in communication so that it will be almost impossible for messages to be intercepted or changed by third parties before they get to the person the message is meant for. One of the mathematical functions used in cryptography is Hashing, also referred to as hash functions.

What is Hashing? Hashing is one of the cryptographic functions. It is the scrambling of info or data beyond recognition. It is also used to securely store passwords, find duplicate records, quickly store and retrieve data, etc. for instance, when you create an account on an app or a website, your passwords are hashed and stored in a database. Since the same input always gives the same hash output, a slight mistake in your password gives an error message because the hash output changes drastically.

A hash function is used to convert input into an output also known as Hash Digest. These functions are irreversible by design. That means you cannot get the input by reversing the calculations or passing it through the same hash functions. A hash output cannot be converted to its original plain text input.

Examples of Hash functions are MD2, MD4, MD5, and the SHA family.

Secure Hashing Algorithms (SHA) are the most secure hashing functions

SHA 0 SHA 1 SHA2 family (SHA 224, ,256, 384, 512, 512/224, 512/256)

A SHA function must meet these criteria:

Deterministic: you’ll always get the same output if you give the same input. This makes data storage easier. The output length is fixed. E.g 32 characters for the SHA1 and 64 characters for SHA 256.

PreImage Resistance: impossible to derive the input from the output. The calculation cannot be reversed by passing the output through the hash function to get the input.

E.g. This is the SHA 256 output for Oluchi Judith

53af3dc3bdfa62a55924f9a0a0c93393baee6b054d2a9a5198cb18cad4437253

If you should try to reverse the hash output by passing it through the SHA 256 function, it will give this:

A591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

Fast Computation: to save transaction time, the conversion has to happen very quickly.

Avalanche Effect: a small change in the input must cause a drastic change in the output. You saw an example in the previous post.

Resistance to Collision or Collision-free: two unique inputs should never give the same output.

The MDs and SHA 0 have been abandoned because of some instances of collision: two unique inputs generated the same output.

WHY SHA 256 was chosen over SHA 1:

I explained in the previous post that 256 means it contains 256 scrambled combinations of 0s and 1s. These are called bits. That means any input passed through the SHA 256 function gives 256 bits which accounts for its 64 character output.

In computer science, it is taught that 4 bits = a character.

If you divide 256 by 4 (256/4), this will give the 64 characters SHA 256 is made up of. There are a series of hard-core mathematical operations the computer processes to give the 64-character fixed output of SHA 256. The conversion above is all you need to know.

SHA 1 has 160 bits. According to the calculation above, the output of SHA 1 will always give a fixed length of 32 characters (160/4). This makes it susceptible to collision.

Mathematically, it will take 2^256. ( 115 quarttuorvigintillion (78 digits) ) attempts for a collision to occur in SHA 256

115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,457,584,007,913,129,639,936 bruteforce attempts are what it will take to get a collision.

Imagine a hacker trying his luck for that long. This makes SHA 256 secure, and the blockchain technology secure.

Consensus Mechanisms:

The protocols or techniques used to have a group of people agree on a decision. Since the Blockchain is a decentralized ledger, there have to be protocols or rules in place to align the actions of the miners or nodes. They take unified decisions to ensure the safety of the blockchain data such as ensuring that all nodes on the Blockchain are synchronized with each other; they also agree on the transactions or data to be added to a block and the blockchain.

Some of the known Blockchain consensus mechanisms are: Proof of Work; Proof of Stake; Proof of History; Proof of Authority; Delegated Proof of Stake; Proof of Weight; Proof of Space and Time etc.

In Proof of Work, before a filled block is added to the blockchain, the network protocol sends a SHA 256 hash digest (output) and the miners are required to calculate the Nonce.

Nonce means number only used once. This is like the password to the block. They are to find the combination of numbers that will generate the output

The output most times starts with a particular number of zeros as seen in the instance of an already mined block below:

00000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f (a SHA 256 function output)

This is the Nonce of the output: 2,083,236,893

Remember, there can only be one right input.

The first to crack this gets to add the block to the network. On the bitcoin network, he is rewarded with about 6.25 bitcoin.

In subsequent posts, I’ll be picking 5 out of the popular consensus mechanisms, and tie each to one blockchain project to make the concepts more concrete; one post at a time.

Assignment.

Play with SHA-256 strings conversions:

timestampgenerator.com/generate-hash/sha256

Also, visit the explorer section of blockchain.com to view the last mined bitcoin.

Has this post helped your block journey a little? Let me know in the comment section.