Unit 1 Notes
Unit 1 Notes
ELEMENTARY CRYPTOGRAPHY
Encryption: The process of converting plaintext into ciphertext using a cryptographic algorithm and key.
Decryption: The reverse process of encryption, converting ciphertext back into plaintext.
Key: A piece of information used by an algorithm to transform plaintext into ciphertext and vice versa.
Symmetric Encryption: Encryption where the same key is used for both encryption and decryption.
Asymmetric Encryption: Encryption where different keys are used for encryption and decryption (public and
private keys).
Hash Function: A function that converts input data into a fixed-size string of characters, which is typically a hash
value.
2. Substitution Ciphers
Definition: A type of encryption where elements of the plaintext are replaced with other elements.
Caesar Cipher: One of the simplest substitution ciphers where each letter in the plaintext is shifted a certain number
of places down the alphabet.
Example:
Plaintext: "HELLO"
Shift: 3
Ciphertext: "KHOOR"
Monoalphabetic Cipher: Each letter of the plaintext is mapped to a unique letter of ciphertext alphabet.
1
Polyalphabetic Cipher: Uses multiple substitution alphabets to encrypt the plaintext.
Vigenère Cipher: A polyalphabetic cipher where a keyword is repeated and each letter of the plaintext is shifted
according to the corresponding letter of the keyword.
3. Transpositions
Definition: A method of encryption where the positions of the characters are shifted according to a certain system.
Columnar Transposition: The plaintext is written in rows and then read out column by column according to a
defined order.
Example:
mathematica
Copy code
W E A R E
D I S C O
V E R E D
F L E E A
T O N C E
Rail Fence Cipher: The plaintext is written in a zigzag pattern and then read off line by line.
Confusion: Ensures that the relationship between the plaintext and ciphertext is as complex as possible.
Diffusion: Ensures that changes in the plaintext affect many parts of the ciphertext.
Avalanche Effect: A slight change in the plaintext or key should produce a significantly different ciphertext.
Key Space: Large enough to resist brute force attacks.
Practices:
Algorithm:
Weaknesses:
Algorithm:
Strengths:
Key Features:
Public key is distributed widely, while the private key is kept secret.
Enables secure communication and digital signatures.
Algorithms:
Properties:
Algorithms:
9. Key Exchange
Purpose: Securely exchanging cryptographic keys over a public channel.
Methods:
Diffie-Hellman Key Exchange: Allows two parties to establish a shared secret key over an insecure channel.
Elliptic Curve Diffie-Hellman (ECDH): A variant of Diffie-Hellman using elliptic curve cryptography, offering
higher security with smaller key sizes.
Process:
Signing: The sender generates a digital signature using their private key.
Verification: The receiver verifies the signature using the sender's public key.
Algorithms:
11. Certificates
Purpose: To bind a public key to an entity's identity.
Components:
Contents of a Certificate:
5
CRYPTOGRAPHY TECHNIQUES
From the beginning any era, human being has two natural needs:
To communicate and share information and
To communicate selectively.
These two needs gave rise to the art of coding the messages in such a way that only the intended
people could have access to the information. Unauthorized people could not extract any
information.
The word “cryptography‟ is the combination of two Greek words, “Krypto” meaning hidden or
secret and “graphene” meaning writing.
Cryptography: It is the art of achieving security by encoding messages to make them non-
readable format.
It is a method of protecting information and communications through the use of codes, so that
only those for whom the information is intended can read and process it.
Cryptanalysis:
6
Cryptology: Cryptology is a combination of Cryptography and Cryptanalysis.
Plain Text: Clear text, or plain text, signifies a message that can be understood by the sender,
the recipient, and also by anyone else who gets access to that message.
Cipher text:-When a plain text message is codifies using any suitable scheme, the resulting
message is called as cipher text.
There are two types of techniques used to covert plain text to cipher text.
Substitution Techniques
Transposition Techniques
Substitution-cipher technique:
In the substitution-cipher technique, the each characters of a plain-text message are
replaced byother characters, numbers or symbols.
ABCDEFGHIJKLMNOPQRSTUVYZ
DEFGHIJKLMNOPQRSTUVWXYZC
PT: KIIT
CT: NLLW
7
Mono-alphabetic Cipher
A monoalphabetic cipher is a substitution cipher where a symbol in the
plaintext has a one-to-one relationship with a symbol in the ciphertext.
It means that a symbol in the plaintext is always replaced with the
samesymbol in theciphertext, irrespective of its position in the
plaintext.
It uses random substitution.
This means that in a given plain-text message, each A can be replaced by any
other alphabet (B through Z), each B can also be replaced by any other random
alphabet (A or C through Z), and so on. The crucial difference being, there is
no relation between the replacement of B and replacement of A. That is, if we
have decided to replace each A with D, we need not necessarily replace each B
with E—we can replace each B withany other character!
character.
8
Playfair Cipher:
The Playfair cipher scheme was invented in 1854 by Charles Wheatstone but was
named after Lord Playfair who promoted the use of the cipher. In playfair cipher
unlike traditional cipher we encrypt a pair of alphabets(digraphs) instead of a
single alphabet.
It was used for tactical purposes by British forces in the Second Boer War and in
World War I and for the same purpose by the Australians during World War II.
This was because Playfair is reasonably fast to use and requires no special
equipment.
The Playfair encryption scheme uses two main processes.
> Creation and population of matrix
> Encryption process
Step 1: Creation and Population of Matrix
• The Playfair cipher makes use of a 5
x 5 matrix (table), which is used to
store a keyword or phrase that
becomes the key for encryption and
decryption.
• The way this is entered into the 5 x 5
matrix is based on some simple rules:
1. Enter the keyword in the matrix row-wise: left-to-right, and then top-to-bottom.
2. Drop duplicate letters.
3. Fill the remaining spaces in the matrix with the rest of the English alphabets (A-Z)
that werenot a part of our keyword. While doing so, combine I and J in the same cell of
the table.
In other words, if I or J is a part of the keyword, disregard both I and J while filling the
remainingslots.
9
rightmost, then wrap itup with the left letter of the row it happens.
5. If the alphabets of the pair appear in same column of the matrix, then substitute
them withtheir immediate below alphabets. If the letter of the plain text is itself
below, then wrap it up with the top letter of the column it happens.
6. If the alphabets of the pair are not in same row or column then define a rectangle
with theoriginal pair and substitute them with other corners of the rectangle.
Example
Hill Cipher
The Hill cipher works on multiple letters at the same time.
Lester Hill invented this in 1929. The Hill cipher uses the matrix theory of mathematics.
Working:
• Treat each letter with a number like A=0, B=1, C=2…… Z=25.
• Let us say, our original message is “TAJ”
• As per the rule, T=19 A=0 J=9
• Convert it into matrix form as:
10
Now multiply the plain text matrix with any number as keys. The multiplying matrix
should beof n x n where n is the number of rows of original matrix
Now compute mod 26 on resultant matrix i.e. take the remainder after dividing by 26.
Example:
Cipher Text: m e m t m r o e t e o o r w
11
Simple Columnar Transposition Technique:
A. Basic Technique
It is a slight variation to the Rail-fence technique, let’s see its algorithm:
1. In a rectangle of pre-defined size, write the plain-text message row by row.
2. Read the plain message in random order in a column-wise fashion. It can be any order
such as 2, 1, 3 etc.
3. Thus Cipher-text is obtained.
Now let’s decide on an order for the column as 4, 1, 3 and 2 and now we will read the text in
column-wise.
Cipher-text: LHIEEIUESSCEPWMNDLAO
B. Columnar Technique with multiple rounds
In this method, we again change the chipper text we received from a Basic technique that is in
round 1 and again follows the same procedure for the cipher-text from round 1.
Algorithm:
1. In a rectangle of pre-defined size, write the plain-text message row by row.
2. Read the plain message in random order in a column-wise fashion. It can be any order
such as 2, 1, 3 etc.
3. Thus, Cipher-text of round 1 is obtained.
4. Repeat from step 1 to 3.
Example:
Original message: "INCLUDEHELP IS AWESOME".
Now we apply the above algorithm and create the rectangle of 4 column (we decide to make a
rectangle with four column it can be any number.)
12
Now let’s decide on an order for the column as 4, 1, 3 and 2 and now we will read the text in
column-wise.
Cipher-text of round 1: LHIEEIUESSCEPWMNDLAO
Round 2:
13
One time pad should be discarded after every single use and this technique is proved highly
secure and suitable for small messages but illogical if used for long messages.
Encryption:-The process of encoding plain text messages into cipher text messages is called as
encryption.
Decryption:-The reverse process of transforming cipher text messages back to plain text
messages is called as decryption.
Symmetric key cryptography (or symmetric encryption) is a type of encryption scheme in which
the same key is used both to encrypt and decrypt messages.
Asymmetric encryption uses the public key for the encryption, and a private key is used for
decryption.
Or
Asymmetric cryptography, also known as public-key cryptography, is a process that uses a pair
of related keys -- one public key and one private key .
14
SYMMETRIC AND ASYMMETRIC KEY ALGORITHMS
It defines what size of plain text should be encrypted in each step of algorithm.
It is of two types:
o Stream Ciphers
o Block Ciphers
Stream Ciphers
Bit-by-bit encryption/decryption.
In this scheme, the plaintext is processed one
bit at a time i.e. one bit of plaintext is taken,
and a series of operations is performed on it to
generate one bit of cipher text.
Technically, stream ciphers are block ciphers
with a block size of one bit.
Example: Suppose the original message (plain
text) is Pay 100 in ASCII (i.e. text format).
When we convert these ASCII characters to their
binary values, let us assume that it translates to
01011100. Let us also Assume that we apply the
XOR logic as the encryption algorithm.
As a result of applying one bit of key for every respective bit of the original message,
suppose thecipher text is generated as 11001001 in binary (ZTU91 A% in text).
Block Cipher
Block-by-block encryption / decryption.
In this scheme, the plain binary text is processed in blocks (groups) of bits at a time; i.e. a block of
plaintext bits is selected, a series of operations is performed on this block to generate a block of
cipher text bits.
The number of bits in a block is fixed. For example, the schemes DES and AES have block sizes
of 64 and 128, respectively.
The basic scheme of a block cipher is given as follows:
Block Cipher Example:
Suppose we have a plain text “FOUR_AND
_FOUR” that needs to be encrypted. By
using this technique FOUR could be
encrypted first followed by _AND_ and
FOUR.
17
Algorithm Modes:
It is a combination of series of basic algorithm steps on block cipher and
some sort of feedbackfrom the previous steps.
It is divided into four modes:
18
Cipher Block Chaining (CBC) Mode:
That is, each block is used to modify the encryption of the next block.
Thus, each block of cipher text is dependent on the corresponding current input plain-text
block, as well as all the previous plain-text blocks.
Operation:
The steps are as follows:
Load the n-bit Initialization Vector (IV). IV is a random generated block of text in a
register.
XOR the n-bit plain text block with data value in IV register.
Encrypt the result of XOR operation with the key K. Result is it produce the cipher
text block.
Feed cipher text block into the IVregister and continue the operation till all plaintext
blocks are processed.
Cipher Feedback (CFB) Mode:
Not all applications can work with blocks of data. Security is also required in
applications that are character-oriented.
For instance, an operator can be typing keystrokes at a terminal, which needs to be
immediately transmitted across the communications link in a secure manner, i.e., by
using encryption.
In such situations, stream cipher must be used. The Cipher Feedback (CFB) mode is
useful in such cases.
In this mode, data is encrypted in units that are smaller (e.g., they could be of size 8 bits,
i.e. the size of a character typed by an operator) than a defined block size (which is
usually 64 bits).
19
Steps of operation are:
Assuming that we are dealing with j bits at a time (as we have seen usually, but not
always, j = 8).
we shall study CFB in a step-by-step fashion.
Step 1 Like CBC, a 64-bit Initialization Vector (IV) is used in the case of CFB mode.
The IV is kept in a shift register. It is encrypted in the first step to produce a
corresponding 64 bit cipher text.
Step 2 Now, the leftmost (i.e. the most significant) j bits of the encrypted IV are
XORed with the first j bits of the plain text.
Step 3 Now, the bits of IV (i.e. the contents of the shift register containing IV) are
shifted left by j positions. Thus, the rightmost j positions of the shift register now
contain unpredictable data. These rightmost j positions are now filled with C.
Step 4 Now, steps 1 through
3 continue until all the plain-
text units are encrypted.
That is, the following steps are repeated:
o IV is encrypted.
o The leftmost j bits
resulting from this
encryption process are
XORed with the next j
bits of the plain text.
o The resulting cipher-text
portion (i.e., the next j
bits of cipher text) is
sent to the receiver.
o The shift register
containing the IV is left-
shifted by j bits.
o The j bits of the cipher
text are inserted from
right into the shift
register containing the
IV.
20
Encryption & Decryption:
Encryption or Encoding or Encode:
The process of converting or transforming plain text or original text into cipher
text is called asencoding.
This new form of the message is totally different from the initial message.
It occurs at the sender’s side.
The sender uses an encryption algorithm and a key to transform the original
message into an encryptedmessage i.e., cipher text.
Encryption is also called enciphering or encipherment.
21
An Overview of Symmetric Key Cryptography
Symmetric key cryptography (or symmetric encryption) is a type of encryption scheme in which
the same key is used both to encrypt and decrypt messages. Such a method of encoding
information has been largely used in the past decades to facilitate secret communication between
governments and militaries.
Data Encryption Standard:
The Data Encryption Standard (DES) is a symmetric-key block cipher published by the National
Institute of Standards and Technology (NIST). DES is an implementation of a Feistel Cipher. It
uses 16 round Feistel structure. The block size is 64-bit.
The Data Encryption Standard (DES) is a symmetric-key block cipher published by the National
Institute of Standards and Technology (NIST).
How DES Works?
DES is an implementation of a Feistel Cipher. It uses 16 round Feistel structure. The block size
is 64-bit. Though, key length is 64-bit, DES has an effective key length of 56 bits, since 8 of the
64 bits of the key are not used by the encryption algorithm (function as check bits only). General
Structure of DES is depicted in the following illustration −
22
Since DES is based on the Feistel Cipher, all that is required to specify DES is −
Round function
Key schedule
Any additional processing − Initial and final permutation
Initial and Final Permutation
The initial and final permutations are straight Permutation boxes (P-boxes) that are inverses of
each other. They have no cryptography significance in DES. The initial and final permutations
are shown as follows −
Round Function
The heart of this cipher is the DES function, f. The DES function applies a 48-bit key to the
rightmost 32 bits to produce a 32-bit output.
Expansion Permutation Box − Since right input is 32-bit and round key is a 48-bit, we first
need to expand right input to 48 bits. Permutation logic is graphically depicted in the following
illustration −
23
The graphically depicted permutation logic is generally described as table in DES specification
illustrated as shown −
XOR (Whitener). − After the expansion permutation, DES does XOR operation on the
expanded right section and the round key. The round key is used only in this operation.
Substitution Boxes. − The S-boxes carry out the real mixing (confusion). DES uses 8 S-boxes,
each with a 6-bit input and a 4-bit output. Refer the following illustration −
There are a total of eight S-box tables. The output of all eight s-boxes is then combined in to 32
bit section.
24
Straight Permutation − The 32 bit output of S-boxes is then subjected to the straight
permutation with rule shown in the following illustration:
Key Generation
The round-key generator creates sixteen 48-bit keys out of a 56-bit cipher key. The process of
key generation is depicted in the following illustration −
The logic for Parity drops, shifting, and Compression P-box is given in the DES description.
25
DES Analysis
The DES satisfies both the desired properties of block cipher. These two properties make cipher
very strong.
Avalanche effect − A small change in plaintext results in the very great change in the ciphertext.
Completeness − Each bit of cipher text depends on many bits of plaintext.
During the last few years, cryptanalysis has found some weaknesses in DES when key selected
are weak keys. These keys shall be avoided.
DES has proved to be a very well designed block cipher. There have been no significant
cryptanalytic attacks on DES other than exhaustive key search.
Asymmetric-key Enclpherment:
The asymmetric-key encipherment also called public-key encipherment or public-key
cryptography, was introduced by Diffie and Hellman in 1976 to overcome the problem
found in symmetric key cryptography.
It uses two different keys for encryption and decryption.
These two keys are referred to as the public key (used for encryption) and the private key
(used for decryption).
Each authorized user has a pair of public and private keys. The public key of each user is
known to everyone, whereas the private key is known to its owner only.
Plaintext: This is the readable message or data that is fed into the algorithm as input.
Encryption algorithm: The encryption algorithm performs various
transformations on the plaintext.This encrypts plain text using public key of
receiver.
Public and Private keys: This is a pair of keys used for encryption; the other is
used for decryption.In figure, encryption is done using public key and decryption
using private key.
Cipher-text: This is the coded message produced as output. It depends on the plaintext
and the key.
Decryption algorithm: This algorithm accepts the cipher text and the matching
key and produces the original plaintext. In figure, decryption algorithm uses
private key.
Now, suppose that a user ·A wants to transfer some information to· user B
securely. The user A encrypts the data by using the public key of B and sends the
26
encrypted message to B.
On receiving the encrypted message, B decrypts it by using his/ her private key.
Since decryption process requires a private key of user B, which is only known to
B, the information is transferred securely. The above figure states the whole
process.
RSA is a well-known example of asymmetric-key algorithm.
The main advantage of public-key cryptography is that the sender and the receiver
need not have to share the secret key. All communication involves only public
keys.
Thus, the private key is never transmitted or shared. Anyone can send a
confidential message using a public key, but the message can only be decrypted
with a private key, which is kept by the intended recipient.
Differentiate between symmetric-key and asymmetric-key cryptography:
Symmetric-key Asymmetric-
key
1. It uses a single key for both encryption and 1. It uses .two different keys-public key for encryption
decryption of data. and
private key for decryption.
2. Both the communicating parties share the 2. Both the communicating parties should have at least
same algorithm and the key. one
of the matched pair of keys.
3.The processes of encryption and decryption 3. The· encryption and decryption processes are
are very fast. slower as
compared to symmetric-key cryptography.
4. Key distribution is a big problem. 4. Key distribution is not a problem.
5.The size of encrypted text is usually same or 5. The size of encrypted text is usually more than the
less than the original text. size
of the original text.
6. It can be used for confidentiality of data as well
6.It can only be used for confidentiality, as for integrity and non-repudiation
that is, only for encryption and decryption of checks (i.e.for digital
data. signatures).
THE RSA ALGORITHM:
This algorithm proposed by Ron Rivest, Adi Shamir, Len Adleman (RSA) in 1978 at
MIT. It is based onasymmetric key cryptography.
Examples of RSA
28
6. Send CT as the cipher-text to the receiver. Send 40 as the cipher text to the receiver.
7. For decryption, calculate the plaintext PT from the cipher-
text CT as follows: PT = CTD mod N.
That is: PT = 4077 mod 119 = 10.
This was the original plaintext of step 5
A hash function in cryptography is like a mathematical function that takes various inputs, like messages or
data, and transforms them into fixed-length strings of characters. Means the input to the hash function is of
any length but output is always of fixed length. This is like compressing a large balloon into a compact ball.
The importance of this process lies in its generation of a unique "fingerprint" for each input. Any minor
alteration in the input results in a substantially different fingerprint, a quality known as "collision resistance."
Hash functions play a crucial role in various security applications, including password storage (hash values
instead of passwords), digital signatures, and data integrity checks. Hash values, or message digests, are
values that a hash function returns. The hash function is shown in the image below −
29
In computing systems, hash functions are frequently used data structures for tasks like information
authentication and message integrity checks. They are not easily decipherable, but because they can be solved
in polynomial time, they are regarded as cryptographically "weak".
Typical hash functions have been improved with security characteristics by cryptographic hash functions, which
make it more challenging to decipher message contents or recipient and sender information.
The hash function are called as "collision-free." As a result, no two input hashes should be equal to the
same output hash.
They are hidden. A hash function's output should make it difficult to figure out the input value from it.
They should to be friendly to puzzles. The selection of an input that generates a predetermined result
needs to be difficult. As such, the input needs to be taken from as wide as possible.
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to
boost your career.
Pre-Image Resistance
According to this feature, reversing a hash function should be computationally difficult.
In other words, if a hash function h generates a hash value z, it should be difficult to identify an input
value x that hashes to z.
This feature defends against an attacker attempting to locate the input with just the hash value.
Second Pre-Image Resistance
This property says that given an input and its hash, it should be difficult to find another input with the
same hash.
In other words, it should be challenging to find another input value y such that h(y) equals h(x) if a
hash function h for an input x returns the hash value h(x).
This feature of the hash function protects against an attacker who wants to replace a new value for the
original input value and hash, but only holds the input value and its hash.
Collision Resistance
This feature says that it should be difficult to identify two different inputs of any length that produce
the same hash. This characteristic is also known as a collision-free hash function.
In other words, for a hash function h, it is difficult to identify two distinct inputs x and y such that
h(x)=h(y).
A hash function cannot be free of collisions because it is a compression function with a set hash length.
The collision-free condition simply indicates that these collisions should be difficult to locate.
This characteristic makes it very hard for an attacker to identify two input values that have the same
hash.
Furthermore, a hash function is second pre-image resistant if it is collision-resistant.
Efficiency of Operation
Computation of h(x) for any hash function h given input x can be an easy process.
Hash functions are computationally considerably faster than symmetric encryption.
Fixed Output Size
Hashing generates an output of a specific length, regardless of the input size, and helps to make an output of
the same size from different input sizes.
30
Deterministic
For a given input, the hash function consistently produces the same output, like a recipe that always yields the
same dish when followed precisely.
Fast Computation
Hashing operations occur rapidly, even for large amounts of data sets.
Hashing algorithms use a sequence of rounds, similar to a block cipher, to process a message. In each round,
a fixed-size input is used, which usually combines the current message block and the result from the previous
round.
This process continues for multiple rounds until the entire message is hashed. A visual representation of this
process is provided in the illustration below.
31
Due to the interconnected nature of hashing, where the output of one operation affects the input of the next,
even a minor change (a single bit difference) in the original message can drastically alter the final hash value.
This phenomenon is known as the avalanche effect. Additionally, it's crucial to distinguish between a hash
function and a hashing algorithm. The hash function itself takes two fixed-length binary blocks of data and
generates a hash code.
A hashing algorithm, on the other hand, establishes how the message is divided into blocks and how the
outcomes of multiple hash operations are combined.
For a number of years, MD5 was the most popular and often used hash function.
The hash functions MD2, MD4, MD5, and MD6 are members of the MD family. It was adopted as the
RFC 1321, Internet Standard. It is a 128-bit hash function.
In the software industry, MD5 digests are frequently used to ensure the integrity of transferred files. To
enable users to compare the checksum of the downloaded file with the pre-computed MD5 checksum,
file servers frequently provide this feature.
In 2004, collisions were found in MD5. It was claimed that an analytical attack using a computer cluster
was successful in under one hour. Since MD5 was compromised by this collision attack, using it is no
longer recommended.
32
Algorithm Steps:
plaintext
Copy code
A = 0x67452301
B = 0xEFCDAB89
C = 0x98BADCFE
D = 0x10325476
plaintext
Copy code
F(B,C,D) = (B AND C) OR ((NOT B) AND D) (for round 1)
F(B,C,D) = (D AND B) OR ((NOT D) AND C) (for round 2)
F(B,C,D) = B XOR C XOR D (for round 3)
F(B,C,D) = C XOR (B OR (NOT D)) (for round 4)
Each operation modifies one of the working variables (A, B, C, or D) and involves an addition, bitwise
operation, and left rotation. The updated value is calculated as:
plaintext
Copy code
A = B + ((A + F(B,C,D) + M[k] + T[i]) << s)
M[k]: One of the sixteen 32-bit words from the message block.
T[i]: A constant derived from the sine function, specific to each operation.
s: The number of bits to rotate left, specific to each operation.
5. Add This Block's Hash to Result So Far:
o After processing all 64 operations for the block, the intermediate hash value is added to the current value
of the MD buffer:
plaintext
Copy code
A = A + AA
B = B + BB
C = C + CC
D = D + DD
33
6. Output:
o The final hash value is obtained by concatenating the variables A, B, C, and D (in little-endian format).
Pseudo-Code:
plaintext
Copy code
MD5 (message)
1. Initialize variables:
A = 0x67452301
B = 0xEFCDAB89
C = 0x98BADCFE
D = 0x10325476
2. Pre-processing:
- Add padding bits
- Add length
- Main loop:
for i from 0 to 63:
if 0 ≤ i ≤ 15:
F = (B AND C) OR ((NOT B) AND D)
g = i
else if 16 ≤ i ≤ 31:
F = (D AND B) OR ((NOT D) AND C)
g = (5×i + 1) mod 16
else if 32 ≤ i ≤ 47:
F = B XOR C XOR D
g = (3×i + 5) mod 16
else if 48 ≤ i ≤ 63:
F = C XOR (B OR (NOT D))
g = (7×i) mod 16
F = F + AA + K[i] + M[g]
AA = DD
DD = CC
CC = BB
BB = BB + leftrotate(F, s[i])
4. Output:
The final hash is the concatenation of A, B, C, and D.
Security:
34
MD5 is no longer considered secure due to vulnerabilities that allow for collision attacks (finding two different
messages that produce the same hash). It should not be used for cryptographic purposes such as SSL/TLS
certificates or digital signatures.
The four SHA algorithms which make up the SHA family are SHA-0, SHA-1, SHA-2, and SHA-3. Despite coming
from the same family, the structure of it differs.
The National Institute of Standards and Technology (NIST) released the first iteration of the 160-bit
hash algorithm, known as SHA-0, in 1993. It did not gain much popularity and had few drawbacks.
SHA-1 was created later in 1995 to address perceived flaws in SHA-0.
SHA-1 is the most widely used of the existing SHA hash functions. It is used in most of the applications
and protocols including Secure Socket Layer (SSL) security.
In 2005, a technique was discovered for SHA-1 collision detection that can be used in a realistic time
frame. So it is doubtful on SHA-1's long-term usability.
SHA-224, SHA-256, SHA-384, and SHA-512 are the other four SHA variants in the SHA-2 family, which
vary based on the number of bits in their hash value. The SHA-2 hash function has not yet been the
target of any effective attacks
Though SHA-2 is a strong hash function. Though significantly different, its basic design still follows the
design of SHA-1. NIST thus demanded the creation of new competitive hash function designs.
The Keccak algorithm was selected by the NIST in October 2012 to replace the SHA-3 standard. Keccak
has several advantages, including effective operation and strong attack resistance.
Developed by the National Security Agency (NSA) and published by the National Institute of Standards and
Technology (NIST) in 1993.
Produces a 160-bit (20-byte) hash value, typically rendered as a 40-digit hexadecimal number.
Algorithm Steps:
plaintext
Copy code
H0 = 0x67452301
H1 = 0xEFCDAB89
H2 = 0x98BADCFE
H3 = 0x10325476
H4 = 0xC3D2E1F0
plaintext
Copy code
TEMP = (A leftrotate 5) + f(B,C,D) + E + W[t] + K[t]
E = D
D = C
C = B leftrotate 30
B = A
A = TEMP
Here, f(B,C,D) is a nonlinear function that changes every 20 rounds, and K[t] is a constant value that
also changes every 20 rounds.
Weaknesses:
SHA-1 is considered weak due to vulnerabilities that allow for practical collision attacks, where two different
inputs produce the same hash value. As a result, it is no longer recommended for cryptographic use.
Part of the SHA-2 family, developed by the NSA and published in 2001.
Produces a 256-bit (32-byte) hash value, typically rendered as a 64-digit hexadecimal number.
Algorithm Steps:
plaintext
Copy code
H0 = 0x6A09E667
H1 = 0xBB67AE85
H2 = 0x3C6EF372
H3 = 0xA54FF53A
H4 = 0x510E527F
H5 = 0x9B05688C
36
H6 = 0x1F83D9AB
H7 = 0x5BE0CD19
plaintext
Copy code
W[t] = W[t-16] + σ0(W[t-15]) + W[t-7] + σ1(W[t-2])
Where:
plaintext
Copy code
σ0(x) = (x rightrotate 7) XOR (x rightrotate 18) XOR (x rightshift 3)
σ1(x) = (x rightrotate 17) XOR (x rightrotate 19) XOR (x rightshift 10)
o Initialize Working Variables: Set the initial values of the working variables to the current
hash values (A, B, C, D, E, F, G, H).
o Compression Function: For each of the 64 rounds, the working variables are updated as
follows:
plaintext
Copy code
T1 = H + Σ1(E) + Ch(E,F,G) + K[t] + W[t]
T2 = Σ0(A) + Maj(A,B,C)
H = G
G = F
F = E
E = D + T1
D = C
C = B
B = A
A = T1 + T2
Where:
plaintext
Copy code
Σ0(x) = (x rightrotate 2) XOR (x rightrotate 13) XOR (x rightrotate 22)
Σ1(x) = (x rightrotate 6) XOR (x rightrotate 11) XOR (x rightrotate 25)
Ch(x,y,z) = (x AND y) XOR ((NOT x) AND z)
Maj(x,y,z) = (x AND y) XOR (x AND z) XOR (y AND z)
Strengths:
37
SHA-256 is widely used and considered secure against currently known attack methods. It provides a good
balance of security and performance.
CityHash
CityHash is another non-cryptographic hash function that is designed for fast hashing of large amounts of
data. It is optimized for modern processors and offers good performance on both 32-bit and 64-bit
architectures.
BLAKE2
BLAKE2 is a fast and secure hash function that improves upon SHA-3. It is widely used in applications like
cryptocurrency mining that need fast hashing. There are two types of BLAKE2 −
BLAKE2b − Best for 64-bit computers, it produces hash values up to 512 bits long.
BLAKE2s − Best for smaller computers (8-32 bits), it produces hash values up to 256 bits long.
CRC (Cyclic Redundancy Check) is a technique used to detect errors in data transfer. It involves adding a
special value called a checksum to the end of a message. This checksum is calculated based on the message's
content and is included during transmission.
When the data is received, the recipient recalculates the checksum using the same method. If the new
checksum matches the original one, it's likely that the message was transmitted without errors. While CRC is
effective for error detection, it's not a security measure. It is primarily used to ensure the integrity of data
during transmission, not to protect it from unauthorized access or modification.
MurmurHash
MurmurHash is a speedy and effective hash function that is not meant for security. It is great for things like
hash tables but not for tasks that need protection against collisions (situations where different inputs produce
the same hash).
Standard Length
Hashing involves converting a data set of any size into a shorter, fixed-length output using a mathematical
formula.
In table I, the message "CFI" is converted into hash values using three algorithms: MD5, SHA-1, and SHA-
256. Each algorithm produces a unique output hash with a fixed length. MD5 generates a hash with 32
hexadecimal characters, SHA-1 with 40 characters, and SHA-256 with 64 characters.
Input
Hash Function Output (Hash Value)
Message
CFI MD5 (128-bit, 16-byte) 3A10 0B15 B943 0B17 11F2 E38F 0593 9A9A
38
32 characters
SHA-1 (160-bit, 20-byte) 569D C9F0 7B48 7F58 9241 AD4C 5C28 7DA0
CFI
40 characters A448 8D08
SHA-256 (256-bit, 32- F3ED 0867 48FF 3641 3091 0BB6 6293 7080
CFI
byte) 64 characters 2958 B5A2 52AF F364 1FC5 07FD E80D 9929
Table II: Using the Same Hash Function (SHA-1) with different Inputs
Besides the data (input) used, a hash function consistently generates a hash value with a fixed number of
characters. As shown in Table II, different messages inputted into the same hash function (SHA-1 in this case)
consistently produce output values of 40 hexadecimal characters in length.
Input Hash
Output (Hash Value)
Message Function
Password Storage
Hash functions provide protection to password storage. Instead of storing passwords in clear, mostly all login
processes store the hash values of passwords in the file.
The Password file is a table of pairs in the format (user id, h(P)).
Even if an attacker has access to the password, all they can see is the hashes of the passwords. Because the
hash function contains the pre-image resistance feature, he cannot use it to log in or get the password from it.
Data integrity checks, commonly using hash functions, provide assurances about the accuracy of data files by
creating checksums. This method allows users to detect any alterations made to the original file.
However, it does not guarantee the authenticity of the file. An attacker could potentially modify the entire file
and generate a new hash, sending it to the receiver. This integrity check is only effective if the user trusts the
file's original source.
39
Hashing vs Encryption
Encryption transforms data into a disguised form, requiring a cipher (key) to decipher and read it. Encryption
and decryption are reversible processes enabled by the cipher. Encryption is used with the goal of later
deciphering the data.
Hashing transforms data of any size into a fixed-length output. Unlike encryption, hashing is typically a one-
way function. The high computational effort needed to reverse a hash makes it difficult to retrieve the original
data from the hashed output.
Data is protected during transmission by encryption, which stops unwanted access. By comparing the data to a
distinct fingerprint (hash) created from the original data, hashing ensures the integrity of the data. Encryption
keeps data confidential, while hashing ensures authenticity by detecting any modifications.
Digital signature:
It is an authentication mechanism that allows the sender to attach an electronic
code with the message. This electronic code acts as the signature of the sender and
hence, is named digital signature.
It is done to ensure its authenticity and integrity.
Digital signature uses the public-key cryptography technique. The sender uses his
or her private keyand a signing algorithm to create a digital signature and the
signed document can be made public. The receiver, uses the public key of the
sender and a verifying algorithm to verify the digitalsignature.
A normal message authentication scheme protects the two communicating parties
against attacks from a third party (intruder). However, a secure digital signature
scheme protects the two parties against each other also.
Suppose A wants to send a signed message (message with A's digital signature) to
B through a network. For this, A encrypts the message using his or her private
key, which results in a signed message. The signed message is then sent through
the network to B.
Now, B attempts to decrypt the received message using A's public key in order to
verify that the received message has really come from A.
If the message gets decrypted, B can believe that the message is from A. However,
if the message or the digital signature has been modified during transmission, it
40
cannot be decrypted using A's public key. From this, B can conclude that either
the message transmission has tampered with, or that the message has not been
generated by A.
Message integrity:
Digital signatures also provide message integrity.
If a message has a digital signature, then any change in the message after the
signature is attached will invalidate the signature.
That is, it is not possible to get the same signature if the message is changed.
Moreover, there is no efficient way to modify a message and its signature such that
a new message with a valid signature is produced.
Non-repudiation:
Digital signatures also ensure non-repudiation.
For example, if A has sent a signed message to B, then in future A cannot deny
about the sending ofthe message. B can keep a copy of the message along with A's
signature.
In case A denies, B can use A’s public key to generate the original message. If
the newly createdmessage is the same as that initially sent by A, it is proved that
the message has been sent by A only
In the same way, B can never create a forged message bearing A's digital
signature, because only Acan create his or her digital signatures with the help of
that private key.
Message confidentiality:
Digital signatures do not provide message confidentiality, because anyone knowing
the sender's public key can decrypt the message.
41
DIGITAL CERTIFICATE & PUBLIC KEY INFRASTRUCTURE
Digital Certificate:
A digital certificate is simply a small computer file. For example, my digital
certificate would actually be a computer file with a file name such as name .cer.
The digital certificate is actually quite similar to a passport. As we know every
passport has a unique passport number, similarly every digital certificate has a
unique serial number. Also gives information of the issuer’s name, serial number,
public key, validity period, etc.
Digital Certificate is issued by a trusted agency called as CA (Certification
Authority).
Another third party called as RA (Registration Authority) acts as a intermediate
entity between CA and end user.
Satisfies the principle of Authentication, non-repudiation.
Certification Authority (CA)
CA has to be someone, who everybody trusts. Consequently, the governments in
variouscountries decide who can and who cannot be a CA.
Usually, a CA is a reputed organization, such as a post office, financial
institution, software company, etc. Two of the world’s most famous CAs are
VeriSign and Entrust. Safescrypt Limited is the first Indian CA.
Thus, a CA has the authority to issue digital certificates to individuals and
organizations,who want to use those certificates in asymmetric-key cryptographic
applications.
Technical Details of a Digital Certificate:
A standard called X.509 defines the structure of a digital certificate. The International
Telecommunication Union (ITU) designs this standard. At that time, it was a part of
another standard called X.500. The current version of the standard is Version 3, called
X.509V3.
42
Contents of Digital Certificate:
43
2. Certificate Creation Steps
Note that the user must not send the private key to the RA—the user must keep it
securely.
44
Step 3: Verification:
After the registration process is complete, the RA has to verify the user’s
credentials. This verification is in two respects, as follows.
1. Firstly, the RA needs to verify the user’s credentials which are provided by the user.
If the user were actually an organization then the RA would perhaps like
to check the business records, historical documents and credibility proofs.
If it is an individual user then simpler checks are in call, such as verifying
the postal address, email id, phone number, passport or driving-license
details can be sufficient.
2. Secondly, check is to ensure that the user who is requesting for the certificate,
whether he/she possesses the private key or not corresponding to the public key
that is sent to the RA.
This is very important, because there must be a record that the user possesses the private
key corresponding to the given public key. Otherwise, this can create legal problems. This
check is called the Proof Of Possession (POP) of the private key.
How can the RA perform this check? There are many approaches to this, the chief
ones being as follows.
The RA can demand that the user must digitally sign his/her Certificate Signing
Request (CSR) using his/her private key. If the RA can verify the signature (i.e.
de-sign the CSR) correctly using the public key of the user, the RA can believe
that the user indeed possesses the private key.
Alternatively, the RA can create a random number challenge; encrypt it with the
user’s public key and send the encrypted challenge to the user. If the user can
successfully decrypt the challenge using his/her private key, the RA can assume
that the user possesses the right private key.
Thirdly, the RA can actually generate a dummy certificate for the user, encrypt it
using the user’s public key and send it to the user. The user can decrypt it only if
he/she can decrypt the encrypted certificate, and obtain the plain-text certificate.
Step 4: Certificate Creation:
Assuming that all the steps so far have been successfully done, and then RA
passes on allthe details of the user to the CA.
The CA does its own verification (if required) and creates a digital certificate for the
user.
The creation of certificate as per the X.509 standard.
The CA sends the certificate to the user, and also retains a copy of the certificate
for itsown record.
The CA’s copy of the certificate is maintained in a certificate directory. This is a
centralstorage location maintained by the CA.
45
Certificate hierarchy relieves the root CA from having to manage all the possible digital
certificates.
As a substitute, the root CA can hand over this job to the second-level CAs. This hand
over can happen region-wise. E.g. one second level CA could be responsible for the
Western region, another for the Eastern region, a third one for the Northern region, and a
fourth one for the Southern region, etc.). Each of these second-level CAs could appoint
third-level CAs state-wise within that region. Each third-level CA could hand over its
responsibilities to a fourth-level CA city-wise, and so on.
The root CA signs its own certificate. This certificate of the root CA is called self-signed
certificate.
Cross-Certification
It is quite possible that user A and user B live in different countries.
This would mean that their root CAs may be different. Because generally each
countryappoints its own root CA. In fact, one country can have multiple root CAs
as well.
For instance, the root CAs
in the US are VeriSign,
Thawte, and the US Postal
Service. In such cases, there
is no single root CA, which
can be trusted by all the
concerned parties.
In our example, why should
user A—a Japanese
national, trust user B’s root
CA—a US-based
organization?
Cross-certification allows
CAs and end users from
different PKI domains to
interact called cross
certification.
Certificate Revocation:
Reasons for revocation:
If the private key corresponding to the public key is stolen.
The CA realizes that it had made mistake while issuing the certificate.
The certificate holder leaves a job and the certificate was issued specifically
while thePerson was employed in that job.
It checks: Online revocation status, Off-line revocation status
46
Key Exchange
Overview: Key exchange allows two parties to share a secret key, which can be used for encrypting and
decrypting messages. This is crucial for establishing secure communication, especially in scenarios where the
parties have not previously shared a secret key.
Algorithm Steps:
1. Choose Parameters:
o Both parties agree on a large prime number ppp and a base ggg (also known as the generator). These
values are not secret and can be shared openly.
2. Generate Private and Public Keys:
o Party A:
Chooses a private key aaa (a random number).
Computes the public key A=gamod pA = g^a \mod pA=gamodp.
o Party B:
Chooses a private key bbb (a random number).
Computes the public key B=gbmod pB = g^b \mod pB=gbmodp.
3. Exchange Public Keys:
o Party A sends its public key AAA to Party B.
o Party B sends its public key BBB to Party A.
4. Compute Shared Secret:
o Party A:
Computes the shared secret s=Bamod ps = B^a \mod ps=Bamodp.
o Party B:
Computes the shared secret s=Abmod ps = A^b \mod ps=Abmodp.
Since s=Bamod p=(gbmod p)amod p=gabmod ps = B^a \mod p = (g^b \mod p)^a \mod p = g^{ab} \mod
ps=Bamodp=(gbmodp)amodp=gabmodp and s=Abmod p=(gamod p)bmod p=gabmod ps = A^b \mod p =
47
(g^a \mod p)^b \mod p = g^{ab} \mod ps=Abmodp=(gamodp)bmodp=gabmodp, both parties end up with the
same shared secret sss.
Security:
The security of the Diffie-Hellman Key Exchange relies on the difficulty of the discrete logarithm problem,
which makes it computationally infeasible for an attacker to derive the shared secret from the public values ppp,
ggg, AAA, and BBB.
The first published public-key algorithm appeared in the seminal paper by Diffie and Hellman that defined
public-key cryptography and is generally referred to as Diffie-Hellman key exchange. A number of commercial
products employ this key exchange technique. The purpose of the algorithm is to enable two users to securely
exchange a key that can then be used for subsequent encryption of messages. The algorithm itself is limited to the
exchange of secret values.
The Diffie-Hellman algorithm depends for its effectiveness on the difficulty of computing discrete logarithms.
Briefly, we can define the discrete logarithm in the following way. First, we define a primitive root of a prime
number p as one whose powers modulo p generate all the integers from 1 to p 1. That is, if a is a primitive root of
the prime number p, then the numbers a mod p, a2 mod p,…, ap1 mod p
are distinct and consist of the integers from 1 through p 1 in some permutation.
For any integer b and a primitive root a of prime number p, we can find a unique exponent i such thatb ≡ai (mod p)
where 0≤ i ≤(p 1). The exponent i is referred to as the discrete logarithm of b for the base a, mod p. We express this
value as dloga,p (b). See Chapter 8 for an extended discussion of discrete logarithms.
Figure 1 summarizes the Diffie-Hellman key exchange algorithm. For this scheme, there are two publicly known
numbers: a prime number q and an integer that is a primitive root of q. Suppose the users A and B wish to exchange
a key. User A selects a random integer XA < q and computes YA = αXA mod q. Similarly, user B independently
selects a random integer XA < q and computes YB = αXB mod q. Each side keeps the X value private and makes
the Y value available publicly to the other side. User A computes the key as K = (YB)XA mod q and user B computes
the key as
48
49
The result is that the two sides have exchanged a secret value. Furthermore, because XA and XB are private, an
adversary only has the following ingredients to work with: q, α, YA, and YB. Thus, the adversary is forced to take a
discrete logarithm to determine the key. For example, to determine the private key of user B, an adversary must
compute XB = dlogα,q (YB) The adversary can then calculate the key K in the same manner as user B calculates it.
The security of the Diffie-Hellman key exchange lies in the fact that, while it is relatively easy to calculate
exponentials modulo a prime, it is very difficult to calculate discrete logarithms. For large primes, the latter task is
considered infeasible.
Example 1
Let us give a trivial example to make the procedure clear. Our example uses small numbers, but note that in a
real situation, the numbers are very large. Assume that g=7 and p=23.The steps are as follows:
The value of K is the same for both Alice and Bob; gxy mod p=718 mod=18
Example 2
Let us give a more realistic example. We used a program to create a random integer of 512bits (the ideal is 1024
bits). The integer p is a 159-digit number.
We also choose g,x, and y as shown below:
50
3. Key Exchange Protocols
Figure 2 shows a simple protocol that makes use of the Diffie-Hellman calculation. Suppose that user A, wishes to
set up a connection with user B and use a secret key to encrypt messages on that connection. User A can generate a
one-time private key XA, calculate YA, and send that to user B. User B responds by generating a private
value XB calculating YB, and sending YB to user A. Both users can now calculate the key. The necessary public
values q and α would need to be known ahead of time. Alternatively, user A could pick values for q and α and
include those in the first message.
As an example of another use of the Diffie-Hellman algorithm, suppose that a group of users (e.g., all users on a
LAN) each generate a long-lasting private value Xi (for user i) and calculate a public value Yi. These public values,
51
together with global public values for q and α, are stored in some central directory. At any time, user j can access
user i‘s public value, calculate a secret key, and use that to send an encrypted message to user A. If the central
directory is trusted, then this form of communication provides both confidentiality and a degree of authentication.
Because only i and j can determine the key,no other user can read the message (confidentiality). Recipient i knows
that only user j could have created a message using this key (authentication). However, the technique does not
protect against replay attacks.
4. Man-in-the-Middle Attack
It is insecure against a man-in-the-middle attack. Suppose Alice and Bob wish to exchange keys, and Darth is the
adversary. The attack proceeds as follows:
1. Darth prepares for the attack by generating two random private keys XD1 and XD2
and then computing the corresponding public keys YD1 and YD2.
mod q.
mod q.
At this point, Bob and Alice think that they share a secret key, but instead Bob and Darth share secret key K1 and
Alice and Darth share secret key K2. All future communication between Bob and Alice is compromised in the
following way:
In the first case, Darth simply wants to eavesdrop on the communication without altering it. In the second case,
Darth wants to modify the message going to Bob. The key exchange protocol is vulnerable to such an attack
because it does not authenticate the participants. This vulnerability can be overcome with the use of digital
signatures and public-key certificates.
Algorithm Steps:
1. Choose Parameters:
o Both parties agree on an elliptic curve EEE defined over a finite field and a base point GGG on the
curve. These values are not secret.
2. Generate Private and Public Keys:
o Party A:
Chooses a private key aaa (a random number).
Computes the public key A=aGA = aGA=aG (point multiplication on the elliptic curve).
o Party B:
Chooses a private key bbb (a random number).
Computes the public key B=bGB = bGB=bG.
3. Exchange Public Keys:
o Party A sends its public key AAA to Party B.
o Party B sends its public key BBB to Party A.
4. Compute Shared Secret:
o Party A:
Computes the shared secret S=aBS = aBS=aB.
o Party B:
Computes the shared secret S=bAS = bAS=bA.
Security:
The security of ECDH relies on the difficulty of the elliptic curve discrete logarithm problem, making it highly
secure with shorter keys compared to traditional Diffie-Hellman.
Practical Applications
53
SSL/TLS: Secure web communication protocols use key exchange methods (like ECDH) to establish secure
connections between browsers and servers.
VPNs: Virtual Private Networks use key exchange protocols to create secure communication channels over the
internet.
Encrypted Messaging: Applications like Signal and WhatsApp use key exchange protocols to secure end-to-
end communication between users.
Key exchange is a foundational aspect of modern cryptography, enabling secure communication in various
digital applications and services.
55
Policy outlines:
Defines policies for the creation of Certificate Policies & Certificate Practice
Statements.
Timestamp & Data Certification Services:
Both are the trusted third parties that provide services to guarantee the
existence ofcertificate & DCS verifies the correctness of data that it receives.
Digital Envelop:
56
References:
4. https://en.wikipedia.org
5. https://nptel.ac.in
6. https://www.geeksforgeeks.org/
57