UNIT2
UNIT2
com
UNIT II BLOCK CIPHERS & PUBLIC KEY CRYPTOGRAPHY
Data Encryption Standard-Block cipher principles-block cipher modes of operation-Advanced
Encryption Standard (AES)-Triple DES-Blowfish-RC5 algorithm. Public key cryptography:
Principles of public key cryptosystems-The RSA algorithm-Key management - Diffie Hellman
Key exchange-Elliptic curve arithmetic-Elliptic curve cryptography.
UNIT-II / PART-A
1. Brief the strengths of triple DES.
Strength of Triple DES
Key size will increase to 56 x 3 = 168 bits. Meet in the middle attack would now
require 2112 trials. This is not practical now and far into the future.
2. What is an elliptic curve ?
An elliptic curve is defined by an equation in two variables, with coefficients. For
cryptography, the variables and coefficients are restricted to elements in a finite field,
which results in the definition of a finite abelian group.
3. State the difference between private key and public key algorithm.
AES – Data structures : Input , state array and output Key , expanded key
Four different stages are used, one of permutation and three of substitution:
ü Substitute bytes: Uses an S-box to perform a byte-by-byte substitution of the block
ü Shift Rows: A simple permutation
ü Mix Columns: A substitution that makes use of arithmetic over GF(28)
ü Add Round Key: A simple bitwise XOR of the current block with a portion of the
expanded key
ü For both encryption and decryption, the cipher begins with an AddRoundKey
stage, followed by nine rounds that each includes all four stages, followed by a
tenth round of three stages.
AES Round Structure :
www.studentsfocus.com
ü Only the AddRoundKey stage makes use of the key. For this reason, the cipher
begins and ends with an AddRoundKey stage.
ü For the Substitute Byte, ShiftRows, and MixColumns stages, an inverse function is
used in the decryption algorithm. For the AddRoundKey stage, the inverse is
achieved by XORing the same round key to the block.
Substitute byte formation :
ü The forward substitute byte transformation, called SubBytes, is a simple table
lookup.
ü AES defines a 16 x 16 matrix of byte values, called an S-box (Table 5.4a), that
contains a permutation of all possible 256 8-bit values.
ü Each individual byte of State is mapped into a new byte in the following way: The
leftmost 4 bits of the byte are used as a row value and the rightmost 4 bits are used
as a column value. These row and column values serve as indexes into the S-box to
select a unique 8-bit output value.
ShiftRows Transformation
Forward and Inverse Transformations
ü The forward shift row transformation, called ShiftRows, is depicted in Figure . The
first row of State is not altered. For the second row, a 1-byte circular left shift is
performed. For the third row, a 2-byte circular left shift is performed. For the fourth
row, a 3-byte circular left shift is performed. The following is an example of
ShiftRows:
Forward and Inverse Transformations The forward mix column transformation, called
MixColumns, operates on each column individually. Each byte of a column is mapped into
a new value that is a function of all four bytes in that column.
Add Round key
Forward and Inverse Transformations
In the forward add round key transformation, called AddRoundKey, the 128 bits of State
are bitwise XORed with the 128 bits of the round key.
2. Explain RSA Algorithm to perform encryption and decryption to the system with p = 7
q = 11 e = 17 M = 8. Explain the possible attacks on RSA.
www.studentsfocus.com
RSA : Algorithm
ü Block cipher asymmetric algorithm developed by Rivest, Shamir & Adleman .
ü It is the best known & widely used public-key scheme and based on exponentiation
in a finite (Galois) field over integers modulo a prime.
ü Security due to cost of factoring large numbers
ü factorization takes O(e log n log log n) operations (hard)
ü Each user will be provided with pair of keys one of which is public key used for
encryption and the other is private used for decryption.
ü Plaintext and cipher text are integers between 0 and n – 1 for some n. (eg . 1024 bits)
Ingredients of RSA Algorithm
RSA Algorithm :
www.studentsfocus.com
RSA Example
1. Select primes: p=7 & q=11
2. Compute n = pq =7×11=77
3. Compute ø(n)=(p–1)(q-1)=6×10=60
4. Select e : gcd(e,60)=1; choose e=17
5. Determine d: de=1 mod 60 and d < 60
Now, we need to compute d = e-1 mod f(n) by using backward substitution of GCD
algorithm:
According to GCD:
60 = 17 * 3 + 9
17 = 9 * 1 + 8
9=8*1+1
8=1*8+0
Therefore, we have:
1=9–8
= 9 – (17 – 9)
= 9 – (17 – (60 – 17 * 3))
= 60 – 17*3 – (17 – 60 + 17*3)
= 60 – 17 *3 + 60 – 17*4
= 60*2 – 17*7
Hence, we get d = e mod f(n) = e mod 60 = -7 mod 60 = (53-60) mod 60 = 53
-1 -1
So, the public key is {17, 77} and the private key is {53, 77}, RSA encryption and
decryption is following:
www.studentsfocus.com
Encryption Decryption
Plaintext cipher text Plaintext
8 57 8
The result is that the two sides have exchanged a secret value.
Ex : ὰ = 3 XA = 97 and XB = 233
A computes YA = 397 mod 353 = 40.
B computes YB = 3233 mod 353 = 248.
After they exchange public keys, each can compute the common secret key:
A computes K = (YB)XA mod 353 = 24897 mod 353 =160.
B computes K = (YA)XB mod 353 = 40233 mod 353 = 160.
Man-in-the-Middle Attack
Suppose Alice and Bob wish to exchange keys, and Darth is the adversary. The attack
proceeds as follows:
1. Alice sends an encrypted message M: E(K2, M).
www.studentsfocus.com
2. Darth intercepts the encrypted message and decrypts it, to recover M.
3. Darth sends Bob E(K1, M) or E(K1, M'), where M' is any message. 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.
This vulnerability can be overcome with the use of digital signatures and public-key
Certificates.
4. Describe DES algorithm with neat diagram and explain the steps.(Apr/May’17)
ü In DES data are encrypted in 64-bit blocks using a 56-bit key. The algorithm
transforms 64-bit input in a series of steps into a 64-bit output. The same steps, with
the same key, are used to reverse the encryption.
(i) First, the 64-bit plaintext passes through an initial permutation (IP) that rearranges the
bits to produce the permuted input.
Permutation table
i)Each entry in the permutation table indicates the position of a numbered input bit in the
output
(ii) This is followed by a phase consisting of sixteen rounds of the same function, which
involves both permutation and substitution functions.
iii) For each of the sixteen rounds, a sub key (Ki) is produced by the combination of a left
circular shift and a permutation. The permutation function is the same for each round,
but a different sub key is produced.
(iv) The output of the last (sixteenth) round consists of 64 bits that are a function of the
input plaintext and the key. The left and right halves of the output are swapped to
produce the pre-output.
(v) Finally, the pre-output is passed through a permutation that is the inverse of the initial
permutation function, to produce the 64-bit cipher text.
www.studentsfocus.com
ü The left and right halves of each 64-bit intermediate value are treated as separate 32-
bit quantities, labeled L (left) and R (right).
ü Each round can be summarized in the following formulae:
ü The round key is 48 bits. The input is 32 bits. This input is first expanded to 48 bits
by using a table that defines a permutation plus an expansion that involves
duplication of 16 of the bits.
www.studentsfocus.com
The resulting 48 bits are XOR-ed with reduced key for the round. This 48-bit result
ü passes through a substitution function that produces a 32-bit output, which is then
permuted.
ü The substitution consists of a set of eight S-boxes, each of which accepts 6 bits as
input and produces 4 bits as output.
ü The first and last bits of the input to box form a 2-bit binary number to select one of
four substitutions defined by the four rows in the table for Si.
ü The middle four bits select one of the sixteen columns. The decimal value in the cell
selected by the row and column is then converted to its 4-bit representation to
produce the output. For example, in S1, for input 011001, the row is 01 (row 1) and
the column is 1100 (column 12) and assuming a value in row 1, column 12 is 9, the
output is 1001.
DES S- BOXES
Key Generation:
ü A 64-bit key is used as input to the algorithm. The bits of the key are numbered
from 1 through 64; every eighth bit is ignored.
ü Decryption uses the same algorithm as encryption, except that the application of the
sub-keys are reversed.
ü ie) sub key of round 16 in encryption - sub key of round 1 in decryption
www.studentsfocus.com
ü sub key of round 15 in encryption - sub key of round 2 in decryption and so on.
Strength of DES
Avalanche effect :
• Key desirable property of encryption algorithm Where a change of one input or key
bit results in changing more than half output bits.
• DES exhibits strong avalanche.
• 56-bit keys have 256 = 7.2 x 1016 values.
• Brute force search looks hard.
Completeness Effect : Completeness effect means that each bit of the cipher text needs to
depend on many bits on the plaintext.
The diffusion and confusion produced by D-boxes and S-boxes in DES, show a very strong
completeness effect.
Attacks on DES
• Brute force attack
• Differential crypt analysis
• Linear crypt analysis
5. Explain the DES structure including key generation phase. Also explain the various
modes of operation.
Key Generation:
ü A 64-bit key is used as input to the algorithm. The bits of the key are numbered
from 1 through 64; every eighth bit is ignored.
Limitation :
A cipher text from ECB can allow an attacker to guess the plaintext by trial-and-error if
the plaintext message is within predictable.
Cipher Block Chaining (CBC) Mode
CBC mode of operation provides message dependence for generating cipher text and
makes the system non-deterministic.
Operation
The operation of CBC mode is depicted in the following illustration. The steps are as
follows −
ü Load the n-bit Initialization Vector (IV) in the top register.
ü XOR the n-bit plaintext block with data value in top register.
ü Encrypt the result of XOR operation with underlying block cipher with key K.
ü Feed cipher text block into top register and continue the operation till all plaintext
blocks are processed.
ü For decryption, IV data is XORed with first cipher text block decrypted. The first
cipher text block is also fed into to register replacing IV for decrypting next cipher text
block.
ü Advantage of CBC over ECB is that changing IV results in different cipher text for
identical message.
ü On the drawback side, the error in transmission gets propagated to few further block
during decryption due to chaining effect.
ü It is worth mentioning that CBC mode forms the basis for a well-known data origin
www.studentsfocus.com
authentication mechanism. Thus, it has an advantage for those applications that
require both symmetric encryption and data origin authentication.
Cipher Feedback (CFB) Mode
In this mode, each cipher text block gets ‘fed back’ into the encryption process in order to
encrypt the next plaintext block.
Operation
The operation of CFB mode is depicted in the following illustration. For example, in the
present system, a message block has a size ‘s’ bits where 1 < s < n. The CFB mode requires
an initialization vector (IV) as the initial random n-bit input block. The IV need not be
secret. Steps of operation are −
ü By converting a block cipher into a stream cipher, CFB mode provides some of the
advantageous properties of a stream cipher while retaining the advantageous
www.studentsfocus.com
properties of a block cipher.
ü On the flip side, the error of transmission gets propagated due to changing of
blocks.
Output Feedback (OFB) Mode
ü It involves feeding the successive output blocks from the underlying block cipher
back to it. These feedback blocks provide string of bits to feed the encryption
algorithm which act as the key-stream generator as in case of CFB mode.
ü The key stream generated is XOR-ed with the plaintext blocks. The OFB mode
requires an IV as the initial random n-bit input block. The IV need not be secret.
ü This shared counter is not necessarily a secret value, but challenge is that both sides
must keep the counter synchronized.
Operation
ü Both encryption and decryption in CTR mode are depicted in the following
illustration. Steps in operation are −
ü Load the initial counter value in the top register is the same for both the sender and
the receiver. It plays the same role as the IV in CFB (and CBC) mode.
ü Encrypt the contents of the counter with the key and place the result in the bottom
register.
ü Take the first plaintext block P1 and XOR this to the contents of the bottom register.
The result of this is C1. Send C1 to the receiver and update the counter. The counter
update replaces the cipher text feedback in CFB mode.
ü Continue in this manner until the last plaintext block has been encrypted.
ü The decryption is the reverse process. The cipher text block is XORed with the
output of encrypted contents of counter value. After decryption of each cipher text
block counter is updated as in case of encryption.
www.studentsfocus.com
Like CFB mode, CTR mode does not involve the decryption process of the block cipher.
This is because the CTR mode is really using the block cipher to generate a key-stream,
which is encrypted using the XOR function. In other words, CTR mode also converts a
block cipher to a stream cipher.
The serious disadvantage of CTR mode is that it requires a synchronous counter at sender
and receiver. Loss of synchronization leads to incorrect recovery of plaintext.
However, CTR mode has almost all advantages of CFB mode. In addition, it does not
propagate error of transmission at all.
ü Encrypt the plaintext blocks using single DES with key K1.
ü Now decrypt the output of step 1 using single DES with key K2.
ü Finally, encrypt the output of step 2 using single DES with key K3.
ü The output of step 3 is the cipher text.
ü Decryption of a cipher text is a reverse process. User first decrypt using
K3, then encrypt with K2, and finally decrypt with K1.
www.studentsfocus.com
Keying options
ü Keying option 1
Advantages :
ü Triple DES systems are significantly more secure than single DES, but these are
clearly a much slower process than encryption using single DES.
Decryption Algorithm
◦ (easily derived from encryption)
◦ Two w-bit words are denoted as A and B
for i = r down to 1 do
B = (( B – S[ 2 * i + 1 ]) >>> A) ⊕ A;
A = (( A – S[ 2 * i ] >>> B) ⊕ B;
B = B - S[1];
A = A - S[0];
RC5 Modes
• 4 modes used by RC5
– RC5 Block Cipher, is ECB mode
– RC5-CBC, is CBC mode
– RC5-CBC-PAD, is CBC with padding by bytes with value being the number of
padding bytes
9. Write in detail about elliptic curve cryptography.
ü Elliptic curve cryptography [ECC] is a public-key cryptosystem just like RSA,
Rabin, and El Gamal.
ü Every user has a public and a private key.
ü Public key is used for encryption/signature verification.
ü Private key is used for decryption/signature generation.
ü Elliptic curves are used as an extension to other current cryptosystems.
ü Elliptic Curve Diffie-Hellman Key Exchange
ü Elliptic Curve Digital Signature Algorithm
ECC- Algorithm
– Alice takes plaintext message, M, and encodes it onto a point, PM, from the
elliptic group.
Encryption : Alice choose another random k – value from { 1,2,… p-1 }
Cipher text : Cm = { KG, Pm + KPB }
Decryption : by Bob
Take the first point from Cm - KG
Multiply KG and private key of Bob : Product = nB KG
Take the second point from Cm and subtract the product from it
Pm + KPB - nB KG
Substitute PB = nB * G Then Pm + K nB * G - nB KG = Pm
A) Encryption
B) Authentication
a) Plaintext: This is a readable message or data that is feed into the algorithm as input.
b) Encryption Algorithm: The encryption algorithm performs various transformations on
the plain text.
c) Public and Private Keys: This is a pair of keys that has been selected so that if one is
used for encryption then the other is used for decryption.
d) Cipher text: This is the scrambled message produced as output. It depends on the key
and the energy algorithm used for a given message two different keys will produce two
different cipher text.
e) Decryption Algorithm: This algorithm accepts the cipher text and the matching key to
produce original plaintext.
The essential steps are the following:
ü Each user generates a pair of keys to be used for encryption and decryption of the
messages.
www.studentsfocus.com
ü Each user places one of the two keys in a public register or other accessible file. This is
the Public key.
ü The companion key is Private As shown in Figure 5.1 that each user maintains a
collection of public keys obtained from others.
ü If Bob wishes to send a confidential message to Alice, Bob encrypts the message with
Alice’s Public key.
ü When Alice receives message. She decrypts it using private key. No other recipient can
decrypt the message because only Alice knows the private key.
ü With this approach, all Participants have access to Public keys and Private keys are
generated locally by each participants.
ü Never distributed, as long as users private key remains protected and secure, incoming
accumulation is secure.
ü At any time system can change its private key and intimate companion, public key to
replace old public key.
11. Explain about Blowfish algorithm with neat diagram.
ü Blowfish is a 64-bit block cipher invented by Bruce Schneier. Blowfish was designed
for fast ciphering on 32-bit microprocessors. Blowfish is also compact and has a
variable key length which can be increased to 448 bits.
ü Blowfish is suitable for applications where the key does not change frequently like
communication
ü links or file encryptors.
ü It is faster than DES when implemented on 32-bit microprocessors.
Round Structure :
ü The algorithm is based on the Feistel structure and has two important parts: The round
structure and the key expansion function.
ü There are 16 rounds, and each round are made of simple transformations which are
iterated. Each round consists of a key-dependent permutation, and a key and data-
dependent substitution.
ü All the operations are additions and XORs on 32 bit words, and lookups in 4 32-bit S-
Boxes.
ü Blowfish has a P-array, P0,P1,…,P18 each of which are 32 bit sub keys.
ü There are 4 S-Boxes, each of which maps an 8-bit input to 32-bits. The round structure
of Blowfish is illustrated in Fig.
www.studentsfocus.com
Key Scheduling Algorithm - The sub keys are computed using the following method:
ü The P-array and then the four S-Boxes are initialized with a fixed string. The string is
the hexadecimal digits of π.
ü P1 is XOR-ed with 32 bits of the key, P2 is XOR-ed with the next 32 bits of the key,
and so on for all the bits of the key. If needed the key bits are cycled to ensure that all
the P-array elements are XOR-ed.
ü An all-zero string is encrypted with the Blowfish algorithm, with the sub keys P1 to
P18 obtained so far in steps 1 and 2.
ü P1 and P2 are replaced by the 64 bit output of step 3.
ü The output of step 3 is now encrypted with the updated sub keys to replace P3 and P4
with the cipher text of step 4.
ü This process is continued to replace all the P-arrays and the S-Boxes in order.
ü This complex key-scheduling implies that for faster operations the sub keys should be
precomputed and stored in the cache for faster access.
12. Describe the mathematical foundations of RSA algorithm. Perform encryption and
decryption for the following: p = 17, q= 7, e = 5, n = 119, message = “6” Use extended
Euclid’s algorithm to find the private key.
Mathematical foundation:
ü The functionality of the RSA algorithm is based on aspects of number theory involving
prime numbers and modulus operations.
ü The essential mathematics needed to understand RSA involve modulus operations and
Euler’s totient.
ü Euler’s Totient or simply the totient is a term that denotes all the integers smaller than
n that have no common factors with n. Another way of stating this is how many
numbers smaller than n are co-prime with n. The symbol for the totient of a number is
Φ(n).
ü For example, if n = 8 then you are asking how many numbers smaller than 8 have no
common factors with 8. The answer would be 3, 5, and 7. 1 is also included as a special
www.studentsfocus.com
case, thus the totient of 8 would be 4. Another term for Euler’s totient is the Euler phi
function.
ü In modular arithmetic, the equal symbol is not used. Rather the congruence symbol is.
So, the mathematically correct way to write this is:
14 mod 12 ≡ 2
26 mod 12 ≡ 2
38 mod 12 ≡ 2