Hash function
Hash function
Hash pointer
One way function
What is a hash function?
• For example, the text “hello”, using the hash function SHA-256,
produces the hash:
• 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e730433629
38b9824
• Hash functions are the vital part of digital signatures that ensures
data integrity and are used for authentication for blockchain
transactions.
Bitcoin transaction --- Address
• Now that you have created your public/private key pair, you are
ready to join the network and receive bitcoin. Your friend, Tom, said
he is willing to give you 10 bitcoin if you provide him your address.
• In order to create an address your public key is hashed into a
pubkeyhash and converted to a base58check format, which generates
the addresses you see today that start with a ‘1’ or ‘3’. Note again,
you can always use your private key to create a public key and you
can always use your public key to create the pubkeyhash, but you
can’t work backwards. It is a one-way street.
• You can, however, go back and forth between a pubkeyhash and a
Bitcoin address.
The chain of blocks:
• Each block header in a block in
the blockchain contains the hash
of the previous block header.
• This ensures that it is not
possible to change even a single
block in a blockchain without
being detected.
• As modifying one block requires
generating new versions of
every following block, thus
increasing the difficulty.
Properties of hash functions
• In order for the bundled block to be added to the blockchain, miners need
to find a hash that meets the target difficulty. Each block contains a
blockheader with the number of the block, the hash of the previous block
and a “nonce”, which includes a timestamp. The purpose of a nonce is
varying the input to a cryptographic hash function, that is increased
randomness, in computation during the mining process.
SHA-256
• SHA 256 is a part of the SHA 2 family of algorithms, where SHA stands
for Secure Hash Algorithm. Published in 2001, it was a joint effort
between the NSA and NIST to introduce a successor to the SHA 1
family, which was slowly losing strength against brute force attacks.
• The significance of the 256 in the name stands for the final hash
digest value, i.e. irrespective of the size of plaintext/cleartext, the
hash value will always be 256 bits.
Some of the standout features of the SHA
algorithm are as follows:
• Message Length: The length of the cleartext should be less than 264
bits. The size needs to be in the comparison area to keep the digest
as random as possible.
• Digest Length: The length of the hash digest should be 256 bits in SHA
256 algorithm, 512 bits in SHA-512, and so on.
• Bigger digests usually suggest significantly more calculations at the
cost of speed and space.
• Irreversible: By design, all hash functions such as the SHA 256 are
irreversible. You should neither get a plaintext when you have the
digest beforehand nor should the digest provide its original value
when you pass it through the hash function again.
Steps in SHA-256 Algorithm
•Padding Bits
•Padding Length
•Output
Process of hasing SHA256
You can divide the complete process into five different segments, as mentioned
below:
Padding Bits
• It adds some extra bits to the message, such that the length is exactly 64 bits short of a
multiple of 512.
• During the addition, the first bit should be one, and the rest of it should be filled with
zeroes.
•
Padding Length
• You can add 64 bits of data now to make the final plaintext a multiple
of 512.
• You can calculate these 64 bits of characters by applying the modulus
to your original cleartext without the padding.
Initialising the Buffers:
• You need to initialize the default values for eight buffers to be used in the rounds as follows:
•
• You also need to store 64 different keys in an array, ranging from K[0] to K[63].
They are initialized as follows:
•
Compression Functions
• The entire message gets broken down into multiple blocks of 512 bits each.
• It puts each block through 64 rounds of operation, with the output of each
block serving as the input for the following block.
• The entire process is as follows:
•
https://sha256algorithm.com/
• While the value of K[i] in all those rounds is pre-initialized, W[i] is
another input that is calculated individually for each block, depending
on the number of iterations being processed at the moment.
• With each iteration, the final output of the block serves as the input
for the next block. The entire cycle keeps repeating until you reach
the last 512-bit block, and you then consider its output the final hash
digest. This digest will be of the length 256-bit, as per the name of
this algorithm.