Basic Crypto Primitives
Basic Crypto Primitives
Digital Signature: Digitally sign the data so that no one can “deny” about their own
activities. Also, others can check whether it is authentic.
Cryptographic Hash Functions
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 also differ
Hiding
Hide the original message; remember about the avalanche effect
Puzzle-friendly
Given X and Y, find out k such that - used to solve the mining puzzle in Bitcoin Proof of Work
Collision Free
Try with randomly chosen inputs to find out a collision – but it takes too long
Collision Free – How Do We Guarantee
Birthday Paradox: Find the probability that in a set of randomly chosen persons, some
of them will have the same birthday
By Pigeonhole Principle, the probability reaches 1 when number of people reaches 366 (not a
leap year) or 367 (a leap year)
0.999 probability is reached with just ~70 people, and 0.5 probability is reached with only ~23
people
Collision Free – How Do We Guarantee
If a hash function produces bits of output, an attacker need to compute only hash
operations on a random input to find two matching outputs with probability > 0.98
For a 256 bit hash function, the attacker needs to compute hash operations – this is
significantly time consuming
If every hash computation takes only 1 microsecond, it will need years
Hash as A Message Digest
We need to remember just the hash value rather than the entire message – we call this as
the message digest
http://www.blockchain-basics.com/HashFunctions.html
Bob Jane
Alice
H(M,KA),M,KA H(M,KA),M,KA
KA is the public key of Alice – A public identity that only Alice can have
Puzzle Friendly
Puzzle friendly property implies that random searching is the best strategy to solve the
above puzzle
Hash Function – SHA256
Secure Hash Algorithm (SHA) that generates 256 bit message digest
Pad the message such that the message size is a multiple of 512
Suppose that the length of the message M is and
Append the bit “1” at the end of the message
Append zero bits, where is the smallest non-negative solution to the equation
Append the 64-bit block which is equal to the number written in binary
The total length gets divisible by 512
Partition the message into 512-bit blocks , ,…,
Every 512 bit block is further divided into 32 bit sub-blocks , ,…,
SHA-256 Algorithm
Sequentially compute ; is the SHA-256 compression function and + means mod addition.
is the hash of .
SHA-256 Algorithm
Independent hashing
Repeated hashing
Combined hashing
Sequential hashing
Hierarchical hashing
Independent hashing
Repeated hashing
Types of Hashing
Combined hashing
Sequential hashing
Types of Hashing
Hierarchical hashing
Hash Pointer
A Cryptographic Hash Pointer (Often called Hash Reference) is a pointer to a location
where
Some information is stored
Hash of the information is stored
DATA
Hash Pointer
http://www.blockchain-basics.com/HashFunctions.html
D (i)
D (i+1)
D (i+2)
Merkle Tree – Organization of Hash Pointers in a Tree
L1 Hash L1 Hash
H0= Hash(H00+H01) H1=Hash(H10+H11)
T1 T2 T3 T4
Blockchain as a Hashchain
Only the signing authority can sign a document, but everyone can verify the signature
M’
Public Key Encryption - RSA
Named over (Ron) Rivest – (Adi) Shamir – (Leonard) Adleman – inventors of the public
key cryptosystem
The encryption key is public and decryption key is kept secret (private key)
Anyone can encrypt the data
Only the intended receiver can decrypt the data
RSA Algorithm
Four phases
Key generation
Key distribution
Encryption
Decryption
Image source:
https://commons.wikimedia.org/
Public and Private Keys in RSA
It is feasible to find three very large positive integers , and ; such that modular
exponentiation for integers :
is used as the public key and is used as the private key. is the message that needs to be
encrypted.
RSA Key Generation and Distribution
https://www.devglan.com/online-tools/rsa-encryption-decryption
Digital Signature using Public Key Cryptography
M, M’
Reduce the Signature Size
Use the message digest to sign, instead of the original message
M, S
A:10, Sig(A)
H(1)
A->B:5, Sig(A)
H(0)
A:10, Sig(A)
A central authority like bank can create and destroy coins based on economic policies
Crucial Question: How can we distribute coin management (creation and destroy)
https://medium.com/bootdotdev/how-sha-2-works-step-by-step-
sha-256-90ecd4f09e4d
https://demoblockchain.org/block
https://bitcoinbook.cs.princeton.edu/
47