Network Security 2
Network Security 2
Block Ciphers
In this scheme, the plain binary text is processed in blocks (groups) of bits
at a time; i.e. a block of plaintext bits is selected, a series of operations is
performed on this block to generate a block of ciphertext bits. The number
of bits in a block is fixed. For example, the schemes DES and AES have
block sizes of 64 and 128, respectively.
Stream Ciphers
In this scheme, the plaintext is processed one bit at a time i.e. one bit of plaintext is taken, and a
series of operations is performed on it to generate one bit of ciphertext. Technically, stream ciphers
are block ciphers with a block size of one bit.
Modern Symmetric Key Encryption
..
Block Size
Though any size of block is acceptable, following aspects are borne in mind while selecting
a size of a block.
● Avoid very small block size − Say a block size is m bits. Then the possible plaintext bits
combinations are then 2m. If the attacker discovers the plain text blocks corresponding
to some previously sent ciphertext blocks, then the attacker can launch a type of
‘dictionary attack’ by building up a dictionary of plaintext/ciphertext pairs sent using that
encryption key. A larger block size makes attack harder as the dictionary needs to be
larger.
● Do not have very large block size − With very large block size, the cipher becomes
inefficient to operate. Such plaintexts will need to be padded before being encrypted.
● Multiples of 8 bit − A preferred block size is a multiple of 8 as it is easy for
implementation as most computer processor handle data in multiple of 8 bits.
Padding in Block Cipher
Block ciphers process blocks of fixed sizes (say 64 bits). The length of plaintexts
is mostly not a multiple of the block size. For example, a 150-bit plaintext provides
two blocks of 64 bits each with third block of balance 22 bits. The last block of bits
needs to be padded up with redundant information so that the length of the final
block equal to block size of the scheme. In our example, the remaining 22 bits
need to have additional 42 redundant bits added to provide a complete block. The
process of adding bits to the last block is referred to as padding.
Too much padding makes the system inefficient. Also, padding may render the
system insecure at times, if the padding is done with same bits always.
Block Cipher Schemes
There is a vast number of block ciphers schemes that are in use. Many of them are publically known. Most popular
and prominent block ciphers are listed below.
● Digital Encryption Standard (DES) − The popular block cipher of the 1990s. It is now considered as a ‘broken’
block cipher, due primarily to its small key size.
● Triple DES − It is a variant scheme based on repeated DES applications. It is still a respected block ciphers
but inefficient compared to the new faster block ciphers available.
● Advanced Encryption Standard (AES) − It is a relatively new block cipher based on the encryption algorithm
Rijndael that won the AES design competition.
● IDEA − It is a sufficiently strong block cipher with a block size of 64 and a key size of 128 bits. A number of
applications use IDEA encryption, including early versions of Pretty Good Privacy (PGP) protocol. The use of
IDEA scheme has a restricted adoption due to patent issues.
● Twofish − This scheme of block cipher uses block size of 128 bits and a key of variable length. It was one of
the AES finalists. It is based on the earlier block cipher Blowfish with a block size of 64 bits.
● Serpent − A block cipher with a block size of 128 bits and key lengths of 128, 192, or 256 bits, which was also
an AES competition finalist. It is a slower but has more secure design than other block cipher.
Block Cipher modes of Operation
Encryption algorithms are divided into two categories based on input type, as block cipher and stream cipher. Block
cipher is an encryption algorithm which takes fixed size of input say b bits and produces a ciphertext of b bits again. If
input is larger than b bits it can be divided further. For different applications and uses, there are several modes of
Electronic code book is the easiest block cipher mode of functioning. It is easier because of direct encryption of each
block of input plaintext and output is in form of blocks of encrypted ciphertext. Generally, if a message is larger than b
bits in size, it can be broken down into bunch of blocks and the procedure is repeated.
Cipher block chaining or CBC is an advancement made on ECB since ECB compromises some security requirements. In
CBC, previous cipher block is given as input to next encryption algorithm after XOR with original plaintext block. In a
nutshell here, a cipher block is produced by encrypting a XOR output of previous cipher block and present plaintext block.
Disadvantages of CBC –
● Parallel encryption is not possible since every encryption requires previous cipher.
Cipher Feedback Mode (CFB) –
In this mode the cipher is given as feedback to the next block of encryption with some new
specifications: first an initial vector IV is used for first encryption and output bits are divided
as set of sandb-s bits the left hand side sbits are selected and are applied an XOR operation
with plaintext bits. The result given as input to a shift register and the process continues. The
encryption and decryption process for the same is shown below, both of them use encryption
algorithm.
...
Advantages of CFB –
The output feedback mode follows nearly same process as the Cipher Feedback mode except
that it sends the encrypted output as feedback instead of the actual cipher which is XOR output. In
this output feedback mode, all bits of the block are send instead of sending selected s bits. The
Output Feedback mode of block cipher holds great resistance towards bit transmission errors. It
a Stream Ciphers. Stream Ciphers operate on a stream of data byte by byte. RC4
stream cipher is one of the most widely used stream ciphers because of its
used in applications such as Secure Socket Layer (SSL), Transport Layer Security
encryption then third parties can not have access to data which we share
that by using a public key and private key. Both sender and receiver are
having their public key and private key through which encryption of plain
to 2048 bits), typically between 5 and 16 bytes. To generate a 256-byte state vector S,
The first step is the array initialization. It is a character array of size 256 i.e. S[256].
After this, we will run the KSA algorithm- KSA is going to use the secret key to scramble this array.
KSA has been scrambled, S[256] array is used to generate the PRGA(Pseudo Random Generation
Algorithm). This is the actual Keystream.
RC4 Block Diagram
..
Working of RC4
Encryption Procedure
Ciphertext.
Example: Let A be the plain text and B be the keystream (A xor B) xor B = A
….
A5/1
A5/1 is a stream cipher used to provide over-the-air
communication privacy in the GSM cellular telephone
standard. It is one of seven algorithms which were specified for
GSM use. It was initially kept secret, but became public
knowledge through leaks and reverse engineering. A number
of serious weaknesses in the cipher have been identified.
MATHEMATICS OF ASYMMETRIC-KEY CRYPTOGRAPHY
● Prime Numbers : A prime number is a whole number greater than 1, which is only divisible by 1 and itself.
First few prime numbers are : 2 3 5 7 11 13 17 19 23 ….
.
● Co-prime Numbers : In number theory, two integers a and b are coprime, relatively prime or mutually
prime if the only positive integer that evenly divides (is a divisor of) both of them is 1. One says also a is prime
to b or a is coprime with b. Consequently, any prime number that divides one of a or b does not divide the
other. This is equivalent to their greatest common divisor (gcd) being 1.
Example : 6 and 35 are coprime, because the factors of 6, 2 and 3, do not divide 35 evenly. On the other
hand, 6 and 27 are not coprime, because 3 divides both 6 and 27. Another example is 4 and 5: 4 = 2*2*1; 5 =
5*1 (Prime). The only common factor is 1, so they are coprime.
● Composite Numbers : A composite number is a positive integer that can be formed by multiplying two
smaller positive integers. Equivalently, it is a positive integer that has at least one divisor other than 1 and
itself.
Example, the integer 14 is a composite number because it is the product of the two smaller integers 2 × 7.
Likewise, the integers 2 and 3 are not composite numbers because each of them can only be divided by one
and itself.
Importance of Prime Numbers in Cryptography
The modulo operation returns the remainder or signed remainder of a division, after
one number is divided by another (called the modulus of the operation).
Given two positive numbers a and n, a modulo n (abbreviated as a mod n) is the
remainder of the Euclidean division of a by n, where a is the dividend and n is the
divisor.
Congruence Modulo N
For Example :
Therefore, 26 ≡ 11 ( mod 5 )
Some more definitions
In modular arithmetic, the modular additive inverse of x is also defined: it is the number a such that a + x ≡ 0
(mod n). This additive inverse always exists. For example, the inverse of 3 modulo 11 is 8 because it is the
solution to 3 + x ≡ 0 (mod 11).
A modular multiplicative inverse of an integer a is an integer x such that the product ax is congruent to 1 with
respect to the modulus m. In the standard notation of modular arithmetic this congruence is written as
For example, the multiplicative inverse of 3 modulo 10 is 7 because it is the solution to 3 + x ≡ 0 (mod 10).
Primality Testing
Divisibility Method
A simple solution is to iterate through all numbers from 2 to n-1 and for every number check if it
divides n. If we find any number that divides, we conclude that the number is not prime.
Note : There are several methods, but this discussion is restricted to just one method.
x ≡ 1 (mod 5)
x ≡ 2 (mod 7)
x ≡ 3 (mod 9)
x ≡ 4 (mod 11)
Notice that the moduli (5,7,9 & 11) are pairwise relatively prime, as required by the theorem.
We have M = 5 x 7 x 9 x 11 = 3465 and
M1 = M/5 = 693 M2 = M/7 = 495
M3 = M/9 = 385, and M4 = M/11 = 315.
x2 ≡ a ( mod n )
1. Quadratic Residues : In equation, x2 ≡ a ( mod p ), ‘a’ is quadratic residue if the equation has
two solutions
2. Quadratic Non-Residues :In equation, x2 ≡ a ( mod p ), ‘a’ is quadratic residue if the equation
has no solution
Example :
Example :
Every prime number can either be expressed as 4k+1 or 4k+3 for some integer k.
Since a composite number ‘n’ can be expressed as product of prime numbers p1,p2, p3...pk
So we can solve each decomposed equation (if solvable) and find k pairs of answers.
For k pairs of answers, we get 2k set of equations that are solved using the Chinese Remainder Theorem.
Example :
Since 7 & 11 are of the form 4k+3, we can use the method discussed earlier
For example:
2^90 = 1237940039285380274899124224
7^256 = 2213595400046048155450188615474945937162517050260073069916366390524704974007989996848003433
83794038078279445526231260759886736342594056001485602786638194645895120583737911647366324673350968
0721264246243189632348313601
These huge values cause our calculators and computers to return overflow errors.
Even if they didn't, it would take a long time to find the mod of these huge numbers directly.
What can we do to reduce the size of terms involved and make
our calculation faster?
Suppose we want to calculate 2^90 mod 13, but we have a calculator that can't hold any numbers
larger than 2^50.
● Here is a simple divide and conquer strategy: ● combine the parts using multiplication property
→ mod C each part 2^90 mod 13 = (2^50 mod 13 * 2^40 mod 13) mod 13
2^90 mod 13 = 12
Fast modular exponentiation
How can we calculate A^B mod C quickly if B is a power of 2 ?
7^1 mod 13 = 7
7^2 mod 13 = (7^1 *7^1) mod 13 = (7^1 mod 13 * 7^1 mod 13) mod 13
We can substitute our previous result for 7^1 mod 13 into this equation.
7^2 mod 13 = 10
7^4 mod 13 = (7^2 *7^2) mod 13 = (7^2 mod 13 * 7^2 mod 13) mod 13
We can substitute our previous result for 7^2 mod 13 into this equation.
7^4 mod 13 = 9
And so on...
How can we calculate A^B mod C quickly for any B ?
5^2 mod 19 = (5^1 * 5^1) mod 19 = (5^1 mod 19 * 5^1 mod 19) mod 19 5^16 mod 19 = 16
5^4 mod 19 = (5^2 * 5^2) mod 19 = (5^2 mod 19 * 5^2 mod 19) mod 19 5^32 mod 19 = (16 * 16) mod 19 = 256 mod 19
5^4 mod 19 = 17
5^8 mod 19 = (5^4 * 5^4) mod 19 = (5^4 mod 19 * 5^4 mod 19) mod 19 = (5^32 mod 19 * 5^32 mod 19) mod 19
5^8 mod 19 = (17 * 17) mod 19 = 289 mod 19 5^64 mod 19 = (9 * 9) mod 19 = 81 mod 19
5^117 mod 19 = ( (51 mod 19) x (54 mod 19) x (516 mod 19) x (532 mod 19) x (564 mod 19) ) mod 19
5^117 mod 19 = 1
Discrete Logarithm
○ 2x (mod 7) = 4
○ x = 2 or 5 x = {1,..,6}
The discrete logarithm for modulus 7 generates distinct remainders when using base value 3 or 5 and the
remainders are in the range {1,…,6}
● The base values 3 and 5 are called the primitive roots of 7 or generators, often indicated by symbol α. It is
called generator because applying the multiplication operation on one single element (αx), generates all
elements in the discrete group {1, … m -1}
● The word discrete in discrete logarithm refer to the aspect that we are working in a discrete group {1, … m -1}
and not any real numbers (meaning fractions 2.58)
● Calculating 311 mod 17 = x is very easy, but doing the opposite, calculating the discrete logarithm
11 = 3x mod 17 is very difficult. Especially if the modulus is at least 309 digits long.
REMEMBER: CALCULATING A DISCRETE LOGARITHM IS HARD. To solve 11 = 3x mod 17 a computer
needs to try each exponent x = 0, 1, 2, 3 … until the equation matches
● Example: α (generator) = 2 and p (modulus) = 11 discrete group {1, …, p -1}
● This is called a cyclic group of generator α. After a certain number of exponentiations and modulus
operations, we have loop.
● If the remainder has value 1, the cycle starts all over again in the same order