SHA-256 is a cryptographic hash function with the SHA-2 family of hash functions. It was developed by the NSA (National Security Agency) in 2016 following the breakdown of its predecessor SHA-1. SHA-256 has never been compromised and is considered one of the most secure cryptographic hash functions.
The SHA-256 hash function takes an input of a random size and produces an output of a fixed size. Hash functions are powerful because they are ‘one-way’ i.e., producing an output from the given input is possible but not the otherwise. Thus, SHA-256 is used in two main ways i.e., mining and creation of Bitcoin addresses.
1. Mining
Mining is a process by which new coins are introduced into the existing circulating supply of the Bitcoin protocol, as well as a method used to secure the Bitcoin network. For an individual to be eligible to add a block to the blockchain, they must first operate as a ‘mining node’. Upon successfully setting up a mining node, an individual can then begin constructing candidate blocks which are then relayed to the Bitcoin network in order to be checked for their validity. Inside a block is what is known as a ‘block header’. The construction of block header involves 6 parameters (as follows) to construct a ‘block header’.
· Version- Version number of the Bitcoin Software
· Previous block hash- Reference to the hash of the previous block
· Merkle Root- A representative hash of all transactions included in the block
· Timestamp- The time at which the block was created
· Target- PoW algorithm for the block
· Nonce- The variable used in the PoW process
As seen in the image above, in order for the miner to produce the ‘previous block hash’ parameter, the block header of the previous block must be put through the SHA-256 algorithm twice, also known as ‘double-SHA-256’.
Previous Block Hash = SHA-256(SHA-256(Block Header))
2. Creation of Bitcoin addresses
In order to produce a Bitcoin address, a ‘private key’, which is a randomly selected number, is multiplied using an elliptic curve to produce a ‘public key’. This public key is then put through both the SHA-256 and RIPEMD160 hashing algorithm.
Where K=public key and A=Bitcoin address
A=RIPEMD160(SHA-256(K))
The use of SHA-256 and RIPEMD160 hashing algorithms for the creation of a Bitcoin address (private key) has one distinct advantage i.e., shorter addresses. While a public key is 256 bits long, Bitcoin address is 160 bits long.
NOTE: RIPEMD-160 is a cryptographic hash function based upon the Merkle–DamgÃ¥rd construction. It is used in the Bitcoin standard. It is a a strengthened version of the RIPEMD algorithm which produces a 128 bit hash digest while the RIPEMD-160 algorithm produces a 160-bit output.
Will review your comment and get back!