Cryptography and Crypto

As the word crypto is nothing but it is a cryptocurrency, you would expected that you need to master cryptography in order to become a blockchain programmer. Actually , this is not true . You only need to know the following points are crucial to understanding cryptography.

Crypto Background :

  • Hash Functions
  • Digital Signatures
Hash Functions: 
  • Takes arbitrarily length of string as input
  •  Produces a fixed sized output
  •  Efficiently Computable
























If you have strong mathematical skills, you can easily comprehend the hash function concept. In cryptography, a hash function (H) accepts a variable length message (M) and produces a fixed size hash value (h). Mathematically, h =H(M).Here, h is called the hash code, hash digest, hash sum etc.

We can look at the following code example:

D:\KnowledgeHunt\blockchain> python

Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> from hashlib import sha256

>>> sha256(b"KnowledgeHunt").hexdigest()

'c6938e3a23e0c241f4db3ee792391c8d1addf55c1bb7c5dbe1e6e45208876805'

>>> sha256(b"Knowledge").hexdigest()

'dcb3e1c00e79236dc91f5fd8b7b37dcc44364a8c2b61f05d04063a26588e77fe'

>>>


As you can see, the length of the inputs have different lengths of characters, but output will always be a length of 64 hexadecimal numeric characters.

Let's examine the Hash function and its role in cryptography. 

Why?

Even for a small change in the contents of the message, the hash code will turn out to be different. So, it can detect if the message was subject to modification attack.

Hash Function Properties :
  1. A hash function (H) can be applied to a block of message (data) of any size.
  2. H produces a fixed-length output irrespective of the length of the message.
  3. H(x) is relatively easy to compute for any given message x, making both hardware and software implementations practical.
  4. For any given hash code h, it is computationally infeasible to find x such that H(x) = h. A hash function with this property is referred to as one-way or pre-image resistant.
  5. For any given block x, it is computationally infeasible to find y ≠ x with H(y) = H(x). A hash function with this property is referred to as second pre-image resistant.
  6. It is computationally infeasible to find any pair (x, y) such that H(x) = H(y). A hash function with this property is referred to as (strong) collision resistant.
Relationship Among Hash Function Properties:
















Digital Signatures :

Algorithms Used:
  • DSS/SHA
  • RSA/SHA
SHA - Secure Hash Algorithm
DSS - Digital Signature Standard
RSA - Rivest Shamir Adleman

A hash code of a message is created using SHA-1. This message digest is encrypted using DSS or RSA with the sender’s private key and included with the message.

Let's say Bob wants to communicate with Alice. Despite the fact that confidentiality of the message is not crucial, he wants Alice to be certain that the message is indeed from him.Bob creates a hash value for the message using a secure hash function, such as SHA-512. A digital signature generation algorithm uses that hash value and Bob's private key as input and generates a short block that serves as a digital signature

Bob sends the message with the signature attached. When Alice receives the message plus signature, she (1.) calculates a hash value for the message; (2.) provides the hash value and Bob’s public key as inputs to a digital signature verification  algorithm. If the algorithm returns the result that the signature is valid, Alice is assured that the message must have been signed by Bob. No one else has Bob’s private key and therefore no one else could have created a signature that could be verified for this message with Bob’s public key. In addition, it is impossible to alter the message without access to Bob’s private key, so the message is authenticated both in terms of source and in terms of data integrity.

Simplified Depiction of Essential Elements of Digital Signature Process:

























Comments

Post a Comment