Ā Blockchain Dr. Bahar Ali
Assistant Professor (CS ), Institute of Management Sciences, Peshawar.
Contents ā Module A What is Blockchain? Distributed P2P Networks Hashing Algorithm Immutable Ledger What is Mining? Consensus Protocol
Hashing Algorithm
Cryptography & Encryption Cryptography: A broad field that involves the study of secure communication techniques in the presence of adversaries. Includes various methods for encrypting and decrypting messages, ensuring data integrity, and authenticating the identity of communicating entities. Encryption: The process of converting plaintext (readable data) into ciphertext (appears as random characters) using an algorithm and a key. The purpose is to protect sensitive information from unauthorized access. Two types of encryption Symmetric and Asymmetric
Symmetric Symmetric Encryption: Uses a single shared key for both encryption and decryption Examples: AES, DES, Triple DES Process: A single secret key is generated and shared securely between the parties. Sender encrypts the plaintext using the shared key to get a ciphertext. Receiver decrypts the ciphertext using the same shared key to get the plaintext back.
Symmetric
Asymmetric Encryption Asymmetric Encryption: U ses a pair of public and private keys. Information encrypted with the public key can only be decrypted with the corresponding private key, and vice versa. Example: RSA (RivestāShamirāAdleman). Process: Public-private key pair is generated The public key is shared with everyone, while the private key is kept secret. The sender encrypts the message using the public/ private key. The receiver decrypts the message using corresponding private/public key.
Symmetric
What a Hash is? Hashing: G enerate a fixed-size hash value (digest) from input data of any size. Hashing is a one-way, irreversible process. Hashing is used to verify the data integrity Example: SHA-256 (Secure Hash Algorithm 256-bit). Process: The algorithm generates a fixed-size hash value as a unique identifier for data. To verify integrity, the algorithm is reapplied, producing a new hash. A match indicates data integrity, while differences suggest the data has been altered or tampered with.
Symmetric
What a Hash is? A fixed size numeric representation of the contents of a message. Also known as message digest Computed by a hash function (One way cryptography). Hash function has no key, so it is not reversible. For same message you always get the same hash Computationally infeasible to find two messages that hash to the same digest.
Encryption vs Hashing Both hashing and encryption involve transforming data, but they serve different purposes. Encryption is a reversible process, while the hashing is irreversible. Symmetric encryption is used for efficient data transmission . Asymmetric encryption is used for secure key exchange Hashing is used for data integrity verification
Encryption vs Hashing
Confidentiality using Asymmetric
Authenticity using Asymmetric
Confidentiality and Authenticity
Digital Signature
What a Hash is? Hash Properties: Computationally efficient Deterministic ( Same input same output hash code ) Pre-image resistant ( Finding another message that has a specific hash output) Collision Resistant (large output space etc.) Avalanche Effect (Drastically/ dramatically changes with minimal change in the input)
Hashing Algorithm The five requirements of Hash Algorithm- One Way Avalanche Effect Withstand Collisions Fast Computation Deterministic Data Encrypted Ā Data ABC 845
Document, Audio , Video etc. Hashing Algorithm SHA256 5819E961F19967B4ECB2429085E17909CFFD4DCB6267D0067F6CAEC22150A7B1 This has 64 hexadecimalĀ characters . Each character is of 4 bits. So in total it has 64* 4 bits i.e. 256 bits .
Hashing Algorithm Block No.-1 Data Hash:0000D8C42 Prev Hash:000000000 Fingerprint Block Fingerprint Authentication is used to recognize/ identify an individual in a group of people Likewise, a hash of a block is used to recognize/ identify a block in the Blockchain
Hashing Algorithm Block No.- Data Hash: Prev Hash: SHA 256
Hashing Algorithm Block No.-1 Data Hash:0000D8C42 Prev Hash:000000000 Block
Hashing Algorithm Block No.-1 Data Hash:0000D8C42 Prev Hash:000000000 Block No.-2 Data Hash: 00003A459 Prev Hash:
Hashing Algorithm Block No.-1 Data Hash:0000D8C42 Prev Hash:000000000 Block No.-2 Data Hash:00003A459 Prev Hash: 0000D8C42
Hashing Algorithm Block No.-1 Data Hash : 0000D8C42 Prev Hash:000000000 Block No.-2 Data Hash:00003A459 Prev Hash : 0000D8C42 Block No.-3 Data Hash: 00003D45F Prev Hash: 00003A459 Genesis Block
Hashing Algorithm Demo Online demonstration (Hash, Block and Blockchain) https://andersbrownworth.com/blockchain/ Running your Node ServerĀ https://github.com/anders94/blockchain-demo/
Immutable Ledger
Immutable Ledger Institution Sales Deed Money House Consider you want to buy a house for yourself. You need cash, and a contract Submit the documents to government institution for registration The information is recorded either in a register book or centralized database
Immutable Ledger Institution Maintain Register Centralized Database Register book: The register can be destroyed Easily altered by someone Centralized database: The record can be hacked and changed The government employee can change the record Letās check, the Immutable register on Blockchain
Immutable Ledger A C E F D B Hacker Attacks Corrupted If the hacker changes block C All the blocks after block C will be corrupted
What is a P2P network?
What is a Centralized Network? Server Client Client Client Client Client Server Model Data stored on Server Client requests data from Server Server sends client the required data Hacker can easily hack the Server and corrupt the data i.e. Banks, Social Networks, etc.
What is a Centralized Network? Server Client Client Client Client Request
What is a Centralized Network? Server Client Client Client Client Respond
What is a centralized network? Server Client Client Client Client
Distributed P2P network No client and no server All peer are equal The data is stored with multiple peers Peers directly request data from each other Hacker must hack all the peer simultaneously, to corrupt the data, which is almost impossible
Distributed P2P network A B C E F Peer Peer Peer Peer Peer
Distributed P2P network in Blockchain
Distributed P2P network A B C E F
Distributed P2P network A B C E F A mines a block and add it to Blockchain
Distributed P2P network A B C E F
Distributed P2P network A B C E F
Distributed P2P network A B C E F
Distributed P2P network A B C E F
Distributed P2P network Q)Why we need Distributed P2P network in Blockchain? To resist tempering in a Blockchain To recover tempered data
Distributed P2P network How data is recovered using Distributed P2P network. If hacker change a block of a specific node The change is reflected in the succeeding blocks Thus, it will invalidate all the succeeding blocks However, if a hacker is smarter, he will also change the succeeding blocks The other peers will update the node that your blocks are changed The chain will be recovered back
Distributed P2P network A C E F D B Concept of Immutability in Distributed P2P Network A C E F D B Hacker Attacks Corrupted Node 1 Node 2