# Blockchain

Blockchain is a linear combination of nodes developed to store interactions between users, in the form of transactions. It is a linked list, with transaction identities and originalities protected by various verification and authentication processes that involve digital signatures in the form of hashes.

Basically, blockchain is a distributed consensus ledger network, the details of which are explained in further sections. It offers a top-of-the-line method of communication and data transfer, safeguarded against any attacker that does not control at least 51 percent of the network. There is no central agency for someone to focus attacks on, and every node is given equal weight. Every transaction entry is agreed upon, and the complete history is visible to every verified node, giving block- chain a democratic setup.

Blockchain’s introduction to the world was accompanied by that of Bitcoin cryptocurrency, so for most people, the two are intertwined. But the fact of the matter is that while bitcoins are specific implementations of blockchain in the creation and usage of a cryptocurrency, blockchain is an encryption and data security mechanism, which uses chains to store the transaction history of the whole group. That data can subsequently be cryptocurrency (as implemented in Bitcoin), or it can be used in internetwork communication and data transfer.

Implementing the IoT network initializes the sensor network in a way similar to the implementation of blockchain. By some minor tweaks to the software protocols, an IoT network can be relatively easily molded into a blockchain-secured network. Blockchain redefines the concept of the ownership of data. Having data means having the permission protocols to modify/share it. Blockchain boasts a centralized data string spread out across all nodes, given equal priority about all transactions of the whole network.

All the transaction records of communication are to be stored in a ledger that is simultaneously updated throughout the network. Since blockchain requires a decentralized transaction record that exists in every node, it is thus verified by the network as a collection. The method of transactions that is associated with block- chain can be loosely translated to data transfer in the IoT.

The actual implementation of data and file transfer in implementing blockchain in the IoT is a little more complex than its Bitcoin variant. In file transfer, the files cannot be stored on the blockchain, as that would create multiple copies of the whole database, wasting too much space and rendering the verification process too slow. The solution to that is something called the Interplanetary File System (IPFS). We store the files to be transferred in a common storage database that is given a tag ID based on hashing. The sender then sends the hash/ID of the file to the receiver, who can then access it from the common IPFS database. This however creates a privacy problem, as the hash ID of the file sent as a message is recorded as a transaction in the blockchain, which is recorded for every user and accessible to all. To resolve this, pairing-based cryptography in blockchain provides the solution. The sender first encrypts the w'hole file with the public key of the recipient, and then the file is uploaded to the IPFS database. By the concepts of public key cryptography, the receiver has the private key to decrypt the file and read it. All data packets except for small communication messages are sent by this mechanism, so as to avoid creating an N-way copy on the server.

## Currently Employed Methods

In cryptography systems throughout the world, a shift from secret key sharing to public key cryptography has been observed. Besides the scope of implementing different pairing mechanisms for faster computation, and the opportunity to introduce pairing-based cryptography systems, the biggest advantage of public key systems over those using secret keys is not having to establish a guaranteed secure transmission channel whereby to share a secret key. The private key is generated by and kept by the recipient, who simply makes the public key public for everyone.

### Public Key Cryptography (Asymmetric Cryptography)

Public key cryptography systems are implemented by first generating a public key and a private key. The logic is that every user’s public key will be available to everyone and can be used to encrypt data to be sent for communication. Encrypted data cannot be decrypted (and therefore understood) without the private key usage, even if the encryption key used is accessible (one-way trapdoor functions) [2]. The encrypted message is then received and decrypted by using the private key to reveal the original message. One of the cornerstones of understanding cryptography systems is to assume a malicious attacker that has access to every message that is in transmission. It is a generic standard to assume an attacker named X, a sender named B, and a receiver named A. The public key of A is assumed to be PubA and the corresponding private key to be PrivA and message M.

В encrypts message M by using PubA. which is freely available to all. The message generated is called £„,. While transmitting £„, through an unprotected transmission medium, attacker X cannot find the message M by the use of £„, and PubA, because of the trapdoor function. A then receives the message £„,, which is then decrypted using PrivA to recover M.

### Rivest-Shamir-Adleman Encryption Technique (RSA)

RSA is an application of asymmetric cryptography. RSA works on the principles of exponents and mod-N mathematics.

Note: Congruence is represented by ~ in the chapter. Two values are said to be congruent in modular mathematics if their values wrapped around the modulus limit N (in a mod N system) are equal.

i.e., *a~b* if a modulo *n* = *b* modulo *n.*

We have a message *M* that is represented by using a number between 0 to *N- *(inclusive).

The public key PubA is called £ (i.e., encryption key).

The private key PrivA is called *D* (i.e., decryption key).

The encrypted message *Em* is called C (i.e., ciphertext).

1. Key generation:

At the receiver’s side, we first choose two very large random prime numbers, p and q, and calculate *N = p* * *q.*

Then we find the totient of *N,* i.e., *ф(N).*

*ф(Ы)* by calculation comes out to be *(p - )(q* - 1).

Then we select a key E, such that it is co-prime with *ф{Ы).*

*D* is calculated by finding a value satisfying the following relation:

i.e.. find a *D* such that *ED*-1 is divisible by (/V).

£ serves as the public key and *D* serves as the private key for the encryption.

2. Message encryption:

At the sender’s side, we have the standard TV, the message *M.* and the public key of receiver *E.*

We calculate C by using £, *M*, and *N* by the relation:

The message is then sent in the form of the ciphertext.

3. Message decryption:

At the receiver’s side, we use *D*, C, and *N* to find the original message by the relation:

Received message: *M _{m} = C^{D}(mod N).* Now, from (9.1)

Applying properties of modular mathematics, we have
Since *DE =* 1 + *К* x (for some value of *K),*

So, from (9.2) we generate *M* from M_{rec}.

Thus we can obtain the original message for all values of *M, p* and *q.*

## Why Blockchain Is the Future

With information security as its most desired and heavily invested-in field, the data industry wants a fault tolerant safe network. The problem with centralized security networks is their dependence on a central node. In the eventuality that the central node is hacked/not working, security is compromised, and the network stops. The IoT is in itself a decentralized concept, which acts on an interconnected web of individual nodes, which are taught a standard language for communication with nodes forming client server pairs, depending on the communication requirements. Blockchain is by far one of the most fault-tolerant systems with no central node. Every node contributes to verifying the validity of the blockchain. Even if one node fails, the network will not be disrupted, as is the requirement in the IoT.

There is no central node, so there is no focus of attack for hijacking the network. The only way to take control of transactions is to take control of more than 51 percent of the network. Such a task is extremely difficult and becomes even more so with the randomization of miners in their physical locations in the blockchain groups formed [3].

## Comparisons between Encryption Techniques

Starting with a theoretical explanation, we understand that encryption techniques are mainly compared on two points: the speed of encryption-decryption and the minimum percentage of the network, the security of which must be breached in order to take control of the whole network. Now, these two points are generally in a multiplicative trade-off with each other, i.e., both of them in relative moderation, which produces the best overall result, whereas trying to get either one into a positive extreme results in the other one deteriorating drastically. Hashing is one of the fastest one-way trapdoor functions we have; it is virtually impossible to reverse, and there are very few approaches to illegally decrypting hashing without using brute force approaches (which are completely cost inefficient). Blockchain also ensures that in order to take control of the entire network, we need a minimum of 51 percent of the nodes in the network. As mentioned before, this ratio is very hard to achieve and thus makes intrusion detection easy and quick.

Parameters for the analysis of cryptographic algorithms include:

- • Number of rounds used for encryption and decryption [4]
- • Size of blocks
- • Length of key to be used
- • Encryption rates [5]

As seen in Figure 9.1, asymmetric algorithms are fewer, but newer. This is because, even though asymmetrical algorithms are better from a security perspective, they require greater computation processing time and higher data storage capabilities.

FIGURE 9.1 Classification of encryption algorithms.

Asymmetric algorithms, such as RSA, use key exchange, and symmetric algorithms use encryption/decryption [6].