Unit II Symmetric Key Cryptography
Unit II Symmetric Key Cryptography
SYMMETRIC KEY
CRYPTOGRAPHY
MATHEMATICS OF SYMMETRIC KEY CRYPTOGRAPHY: Algebraic structures –
Modular arithmetic-Euclid‟s algorithm- Congruence and matrices – Groups, Rings,
Fields- Finite fields- SYMMETRIC KEY CIPHERS: SDES – Block cipher Principles of
DES – Strength of DES – Differential and linear cryptanalysis – Block cipher
design principles – Block cipher mode of operation – Evaluation criteria for AES –
Advanced Encryption Standard – RC4 – Key distribution.
Cryptography is based on some specific areas of mathematics, including number theory, linear algebra,
and algebraic structures.
● To review integer arithmetic, concentrating on divisibility and finding the greatest common divisor
using the Euclidean algorithm
● To understand how the extended Euclidean algorithm can be used to solve linear Diophantine
equations, to solve linear congruence equations, and to find the multiplicative inverses
● To emphasize the importance of modular arithmetic and the modulo operator, because they are
extensively used in cryptography
● To emphasize and review matrices and operations on residue matrices that are extensively used in
cryptography
● To solve a set of congruent equations using residue matrices
INTEGER ARITHMETIC
Set of Integers
Z = { . . . , −2, −1, 0, 1, 2, . . . }
Binary operations
Integer Division
a=q×n+r
Given any positive integer n and any nonnegative integer a, if we divide a by n, we get an
integer quotient q and an integer remainder r that obey the following relationship:
a = qn + r ;0 r≤ 6 <n; q = a/n
EUCLIDEAN ALGORITHM
➔ a simple procedure for determining the greatest common divisor of two positive integers.
➔ Two integers are relatively prime if their only common positive integer factor is 1.
gcd(a, b)
Suppose we have integers a, b such that d = gcd(a, b). Because gcd( a , b) = gcd(a, b),
there is no harm in assuming a ≥ b > 0. Now dividing a by b and applying the division
algorithm,
a = qn + r
Two integers a and b are said to be congruent modulo n, if (a mod n) = (b mod n). This is
written as a ⩭ b (modn)2
Properties of Congruences
The Euclidean algorithm can be based on the following theorem: For any integers a, b,
with a ≥ b ≥ 0,
let d = gcd(a, b). Then, by the definition of gcd, d| a and d | b. For any positive integer b,
we can express a as,
a = kb + r ⩭ r (mod b)
a mod b = r
Thus, the set of common divisors of a and b is equal to the set of common divisors of b and
(a mod b). Therefore, the gcd of one pair is the same as the gcd of the other pair, proving
the theorem.
The Extended Euclidean Algorithm
computations in the area of finite fields and in encryption algorithms, such as RSA.
For given integers a and b, the extended Euclidean algorithm not only calculate the
greatest common divisor d but also two additional integers x and y that satisfy the
following equation.
ax + by = d = gcd(a, b)
when a = 42 and b = 30,then gcd(42,30)=6,a partial table of values for 42x + 30y
Every number is of the form 42x + 30y = 6(7x + 5y) is a multiple of 6
Note also that gcd(42, 30) = 6 appears in the table. In general, it can be shown
that for given integers a and b, the smallest positive value of ax + by is equal to
gcd(a, b).
Now let us show how to extend the Euclidean algorithm to determine (x, y, d)
given a and b.
we assume that at each step i we can find integers xi and yi that satisfy ri = axi +
byi.
Euclidean Algorithm
https://www.youtube.com/watch?v=Sy0sXa73PZA
Stream Ciphers and Block Ciphers
Stream Cipher Block Cipher
A stream cipher is one that encrypts a digital A block cipher is one in which a block of
data stream one bit or one byte at a time. plaintext is treated as a whole and used to
produce a ciphertext block of equal length(a
in which the keystream (ki ) is as long as the block size of 64 or 128 bits is used).
plaintext bit stream (pi )
There are 2n possible different plaintext blocks and, for the encryption to be reversible/non
singular
when n=2 a ciphertext of 01 could have been produced by one of two plaintext blocks. So
if we limit ourselves to reversible mappings, the number of different transformations is
2n!.2
Feistel refers to this as the ideal block cipher, because it allows for the maximum number of
possible encryption mappings from the plaintext block
In this case, using this straightforward method of defining the key, the required key length is (4
bits) * (16 rows) = 64 bits. In general, for an n-bit ideal block cipher, the length of the key
defined in this fashion is n * 2n bits. For a 64-bit block, which is a desirable length to thwart
statistical attacks, the required key length is 64 * 264 = 270 ≈ 1021 bits.
The Feistel Cipher
Feistel proposed that we can approximate the ideal block cipher by utilizing the concept of
a product cipher, which is the execution of two or more simple ciphers in sequence in such
a way that the final result or product is cryptographically stronger
The essence of the approach is to develop a block cipher with a key length of k bits and a
block length of n bits, allowing a total of 2k possible transformations, rather than the 2n !
transformations
● Substitution
● Permutation
In diffusion, the statistical structure of the plaintext is dissipated into long-range statistics
of the ciphertext. This is achieved by having each plaintext digit affect the value of many
ciphertext digits
confusion seeks to make the relationship between the statistics of the ciphertext and the
value of the encryption key as complex as possible, again to thwart attempts to discover
the key.
Fiestel Structure
Key size
Round function F
DES
DES-DATA ENCRYPTION STANDARD
-A round in DES
Expansion permutation
S-box
P10
3 5 2 7 4 10 1 9 8 6
P8
6 3 7 4 8 5 10 9
IP 1 2345678
IP −1
41357286
E/P
P4
2431
41232341
AVALANCHE EFFECT
● change in one bit of the plaintext or one
bit of the key should produce a change
in many bits of the ciphertext
The Strength of DES
● Use of 56 bit key
● 256 possible permutations and substitutions in order to perform brute-force
attack.
● It requires about 1year to decrypt the ciphertext if intruder tries using a PC
● Multiple PC’s it would take about months
● Super computers-10hours
● Key size increased – 56,128,168,192,256…
Timing Attacks
● Information about the key or the plaintext is obtained by observing how long it
takes a given implementation to perform decryptions on various ciphertexts
Block cipher design principles
->bit independence criterion(BIC), which states that output bits j and k should
change independently when any single input bit i is inverted for all i, j, and k
Key schedule Algorithm
● With any Feistel block cipher, the key is used to generate one subkey for each
round.
deducing individual subkeys and the difficulty of working back to the main key
DOUBLE DES
1. Given a known pair, (P, C), the attack proceeds as follows. First, encrypt P
for all 256 possible values of K1
2. Store these results in a table and then sort the table by the values of X.
3. Next, decrypt C using all 256 possible values of K2,check the result against
the table for a match.
4. If match found try with another pair(P,C)
-->for a given plaintext P, the number of different 112-bit keys that will
produce a given ciphertext C is 2112/264 = 248 false alarms
DES has been vulnerable to brute-force attack because of 56 bits key length
With the increasing popularity of block ciphers with longer key lengths,
including triple DES--> brute-force attacks
Consider the original plaintext block ‘m’ to consist of two halves ‘m0’,’m1’
Each round of DES maps the right-hand input into the left-hand output and sets the
right hand output to be a function of the left-hand input and the subkey for this
round-->new block mi(2 <= i <= 17)
Intermediate message half,
Dm =m and m'
if we know mi-1 and mi with high probability, then we know mi+1 with
high probability.
➔ there are two probable patterns of differences for the two 32-bit halves:
( m17||m16)
➔ Next,we submit m and m' for encryption to determine the actual difference
under the unknown key and compare the result to the probable difference.
If there is a match,
DES key given 243 known plaintexts, as compared to 247 chosen plaintexts for
differential cryptanalysis
For a cipher with n-bit plaintext and ciphertext blocks and an m-bit key, let the
plaintext block be labeled P[1], ... P[n], the cipher text block C[1], ... C[n], and
the key K[1], ... K[m]. Then define
P[𝜶1, 𝜶2, ..., 𝜶a] C[𝜷1, 𝜷2, ..., 𝜷b] = K[𝜸1, 𝜸2, ..., 𝜸c]
➔ the procedure is to compute the results of the left hand side of the
preceding equation for a large number of plaintext-ciphertext pairs.
➔ If the result is 0 more than half the time, assume K[𝜸1, 𝜸2, ..., 𝜸c] = 0. If it is
1 most of the time, assume K[𝜸1, 𝜸2, ..., 𝜸c]= 1.
➔ This gives us a linear equation on the key bits.Try to get more such
relations so that we can solve for the key bits.
ADVANCED ENCRYPTION
STANDARD(AES)
● Triple DES is slow
● Rijndael designed AES algorithm for 128/192/256 bit data
● Iterative process
○ Operates on entire data block in every round
○ Processes data as block of 4 columns of 4 bytes
Advantages
● Resistance against known attacks
● Speed and code compactness on many CPUs
● Design Simplicity
1. Rijndael, do not use a Feistel structure but process the entire data block in
parallel during each round using substitutions and permutation.
2. The key that is provided as input is expanded into an array of forty-four
32-bit words, w[i]. Four distinct words (128 bits) serve as a round key for
each round
3. Four different stages are used, one of permutation and three of
substitution:
x8 + x4 + x3 + x + 1.
The elements {53} and {CA} are multiplicative inverses of one another since their product is 1
Find the multiplicative inverse of 25 mod 33 in GF(2^8)
4.The structure is quite simple. 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.
6.The AddRoundKey stage is a form of Vernam cipher, the other three stages
together provide confusion, diffusion, and nonlinearity
7.Each stage is easily reversible. 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, using the result that A xor A xor B = B.
8. the decryption algorithm makes use of the expanded key in reverse order
9.Once it is established that all four stages are reversible, it is easy to verify
that decryption does recover the plaintext.
10.The final round of both encryption and decryption consists of only three
stages. Again, this is a consequence of the particular structure of AES and is
required to make the cipher reversible.
Steps for Encryption
● The inverted byte is then interpreted as a column matrix with the least significant
bit at the top and the most significant bit at the bottom.
● This column matrix is multiplied by a constant square matrix,X, and the result,
which is a column matrix, is added with a constant column matrix, y,to give the
new byte.
● Note that multiplication and addition of bits are done in GF(2).
● The invsubbyte is doing the same thing in reverse order.
Add Round Key
2. SubWord performs a byte substitution on each byte of its input word, using
the S-box
The round constant is a word in which the three rightmost bytes are always 0
AES DECRYPTION
● Reverse of encryption
It is near impossible to crack it even if brute force is applied – trying every combination of numbers possible until the
correct key is found. The longer the key size, the more attempts are needed.
A hacker trying to crack a 256-bit key would need 2 to the power of 256 attempts to find the right key. Even if hackers
use Tianhe-2 (MilkyWay-2), the fastest supercomputer in the world, it will take them a few million lifetimes to crack a
256-bit AES encryption.
The bottom line is, entities that face threats from all directions, like the U.S. Military or your Office 365 that stores
business-critical information, need AES 256-bit protection.
1. Show that 3 is a primitive root of 7
2. Find the given polynomial is irreducible or not.x4+x3+x2+x+1 in Z3
BLOCK CIPHER MODES OF OPERATION
● A block cipher takes a fixed-length block of text of length ‘b’ bits and a key
as input and produces a b-bit block of ciphertext.
● If the amount of plaintext to be encrypted is greater than ‘b’ bits, then the
block cipher can still be used by breaking the plaintext up into b-bit blocks.
● When multiple blocks of plaintext are encrypted using the same key, a
number of security issues arise.
● To apply a block cipher in a variety of applications, five modes of operation
have been defined by NIST
Electronic Code Book(ECB)
Cj = E(K, Pj )
Pj = D(K, Cj )
Strength
Cj = E(K, [Cj-1 ⊕ Pj ])
P1 = IV ⊕ D(K, C1)
-->it is possible to convert a block cipher into a stream cipher, using one of the
three modes to be discussed in this and the next two sections: cipher feedback
(CFB) mode, output feedback (OFB) mode, and counter (CTR) mode.
Cj = Pj ⊕ E(K, Tj )
Pj = Cj ⊕ E(K, Tj )
RC 4 ALGORITHM
➔ RC4 is a stream cipher designed in 1987 by Ron Rivest for RSA Security.
➔ It is a variable key size stream cipher with byte-oriented operations.
➔ uses of a random permutation.
➔ RC4 is used in the (SSL/TLS) standards that have been defined for
communication between Web browsers and servers.
➔ Used in Wired Equivalent Privacy(WEP) protocol and the WiFi Protected
Access (WPA) protocol
➔ Byte of a plaintext is XOR with byte of the key -->ciphertext(byte)
➔ The key to perform XOR is random b/w 0 to 255.
Initialization of S
for i = 0 to 255 do
S[i] = i;
Next we use T to produce the initial permutation of S. This involves starting with
S[0] and going through to S[255], and for each S[i], swapping S[i] with another
byte in S according to a scheme dictated by T[i]:
/* Initial Permutation of S */
j = 0;
for i = 0 to 255 do
i, j = 0;
while (true)
i = (i + 1) mod 256;
k = S[t];
To encrypt, XOR the value k with the next byte of plaintext.
Strength of RC4
E(PU b,(IDA||N1)
Request||T2
• B sends a message to A encrypted with PUa and containing
A’s nonce (N1) as well as a new nonce generated by B (N2)
E(PU a ,(N1,N2))
• A returns N2, which is encrypted using B’s public key, to assure
B that its correspondent is A.
E(PU b||N2)
Public Key Certificate
• Any participant can read a certificate to determine the name
and public key of the certificate’s owner.