Network Security Notes
Network Security Notes
The IP and TCP headers are without any optional data. Answer the
following questions:
Cryptography Terminology
1. Plaintext – An original message in its ‘as-it-is’ form.
2. Ciphertext – Coded message. Cannot be understood just by
reading it.
3
3. Encryption (Enciphering) – The process of converting
plaintext to ciphertext.
4. Decryption (Deciphering) – The process of restoring plaintext
from ciphertext.
5. Cryptographic System (Cipher) - A scheme/algorithm used
for encryption.
6. Cryptography – The area of study of schemes/algorithms used
for encryption/decryption.
7. Cryptanalysis – The area in which techniques are used for
deciphering a message without any knowledge of the
enciphering details. Colloquially called ‘breaking the code’.
Ethical or Unethical?
8. Cryptology - The areas of cryptography and cryptanalysis.
Hash Function
1. In Cryptography, a hash function (H) accepts a variable length
message (M) and produces a fixed size hash value (h).
Mathematically, h=H(M). Here, h is called the hash code,
Digital Signature
digest, hash sum etc. 1. We have reviewed that in the asymmetric (or public) key
2. A good hash function is expected to produce random and cryptography, there is a concept of public key (PU) and
evenly distributed hash code but of the same size. private key (PR). PR is private to the receiver. PU is shared
3. It is an important concept for Network Security because: with senders who are expected to send encrypted messages to
a. Irrespective of the length of the input message, hash the receiver.
code length is always same. Storage and transmission 2. Public (Asymmetric) Key Encipherment Scenario - Let us say,
overhead can be estimated. there is a sender X and a receiver Y. The X encrypts the data
b. Even for a small change in the contents of the with PU of Y and the Y decrypts the data with its own PR
message, the hash code will turn out to be different. after receiving the data.
So, it can detect if the message was subject to the 3. Added Digital Signature Scenario – While sending the data, X
modification attack. also calculates the hash code of the data and encrypts it using
4. The hashing function takes an input m and produces a fixed its own PR. This encrypted hash code is called the digital
size code H(m) as an output. The output is called the hash signature. The data and the signature is sent together to Y.
code or the digest. 4. When Y receives the data, it decrypts the data using its PR and
5. Example: Cyclic Redundancy Check (CRC) that is used in it decrypts the signature using X’s PU.
layer-2 networking protocol can be considered as a hashing 5. After decryption, Y re-calculates the hash code on the data
function. and compare it with the decrypted signature. If both match, it
6. In network security it is a requirement that it should be establishes that there was no modification attack on the data.
computationally infeasible to find out another message n for Otherwise, Y may discard the data.
which H(n) = H(m).
7. The above property essentially means that an intruder should How Digital Signature Works
not be able to substitute or modify the original message so that
the hash code remains intact.
8. Hashing function and thus the hash code is used for data
integrity checking.
9. Checksum: an example of a poor hashing function; message is
altered but the checksum (hash-code) does not change:
4
Message Authentication Code (MAC) High Level Flow of Events
1. Let us say, there is a sender X and a receiver Y.
2. Both of these two users have a shared secret code β. It is also
called the MAC key.
3. X creates a message m: concatenates it with β, and then
calculates the hash code on the combined data. Hash code is
appended to the m and then transmitted to Y. The calculated
hash code is called the Message Authentication Code (MAC)
using H as the hashing function.
4. So Y receives = [m + H(m, β)] or [m || H(m, β)]
5. Y having the same β, calculates the H(m, β) and compares it
with the received H(m, β) to verify the authenticity of the
sender.
6. Does MAC prove that the message came from the intended How is Certificate Signature verified?
sender?
1. Certificates are issued by CA to the subjects along with CA
7. What if an attacker records this transmission and replay it?
signature value and algorithm which was used to calculate the
8. To avoid the replay attack, sender and receiver can exchange a
signature.
random number (nonce) per session that can be included in
2. Subjects share the certificate with users.
the MAC as β. The value of β can be frequently changed as
3. Users (browsers) verifies the certificates by verifying the CA
desired.
signature value.
9. But how this β is shared then? This can also be subject to the
4. The question is How?
attack!
5. Users (browsers) re-calculate the certificate hash code and
Public Key Certificate compare it with the signature value received in the certificate.
6. CA’s signatures are encrypted hash code, so CA’s public key is
1. Public Key Certificates are issued by an established required for decryption.
Certificate Authority (CA) after a rigorous verification 7. Browsers store/access different CAs’ public keys (run cert
procedure. mgr.msc from
2. ITU-T X.509 specifies the standard and syntax for the public 8. Windows command prompt), which browsers use to decrypt
key certificates. the signature and get the hash code.
3. Once the CA verifies the entity (subject) who needs the 9. Decrypted signature value and calculated hash code are
certificate, a certificate is issued to it and it binds a specific compared to establish the authenticity.
private/public key pair to that entity. Private key is retained by 10. Once certificates are verified, it can be used to get the public
the entity and public key can be shared. key of the subjects.
4. A certificate contains useful information like: subject’s
(owner’s) name, subject public key, issuer name, validity etc.
5. A entity can distribute its certificate to other users (how?). A
certificate may contain a certificate signature value. Which
receiver can verify using the CA’s public key.
6. A CA has provided the certificate to Google Email Server.
7. When users access Gmail, the browser address bar shows the
lock.
8. After clicking the lock, certificate details can be seen.
9. Few important fields are:
a. Subject: to whom the certificate is issued (here it is
Google).
b. Subject Public Key Algorithm: which asymmetric
encryption algorithm is to be used.
c. Subject’s Public Key: value of the public key. Now it
is available to the users.
d. Certificate Signature Algorithm: which algorithm Pretty Good Privacy (PGP)
the CA used to calculate the signature of the
certificate. 1. PGP was created by Phillip R. Zimmermann. He is a member
e. Certificate Signature Value: The value of the and leading advisor with many universities, Internet and
signature. security research groups.
f. Fingerprint (or Thumbprint): A hash value of the 2. It provides protection from Confidentiality and Integrity
complete certificate to compare its uniqueness. attacks on E-Mails and file storage applications.
5
3. First published on the Internet in 1991. E-Mail Confidentiality using PGP
4. Many products and web browser plug-ins use PGP for
providing e-mails security. How to ensure that the confidentiality is maintained for the
5. It is based on cryptographic algorithms that are time tested, email that is received? That is; it was not accessed or viewed by
reviewed and considered extremely safe. anyone else except whom it was sent for.
6. Originally it was not created keeping any standardization in
Approach using Encryption:
mind. But now it is on the standards track with IETF RFC-
4880 and RFC-3156. 1. The sender encrypts the message (along with its encrypted has
code) using a symmetric key encryption that is called the one-
E-Mail Integrity using PGP time session key.
2. The session key itself is encrypted using the public key of the
How to ensure that the integrity is maintained for the email that
receiver (asymmetric key encryption) and prepended along
is received? That is; it was not subjected to unauthenticated
with the encrypted message.
modification or destruction and it is indeed coming from the
3. The receiver uses its private key to decrypt the session key.
source what it claims from.
4. The receiver using the session key decrypts the message.
Approach using Digital Signature:
Server-Side Procedure
1. A hash code (digest) for the message is generated and it is
encrypted with the sender’s private key and sent along
prepended with the message.
2. Receiver decrypts the hash code with the sender’s public key
and recalculates the hash code on the message.
3. Email integrity is maintained if the decrypted hash code and
the recalculated hash code match.
4. Compression can be used over the whole packet to conserve
the bandwidth.
6
b. If a segment-P is received after segment-O with sequence Examples:
number 325 containing 50 bytes, with what number it will 1. 23 mod 11 = 1
be acknowledged by the host-B? 2. 19 mod 19 = 0
2. For a user X, KX# represents its public key, KX$ its private 3. 19 mod 22 = 19
key and K a symmetric key that it can use with any other user 4. -13 mod 12 = -1 and final r = -1+12 = 11
who also has K. If X wants to encrypt a message m with its 5. -7 mod 10 = -7 and final r = -7+10 = 3
private key, it is represented as KX$ (m), the message hash 6. In cryptography we will not come across the situations
digest as H(m) and the append operation as + sign. User A where the divisor (modulus) is negative.
sends a message m to user B where the digital signature of the 7. Note: When n is the divisor, the remainder can be from 0
message is appended to the message. The whole data is then to (n-1) only.
encrypted using the symmetric key. Assuming A and B both
have the same symmetric key, obtain the mathematical
expression for what is received by the user B. Use the
notations as explained in the beginning.
3. In PGP why sender used a symmetric key to encrypt the English Letter Encoding
message symmetrically? It had the public key of the receiver,
so it could very well do the asymmetric encryption also. 1. Subsequent slides use the following encoding.
2. 26 alphabets of English language mapped in a sequence
Classical Encryption Techniques from 0 to 25.
3. Few texts and references take plain text in lower case and
Kerckhoffs’ Principle ciphertext in upper case. But that is not really necessary
Kerckhoffs' Principle: Auguste Kerckhoffs, a 19th century unless specified.
professor of languages and an cryptographer in Paris formulated
that one should always assume that an adversary knows the
encryption and decryption algorithm. The resistance of the cipher
to attack must be based only on the secrecy of the key.
Exercise
8
Where Aij is a matrix obtained from A by deleting i th row and j th Residue Matrix & Multiplicative Inverse
column.
1. When a number is divided by n; the remainder is always from
0 to (n-1).
For a 2x2 matrix, the determinant can be calculated
2. Residue Set: Zn represents this set of 0 to (n-1) elements. E.g.
quickly as det(A) = (a.d - b.c)
Z5= {0, 1, 2, 3, 4} and Z26 = {0, 1, ……25}.
Matrix: Identity and Inverse 3. Multiplicative Inverse: Two Zn elements are multiplied and
divided by n. If the remainder is 1, these two elements are
1. In an identity matrix I, all the elements are 0 except main called multiplicative inverse of each other in the set of Zn.
diagonal elements from upper left to lower right which are all Examples: 3 and 2 in Z5 are two such elements because (3x2)
1. mod 5 = 1.
19 and 11 in Z26 are two such elements because (19x11) mod
26 = 1.
4. Test for Multiplicative Inverse: If there is an element x from
Zn, it will have a multiplicative inverse in Zn if GCD (x, n) =
1. Here x and n are called relatively prime.
5. Residue Matrix: Cryptography uses residue matrices
2. We represent a matrix with an uppercase alphabet (e.g. M, A, extensively. It is the matrix where all the elements are drawn
K etc.) from Zn. If n = 26, it means all elements of a Z26 matrix will
3. Inverse M-1 of a square matrix M is defined in such a way be drawn from {0, 1, 2......25}.
that M x M-1 = M-1 x M = I, where I is the identity matrix. 6. A residue matrix M of Zn will have a multiplicative inverse
4. If the matrix determinant is 0, it is called the singular matrix, matrix (𝑀−1 ) so that M x 𝑀 −1 = I:
and such matrix will not have an inverse. a. If the determinant (let us say d) of that matrix M has
a multiplicative inverse in set Zn.
Illustration b. In other words, if GCD (d, n) = 1, there would be a
multiplicative inverse matrix of M.
Is the following matrix an Identity Matrix in mod-26 mathematics?
Multiplicative Inverse in Zn
9
Where: multiplicative inverse but still there is a large count of key
possibilities. It makes cryptanalysis more difficult.
1. (𝐝𝐞𝐭(𝑲))−𝟏 = Multiplicative inverse of det(K) in Z26. It can
be found out using Extended Euclidean Method. Illustration
2. Dji = Determinant of the matrix deleting the jth row and ith
Hill Cipher -Encryption
column.
1. In this illustration, K and 𝐾 −1 will be used as obtained in the
Illustration
previous illustration.
Multiplicative Inverse of a Matrix in Z26
10
Polyalphabetic Cipher 3. To explain the procedure of Vernam Cipher, let us say it has to
be applied on English language of 26 alphabets which are
1. Caesar Cipher is a monoalphabetic substitution cipher. A numbered from 0 to 25 respectively.
character in plaintext will be substituted by a fixed 4. For encryption: the plaintext alphabets are added to the key
replacement character every time as long as the key k is fixed. alphabets one at a time. If the resulting number is >= 26, then
2. One of the ways to improve the simple monoalphabetic 26 is subtracted from it. The resulting numbers
technique is to use different monoalphabetic substitutions as 5. are the ciphertext alphabets.
one processes the plaintext message – character by character. 6. For decryption: the key alphabets are subtracted from
3. The general name for this approach is polyalphabetic ciphertext alphabets. If the resulting number is < 0, then 26 is
substitution cipher. added. The resulting numbers are the plaintext.
4. These techniques have the following features in common:
a. A set of related monoalphabetic substitution rules is
used.
b. A key determines which particular rule is chosen for
a given transformation.
Vigenère Cipher
1. One of the simplest polyalphabetic cipher. Named after Blaise
de Vigenère, a 19th century cryptographer in France.
2. There is a sequence of n plaintext letters: Vernam Cipher with XOR Operation
P = p0 , p1 , p2 , p3 ,...pn-1
3. There is a key consisting of m letters (assuming m < n) 1. In the binary systems, Vernam Cipher operation is equivalent
K = k0 , k1 , k2 , k3 ,...km-1 of using XOR (⊕) operation.
4. The sequence of n ciphertext letters are calculated as: 2. Example XOR operation for binary numbers:
Ci = (pi + ki mod m) mod 26; where i = 0 to (n-1) 110011 ⊕ 001100 = 111111
5. Similarly, the plaintext is restored from ciphertext as: 111111 ⊕ 001100 = 110011
pi = (Ci - ki mod m) mod 26; where i = 0 to (n-1) 3. It can be observed that the XOR operation between any two
6. Since we assumed that m < n, so (i mod m) will wraparound numbers would result the third number. This property can be
(reuse) the values of key letters. used in the Vernam Cipher.
4. Vernam Cipher proposed a key stream generator to generate
Example
the key which would eventually repeat the sequence.
Keyword = deceptive
key: deceptivedeceptivedeceptive
plaintext: wearediscoveredsaveyourself
ciphertext: ZICVTWQNGRZGVTWAVZHCQYGLMGJ
One Time Pad
1. A US army officer Joseph Mauborgne proposed an
improvement over Vernam Cipher in 1914.
2. Mauborgne suggested using a random key that is as long as
the message, so that the key need not be repeated. In addition,
the key is to be used to encrypt and decrypt a single message,
and then it is discarded.
12
c. If n is not divisible by any of these prime numbers, 2. Examples:
then n is a prime number. 91 = 71 x 131
6. Example-1: 3600 = 24 x 32 x 52
a. Floor of 97 = 9 // 97 is 9.8488... But when we 11011 = 71 x 112 x 131
take floor we take greatest integer <= 9.8488.
b. Prime numbers <= 9 are 2, 3, 5, and 7. Fermat’s Theorem
c. 97 is not divisible by any one of these. So 97 is 1. Named after 17th century French mathematician
prime. 2. Pierre de Fermat.
7. Example-2: 3. Also called Fermat’s Little Theorem.
a. Floor of 301 = 17 // 301 is 17.3493... But when 4. It states that if p is a prime number and a is a positive integer,
we take floor we take greatest integer <= 17.3493. then:
b. Prime numbers <= 17 are 2, 3, 5, 7, 11, 13 and 17.
c. 301 is divisible by 7. So 301 is not prime.
13
called the set of multiplicative inverses for n. This subset of
Zn is represented by Zn*. For example:
• Z6*= {1, 5} // E.g. (1*1) mod 6 = 1 and (5*5) mod 6 = 1
• Z7*= {1, 2, 3, 4, 5, 6} // E.g. (3*5) mod 7 = 1, (6*6) mod
7 = 1 etc.
3. If n is a prime number, then all elements from 1 to (n-1) will
be present in Zn*.
Abelian Group
Example-1
Basic Logarithms
1. logx(1) = 0
2. logx(x) = 1
3. logx(y.z) = logx(y) + logx(z)
Note: 4. logx(𝑚𝑛 ) = n. logx(m)
Examples:
15
Example-1 Property-3:
1. Rewrite in dlog form: 1. dloga,p (x.y) ≡ [dloga,p (x) + dloga,p(y)] mod [ɸ (p)]
2. 26 (mod 19) ≡ 7 2. dlog14,19 (18) ≡ [dlog14, 19 (3) + dlog14, 19(6)] mod [ɸ(19)]
3. 6 = dlog2,19(7) 3. Because 9 = 7 + 2
Example-2 Property-4:
Example-3
Example-4
1. Since, 16 ≡ 3
2. 10 (mod 19), so
3. dlog3,19(16) = 10
Example-5
1. Find out the discrete log of 16 for the primitive root 10 of 19.
2. dlog10, 19(16) is to be found out.
3. Since, 16 ≡ 1014 (mod 19), so dlog10, 19(16) = 14
x = a1 in mod m1
x = a2 in mod m2
……………..
x = ak in mod mk
Where,
Property-1: M = m1 x m2 x m3 x ……x mk and
Mk = M/mk
1. dloga, p(1) ≡ 0 mod [ɸ (p)]
Mk^-1 is the multiplicative inverse of Mk in the
2. dlog2, 19 (1) ≡ 18 mod [ɸ (19)] = 0
corresponding modulus.
3. True for all primitive roots of 19.
Example: Solve the following equations for x:
Property-2:
1. x = 2 in mod 3
1. dloga,p (a)≡ 1 mod [ɸ(p)]
2. x = 3 in mod 5
2. dlog13,19(13) ≡ 1
3. x = 2 in mod 7
3. True for all primitive roots of 19.
Moduli 3, 5 and 7 are relatively prime and there is only one
variable x, so CRT is applicable.
M = 3 x 5 x 7 = 105
16
M1 = 105/3 = 35, M2 = 105/5 = 21, M3 = 105/7 = 15
M1^(-1)= 2, M2^-1 = 1, M3^-1 = 1
x = [(a1 x M1 x M1^-1) + (a2 x M2 x M2^-1)+ (a3 x M3 x
M3^-1)] mod M
[(2x35x2) + (3x21x1) + (2x15x1)] mod 105
[140+63+30] mod 105
233 mod 105
23
Mathematics
17
3. C = 𝑷𝒆 mod n and decryption private key (d, n) is safely kept 5. C = 𝑷𝒆𝒅 mod n
with the receiver. 6. We selected e and d in a way such that e.d = 1 mod ɸ(n)
4. Assume C is being transmitted. Attacker can get C, but how = {k.ɸ(n) + 1} mod ɸ(n)
will he get P from it? 7. // for some integer k
5. So for an attacker to decipher the message it is required to 8. So:
calculate the following: P = 𝑪𝟏/𝒆 mod n, that is the eth root of P1 = 𝑷𝒆𝒅 mod n
C in modular arithmetic. 𝑷𝒌ɸ(𝒏)+𝟏 mod n
6. It is not feasible to calculate it in the available time and cost if P mod n // Generalized form of the Euler’s Theorem second
n is very large. It has to be Computationally Secure. version
7. P = 𝑷𝒆𝒅 mod n for this equation to be true, e and d are 9. Hence, P1 = P
selected from Zɸ(n)* in such a way so that e and d are
multiplicative inverse of each other in modulo ɸ(n): Strength
e.d = 1 mod ɸ(n) 1. RSA is based on the idea that modulus (n) is to be so large
d = 𝒆−𝟏 mod ɸ(n) that it can not be factorized into primes in feasible time. This
8. In other terms, d and e is relatively prime to ɸ(n). is NP (Non-deterministic Polynomial) class of problem.
9. That is, gcd (ɸ(n), d) = 1 and gcd (ɸ(n), e) = 1. 2. If an attacker finds the factors of n, it needs to calculate the
value of ɸ(n).
Procedure
3. Then finally the decryption key is to be found out as d = e -1
1. Select a large number n. mod ɸ(n), assuming e is known as public key exponent.
2. Factorize n into prime numbers# . 4. RSA algorithm can be considered secure as long as a time
3. For the sake of example, let us say n = p.q efficient algorithm for finding out prime factors of a large
4. Calculate ɸ(n) = (p-1)(q-1) number is not found.
5. Select integer e such that gcd (ɸ(n), e) = 1
6. Calculate d such that d = 𝒆−𝟏 mod ɸ(n) Diffie-Hellman Key Exchange
7. Public Key (PU) = {e, n} 1. We have reviewed that a shared secret is used in MAC.
8. Private Key (PR) = {d, n} 2. Not just in MAC, in Network Security a symmetric key is also
9. For encryption, ciphertext C = 𝑷𝒆 mod n required many times whenever a symmetric encryption is
10. For decryption, plaintext P = 𝑪𝒅 mod n utilized.
Example 3. We will also review that shared secret is used to generate
other keys in transport layer security.
1. Let us say n = 77 4. Let us take a break from asymmetric key cryptography and
2. So, n = p x q where, p = 7, q= 11 review a mathematical approach to exchange a shared secret
3. φ(n) = (7 − 1) (11 − 1) = 60 (or a shared key) without divulging any secret.
4. Two values (e, d) are to be chosen from the elements of Z60∗ 5. Why are we reviewing it in this module?
which are multiplicative inverse 6. Because it utilizes the concepts of prime numbers and
5. of each other in mod φ(n) mathematics, where φ(n) = 60. primitive roots which in general are used in asymmetric key
e = 13 cryptography.
d = 37 7. Developed by W. Diffie and M. E. Hellman professors of
6. Note that e and d could be chosen same also (but usually not). Stanford University in 1976.
E.g. 5 and 5 in mod 6. 8. Extensively used even today!
7. Let us say sender wants to send an alphabet ‘F’ which can be
represented as 05 as an integer. Formulation
8. Sender will encrypt it as 𝑷𝒆 mod n 1. There are two publicly known numbers: a prime number p and
= 513 mod 77 = 26 e a primitive root of it. Users A and B want to create a shared
9. Receiver will decrypt it as 𝑪𝒅 mod n secret key.
= 2637 mod 77 = 5 2. User A selects a random number XA < p and calculates
YA = 𝒆𝑿𝑨 mod p.
Mathematical Insight
3. Similarly, user B selects a random number XB < p and
1. Receiver of the message restores some plaintext (P1) as: calculates YB = 𝒆𝑿𝑩 mod p.
P1 = 𝑪𝒅 mod n ----- (i) 4. User A keeps XA with himself and shares YA with B.
2. Where C was calculated over the original plaintext (P) as: 5. Similarly, user B keeps XB with him and shares YB with A.
C = 𝑷𝒆 mod n ----- (ii) 6. Now A computes a key KA as: KA = 𝒀𝑩𝑿𝑨 mod p.
3. How are we so sure that P1 = P? What was sent is equal to 7. B also computes a key KB as: KB = 𝒀𝑨𝑿𝑩 mod p.
what is restored? 8. Both the keys KA and KB are same as proved below:
4. We know that: P1 = 𝑪𝒅 mod n KA = 𝒀𝑩𝑿𝑨 mod p
(𝑷𝒆 𝒎𝒐𝒅 𝒏 )𝒅 mod n // replacing the value of C from (ii) = (𝒆𝑿𝑩 𝒎𝒐𝒅 𝒑)𝑿𝑨 mod p
18
= 𝒆𝑿𝑩.𝑿𝑨 mod p 7. Attack (volunteers passing the buckets of water hop by hop!).
= (𝒆𝑿𝑨 𝒎𝒐𝒅 𝒑)𝑿𝑩 mod p To avoid this attack, legitimate users can use authentication
= (𝒀𝑨)𝑿𝑩 mod p techniques.
= KB
9. The key K (= KA = KB is the shared secret key) which is
generated without sharing the individual random numbers XA
and XB and its value is K = 𝒆𝑿𝑩.𝑿𝑨 mod p.
Flow of Events
19
Mathematics & Logic a. Uniform Distribution: The distribution of bits in the
sequence should be uniform; that is, the frequency of
Sender sends two ciphertexts:
occurrence of ones and zeros should be approximately
i. C1 = (𝒆𝟏)𝒓 mod p -----------(i) equal.
b. Independence: No subsequence in the sequence can be
ii. C2 = (P x (𝒆𝟐)𝒓 ) mod p -----------(ii) inferred from the others.
2. Pseudo Random Numbers (PRN): Cryptographic
Receiver decrypts it as:
applications typically make use of algorithmic techniques for
P = [𝑪𝟐 x(𝑪𝟏𝒅 )−𝟏 ] mod p -----------(iii) random number generation. These algorithms are
deterministic and therefore produce sequences of numbers that
Sender does not know d and the receiver does not know r so how are not statistically random. However, if the algorithm is
does the logic work? good, the resulting sequences will generate a sequence of
“near random numbers” which are called pseudo random
numbers.
3. True Random Numbers (TRN): A true random number is
generated taking inputs from sources that are effectively
random. These sources are called Entropy Sources. The
entropy source could be drawn from the physical environment
of the computer and could include things such as keystroke
Example
timing patterns, hard disk activity, mouse movements,
1. Receiver selects a prime number p = 19 temperature of the PCB etc. These are used to generate true
2. Primitive roots# of 19 = {2, 3, 10, 13, 14, 15} random numbers.
3. Receiver selects e1 = 10 (one of the primitive roots) and a
random number d = 5
Blum Blum Shub (BBS)
4. Then, e2 = e1 d mod p = 105 mod 19 = 3 1. Named after US Computer Scientists and Mathematicians
5. The private key for the receiver PR = {19, 10, 3, 5} // {p, e1 , who developed it - Lenore Blum, Manuel Blum and Michael
e2 , d} Shub.
6. The public key for the sender PU = {19, 10, 3} // {p, e1 , e2 } 2. Strongest cryptographic strength as proved publically
7. The sender wants to send P = 17 and selects random number r (experience so far).
=6 3. First, choose two large prime numbers, p and q, such that both
8. Sender then calculates C1 and C2 as below: have a remainder of 3 when divided by 4. That is p = q = 3
C1 = 𝑒1𝑟 mod p = 106 mod 19 = 11 (mod 4). Details Link.
C2 = (P x 𝑒2𝑟 ) mod p = (17 x 36 ) mod 19 = 5 E.g. 7 = 11 = 3 (mod 4)
9. The receiver decrypts C1 and C2 as: 4. Let n = p x q
P = [C2 x (𝐶1𝑑 )−1 ] mod p 5. Choose a random number (initial seed) s, such that s is
= [5 x (115 )−1 ] mod 19 relatively prime to n; this is equivalent to saying that neither
= [5 x 11] mod 19 p nor q is a factor of s.
= 17 (the original plaintext) 6. Then the BBS generator produces a sequence of random
numbers (Xi ) and random bits (Bi ) according to the
Usage of Random Numbers following algorithm:
1. Cryptographic Key Generation: Many systems use
random numbers to use a key for encryption and decryption.
These include both symmetric and public key algorithms.
2. To Avoid Replay Attacks: Random numbers are used for
handshaking to prevent replay attacks in many network
security protocols. This is called nonce. The use of random Example:
numbers for the nonces frustrates an opponent’s efforts to
determine or guess the nonce, in order to repeat an obsolete
transaction. Example: TLS/SSL protocol.
3. Bit Stream Generation: a bit stream for symmetric stream
encryption Example: RC4 stream cipher.
20
Next Bit Test Design Considerations
1. The BBS is referred to as a Cryptographically Secure Pseudo 1. The key stream generator sequence should have a large
Random Bit Generator (CSPRBG). A CSPRBG is defined as period.
one that passes the next-bit test. a. A pseudorandom number generator uses a function that
2. Next-Bit Test: produces a deterministic stream of bits that eventually
a. The first m bits are captured that are generated by a might repeat itself.
random number generator (RNG). b. The longer the period of repeat the more difficult it would
b. Let us say there is some polynomial time algorithm that be to do the cryptanalysis.
can predict the next bit given the few previous generated 2. The key stream should approximate the properties of a true
bits. random number stream as close as possible.
c. Using the m random bits and such algorithms the next 3. The output of the pseudorandom number generator is
(m+1) th bit cannot be predicted with probability more conditioned on the value of the input key (K). To guard
than 50%. against brute-force attacks, this key needs to be sufficiently
d. Then such RNG that generated the m random bits is long and random.
considered to have passed the Next-Bit Test.
RC4 Stream Cipher
True Random Number Generator (TRNG)
1. Rivest Cipher-4 (RC4) was designed in 1987 by Ron Rivest
1. True Random Number Generator (TRNG) uses a for RSA Security.
nondeterministic source to produce randomness. Most operate 2. It is a variable key size stream cipher with byte-oriented
by measuring unpredictable natural processes, such as gas operations.
discharge tubes, leaky capacitors, computer peripheral sound 3. RC4 was kept as a trade secret by RSA Security. In September
and movements. 1994, the RC4 algorithm was anonymously posted on the
2. Intel has developed a commercially available chip that Internet.
samples thermal noise by amplifying the voltage measured 4. RC4 is used in the following security protocols (not limited
across hardware circuitry. to):
3. RFC-4086 specifies some possible sources of randomness: a. Transport Layer Security (TLS) until 2015.
a. The input from a sound digitizer with no source plugged b. Wired Equivalent Privacy (WEP) protocol and the newer
in or from a camera with the lens cap on. WiFi Protected Access (WPA) protocol that are part of the
b. Random fluctuations in disk drive rotational speed due to IEEE 802.11 wireless LAN standards.
chaotic air turbulence surrounding the disk. 5. The RC4 algorithm is simple and easy to explain and
4. Example: an online service (random.org), can deliver random implement.
sequences securely over the Internet for variety of purpose –
RC4 Operations
lotteries, games, key generation etc.
1. S is a state vector to store 256 bytes, with elements S[0],
Stream Cipher
S[1]........S[255].
1. A stream cipher may be designed to operate on one bit at a 2. The entries of S are set equal to the values from 0 through 255
time or on units larger than a bit at a time (bytes, words etc.). in ascending order; that is, S[0] = 0, S[1] = 1, ...... S[255] =
But usually not large like 64-bit blocks! 255.
2. In the figure below, a key (K) is input to a pseudorandom byte 3. A key (K) of variable length <= 256 bytes is chosen.
generator that produces a stream of bytes (k) that are expected 4. A temporary vector T of 256 bytes is filled with the values of
to be random. Notice K and k. K. If K = 256, then all of K is filled in T, else K is repeated as
3. The output of the generator, called a key stream (k), is required to fill T.
combined one byte at a time with the plaintext stream (P)
using the bitwise exclusive-OR (XOR) operation.
4. Decryption requires the use of the same pseudorandom byte
sequence to restore the plaintext.
21
Initial Permutation 3. RC4 algorithm strength depends on the key. Many research
and studies demonstrated that a weak key makes the RC4
1. T is used to produce the initial permutation of S.
system vulnerable.
2. 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 Web Security Threats
according to a scheme dictated by T[i].
Bob is surfing the Web and arrives at the Alice Inc. website, which
is selling electronic goods. The Alice Inc. site displays a form in
which Bob is supposed to enter the type of item and quantity
desired, address, and his payment card number. Bob enters this
information, clicks on submit, and expects to receive the goods at
some time in future.
TLS Architecture
1. TLS is not a single protocol but rather two sublayers of
5. Now, both Bob and Alice can send secured data to each other.
protocols.
6. Data for TCP is a byte stream of variable length,where the
2. These two sublayers can be seen sandwiched between the
MAC will be put?
application and the transport layers.
a. The data stream is broken into records of equal size.
3. Handshake Protocol allows server and client to exchange
b. MAC is calculated for each record using MAC key
different security parameters.
and a hash function. MAC appended with the record.
4. This protocol performs its job before application data starts
c. Then the (record + MAC) is encrypted using
transmitting.
encryption key and sent over the TCP transport.
5. Change Cipher Spec Protocol is used to update the cipher
7. Where these processing take place?
specifications to be used for the connection based on the
8. Receiver decrypts the received data using symmetric key –
recent handshake.
confidentiality.
6. Alert Protocol is used to convey TLS related alarms between
the client and the server.
23
7. Heartbeat Protocol is used to check if the other host is alive 1. Client Random or nonce (CR): This field contains 4 bytes
and during the idle duration to avoid the premature closure of Unix time stamp (epoch) + 28 bytes of random number
the connections. This protocol was added later in TLS through generated by the client. Used to prevent replay attacks.
RFC-6520. 2. Session Id: Variable length session identifier. If empty
8. Record Protocol based on the exchanged cipher parameters (null/0), indicates a new connection on a new session,
by the handshake protocol, this layer provides confidentiality otherwise indicates that client wants to updates the existing
and integrity services to the upper layers. connection parameters or wants to have a new connection on
this existing session. Note that Client can send client_hello
message during a connection also to re-negotiate the security
parameters from its end during the existing connection.
3. Cipher Suites: Combination of cryptographic algorithms in
decreasing order of preference in two bytes. Each combination
conveys – key exchange, encryption and hash algorithms.
4. Compression Methods: List of compression method that
client supports.
25
4. A(i) is defined as:
Resuming Sessions
1. Client in the client_hello message can use an older session id
that indicates that it wants to re-use an older session:
a. The client wants to refresh the keys of the ongoing
session.
b. Or, the client wants to have a new connection on an older
session.
2. In this case if server is not willing to reuse the session or if it
Connection: is expired with it, a new session id value will be put in the
server_hello message.
1. In TLS, peer-to-peer relationship is transport. E.g. A client can 3. When a connection is established by resuming a session, new
exchange application data with a server, so there is a Client Random (CR) and Server Random (SR) values
connection. (exchanged through Hello Messages) are hashed with the old
2. Connection is transient and associated with a session. session's master secret (M). The generated hash is used to
create encryption and MAC keys.
4. An upper limit of 24 hours is suggested in RFC-5246 for
session ID lifetime for having a new connection over an old
sessions. After which session id should expire.
5. On the other hand, if client is using an empty session id, and
server can continue with the handshake, the server will put a
new session id indicating a new session. In this case, all
phases of handshake will take place afresh.
6. If the server responds with empty session id value, it indicates
that the server is no going cache the session details.
28
3. Therefore, the total packet length before adding TLS Record TLS Protocol Message Formats
Protocol Header must not exceed 214 +2048 bytes, otherwise
must report error through Alert protocol. Handshake Protocol
4. On the receiver side, it throws an alert fatal error if the
decompressed fragment is larger than 214 bytes.
Calculation of MAC
Calculation of MAC is defined as follows:
Sequence Number +
Content Type +
Version +
Length +
A Typical Client Hello Message
Fragment)
1. MAC Key: it is obtained from the Key Material. Application Data
2. Sequence Number: it is put by the sender record protocol
sequentially from 0 264 -1 for each record. It helps the receiver
to detect missing or re-ordered TLS record.
3. Content Type: one of the Change_cipher_spec (20), Alert
(21), Handshake (22), Application data (23), Heartbeat (24) or
invalid (0).
4. Version: Major and Minor Versions.
5. Length: length of the record fragment.
6. Fragment: the fragment itself.
TLS Connection Closure
TLS Protocol Message Examples - Change Cipher
Spec and Alert Protocols 1. If any of the client or server wants to close the connection, it
can send TCP FIN segment to indicate that.
2. This solution is not elegant, because an intruder may also can
come as the man-in-the-middle and send TCP FIN. This is
called a Truncation Attack.
3. TLS is not truncation attack safe.
4. TLS alert provides an elegant way by using Alert Code: 0
(close_notify) through TLS Alert Protocol.
5. Reception of TCP_FIN before close_notify is an indication of
abnormal termination.
6. If a peer receives TCP FIN before TLS alert close_notify, it
can take preventive measures for graceful closure e.g.
29
generating the close_notify from its end and clearing the 34 cd 86 75 00 00 16 03 03 0a f5 0b. Identify who is sending
resources allocated. this message and all the message bytes (with meaning) carried
in this TCP segment.
Transport Layer Security for UDP
Remote Login and Security
1. Unlike TCP, UDP suffers from issues like packet reordering
and loss. 1. Remote Login is a client-server program and protocol that
2. Any protocol expected to provide security services for UDP provides an interactive command line interface to a remote
first need to deal with these above issues. computer, using a protocol over a computer network,
3. IETF RFC-6347 is an attempt to standardize Datagram simulating a locally attached terminal.
Transport Layer Security (DTLS). 2. There are remote login facilities like telnet and rlogin, which
4. Example: WebRTC uses DTLS (a free, open project that are insecure.
provides browsers and mobile applications with Real-Time 3. Secure Shell (SSH) is aimed to provide a secure login to a
Communications (RTC) capabilities via simple APIs). remote server.
4. SSH allows a user to run commands on a machine's command
TLS Handshake Protocol: Summary prompt without them being physically present near the
machine. It also allows a user to establish a secure channel
over an insecure network in a client-server architecture,
connecting an SSH client application with an SSH server
Exercise
1. During the TLS Handshake Protocol, Phase-1 of establishing
security capabilities, random numbers are exchanged. They
are used in calculating the master secret. How
2. this prevents replay attacks?
3. What could be the possible reasons that a client needs to SSH Transport Layer Protocol - IETF RFC-4253
explicitly provide the
Once the TCP connection is established, the following messages
4. verification of its certificate and server does not?
are exchanged between client and server:
5. Do you agree that an intruder may remove the difficult-to-
crack cryptographic 1. ID String Exchange: Client and server exchange SSH
6. algorithms during TLS Handshake Protocol in the phase-1 of protocol and software version identification strings. E.g.
establishing security SSH-2.0-newBranch_3.3.1 <Space> comments <CR><LF>
7. capabilities? Justify your answer. 2. Algorithm Negotiation: List of key exchange methods,
8. Do you agree that an intruder may alter the sequence of TLS Encryption, MAC and compression algorithms are exchanged.
records? Justify your answer. 3. Key Exchange: Using client and server side messages
9. Few bogus clients try to bring down an e-commerce server by exchanged in step-1 and 2 and Diffie-Hellman key exchange
these two ways. How TLS provides protection? parameters, both client and server shares a common master
a. TCP SYN flooding key (K). Client can also optionally authenticate the server. K
b. Sending multiple client_hello messages (interesting is used to generate other keys.
blog for methods)
10. A hex dump is captured starting from TCP header (no
optional fields) as: 01 bb e5 9c 2d 52 f7 09 64 81 29 15 50 18
30
4. End of Key Exchange: It is an indication that each side can IETF RFC-4252
start using encryption, MAC and compression algorithms
using the new keys which are generated K. 1. The SSH server may send an
5. Service Request: Client signals either User Authentication or SSH_MSG_USERAUTH_BANNER message at any time
Connection protocol. All data exchanged after this is after this authentication protocol starts and before
encrypted and MAC protected. authentication is successful.
2. The client sends SSH_MSG_USERAUTH_REQUEST with a
username, service name as connection protocol and requested
authentication method as none.
3. The server checks the username . If the username is not valid,
server returns SSH_MSG_USERAUTH_FAILURE with
partial success value as FALSE.
4. If username is valid, server returns
SSH_MSG_USERAUTH_FAILURE with a list of one or
more authentication methods to be used.
5. The client selects acceptable authentication method and sends
SSH_MSG_USERAUTH_REQUEST with necessary
authentication fields.
6. If authentication succeeds and server needs more
authentication, it again proceeds from step-3 above using
partial success value to TRUE. If authentication failed, it
proceeds from stpe-3 with partial value as FALSE.
7. When all authentication succeed, severer sends
SSH_MSG_USERAUTH_SUCCESS.
31
3. Host Based: Authentication is performed on the client’s host 1. Channel Type: the application for this channel.
rather than the client itself. Thus, a host that supports multiple 2. Sender Channel: is the local channel number.
clients would provide authentications for all its clients. This 3. Initial Window Size: how many bytes of channel data can be
method works by having the client send a signature created sent to the sender of this message without adjusting the
with the private key of the client host. Thus, rather than window.
directly verifying the user’s identity, the SSH server verifies 4. Maximum Packet Size: the maximum size of an individual
the identity of the client host. data packet that can be sent to the sender. For example, one
might want to use smaller packets for interactive connections
SSH Connection Protocol to get better interactive response on slow links. (Message
window size can be adjusted, for details refer to RFC-4254)
IETF RFC-4254
Channel Types
1. An authenticated transport layer connection created by SSH is
called a tunnel. A tunnel can be used to multiplex a number of 1. session: The remote execution of a program. The program
logical channels. may be a shell, an application such as file transfer or email, a
2. For each channel, client and server associate a unique channel system command, or some built-in subsystem. Once a session
number (need not be same). channel is opened, subsequent requests are used to start the
3. Channel are flow controlled using a window mechanism. remote program.
4. Life of a channel progresses through three stages: 2. x11: This refers to the X Window System, a computer
a. Opening software system and network protocol that provides a
b. Data Transfer graphical user interface (GUI) for networked computers. X
c. Closing allows applications to run on a network server but to be
5. SSH_MSG_CHANNEL_OPEN: This message is sent when displayed on a desktop machine.
either side wishes to open a channel. 3. forwarded-tcpip: This is remote port forwarding. Details
6. SSH_MSG_CHANNEL_OPEN_CONFIRMATION: This follow.
message is returned when the remote side is able to open the 4. direct-tcpip: This is local port forwarding. Details follow.
channel otherwise
SSH_MSG_CHANNEL_OPEN_FAILURE is returned. Port Forwarding -Local Forwarding
7. SSH_MSG_CHANNEL_DATA: Once the channel is,
SSH has a functionality called SSH port forwarding (or SSH
opened, data is exchanged using this message.
tunnelling), where a connection is forwarded to a different port
8. SSH_MSG_CHANNEL_CLOSE: Either side can close the
where the actual communication is made on the SSH connection.
channel using this message.
This can be done either on the SSH client or the SSH server side.
32
Port Forwarding -Remote Forwarding Hash Function
1. Let us say destination server is behind a firewall and it cannot 1. The hashing function takes an input m and produces a fixed
be accessed by the client which is at some other location. size code H(m) as an output. The output is called the hash
2. From the destination side, a SSH tunnel can be established code or the digest.
because it is a secure outward tunnel (note that the firewall 2. Cyclic Redundancy Check (CRC) that is used in layer-2
may not allow a SSH tunnel from the other side). networking protocol is a kind of hashing function.
3. From the destination side SSH server is configured (on the 3. For security it is a must requirement that it should be
other side) to take the received SSH traffic and divert it to port computationally infeasible to find out another message n for
A. which H(n) = H(m).
4. The above property essentially means that an intruder should
not be able to substitute or alter the original message so that
the hash code remains intact.
5. Hashing function and thus the hash code is used for data
integrity checking.
6. Checksum: an example of a poor hashing function; message is
altered but the checksum (hash-code) does not change:
Integrity Attacks
33
Hash Function Properties 4. Padding is always added, even if the message is already of the
desired length. The number of padding bits is in the range of 1
1. A hash function (H) can be applied to a block of message to 1024.
(data) of any size. 5. The padding consists of a single 1 bit followed by the
2. H produces a fixed-length output irrespective of the length of necessary number of 0 bits.
the message. 6. Now to this message, length of the original message before
3. H(x) is relatively easy to compute for any given message x, padding in unsigned 128-bit integer is appended keeping most
making both hardware and software implementations significant byte first.
practical. 7. The message is now a multiple of 1024 bits (896+128=1024)
4. For any given hash code h, it is computationally infeasible to which is treated as blocks of 1024 bits each (M1, M2…….MN
find x such that H(x) = h. A hash function with this property is ).
referred to as one-way or pre-image resistant. 8. Each block of 1024 bits is called a block of 16 words (W)
5. For any given block of message x, it is computationally where each word is 64 bits or 8 bytes.
infeasible to find another message y where y ≠ x and H(y) =
H(x). A hash function with this property is referred to as
second preimage resistant.
6. It is computationally infeasible to find any pair (x, y) such that
H(x) = H(y). A hash function with this property is referred to
as (strong) collision resistant.
7. A hash function that follows all the above six properties is
called strong hash function.
Step-1: Append Padding Bits & Step-2: Append Length Step-3: Initial Value
1. It takes a message which is < 2 128 bits and produces a 512- 1. A 512-bit buffer is used to hold the intermediate and the final
bit message digest. Do not worry; it would be in Yottabytes! results of the hash function.
2. The input is processed in the blocks of 1024 bits. 2. The buffer can be represented as eight 64-bit registers (A, B,
3. The message is first padded so that its length ≡ 896 (mod C, D, E, F, G, H).
1024) bits. 3. These registers are initialized to the following 64-bit integers
in hexadecimal (the initial value):
34
A = 6A 09 E6 67 F3 BC C9 08 Inside Each Round of Compression Function
B = BB 67 AE 85 84 CA A7 3B
C = 3C 6E F3 72 FE 94 F8 2B
D = A5 4F F5 3A 5F 1D 36 F1
E = 51 0E 52 7F AD E6 82 D1
F = 9B 05 68 8C 2B 3E 6C 1F
G = 1F 83 D9 AB FB 41 BD 6B
H = 5B E0 CD 19 13 7E 21 79
4. These values are obtained by taking the first sixty-four bits of
the fractional parts (after multiplying it with 2^64) of the
square roots of the first eight prime numbers.
• First prime number = 2 it square root is 1.414…
• Multiply the fractional part of it (0.414….) with 2^64
• Convert the whole part of the result in hexadecimal and
take first 64 bits.
Derivation of Wi
Exercise:
35
and 0xE, respectively, what is the leftmost digit of the result? 6. A hash function is used on the combined data that generates a
(Answer: 0xE) hash code of n bits.
2. When applied the Conditional function on E, F, and G 7. Using the Initial Value (IV) a hash is calculated and prepended
buffers. If the leftmost hexadecimal digits of these buffers are with 0s to make it b bits long.
0x9, 0xA, and 0xF respectively, what is the leftmost digit of 8. oPAD is fixed 0x5C repeated b/8 times, so it is b bits long.
the result? (Answer: 0xE) 9. K is again XORed with oPAD and the output Sj is prepended
3. Expand the formula to calculate W60 in SHA-512. to padded hash code calculated earlier.
10. Hash is calculated again on this prepared block and the final
Message Digests (MD) hash value is the desired HMAC of the message M using key
K.
1. Message Digest Algorithms (MD2, MD4, MD5 and MD6) are
different hash functions designed by Ron Rivest, professor of
MIT from 1989 onwards. They are standardized by IETF in
the form of RFC and also adapted by NIST for SHA:
a. MD4: RFC-1320
b. MD5: RFC-1321
c. MD-6 proposed to NIST for RSA-3
2. The operational structure of MD is similar to SHA.
Message Authentication
1. A hash code does not authenticate the sender of the message.
2. To provide message authentication, sender needs to provide
proof that it is “the sender” sending the message and not an Polynomial Representation For Binary Words
impostor.
3. The hash code created by a cryptographic hash function (e.g.
SHA) is normally called a Modification Detection Code
(MDC).
4. What we need for message authentication is a Message
Authentication Code (MAC).
Polynomial Addition ⊕
Exercise
37
IP Security: Working 6. Router R2 performs decryption, authenticates and verifies the
integrity stripping off the security header and trailer. Original
IP header is restored after decryption and checking integrity
and verifying authenticity.
7. After original IP header is restored, R2 routes the packet to the
actual destination inside the branch office.
8. The same procedure is followed for the salesperson in hotel
also. But, in this case, there is no second router. Salesman’s
laptop (or any other device) itself performs decryption,
authentication and integrity check.
38
2. Destination Address (DA): Destination endpoint of the SA.
3. Protocol (P): AH or ESP.
4. Sequence Number (SN): 32-bit value used in security
headers.
5. Overflow (OF): Flag to indicate SN overflow.
6. Anti-Replay Window (ARW): Used to detect replay.
7. AH/ESP: Protocol information (algorithms, keys etc.)
8. Lifetime (LT): Lifetime of an SA.
9. Mode: Tunnel or Transport.
10. Maximum Transfer Unit (MTU): Maximum size of the
secured datagram that does not need fragmentation.
IP Security More Possibilities -Encryption and /or
Authentication?
1. Whatever has been discussed so far, encryption is mandatory,
but authentication is optional. This IP Security protocol is
called Encapsulating Security Payload (ESP) and
standardized through IETF RFC-4303.
2. If encryption is never required, standardization allows it also
through Authentication Header (AH) IP Security Protocol
with IETF RFC-4302.
39
4. Name: A symbolic identifier to a security policy entry. Not If the first matching entry has a policy of Not BYPASS, or if
shown in the table below. there is no matching entry, the packet is discarded.
5. Local and Remote Ports: These may be individual TCP or 3. For a secured packet, IPSec searches the SAD. If no match is
UDP port values, an enumerated list of ports, or a wildcard found, the packet is discarded. Otherwise, IPSec applies the
port. appropriate ESP or AH processing. Then, the IP header is
6. Link to SAD entry (not shown in the table): for outbound processed and stripped off and the packet body is delivered to
IPSec processing a policy entry also refers to a SAD entry. If the next higher layer, such as TCP.
there is no entry, IKE is used to establish new SA. (More
details RFC-2401 section 4.4.3).
IP Security Policy
Model for Outbound Packets
40
ESP Tunnel Mode Replay Attacks Issues
Issue# 1:
Issue# 2:
Anti-Replay Service
Solution to Issue#1: Usage of SN and OF Fields
Establishment of IKE_SA
Initial Exchange: IKE_SA_INIT (RFC-7296 )
Establishment of SA
Initial Exchange: IKE_AUTH (RFC-7296)
The Initiator (i) sends the following parameters and responder (r)
responds with the corresponding answers:
1. All IKE payloads begin with the same generic payload header
following the IKE header.
2. The Next Payload field has a value of 0 if this is the last
1. Initiator SPI (64 bits): A value chosen by the initiator to payload in the message; otherwise its value is the type of the
identify a unique IKE security association (SA). next payload.
2. Responder SPI (64 bits): A value chosen by the responder to 3. The Payload Length field indicates the length in octets of this
identify a unique IKE SA. payload, including the generic payload header.
These SPI are different from Security header SPI 4. The critical bit (C):
3. Next Payload (8 bits): Indicates the type of the first payload a. It is set to 0 if the sender wants the recipient to skip
in the message. this payload if it does not understand the payload
4. Major and Minor Versions (4 bits each): Indicates major type code in the Next Payload field of the previous
and minor versions of IKE in use. payload.
5. Exchange Type (8 bits): Indicates the type of exchange. E.g. b. It is set to 1 if the sender wants the recipient to reject
IKE_SA_INIT, IKE_AUTH, CREATE_CHILD_SA or this entire message if it does not understand the
INFORMATIONAL. payload type.
6. Flags (8 bits): Indicates specific options set for this IKE
Block Ciphering Techniques: Feistel Cipher
exchange. Three bits are defined so far:
a. The initiator bit (I)- whether this packet is sent by the Structure and DES
SA initiator.
Block Cipher
b. The version bit indicates (V)- the transmitter is
capable of using a higher major version number than 1. In a block cipher, the message that is to be encrypted is
the one currently indicated. processed in blocks of k bits each.
c. The response bit (R) indicates whether this is a 2. E.g. if k = 64, the message is broken down in the blocks of 64
response to a message containing the same message bits each and then each block is encrypted individually.
ID. 3. As an obvious choice, a cipher can use one-to-one mapping
7. Message ID (32 bits): Used to control retransmission of lost between plaintext and the ciphertext. That means a plaintext
packets and matching of requests and responses. block of 64 bits maps to another ciphertext block of 64 bits.
8. Length (32 bits): Length of total message (header plus all 4. Let us say k = 2, so one possible plaintext and corresponding
payloads) in octets. ciphertext would be as follows.
5. Obviously, reversible mapping is of interest here because it
produces unique ciphertext block for each plaintext block.
44
2. In 1970s, he was instrumental in developing the Data
Encryption Standard (DES) – a first application based on the
Feistel Cipher Structure.
3. In Feistel Cipher structure two operations are performed
alternatively for a number of times:
a. Substitution: A plaintext element is replaced by
corresponding ciphertext.
b. Permutation: The sequence in which the plaintext
Challenges in this Approach element appears is changed several times.
1. The plaintext is divided into two equal halves LEi and REi .
(E stands for Encryption)
2. A subkey Ki+1 is derived from the key K.
3. A function F is defined which takes subkey Ki+1 and right
1. The sender and receiver need to share the key table.
half REi of the data as inputs.
2. Notice that for a given k, there would be 2𝑘 entries in the key
4. The output of the function F is XORed with the left half of the
table. E.g. there are 22 =4 entries in the table shown in the
data (LEi ) and made the new right half (REi+1 ).
previous slide. For k = 3, there would be 23 =8 entries, and so
5. Right half (REi ) of the previous round makes the left half for
on. the next round (LEi+1 ).
3. Since each entry is k bits, it would need minimum 2.k.2𝑘 bits 6. The iteration is repeated 16 times and the left and right halves
to store plaintext and ciphertext combinations. are swapped.
4. The value k is required to be large otherwise cryptanalysts can 7. The final output is the ciphertext.
do brute force attacks. 8. The same steps are used for decryption. (D stands for
5. For k = 64, the key table size is 2x64x264 ; 256 exabytes - an Encryption)
enormously large value! 9. In all steps, substitution is performed on the left half XORing
6. The first value in the shown table can be 1-of-4, second can be it with the output of function F and then permutation is
1-of-3 and so on. So, the values in the table can be permuted performed by swapping the right and left halves.
in 4! ways (or 2𝑘! ) 10. In another words, Confusion and Diffusion is attempted to be
7. So the sender and receiver will be sharing one of these 2𝑘! induced through multiple iterations.
combinations and store it.
8. How one of such key combination out of 264! will be agreed
upon and shared – even a bigger challenge!
46
XOR Operation
Between Compressed Key and Expanded Right Half of the
Data
S-Box Substitution
1. The 48 bit input is divided into 8 groups of 6 bits each.
2. Each group acts as an input to an individual S-Box (S1 to S8).
3. Each S-Box produces 4 bits of output. So total 48 bits produce
32 bits.
4. Each S-Box is a 4x16 matrix. Each matrix element is 4 bit
number.
5. Let us assume b1 b2 b3 b4 b5 b6 are six input bits. Values of
b1b6 decide the row number (0 to 3) in a S-Box and b2 b3 b4
b5 decide the column number (0 to 15) in that S-Box. E.g. if 6
input bits are 010111, so row number is 01 (decimal 1) and The Final Permutation
column number is 1011 (decimal 11).
Two halves of the output of 16th round are swapped and passed
6. So essentially, 6 input bits select a 4 bit matrix element in a S-
through the Inverse Permutation (IP-1 ) using the table below to
Box and that element becomes the output of that S-Box.
get the final ciphertext.
7. The matrix elements of eight S-boxes are provided in
Appendix-A.
DES Decryption
P-Box Permutation
DES Decryption steps are same as Encryption except the
The 32 bits from S-Box permutation are permuted using the table following:
below:
• The sub-keys are used in the reversed order (K16....K1).
• IP and IP −1 are used in the reverse order.
48
9. Why A performed some function on NB and sent it back to B? Modus Operandi:
10. Why A and B used session key KS for the last two messages?
11. Could A and B use their respective master keys (KA and KB) • Generate a shared master key between two users.
for the last two messages for encryption? • Use this master key to protect session key for securing
12. A and B are authenticated with KDC as they shared master messages. Probably one session key per message.
keys (KA and KB) with KDC. Are A and B authenticating • Alter keys frequently to protect the system.
each other? If this is an issue, was it being taken care of?
Distribution of Symmetric Key
How?
Using Asymmetric Encryption (Public) Keys –Simple Mode
Hierarchical Key Control
1. User A generates its public/private key pair (PUA /PRA ) and
1. There can be local KDCs, each responsible for a small domain sends the public key PUA and its id IDA to B.
of the overall internetwork. E.g. single LAN or a single 2. B generates a secret session key, KS , and transmits it to A,
building. which is encrypted with A’s public key.
2. If two entities in different domains desire a shared key, then 3. Only A can decrypt it using its private key PRA and make use
the corresponding local KDCs can communicate through a of the session key KS .
global KDC and one of them actually select the key. E.g. 4. A and B can discard PUA , PRA and KS after the session.
entities in the different states.
3. The same concept can be extended depending on the
complexity of the geographic scope and population.
49
5. A selects a secret shared key KS , encrypts it with its private 2. Each participant registers a public key with the directory
key and then encrypt the whole message with B’s public key authority. Registration would have to be in person or by some
and sends it to B. form of secure authenticated communication.
B decrypts the message first with its own private key and the 3. A participant may replace the existing key with a new one at
result with A’s public key to get the KS . any time, either because of the desire to replace a public key
that has already been used for a large amount of data, or
because the corresponding private key has been compromised
in some way.
4. Participants could also access the directory electronically. For
this purpose, secure, authenticated communication from the
authority to the participant is mandatory.
5. Safer than public announcement but confidentiality and
integrity of the directory is crucial.
Exercise
Public Key Authority
Analyse and answer the following questions for Key Distribution
1. Initiator A requests the Public-Key Authority (PKA) the
Scenario in the previous slide:
public key of B. The message is time stamped TA
• How is A ensured about the authenticity of B from the 2. PKA sends an encrypted response with its private key. The
messages? message contains the public key of B (PUB) and the original
• How is B ensured about the authenticity of A from the request and time stamp sent by A.
messages? 3. A saves B’s public key and sends an encrypted message with
• When A sends the shared secret key KS to B, how A B’s public key (PUB) to B. The message contains A’s identity
ensures that only B can read it and how B ensures that (IDA ) and a nonce generated by A (NA).
only A could send it? 4. B also gets the public key of A (PUA) in the same manner
from PKA.
Distribution of Public Keys 5. At this point of time, both A and B have each other’s public
keys.
Public Announcement 6. B sends an encrypted message with the public key of A. The
message contains the nonce generated by A and a new nonce
Any participant can send his or her Public Key (PU) to any other
generated by B.
participant or broadcast the key to the community at large.
7. A responds with the nonce generated by B encrypted with the
Drawback: Anyone can forge such a public announcement. E.g. public key of B.
some users could pretend to be user A and send a public key to
another participant or broadcast such a public key. Until such time
as user A discovers the forgery and alerts other participants, the
forger is able to read all encrypted messages intended for A.
50
Exercise 3. B also receives its certificate from CA in the same manner.
4. A and B now can exchange their certificates directly without
Analyse and answer the following questions for Public Key
CA in between.
Distribution Scenario in the previous slide:
5. B can decrypt the certificate of A using the public key of CA
1. Why A time stamped his first message and why PKA included and retrieve TA , IDA and PUA . In the same manner, A can
this time stamp in his response to A? also decrypt the certificate of B.
2. When PKA provided B’s public key to A, the message was 6. If time stamp (T) is old the certificate must be considered
encrypted with the private key of the PKA itself. How will A expired
decrypt it?
3. Why A contacted B with its id and its nonce in a message
encrypted with B’s public key?
4. Why B responded to A with A’s nonce and its own nonce?
5. Why A replied to B with B’s nonce and why the message was
encrypted with the public key of B?
6. Can we conclude for PKA mechanism to work, PKA’s public
key must be known to the other users first?
7. What are the disadvantages of this scheme?
Answer:
a. Overhead of approaching PKA for every public key.
b. Confidentiality and integrity of the public key
database with PKA.
Public-Key Certificates
1. Certificates can be used by participants to exchange keys Public Key Certificates
without contacting a public-key authority, in a way that is as
reliable as if the keys were obtained directly from a public- 1. s reviewed in the previous slides, certificates is the most
key authority. prominent way to distribute the public keys.
2. A certificate consists of a public key, an identifier of the key 2. In place of encrypting the whole message, only the calculated
owner, and the whole block signed by a trusted third party. hash code is encrypted by the Certification Authority (CA)
3. A user can present his or her public key to the authority in a using its private key and verified by the user to establish the
secure manner and obtain a certificate. authenticity using CA’s public key.
4. The user can then publish the certificate. Anyone needing this 3. X.509 is part of the ITU-T X.500 series. It defines a directory
user’s public key can obtain the certificate and verify that it is service. Directory is a server or distributed set of servers that
valid by way of the attached trusted signature. maintains a database of information about users. X.509
5. Requirements of Public-Key Certificate: defines the certificate structure and other details.
a. Any participant can read a certificate to determine
Basic Concept –Establishing CA’s Authenticity
the name and public key of the certificate’s owner.
b. Any participant can verify that the certificate
originated from the certificate authority and is not
counterfeit.
c. Only the certificate authority can create and update
certificates.
d. Any participant can verify the currency (freshness) of
the certificate.
Basic Idea
1. A applies to the Certificate Authority (CA), supplying its
public key (PUA ) and requesting a certificate.
2. Certificate Authority (CA) prepares a certificate CA for A
which is an encrypted message of the following using its
private key (PRCA):
a. Time stamp (TA )
b. ID of A (IDA ) as known to CA.
c. Public Key of A (PUA ) supplied by A.
51
X.509 Certificate Structure Revocation of X.509 Certificates
ITU-T X.509 Structure of Certificate Revocation List (CRL)
Base-64 Encoding
The X.509 certificates can be stored in the PEM (Privacy
Enhanced Mail) format. That uses Base-64 encoding. Other
formats are binary as Distinguished Encoding Rules (DER) and
Public Key Cryptography System (PKCS) variants as binary and
base-64.
52
4. Registration authority (RA): An optional component that
can assume a number of administrative functions from the
CA.
5. CRL issuer: An optional component that a CA can delegate to
publish CRLs.
6. Repository: A generic term used to denote any method for
storing certificates and CRLs
• Registration
• Initialization
• Certification
Examples and Observations • Key Pair Recovery
• Key Pair Update
1. 8 bit byte stream (characters) is converted into 6 bits
• Revocation Request
characters in base-64 conversion.
• Cross Certification
2. If the bit stream does not have a bit count that is multiple of 6,
dummy 0s are appended. X.509 Version-3 Extensions
3. The final base-64 encoding must have 4 characters or multiple
of it. If not, padding characters (=) are added for the required 1. here are certain limitations in X.509 version-2 to meet the
count. requirements of new network implementation:
4. When base-64 characters are decoded, padding (=) is dropped a. Subject field need to carry e-mail or URL type of
and 8 bits characters are decoded doing a reverse procedure. identities.
Dummy 0s are also dropped. b. To carry security policy information.
5. Important Observations: c. Differentiation among different keys by the same
a. If there are 2 padding characters out of 4, there will owner.
be only one 8 bit decoded character. 2. Version-3 of X.509 facilitate providing a flexible extension
b. If there is only 1 padding character in 4, there will be format in place of fixed fields.
two 8 bit decoded characters 3. The certificate extensions fall into three main categories:
a. Key and policy information.
b. Subject and issuer attributes.
c. Certification path constraints.
Public Key Infrastructure (PKI) 1. Authority and Subject key identifier: The same user
(subject) can have multiple public keys certified by the same
1. IETF and ITU-T working groups jointly defined a Public Key CA for different purpose. These fields support to differentiate
Infrastructure. With the following entities: among them.
2. End Entity: A generic term used to denote end users. 2. Key Usage: Defines or imposes restrictions for what a
3. Certification Authority (CA): The issuer of certificates and particular public key can be used – signature, non-repudiation,
CRLs. data encryption etc.
3. Private Key Usage Period: Indicates the duration of a private
key that can be used for a public key associated with the
53
certificate. E.g. Duration for the private key for digital
signature could be shorter than for anything else, so
differentiation may be required.
4. Certificate Policy: Data to be used in the situation where
multiple policies apply.
5. Policy Mappings: Indicates when multiple CA exist who can
certify which CA etc.
6. The policies combine set of rules into one object and
identified by an Object Identifier (OID).
54