Cryptographic Hash Function
Used to connect the “blocks” in a “chain” in a
tamper proof way
Take any arbitrary size string as input (Input M:
Message)
Fixed size output (we typically use 256 bits in
blochchain)
Output H(M) = Message Digest
Efficiently computable
Cryptographic Hash Function: Properties
Deterministic:
Always yield identical hash Value for identical input data
Collision free:
If two messages are different, then their digests are also
different
Hiding:
Hiding the original message
Puzzle Friendly:
Given X & Y find out k such that Y = H(X||k): used to
solve mining puzzle in Bitcoin proof of work
Collision Free
Hash functions are one way; Given an X it is easy to find
H(X), However given H (X), one cannot find X
It is difficult to find x & y where x ≠ y, but H(x) = H(y)
Collision is not possible
Try randomly chosen inputs to find out collision, but it
takes too long
If a hash function produces ‘n’ bits output, an attacker
needs to compute only 𝟐𝒏/𝟐 hash operations on random
input to find two matching outputs with probability > 0.98
For SHA 256 , attacker needs to compute
𝟐𝟏𝟐𝟖 𝒉𝒂𝒔𝒉 𝒐𝒑𝒆𝒓𝒂𝒕𝒊𝒐𝒏𝒔 𝒔𝒊𝒈𝒏𝒊𝒇𝒊𝒄𝒂𝒏𝒕𝒍𝒚 𝒕𝒊𝒎𝒆 𝒄𝒐𝒏𝒔𝒖𝒎𝒊𝒏𝒈
If every hash computation requires 0.1 microsec., it will
need around
𝟏𝟎𝟐𝟓 𝒚𝒆𝒂𝒓𝒔
Hash as a message digest
If we observe H(x) = H(y), it is safe to assume that x = y
We need to remember just a hash value rather than entire
message – we call this as a message digest
To check if two messages x & y are same ; simply check if
H(x) = H(y)
This is efficient because the size of the digest is significantly
less than the size of the original messages.
Hashing illustration:
http://www.blockchain-basics.com/HashFunctions.html
Information hiding through hashing
Hiding helps to commit a value
Hash Function: SHA 256
SHA 256 used in bitcoin mining- to generate bitcoin
blockchain
Secured hash algorithm that generates 256 bit
message digest
Set of cryptographic hash functions designed by
United States National Security Agency (NSA)
SHA 256: Preprocessing Algorithm
Aim: Pad a message such that it is multiple of 512
Suppose length of message ‘m’ is l, then l mod 512 ≠ 0
Appen bit ‘1’ at the end of the message
Append k ‘0’ bits, where k is smallest non-negative solution to
the equation l+1+k = 448 mod 512
Append the 64 bit block which is equal to number ‘l ’ written
in binary
Total length get divisible by 512
Divide the message into N number of 512 blocks 𝑴𝟏 𝑴𝟐 𝑴𝟑 ..
𝑴𝑵
Every 512 block is further divided into 32 bit sub-blocks
𝑴𝟎(𝒊) , 𝑴𝟏(𝒊) , 𝑴𝟐(𝒊) ,.. 𝑴𝟏𝟓(𝒊) ,
SHA 256: Preprocessing Algorithm
The message blocks are processed one at a time
Start with fix initial value 𝑯(𝟎)
i
i 1 i 1
Sequentially compute H H C M ( i ) ( H )
Where C is a SHA 256 compression Function and 𝑯𝑵 is the
hash of M
Patterns of Hashing
• Independent
• Repeated
• Combined
• Sequential
• Hierarchical
Cryptographic hash pointer
Hash Pointer
• A cryptographic hash pointer (hash reference)
is a pointer to a location where
– Some information is stored
– Hash of the information is stored
With the hash pointer we can
– Retrieve the information
– Check that the information has not been modified(by
computing the message digest and then matching the
digest with the stored hash value)
Merkle Tree
Basic concepts of cryptography
• Symmetric key cryptography
– Same key is used for encryption and decryption
– How to share the key securely
– Cannot address certain requirements
• Public key cryptography
– One key for encryption , one for decryption
– Handles several requirements like those in blockchain
Digital Signature
• A digital code which can be included with an
electronically transmitted document to verify
• The content of the document is authenticated
• The identity of the sender
• Prevent non-repudiation- sender will not be
able to deny the origin of the document
Purpose of Digital signature
• Only the signing authority can sign the
document but everyone can verify the
signature
• Signature is associated with the particular
document
• Signature of one document cannot be
transferred to another document
Public Key Cryptography
• Also known as asymmetrical cryptography or
asymmetric key cryptography
• Key: a parameter that determines the functional
output of a cryptography algorithm
• Encryption: The key used to convert a plain text to a
cipher text; 𝑀′ = E(M, k)
• Decryption: The key used to convert a cipher text to
a plain text ; M = D(𝑀′ , 𝑘)
Public Key Cryptography
• Properties of a cryptographic key(you need to
prevent it from being guessed)
• Generate the key truly randomly so that the attacker
cannot guess it
• The key should be of sufficient length- increasing
length makes the key difficult to guess
• The key should contain sufficient entropy, all the bits
of the key should be equally random
Public Key Cryptography
Two keys are used
•Private key: Only Alice has her private key
•Public Key: “Public to everyone – everyone knows Alice’s
public key”
Public Key Encryption - RSA
• Named over Rivest, Shamir, Adleman – inventors of
public key cryptosystem
• The encryption key is public and decryption key is
kept secret (private key)
– Anyone can encrypt data
– Only intended receiver can decrypt the data
RSA Algorithm
• Four phases
– Key generation
– Key distribution
– Encryption
– Decryption
Digital Signature