Cryptography in Blockchain

Blockchain is not an entirely new technology. Rather it is an amalgamation of already existing technologies in which Cryptography on of the building blocks. To be precise the Blockchain Technology uses well known computer science mechanisms combined with cryptographic primitives (Cryptographic hash functions, Digital Signatures, Asymmetric Key Cryptography) and record keeping concepts.

In this article I will try and touch base the cryptographic primitives (Cryptographic hash functions, Digital Signatures, Asymmetric Key Cryptography).

Definition

Simply put Cryptography is the science of maintaining the Security, Confidentiality, Integrity and Authenticity of data which is shared in the presence of adversaries (people or groups which can tweak or manipulate the data). Let us see (in short) how.

  1. Security: The data in which cryptography is applied cannot be read by a human being. This means that the data is in a form which will need a key in order to decipher the data into a human readable form.
  2. Confidentiality: This assures that the data or information is only available to authorized entities.
  3. Integrity: This ensures that the data can only be modified by authorized entities.
  4. Authenticity: Authenticity assures that the data is sourced from a valid entity.

How does cryptography work?

We saw that cryptography helps in securing information, but let us now see what is the basic idea or concept in which cryptography works.
The basic idea in Cryptography is that a Data Sender (lets say A) uses a Key to encrypt (convert into a code which cannot be read by a human being) the information. This Encrypted data is sent to the receiver (lets say B) who again uses a Key (can be the same key or a different key as that of A) to decrypt the data or information into a human readable form. In this process while the data is being transferred from A to B, any adversary cannot read the data (since it is encrypted), hence maintaining the confidentiality of the data.

Hash Function

Hash is a Cryptographic function which when applied on any data of any length or form (text, image, audio, etc.) produces a unique output (called Digest) which is of a definite length. Also this output value is unique for each and every input value.
The below table shows the SHA 256 Hash function applied to different input values.

Now that we have a basic idea of the Hashing and the Hash function in Blockchain, we should note the below points.

Collision Resistant and Second Preimage Resistant: This means that for any two input values, you cannot get the same output or digest value. Therefore for any input values x and y, we cannot find hash (x) and hash (y), such that hash(x)=hash(y).

A specific cryptographic hash function used in many blockchain implementations is the Secure Hash Algorithm (SHA) with an output size of 256 bits (SHA-256). Many computers support this algorithm in hardware, making it fast to compute. SHA-256 has an output of 32 bytes (1 byte = 8 bits, 32 bytes = 256 bits), generally displayed as a 64-character hexadecimal string (see Table 1 below).
This means that there are 2256 ≈ 1077, or 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 possible digest values. The algorithm for SHA-256, as well as others, is specified in Federal Information Processing Standard (FIPS) 180-4 [5]. The NIST Secure Hashing website [6] contains FIPS specifications for all NIST-approved hashing algorithms.
Since there are an infinite number of possible input values and a finite number of possible output digest values, it is possible but highly unlikely to have a collision where hash(x) = hash(y) (i.e., the hash of two different inputs produces the same digest). SHA-256 is said to be collision resistant, since to find a collision in SHA-256, one would have to execute the algorithm, on average, about 2128 times (which is 340 undecillions, or more precisely 340,282,366,920,938,463,463,374,607,431,768,211,456; roughly 3.402 x 1038).
To put this into perspective, the hash rate (hashes per second) of the entire Bitcoin network in 2015 was 300 quadrillion hashes per second (300,000,000,000,000,000/s) [7]. At that rate, it would take the entire Bitcoin network roughly 35,942,991,748,521 (roughly 3.6 x 1013) years2 to manufacture a collision (note that the universe is estimated to be 1.37 x 1010 years old)3. Even if any such input x and y that produce the same digest, it would be also very unlikely for both inputs to be valid in the context of the blockchain network (i.e., x and y are both valid transactions).

Uses of Hash Function in the Blockchain Technology

As we have explained the Hash Function is an important element of the Blockchain Technology. Rather we can say that it is one of the foundations on which the Blockchain relies to accomplish itself. The various places or instances where the Hash Function is used in the Blockchain are listed below:

  1. Used to hash the data or information which is shared by a node or user of the Blockchain network.
  2. Used to hash the Header value of the Block.
  3. Used to create unique addresses of the nodes or users in the Blockchain Network.
There are many families of cryptographic hash functions utilized in blockchain technology (SHA-256 is not the only one), such as Keccak (which was selected by NIST as the winner of a competition to create the SHA-3 hashing standard), as well as RIPEMD-160.

Cryptographic Nonce

As you might be knowing that a node or a user of the Blockchain Network needs to compete with other nodes or users in the network, in order to publish a Block containing data of different candidate or individual transactions. You may refer to https://thinkblockchain07.com/2020/05/23/how-does-a-blockchain-work/ to get more clarity of this specific phenomena of the Blockchain technology.
There are different Consensus Models in order to decide for which node or user in the Blockchain Network will publish the next Block. Proof of Work is one such widely accepted Consensus Model. In the Proof of Work model, the competing (publishing) nodes or users of the Blockchain Network are required to solve a computationally intensive puzzle (these puzzle is not solved manually rather computer programs are used to solve them. Running these computer programs to solve these Proof of Work puzzle consumes Power and Energy). The user or node which is first in solving the puzzle gets his Block added to the Blockchain. Please note that this puzzle is hard to solve but easy to validate. Hence once a user solves the puzzle, other nodes easily validate the solution for its correctness and the user gets to add his Block to the Blockchain. The user which adds the Block is compensated with rewards (Bitcoin in the case of Bitcoin Blockchain).

Now that we understand the Proof of Work Consensus model, please note that a common puzzle method is to make the Hash Digest of the Block Header less than a particular value. We know that the Hash Value of any data is a unique value. Then how to change the Hash value of the Block Header. In order to do so, the publishing nodes use specific arbitrary numbers that are only used once. These arbitrary numbers are known as Cryptographic Nonce. A cryptographic nonce can be combined with data to produce different hash digests per nonce:
hash (data + nonce) = digest
Only changing the nonce value provides a mechanism for obtaining different digest values while keeping the same data.

Symmetric Cryptography and Asymmetric Cryptography

The Blockchain Technology uses Asymmetric Key Cryptography. Asymmetric Key Cryptography uses a pair of keys- Public Key and a Private Key, which are mathematically related to each other. The Public key is the identity which is shared with other users in the Blockchain network. Whereas the Private Key is kept confidential and must not be shared or known to other users of the network in order to maintain the data assets confidential. Even though there is a relationship between the two keys, the private key cannot efficiently be determined based on knowledge of the public key. One can encrypt with a private key and then decrypt with the public key. Alternately, one can encrypt with a public key and then decrypt with a private key.

Below we have shown a generic model of the Cryptography phenomena.

As you can see the Sender uses a Key (Key 1) to encrypt the plain text into the Ciphered text or coded text. The receiver uses Key (Key 2) in order to reconvert the ciphered text to plain text which is readable to the human being.

Symmetric Cryptography: For the above example, if both the keys (Key 1 and Key 2) are same (pre-decided between the sender and the receiver), then such a cryptographic arrangement is known as Symmetric Cryptography.

Asymmetric Cryptography: When both the sender and receiver use different keys (Key 1 and Key 2 in the above example) then it is called a Asymmetric Cryptography.

Summary

In this article we went through the concepts of Cryptography which are used in the Blockchain Technology. Basically we understood the concepts of Hash functions, Nonce and Asymmetric Cryptography. Please note that this article is not a comprehensive or an ‘all in one’ guide for cryptography, it just touches the concepts that are used in Blockchain. I will recommend the below link https://pixelprivacy.com/resources/cryptography-guide/ for an elaborated view on Cryptography if you wish to go in depth of the subject.

Thanks and Happy Reading

Leave a Reply