Unit 2
Unit 2
UNIT II
SDES-Block Ciphers- -Block cipher mode of operation - AES - Pseudorandom Number Generators-
RC4-Key distribution- RSA cryptosystem - Key distribution - Key management - Diffie Hellman key
exchange - Elliptic curve cryptography -DA.
2 Marks:
1.How is the key generation process in SDES carried out?
Answer:
In SDES, the key generation process involves using a 10-bit key to generate two 8-bit subkeys:
1. Initial Permutation (P10): The 10-bit key undergoes a permutation using a P10 table, creating
a 10-bit key.
2. Left Shift: The 10-bit key is split into two 5-bit halves, each of which is shifted left by one
position.
3. Subkey Generation: After the left shift, the two halves are recombined, and a permutation P8
is applied to produce an 8-bit subkey (K1). The process is repeated for the second subkey
(K2) after another left shift.
2. What is the role of Initialization Vector (IV) in CBC mode?
Answer:
In CBC (Cipher Block Chaining) mode, the Initialization Vector (IV) is used to ensure that identical
plaintext blocks do not result in identical ciphertext blocks. The IV is XORed with the first plaintext
block before encryption. It is unique for each encryption session and is usually sent alongside the
ciphertext, but it does not need to be kept secret. The IV ensures that the same plaintext, encrypted
with the same key, produces different ciphertexts each time.
5 and 10 Marks :
1. Explain about SDES ?
c. Permutation P4 –
3. Switch (SW) –
4. Inverse of Initial Permutation (IP-1) –
S1= [0,1,2,3
2,0,1,3
3,0,1,0
2,1,0,3]
For l = 0 1 0 0
row = 00 = 0, column = 10 = 2
S0 = 3 = 11
For r = 1 1 1 1
row = 11 = 3, column = 11 = 3
S1 = 3 = 11
P4 is defined as - 2 4 3 1
After P4 = 1 1 1 1
l = 1 1 0 1 and r = 1 0 1 0
On the right half, we perform expanded permutation using EP table which converts 4 bits into
8 bits. Expand permutation is defined as –
EP(k1, k2, k3, k4) = (k4, k1, k2, k3, k2, k3, k4, k1)
After second ep = 0 1 0 1 0 1 0 1
We perform XOR operation using second key K2 with the output of expanded permutation.
Key-2 is - 0 1 0 0 0 0 1 1
(0 1 0 0 0 0 1 1) XOR (0 1 0 1 0 1 0 1) = 0 0 0 1 0 1 1 0
After XOR operation with 2nd Key = 0 0 0 1 0 1 1 0
Again we divide the output of XOR into 2 halves of 4 bit each.
l = 0 0 0 1 and r = 0 1 1 0
We take the first and fourth bit as row and the second and third bit as a column for our S
boxes.
S0 = [1,0,3,2
3,2,1,0
0,2,1,3
3,1,3,2]
S1 = [0,1,2,3
2,0,1,3
3,0,1,0
2,1,0,3]
For l = 0 0 0 1
row = 01 = 1 , column = 00 = 0
S0 = 3 = 11
For r = 0 1 1 0
row = 00 = 0 , column = 11 = 3
S1 = 3 = 11
2.What is block cipher and what are the operations of block cipher?
Block Cipher
Block cipher is an encryption and decryption method which operates on the blocks of plain
text, instead of operating on each bit of plain text separately. Each block is of equal size and
has fixed no of bits. The generated ciphertext has blocks equal to the number of blocks in
plaintext and also has the same number of bits in each block as of plain text. Block cipher
uses the same key for encryption and decryption.
While decryption also only one block of ciphertext is operated to produce its
corresponding plain text. Data Encryption Standard (DES) is the best example of it.
DES divides the plain text into the number of blocks, each of 64-bit. DES operates on
one block of plain text at a time. Key of 56-bit is applied to each block of plain text to
produce its corresponding ciphertext of 64-bit.
During decryption also only one block of ciphertext is operated at a time to produce
its corresponding block plain text. In DES the decryption algorithm is the same as the
encryption one.
Block Cipher Principles
A block cipher is designed by considering its three critical aspects which are listed as below:
1. Number of Rounds
2. Design of Function F
3. Key Schedule Algorithm
1. Number of Rounds
The number of rounds judges the strength of the block cipher algorithm. It is considered that
more is the number of rounds, difficult is for cryptanalysis to break the algorithm.
It is considered that even if the function F is relatively weak, the number of rounds would
make the algorithm tough to break.
2. Design of Function F
The function F of the block cipher must be designed such that it must be impossible for any
cryptanalysis to unscramble the substitution. The criterion that strengthens the function F is it
non-linearity.
More the function F is nonlinear, more it would be difficult to crack it. Well, while designing
the function F it should be confirmed that it has a good avalanche property which states that a
change in one-bit of input must reflect the change in many bits of output.
The Function F should be designed such that it possesses a bit independence criterion which
states that the output bits must change independently if there is any change in the input bit.
3. Key Schedule Algorithm
It is suggested that the key schedule should confirm the strict avalanche effect and bit
independence criterion.
Block Cipher Modes of Operation
There are five important block cipher modes of operation defined by NIST. These five modes
of operation enhance the algorithm so that it can be adapted by a wide range of applications
which uses block cipher for encryption.
1. Electronic Code Book Mode
2. Cipher Block Chaining Mode
3. Cipher Feedback Mode
4. Output Feedback Mode
5. Counter Mode
1. Electronic Feedback Mode
This is considered to be the easiest block cipher mode of operation. In electronic codebook
mode (ECB) the plain text is divided into the blocks, each of 64-bit. Each block is encrypted
one at a time to produce the cipher block. The same key is used to encrypt each block.
When the receiver receives the message i.e. ciphertext. This ciphertext is again divided into
blocks, each of 64-bit and each block is decrypted independently one at a time to obtain the
corresponding plain text block. Here also the same key is used to decrypt each block which
was used to encrypt each block.
Advantages of using ECB
Parallel encryption of blocks of bits is possible, thus it is a faster way of encryption.
Simple way of the block cipher.
Disadvantages of using ECB
Prone to cryptanalysis since there is a direct relationship between plaintext and
ciphertext.
Identical plaintext blocks produce identical ciphertext blocks, which can reveal
patterns.
2. Cipher Block Chaining Mode
To overcome the limitation of ECB i.e. the repeating block in plain text produces the
same ciphertext, a new technique was required which is Cipher Block Chaining
(CBC) Mode. CBC confirms that even if the plain text has repeating blocks its
encryption won’t produce same cipher block.
To achieve totally different cipher blocks for two same plain text blocks chaining has
been added to the block cipher.
Encryption steps of CBC
Step 1: The initialization vector and first plain text block are XORed and the result of
XOR is then encrypted using the key to obtain the first ciphertext block.
Step 2: The first ciphertext block is fed to the encryption of the second plain text
block. For the encryption of second plain text block, first ciphertext block and second
plain text block is XORed and the result of XOR is encrypted using the same key in
step 1 to obtain the second ciphertext block.
And the process continues to obtain all the ciphertext blocks.
Decryption steps of CBC:
Step 1: The first ciphertext block is decrypted using the same key that was used for
encrypting all plain text blocks. The result of decryption is then XORed with the
initialization vector (IV) to obtain the first plain text block.
Step 2: The second ciphertext block is decrypted and the result of decryption is
XORed with the first ciphertext block to obtain the second plain text block. And the
process continues till all plain text blocks are retrieved.
It has a limitation that if there occur a bit error in any ciphertext Ci it would affect all the
subsequent ciphertext units as Ci is fed to the encryption of next Pi+1 to obtain Ci+1. In this way,
bit error would propagate.
Advantages of CBC
CBC works well for input greater than b bits.
CBC is a good authentication mechanism.
Better resistive nature towards cryptanalysis than ECB.
More secure than ECB as it hides patterns.
Disadvantages of CBC
Requires the previous ciphertext block for encryption and decryption, making parallel
processing difficult.
3. Cipher Feedback Mode
All applications may not be designed to operate on the blocks of data, some may
be character or bit-oriented. Cipher feedback mode is used to operate on smaller
units than blocks.
Encryption steps in cipher feedback mode:
Step 1: Here also we use initialization vector, IV is kept in the shift register and it is
encrypted using the key.
Step 2: The left most s bits of the encrypted IV is then XORed with the first fragment
of the plain text of s bits. It produces the first ciphertext C1 of s bits.
Step 3: Now the shift register containing initialization vector performs left shift by s
bits and s bits C1 replaces the rightmost s bits of the initialization vector.
Decryption Steps:
Step 1: The initialization vector is placed in the shift register. It is encrypted using the
same key.
Keep a note that even in the decryption process the encryption algorithm is
implemented instead of the decryption algorithm.
Then from the encrypted IV s bits are XORed with the s bits ciphertext C1 to retrieve
s bits plain text P1.
Step 2: The IV in the shift register is left-shifted by s bits and the s bits C1 replaces
the rightmost s bits of IV.
The process continues until all plain text fragments are retrieved.
Advantages of CFB
Since, there is some data loss due to the use of shift register, thus it is difficult for
applying cryptanalysis.
Can handle data streams of any size.
Disadvantages of using CFB
The drawbacks of CFB are the same as those of CBC mode. Both block losses and
concurrent encryption of several blocks are not supported by the encryption.
Decryption, however, is parallelizable and loss-tolerant.
Slightly more complex and can propagate errors.
4. Output Feedback Mode
The output feedback (OFB) mode is almost similar to the CFB. The difference
between CFB and OFB is that unlike CFB, in OFB the encrypted IV is fed to the
encryption of next plain text block. The other difference is that CFB operates on a
stream of bits whereas OFB operates on the block of bits.
Steps for encryption:
Step 1: The initialization vector is encrypted using the key.
Step 2: The encrypted IV is then XORed with the plain text block to obtain the
ciphertext block.
Steps for decryption:
Step 1: The initialization vector is encrypted using the same key used for encrypting
all plain text blocks.
Note: In the decryption process also the encryption function is implemented.
Step2: The encrypted IV is then XORed with the ciphertext block to retrieve the plain
text block.
The encrypted IV is also fed to the decryption process of the next ciphertext
10 128
12 192
14 256
for i in range(5):
print(random.randint(0, 10), end="\t")
Output1:
3 7 0 9 8
Output 2:
7 6 8 1 4
Time Complexity: O(1)
Auxiliary Space: O(1)
Explanation: srand() sets the seed which is used by rand() to generate random
numbers.time(NULL) return no. of second from JAN 1, 1971 i.e every time we run program
we have difference of few seconds which gives the program new seed.
6.Discuss about RSA Cryptography.
Thia algorithm named after its inventors, Rivest, Shamir, and Adleman (RSA)
It is a widely used public-key cryptosystem for secure data transmission.
The RSA algorithm uses mathematical functions that are complex enough to resist
brute force attacks but efficient enough to work quickly after being deployed.
It uses the receiver’s public key to encrypt the data, and it uses the receiver’s private
key in decrypting the data. Thus, there is no need to exchange any keys in this
scenario.
There are two broad components when it comes to RSA cryptography, they are:
i)Key Generation: Generating the keys to be used for encrypting and decrypting the data to be
exchanged.
ii)Encryption/Decryption Function: The steps that need to be run when scrambling and
recovering the data.
STEPS IN RSA:
Example 1:
This example shows how we can encrypt plaintext 9 using the RSA public-key encryption
algorithm. This example uses prime numbers 7 and 11 to generate the public and private
keys.
Explanation:
Step 1: Select two large prime numbers, p, and q.
p=7
q = 11
Step 2: Multiply these numbers to find n = p x q, where n is called the modulus for
encryption and decryption.
First, we calculate
n=pxq
n = 7 x 11
n = 77
Step 3: Choose a number e less that n, such that n is relatively prime to (p - 1) x (q -1).
It means that e and (p - 1) x (q - 1) have no common factor except 1.
Choose "e" such that 1<e < φ (n), e is prime to φ (n), gcd (e, d (n)) =1.
Second, we calculate
φ (n) = (p - 1) x (q-1)
φ (n) = (7 - 1) x (11 - 1)
φ (n) = 6 x 10
φ (n) = 60
Step 4: A plaintext message m is encrypted using public key <e, n>. To find ciphertext from
the plain text following formula is used to get ciphertext C.
C = me mod n
C = 97 mod 77
C = 37
Step 5: The private key is <d, n>. To determine the private key, we use the following formula
d such that:
De mod {(p - 1) x (q - 1)} = 1
7d mod 60 = 1, which gives d = 43
The private key is <d, n> = (43, 77)
Step 6: A ciphertext message c is decrypted using private key <d, n>. To calculate plain
text m from the ciphertext c following formula is used to get plain text m.
m = cd mod n
m = 3743 mod 77
m=9
In this example, Plain text = 9 and the ciphertext = 37
Example 2:
ADVANTAGES OF RSA
Very fast, very simple encryption and verification.
Easier to implement than Elliptical Curve Cryptography (ECC).
Easier to understand.
Widely deployed, better industry support.
DISADVANTAGES OF RSA
Very slow key generation.
Slow decryption, which is slightly tricky to implement securely.
Two-part key is vulnerable to GCD attack if poorly implemented.
2. Publicly Available Directory: In this type, the public key is stored in a public directory.
Directories are trusted here, with properties like Participant Registration, access and allow to
modify values at any time, contains entries like {name, public-key}. Directories can be
accessed electronically still vulnerable to forgery or tampering.
3. Public Key Authority: It is similar to the directory but, improves security by tightening
control over the distribution of keys from the directory. It requires users to know the public
key for the directory. Whenever the keys are needed, real-time access to the directory is made
by the user to obtain any desired public key securely.
4. Public Certification: This time authority provides a certificate (which binds an identity to
the public key) to allow key exchange without real-time access to the public authority each
time. The certificate is accompanied by some other info such as period of validity, rights of
use, etc. All of this content is signed by the private key of the certificate authority and it can
be verified by anyone possessing the authority’s public key.
First sender and receiver both request CA for a certificate which contains a public key and
other information and then they can exchange these certificates and can start communication.
Channel of Distribution:
o Key Distribution is possible in-band or out-of-band.
o "Channel of distribution" means the way information or keys are swapped between
two parties.
o "Key exchange" is when two parties share secret codes or 'keys' to communicate
securely.
o "In-band" key exchange means the keys are swapped through the same communication
channel being used for the actual data.
o "Out-of-band" key exchange means the keys are shared through a separate, different
communication channel from the one used for the actual data
o the problem for key exchange −
The Diffie-Hellman key exchange is a widely used cryptographic method for securely
exchanging keys over an insecure channel. It is commonly used in:
1. Secure Communication Protocols – Diffie-Hellman is integral to protocols like
SSL/TLS and SSH, allowing secure communication by enabling parties to agree on a
shared secret key for encryption and decryption.
2. Virtual Private Networks (VPNs) – It is employed in VPNs to establish a
secure connection between clients and servers, ensuring that traffic exchanged over
the VPN is encrypted.
3. Secure File Transfer Protocols – In protocols like SFTP and FTPS, Diffie-
Hellman helps establish secure channels for transferring files, ensuring confidentiality
by encrypting the data exchanged.
4. Other Applications – It is also used in secure email, web browsing, and voice
over IP (VoIP) to ensure secure communications across various platforms.
In short, Diffie-Hellman provides a reliable and flexible means of establishing secure
channels in numerous digital communications and transactions.
Diffie-Hellman algorithm:
The Diffie-Hellman algorithm is being used to establish a shared secret that can be used for
secret communications while exchanging data over a public network using the elliptic curve
to generate points and get the secret key using the parameters.
• For the sake of simplicity and practical implementation of the algorithm, we
will consider only 4 variables, one prime P and G (a primitive root of P) and two
private values a and b.
• P and G are both publicly available numbers. Users (say Alice and Bob) pick
private values a and b and they generate a key and exchange it publicly. The opposite
person receives the key and that generates a secret key, after which they have the
same secret key to encrypt.
Alice Bob
Example:
Step 1: Alice and Bob get public numbers P = 23, G = 9
Step 2: Alice selected a private key a = 4 and Bob selected a private key b = 3
The Diffie-Hellman key exchange, while widely used and trusted, has some vulnerabilities
that can be exploited if not properly implemented. Some of the main vulnerabilities include:
1. Man-in-the-Middle Attacks – If an attacker intercepts and alters the
messages exchanged between the parties (Alice and Bob), they could impersonate one
party and establish separate secure channels with each party. This allows the attacker
to decrypt and modify the communication. To defend against this, certificate-based
authentication and message authentication codes (MACs) should be used to verify the
authenticity of the parties involved.
2. Small Subgroup Attacks – If the prime number pp used in the key exchange
has small subgroups, an attacker may exploit this to compute the shared secret key
more easily. Using a large prime number with no known small subgroups helps
mitigate this risk and ensures the security of the key exchange.
3. Exponent Attacks – If the secret exponents (the private keys) are not chosen
randomly or are predictable, an attacker could potentially guess or deduce the secret
exponents and recover the shared key. To counteract this, a strong random number
generator should be used to generate the exponents, ensuring they are difficult to
predict or compute.
While Diffie-Hellman is a robust method for secure key exchange, careful implementation
and the use of appropriate security measures are essential to protect against these
vulnerabilities.
9.Explain about Elliptic Curve Cryptography in detail.
ECC, as the name implies, is an asymmetric encryption algorithm that employs the algebraic
architecture of elliptic curves with finite fields.
Elliptic Curve Cryptography (ECC) is an encryption technology comparable to RSA that
enables public-key encryption.
While RSA’s security is dependent on huge prime numbers, ECC leverages the mathematical
theory of elliptic curves to achieve the same level of security with considerably smaller keys.
Victor Miller and Neal Koblitz separately proposed elliptic curve ciphers in the mid-1980s. On a high
level, they are analogs of actual public cryptosystems in which modular arithmetic is substituted by
elliptic curve operations
Components of Ellliptic Curve Cryptography:
1. ECC keys:
Private key: ECC cryptography’s private key creation is as simple as safely producing a
random integer in a specific range, making it highly quick. Any integer in the field represents
a valid ECC private key.
Public keys: Public keys within ECC are EC points, which are pairs of integer coordinates x,
and y that lie on a curve. Because of its unique features, EC points can be compressed to a
single coordinate + 1 bit (odd or even). As a result, the compressed public key corresponds to
a 256-bit ECC.
2.Generator Point:
ECC cryptosystems establish a special pre-defined EC point called generator point G
(base point) for elliptic curves over finite fields, which can generate any other position in its
subgroup over the elliptic curve by multiplying G from some integer in the range [0…r].
Elliptic curve subgroups typically contain numerous generator points, but cryptologists
carefully select one of them to generate the entire group (or subgroup), and is excellent for
performance optimizations in calculations. This is the “G” generator.
Encryption algorithms:
Elliptic Curve Integrated Encryption Scheme (ECIES): ECIES is a public-key authenticated
encryption scheme that uses a KDF (key-derivation function) to generate a separate Medium
Access Control key and symmetric encryption key from the ECDH shared secret. Because the
ECIES algorithm incorporates a symmetric cipher, it can encrypt any amount of data. In
practice, ECIES is used by standards such as Intelligent Transportation Systems.
The elliptic curve cryptography (ECC) uses elliptic curves over the finite field 𝔽p (where
p is prime and p > 3) or 𝔽2m (where the fields size p = 2_m_). This means that the field is a
square matrix of size p x p and the points on the curve are limited to integer coordinates
within the field only. All algebraic operations within the field (like point addition and
y2 ≡ x3 + _a_x + b (mod p)
y2 ≡ x3 + 7 (mod p)
ECC uses the points {x, y} within the Galois field 𝔽p (where x and y are integers in the
Unlike RSA, which uses for its key space the integers in the range [0...p-1] (the field ℤp), the
range [0...p-1]).
An elliptic curve over the finite field 𝔽p consists of:
y2 ≡ x3 + 7 (mod 17)
Note that the elliptic curve over finite field y2 ≡ x3 + 7 (mod 17) consists of the blue points
at the above figure, i.e. in practice the "elliptic curves" used in cryptography are "sets of
points in square matrix", not classical "curves".
For example let's take the EC point G = {15, 13} on the elliptic curve over finite field y2 ≡ x3 + 7
(mod 17) and multiply it by k = 6. We shall obtain an EC point P = {5, 8}: