Cryptography and Network Security
Cryptography and Network Security
SYMMETRIC 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.
GROUPS
A group G, sometimes denoted by {G, •}, is a set of elements with a binary operation denoted by • that
associates to each ordered pair (a, b) of elements in G an element (a • b) in G, such that the following
axioms are obeyed:
RINGS
A ring R, sometimes denoted by {R, +, *}, is a set of elements with two binary operations, called addition
and multiplication,6 such that for all a, b, c in R the following axioms are obeyed.
(A1–A5) R is an abelian group with respect to addition; that is, R satisfies axioms A1 through A5.
(M1) Closure under multiplication: If a and b belong to R, then ab is also in R.
(M2) Associativity of multiplication: a(bc) = (ab)c for all a, b, c in R.
(M3) Distributive laws: a(b + c) = ab + ac for all a, b, c in R.
(a + b)c = ac + bc for all a, b, c in R.
A ring is said to be commutative if it satisfies the following additional condition:
(M4) Commutativity of multiplication: ab = ba for all a, b in R.
An integral domain, which is a commutative ring that obeys
the following axioms.
(M5) Multiplicative identity: There is an element 1 in R such that a1 = 1a = a for all a in R.
(M6) No zero divisors: If a, b in R and ab = 0, then either a = 0 or b = 0.
FIELDS
A field F, sometimes denoted by {F, +, *}, is a set of elements with two binary operations, called
addition and multiplication, such that for all a, b, c in F the following axioms are obeyed.
(A1–M6) F is an integral domain; that is, F satisfies axioms A1 through A5 and M1 through M6.
(M7) Multiplicative inverse: For each a in F, except 0, there is an element a-1 in F such that
aa-1 = (a-1)a = 1
1
MODULAR ARITHMETIC
If a is an integer and n is a positive integer, we define a mod n to be the remainder
when a is divided by n. The integer n is called the modulus.
Congruent modulo
Two integers a and b are said to be congruent modulo n if
a (mod n)≡ b (mod n)
a ≡ b (mod n)
73 ≡ 4 mod 23
EUCLID(a, b)
1. A a; Bb
2. if B = 0 return A = gcd(a, b)
3. R = A mod B
4. AB
5. BR
6. goto 2
2
Euclidean Algorithm Revisited
For any integers a, b, with a ≥ b ≥ 0,
gcd(a, b) = gcd(b, a mod b)
Example
gcd(55, 22) = gcd(22, 55 mod 22) = gcd(22, 11) = 11
gcd(18, 12) = gcd(12, 6) = gcd(6, 0) = 6
gcd(11, 10) = gcd(10, 1) = gcd(1, 0) = 1
K1=P8(Shift(P10(key)))
K2=P8(Shift(Shift(P10(key)
P10
3 5 2 7 4 10 1 9 8 6
P8
3 3 7 4 8 5 10 9
5
P4
2 4 3 1
IP
2 6 3 1 4 8 5 7
IP-1
4 1 3 5 7 2 8 6
E/P
4 1 2 3 2 3 4 1
The first and fourth bits are treated as a 2 bit number that specify a row of the s-box and the
second and third bits specify a column of the S-boxes.
Example
Key Generation
1) Applying P10 on key, we get:1000001100
2) Applying circular left shift by 1 bit on two 5 bits part, we get: 0000111000
3) Applying P8, we get K1:10100100
4) Applying circular left shift by 2 bits: 0010000011
5) Applying P8, we get K2:01000011
6
i) Apply E/P on 1100: 0110 1001
ii) XOR with K2:00101010
iii) Pass 0010 to S0 box:00
iv) Pass 1010 to S1 box:00
v) Combining both results from s. boxes:0000
vi) Applying P4 on it: 0000
Now we have at the end: 1110 1100
5) Apply IP-1 on it we get: 0111 0101 which is our cipher text.
Cipher text= 01110101
Inverse operation for this cipher text will give plain text.
7
DES-DATA ENCRYPTION STANDARD
DES is also called as Data Encryption Algorithm. This algorithm is proposed by National
Institute of Standards and Technology (NIST) in 1977.
DES working principle:
DES is a block cipher.
DES takes plain text of block size 64 bits and produces 64-bit as cipher text.
Key is of 56 bit size.
DES has 16 rounds.
Same algorithm is used for encryption and decryption.
DES is based on substitution and Transposition.
The processing of the algorithm proceeds in 3 phases
Phase 1- Permutation phase, which rearranges the bits to produce permuted input (IP)
Phase 2- This phase has 16 rounds. Each round has permutation and substitution steps.
Phase3-Theoutputofthephase2ispassedthroughpermutationwhichistheinverseofinitial
permutation. The final output is 64 bit ciphertext.
8
Single round of a DES algorithm
1. Keytransformation
56-bit key is divided into two halves. Each of 28 bits are circularly shifted one or two
positions based on the round
After appropriate shifts 48 bits of 56 bits are selected as key for each round
2. Expansionpermutation
In this step Right Plain text is expanded from 32bits to 48 bits.
48 bit key is XOR with 48 bit Right Plain text and resulting output is given to next step.
3. Substitution BoxesS
S-box substitution is a process that accepts 48-bit input from XOR operation and
produces 32 bit output
4. Permutation
The output of s-box consists of 32 bits. These 32 bits are permuted using p-box.
5. XOR and swap
All the above operations are performed only on 32 bits Right Plain text.
Now Left Plain text is XOR with p-box output.
The result of XOR operation becomes the new right half. The old right half becomes
the new left half.
Inverse Initial permutation
At the end of 16 rounds simple transposition is performed.
DES decryption
It uses the same algorithm as encryption except the key is used in reverse order.
Avalanche Effect
When there is a small change in either the plaintext or the key should produce a significant
changeintheciphertext.Inparticular,achangeinonebitoftheplaintextoronebitofthekey should
produce a change in many bits of the cipher text. This is referred to as the avalanche effect.
DES exhibits a strong avalanche effect.
9
Strength of DES
1) The use of 56 bitKey
As the key length is 56 bits, for brute force attack there are 2 56 possible keys. Hence, it
is impractical.
2) The Nature of the DESAlgorithm
For cryptanalysis attack, the characteristic of DES needs to be analysed. Hence, it
makesuseofsubstitutionboxescalledS-boxes.AlgorithmforthedesignofS-boxwasknown to
thepublic.
When this algorithm is known, then then there is a crypt analytic attack. But until now
there is no such attack.
3) Timingattack
Timing attack is one in which information about the key or the plaintext is obtainedby
observing how long it takes a given implementation to perform decryptions on various cipher
texts. A timing attack exploits the fact that an encryption or decryption algorithm often takes
slightlydifferentamountsoftimeondifferentinputs.AnapproachknownasHammingweight, yields
number of bits equal to the secret key. This is a long way from knowing the actual key. The
authors conclude that DES appears to be fairly resistant to a successful timingattack.
1) Number ofRounds
Whenthenumberofroundincreasesthedifficultytoperformcryptanalysisalsoincreaseseven
whenweakF.Thenumberofroundsistobechosensothatknowncryptanalyticeffortsshould be
greater than the efforts of brute-forceattack.
2) Design of FunctionF
Criteria needed for F,
It must be difficult to unscramble the substitution done byF.
The function should satisfy strict avalancheeffect.
The function should satisfy bit independence criterion. Output bits j and k should
change independently when any single input bit i is inverted for all i, j, andk.
The S- box should have guaranteed avalancheeffect.
3) Key ScheduleAlgorithm
The key generation algorithm is used to generate one subkeys for each round. The subkeys
should be different for each round and it should be difficult to deduce the subkeys and trace
the main key.
10
BLOCK CIPHER MODES OF OPERATION
To apply a block cipher in a variety of applications, four "modes of operation" have been
defined by NIST.
Amodeofoperationisatechniqueforenhancingtheeffectofacryptographicalgorithm or
adapting the algorithm for an application, such as applying a block cipher to a sequence of
data blocks or a datastream.
CN=E(K, PN),N=1,…,n
PN=D(K,CN),N=1,…,n
Advantages
The ECB method is ideal for a short amount of data, such as an encryptionkey.
Disadvantages
Forthesameb-bitblockofplaintext,ifitappearsmorethanonceinthemessage,ECB always
produces the same ciphertext.
For lengthy messages, the ECB mode may not besecure.
(ii) Cipher Block Chaining Mode(CBC)
ToovercomethedrawbackofECB,atechniqueinwhichthesameplaintextblockifrepeated,
produces different ciphertext blocks. In this scheme, the input to the encryption algorithm is
theXORofthecurrentplaintextblockandtheprecedingciphertextblock;thesamekeyisused for
eachblock.
11
where - IV- Initialization vector (only known to the communication parties)
Theinputtotheencryptionfunctionforeachplaintextblockbearsnofixedrelationshiptothe plain
text block. Therefore, repeating patterns of bits are not exposed. For decryption, each cipher
block is passed through the decryption algorithm. The result is XORed with the preceeding
cipher text block to produce the plain textblock.
Encryption : Cj = E(K, [Cj-1⊕Pj])
Decryption :D(K, Cj) = D(K, E(K, [Cj-1⊕Pj]))
Advantages:
An appropriate mode for encrypting messages of length greater than bbits.
In addition to its use to achieve confidentiality, the CBC mode can be used for
authentication.
For decryption, the same scheme is used, except that the received ciphertext unit is XORed
with the output of the encryption function to produce the plaintext unit.
Encryption function
Let Ss(X) be defined as the most significant s bits of X.
C1 = P1⊕Ss[E(K, IV)]
Therefore,
P1 = C1⊕Ss[E(K, IV)]
12
(iv) Output feedbackmode
The output feedback (OFB) mode is similar in structure to that of CFB. The output of the
encryptionfunctionthatisfedbacktotheshiftregisterinOFB,whereasinCFBtheciphertext unit is
fed back to the shiftregister.
Advantage
One advantage of the OFB method is that bit errors in transmission do not propagate.
Disadvantage
The disadvantage of OFB is that it is more vulnerable to a message stream modification
attack than is CFB.
13
(v) Counter Mode –(CTR)
Here, the counter is equal to the plaintext block size is used. The counter value must be
differentforeachplaintextblock.Thecounterisinitializedtosomevalueandthenincremented
by1foreachsubsequentblock.Forencryption,thecounterisencryptedandthenXORedwith the
plaintext block to produce the cipher text block; there is nochaining.
For decryption, the same sequence of counter values is used, with each encrypted counter
XORed with a cipher text block to recover the corresponding plaintext block.
14
Advantages
Hardware efficiency: Unlike the three chaining modes, encryption (or decryption) in CTR
mode can be done in parallel on multiple blocks of plaintext or cipher text.
Software efficiency: Similarly, because of the opportunities for parallel execution in CTR
mode, processors that support parallel features can be utilized.
Preprocessing: The execution of the underlying encryption algorithm does not depend on
input of the plaintext or cipher text.
Random access: The ith block of plaintext or ciphertext can be processed in random-access
fashion.
The cipher takes a plaintext block size of 128 bits, or 16 bytes. The key length can be
16, 24, or 32 bytes (128, 192, or 256 bits). The algorithm is referred to as AES-128,AES-192,
or AES-256, depending on the keylength.
ThecipherconsistsofNrounds,wherethenumberofroundsdependsonthekeylength:
10roundsfora16-bytekey,12roundsfora24-bytekey,and14roundsfora32-bytekey.The first N - 1
rounds consist of four distinct transformationfunctions:
SubBytes,
ShiftRows,
MixColumns, and
AddRoundKey
Thefinalroundcontainsonlythreetransformations,andthereisainitialsingletransformation
(AddRoundKey)beforethefirstround,whichcanbeconsideredRound0.Eachtransformation takes
one or more 4 x4 matrices as input and produces a 4x4 matrix as output. Also, the key
expansion function generates N + 1 round keys, each of which is a distinct 4x4 matrix. Each
round key serves as one of the inputs to the AddRoundKey transformation in eachround.
Detailed Structure
1. AES is not a Feistel structure. In Feistel structure, half of the data block is used to modify
the other half of the data block and then the halves are swapped. AES instead processes the
entire data block as a single matrix during each round using substitutions andpermutation.
2. The key expanded into an array of forty-four 32-bitwords.
3. Four different stages areused,
• Substitutebytes
• ShiftRows
• MixColumns
• AddRoundKey
4. The structure is 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 threestages.
15
5. Only the AddRoundKey stage makes use of the key. For this reason, the cipher begins and
ends with an AddRoundKey stage. Any other stage, applied at the beginning or end, is
reversible without knowledge of the key and so would add nosecurity.
6. The AddRoundKey stage is, in effect, a form of Vernam cipher and by itself would not be
formidable. This scheme is both efficient and highlysecure.
7. Eachstageiseasilyreversible.FortheSubstituteByte,ShiftRows,andMixColumnsstages, an
inverse function is used in the decryptionalgorithm.
8. The decryption algorithm uses the expanded key in reverseorder.
9. Once it is established that all four stages are reversible, it is easy to verify that decryption
reverse order. However, the decryption algorithm is does recover the plaintext. At each
horizontal point (e.g., the dashed line in the figure), State is the same for both encryption and
decryption.
10. The final round of both encryption and decryption consists of only threestages.
16
ShiftRows Transformation
The forward shift row transformation, also called ShiftRows.The first row of State is
notaltered. Forthesecondrow,a1-bytecircularleftshiftisperformed. Forthethirdrow, a2-
bytecircularleftshiftisperformed.Forthefourthrow,a3-bytecircularleftshiftisperformed. The
following is an example ofShiftRows.
The inverse shift row transformation, called InvShiftRows, performs the circularshifts
intheoppositedirectionforeachofthelastthreerows,witha1-bytecircularrightshiftforthe second
row, and so on.
17
MixColumns Transformation
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. The transformation can be defined by the following matrix
AddRoundKey Transformation
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.
18
Key Expansion Algorithm
The input to this algorithm is 4 word key. The output is 44 words. The key is copied
to the first 4-words of the expanded key. The remainder of the expanded key is filled in four
words at a time. Each added word depends on the immediately preceding wordw(i-1) and the
word four positions back, w(i-4).
KeyExpansion (byte key[16], word w[44])
{
word temp
for (i = 0; i < 4; i++)
w[i] = (key[4*i], key[4*i+1], key[4*i+2], key[4*i+3]);
for (i = 4; i < 44; i++)
{
temp = w[i - 1];
if (i mod 4 = 0)
temp = SubWord (RotWord (temp))⊕Rcon[i/4];
w[i] = w[i-4] ⊕ temp
}
}
19
DOUBLE DES
The simplest form of multiple encryption has two encryption stages and two keys. Given a
plaintext P and two encryption keys K1 and K2, ciphertext C is generated as
C = E(K2, E(K1, P))
Drawback
Meet-in-the-middleattack
Givenaknownpair,(P,C),theattackproceedsasfollows.First,encryptPforall256possible values of
K1. Store these results in a table and then sort the table by the values of X. Next,
decryptCusingall256possiblevaluesofK2.Aseachdecryptionisproduced,checktheresult against
the table for a match. If a match occurs, then test the two resulting keys against a new known
plaintext-ciphertext pair. If the two keys produce the correct ciphertext, accept themas the
correctkeys.
TRIPLE DES
To overcome the meet-in-the-middle attack, three stages of encryption with the
different key is used. This is called triple DES.
Tuchman proposed a triple encryption method that uses only two keys. The function
follows an encrypt-decrypt-encrypt sequence
20
RC5 is a family of ciphers RC5-w/r/b
– w = word size in bits (16/32/64) nbdata=2w
– r = number of rounds(0..255)
– b = number of bytes in key(0..255)
• nominal version isRC5-32/12/16
– ie 32-bit words so encrypts 64-bit datablocks
– using 12rounds
– with 16 bytes (128-bit) secretkey
Asymmetric algorithm uses one key for encryption and another key for decryption. Tthe
essential steps for public key cryptography are:
Each user generates a pair of keys to be used for the encryption anddecryption.
Each user places one of the two keys in a public register. This is the public key. The
companion key is jeptprivate.
If Bob wishes to send a confidemtial message to alice,bob encrypts the message using
alice publickey.
When Alice receives the message and decrypts it using her private key. No other
receipent can decrypt the message because only Alice knows Alice’ s privatekey.
21
Source A that produces a message in plaintext, X =[X 1, X2,..., XM]. The message is intended
fordestinationB.Bgeneratesarelatedpairofkeys:apublickey,PUb,andaprivatekey,PRb. PRb is
known only to B, whereas PUb is publicly available and therefore accessible byA.
Encryption
Y = E(PUb, X)
Decryption
X = D(PRb, Y)
22
Public-Key Cryptosystem: Authentication and Secrecy
Itispossibletoprovideboththeauthenticationfunctionandconfidentialitybyadoubleuseof the
public-keyscheme.
Z = E(PUb, E(PRa,X))
X = D(PUa, E(PRb,Z))
First, encrypt a message, using the sender's private key. This provides the digital signature.
Next,encryptagain,usingthereceiver'spublickey.Thefinalciphertextcanbedecryptedonly by the
intended receiver, who alone has the matching private key. Thus, confidentiality is provided.
The disadvantage of this approach is that itscomplexity.
23
KEYMANAGEMENT
There are two distinct aspects to the use of public-key cryptography:
I) The distribution of publickeys
II) The use of public-key encryption to distribute secretkeys
I) Distribution of PublicKeys
There are four different schemes
i. Publicannouncement
ii. Publicly availabledirectory
iii. Public-keyauthority
iv. Public-keycertificates
(i) Publicannouncement
Any participant can send his or her public key to any other participant or broadcast the key to
the community.
Limitation
Anyone can forge such a public announcement. That is, some user could pretend to be user A
and send a public key to another participant or broadcast such a public key. Authentication is
needed to avoid this problem.
24
Advantage
More secure than individual public announcement.
Limitation
Problem arises if the opponent captures the private key of the directory authority.
(iii) Public-keyauthority
Stronger security for public-key distribution can be achieved by providing tighter controlover
the distribution of public keys from the directory. The central authority maintains all public
keys of participants in its dynamic directory. Each participant knows the public key of the
authority, but the private key of the authority is keptsecret.
1. A sends a timestamped request to public-key authority for the public key ofB.
2. The authority replies with a message that is encrypted using the authority's private
key, PRauth. A is know the public key of authority. Therefore, A decrypts the
message. The message includes thefollowing:
• B's public key,PUb
• Request already sent by A (forverification)
25
• Time1 already sent by A (prove that the message is old ornot)
3. A stores B's public key and send message to B in an encrypted format using B’s
public key. This message consistsof
• A’s identity, (IDA)
• Nonce (N1), which is used to identify this transactionuniquely.
4. B retrieves A's public key from the authority in the same manner as A retrievedB's
publickey.
5. 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)
6. A returns N2, encrypted using B's public key, to assure B that its correspondent isA.
Advantage
More secure and attractive than previous two.
Limitations
• Each and every time the user must appeal to the authority for a public key for every
other user that it wishes tocontact.
• The directory of names and public keys maintained by the authority is vulnerable to
tampering.
(iv) Public keycertificate
Itusescertificatesthatcanbeusedbyparticipantstoexchangekeyswithoutcontactingapublic key
authority for its everytransaction.
Each certificate contains a public key and other information created by certificate authority.
Each participant conveys its key information to its corresspondant by transmitting their
certificates. Other participant can verify that the certificate was created by the authority.
26
II) Public key encryption todistribute
(i) Simple secret keydistribution
(ii) Secret key distribution with confidentiality andauthntication
(i) Simple secret keydistribution
27