Module 2(Part 2)
Module 2(Part 2)
STANDARD (AES)
FINITE FIELD ARITHMETIC
RING
A set of “numbers” with two operations (addition and multiplication) which are:
a) An abelian group with addition operation
b) Multiplication:
has closure
is associative
distributive over addition: a(b+c) = ab + ac
A ring is a set in which we can do addition, subtraction, and multiplication
without leaving the set.
If multiplication operation is commutative, it forms a commutative ring
If multiplication operation has inverses and no zero divisors, it forms an integral
domain
FIELD
A field is a commutative ring in which every nonzero element is invertible.
A field denoted as F is a structure that supports two pairs of operations:
addition/subtraction
multiplication/division
There is one exception: division by zero is not allowed.
▪ A field is a set in which we can do addition, subtraction,
multiplication, and division without leaving the set
▪ Division is defined with the following rule: a /b = a (b-1 )
Examples of fields are rational numbers, real numbers, complex numbers.
FINITE FIELD
A finite field is a field with a finite number of elements.
Cryptographic algorithms and protocols process messages as numbers
or elements in a finite space.
Finite fields play a crucial role in many cryptographic algorithms
An example of a finite field is the set Zp consisting of all the integers {0,
1, . . . . , p - 1}, where p is a prime number and in which arithmetic is
carried out modulo p
FINITE, OR GALOIS FIELDS
For a field to be finite, the number of elements should be pn, where p is a
prime and n is a positive integer.
The finite field of order pn is generally written GF(pn )
GF stands for Galois Field, in honor of the mathematician who first
studied finite fields
A finite field is also known as a Galois* Field
We often use the fields:
GF(p)
GF(2n)
Example: GF(5)
FINITE FIELDS OF THE FORM GF(2N)
GF(2n) Fields
Uses a set of 2n elements
The elements in this set are n-bit words.
For example, if n = 3, the set is
{000, 001, 010, 011, 100, 101, 110, 111}
Define a set of n-bit words and two new operations that satisfy the
properties defined for a field.
AN EXAMPLE OF A GF(22 ) FIELD
17
ADVANCED ENCRYPTION STANDARD (AES)
Needed a better replacement for DES
NIST called for proposals in 1997 with criteria: Security, computational
efficiency, memory requirements, hardware and software suitability, and
flexibility with 128, 256, 256 keys.
Selected Rijndael in Nov 2001
The Advanced Encryption Standard (AES) is a symmetric key block cipher
Uses 128-bit data & 128/192/256-bit keys
AES was published as FIPS 197 in December 2001.
Now widely available commercially 18
VIT/SCOPE/BCSE309-CNS/MODULE 2
AES…
AES is a non-Feistel cipher that encrypts and decrypts a plaintext block of 128 bits
(16 bytes).
The cipher consists of N rounds, where the number of rounds depends on the key
length
AES has defined three versions, with 10, 12, and 14 rounds.
The key size can be 16, 24 or 32 bytes (128, 192, or 256 bits), depends on the
number of rounds
The algorithm is referred to as AES-128,AES-192, or AES-
256, depending on the key length.
VIT/SCOPE/BCSE309-CNS/MODULE 2 19
▪ AES operates on 8-bit bytes.
▪ The addition of two bytes is defined as the bitwise XOR operation.
▪ Multiplication of two bytes is defined as multiplication in the finite field
GF(28), with the irreducible polynomial m(x) = x8+ x4 +x3 +x + 1.
VIT/SCOPE/BCSE309-CNS/MODULE 2 20
GENERAL DESIGN OF AES ENCRYPTION CIPHER
VIT/SCOPE/BCSE309-CNS/MODULE 2 21
AES STRUCTURE
23
VIT/SCOPE/BCSE309-CNS/MODULE 2
STRUCTURE OF EACH ROUND
The first N - 1 rounds consist of four distinct
transformation functions:
SubBytes
ShiftRows
MixColumns
AddRoundKey
The final round contains only 3 transformations
There is an initial single transformation
(AddRoundKey) before the first Round (Round 0).
VIT/SCOPE/BCSE309-CNS/MODULE 2 25
AES Encryption Round
AES TRANSFORMATION FUNCTIONS
01 02 03 04
Substitute Shift Rows Mix Columns Add Round
Bytes Key
VIT/SCOPE/BCSE309-CNS/MODULE 2 27
SUBSTITUTE BYTES
TRANSFORMATION
The forward
substitute byte
transformation,
called SubBytes, is a
simple table lookup.
AES defines a 16 * 16
matrix of byte values,
called an S-box, that
contains a permutation
of all possible 256 8-bit
values
VIT/SCOPE/BCSE309-CNS/MODULE 2 28
SUBSTITUTE BYTES TRANSFORMATION
S-Box
VIT/SCOPE/BCSE309-CNS/MODULE 2 29
SUBSTITUTE BYTES TRANSFORMATION…
Inverse S-Box
SUBSTITUTE BYTES TRANSFORMATION…
EXAMPLE FOR SUBBYTES TRANSFORMATION
VIT/SCOPE/BCSE309-CNS/MODULE 2 31
TRANSFORMATION USING GF(28) FIELD
• Transformation
TRANSFORMATION using
USING THE GF(28) the
FIELD GF(28)
field with the irreducible
polynomial
x8 + x4 + x3+ x + 1
• The SubBytes transformation
repeats a routine, called subbyte,
16 times.
• The InvSubBytes repeats a routine
called invsubbyte.
• Each iteration transforms one byte.
• Multiplication and addition of bits
are done in GF(2).
SHIFT ROWS
TRANSFORMATION
VIT/SCOPE/BCSE309-CNS/MODULE 2 33
SHIFT ROWS TRANSFORMATION…
VIT/SCOPE/BCSE309-CNS/MODULE 2 34
MIX COLUMN TRANSFORMATION
VIT/SCOPE/BCSE309-CNS/MODULE 2 35
MIX COLUMN
TRANSFORMATION…
VIT/SCOPE/BCSE309-CNS/MODULE 2 36
MIX COLUMN TRANSFORMATION…
VIT/SCOPE/BCSE309-CNS/MODULE 2 37
ADD ROUND KEY
TRANSFORMATION
AddRoundKey also
proceeds one column
at a time
Adds a round key word
with each state column
matrix
The 128 bits of State
are bitwise XORed
with the 128 bits of the
round key.
VIT/SCOPE/BCSE309-CNS/MODULE 2 38
ADD ROUND KEY TRANSFORMATION…
VIT/SCOPE/BCSE309-CNS/MODULE 2 39
Inputs for Single AES Round
VIT/SCOPE/BCSE309-CNS/MODULE 2 40
AES KEY
EXPANSION
The AES key
expansion algorithm
takes as input a four-
word (16-byte) key
and produces a linear
array of 44 words
(176 bytes)
VIT/SCOPE/BCSE309-CNS/MODULE 2 41
AES KEY EXPANSION…
VIT/SCOPE/BCSE309-CNS/MODULE 2 42
Key expansion in AES-128
43
AES KEY EXPANSION…
Round Constants
Each round constant, RCon, is a 4-byte value in which the rightmost three
bytes are always zero.
The round constant is different for each round and is defined as
Rcon[j] = (RC[j], 0, 0, 0), with RC[1] = 1, RC[j] = 2 . RC[j - 1]
and with multiplication defined over the field GF(28).
RCon constants
VIT/SCOPE/BCSE309-CNS/MODULE 2 44
EXAMPLE ROUND KEY CALCULATION
VIT/SCOPE/BCSE309-CNS/MODULE 2 51
ANALYSIS OF AES
VIT/SCOPE/BCSE309-CNS/MODULE 2 54
INTERNATIONAL DATA
ENCRYPTION ALGORITHM (IDEA)
VIT/SCOPE/BCSE309-CNS/MODULE 2 55
INTERNATIONAL DATA ENCRYPTION ALGORITHM (IDEA)
A block cipher that operates on 64-bit data and key of 128 bits
Invented by Xuejia and James Massey in 1990.
Design principle is the “mixing of arithmetic operations from different algebraic
groups”
Operations involved are:
Exclusive OR
Addition modulo 216
Multiplication modulo 216 +1
VIT/SCOPE/BCSE309-CNS/MODULE 2 56
64-bit Plaintext Overall Structure of IDEA
X1 X2 X3 X4
K1
Round 1
K6
K7
Round 2
K12 Subkey
Generation 128 Bit Key
K43 Algorithm
Round 8
K48
K49
Output Transformation
VIT/SCOPE/BCSE309-CNS/MODULE 2 57
K52
Y1 Y2 Y3 Y4
64-bit ciphertext
ROUND TRANSFORMATION OF IDEA
VIT/SCOPE/BCSE309-CNS/MODULE 2 59
ROUND TRANSFORMATION OF IDEA…
60
ROUND TRANSFORMATION OF IDEA
11. XOR the results of steps 1 and 9.
12. XOR the results of steps 3 and 9
13. XOR the results of steps 2 and 10
14. Bitwise XOR the results of steps 4 and 10.
The output of steps 11,12,13, and 14 are stored in 4 words of 16-bits each : Y1,Y2,Y3,
Y4
Blocks Y2 and Y3 are swapped
The resultant 4 blocks are the output of a round of IDEA
Swapping occurs for every round until the final round (round 8).
61
Single Round of IDEA
x1 x2 x3 x4
VIT/SCOPE/BCSE309-CNS/MODULE 2 62
Y1 Y2 Y3 Y4
Final Output Transformation Stage of IDEA
Y1 Y2 Y3 Y4
C1 C2 C3 C4
63
SUBKEY GENERATION
VIT/SCOPE/BCSE309-CNS/MODULE 2 64
DECRYPTION IN IDEA
The decryption process uses the same steps as the encryption process.
However, different 16-bit key subblocks are generated.
The subkeys are reversed ( Either multiplicative or additive inverse of the
encryption keys)
VIT/SCOPE/BCSE309-CNS/MODULE 2 65
MODES OF OPERATION
MODES OF OPERATION
VIT/SCOPE/BCSE309-CNS/MODULE 2 67
MODES OF OPERATION
Counter (CTR)
69
ELECTRONIC CODE BOOK (ECB) MODE
Plaintext is handled one block at a time and each block of plaintext is encrypted
using the same key
The term codebook is used because, for a given key, there is a unique ciphertext for
every b-bit block of plaintext.
ECB mode can be defined as:
ECB mode is used only to secure messages shorter than a single block of underlying
cipher
If the same b-bit block of plaintext appears more than once in the message, it always
produces the same ciphertext.
For lengthy messages, the ECB mode may not be secure.
VIT/SCOPE/BCSE309-CNS/MODULE 2 70
71
ECB MODE…
The input to the encryption algorithm is the XOR of the current plaintext block and
the preceding ciphertext block; the same key is used for each block.
The input to the encryption function for each plaintext block bears no fixed
relationship to the plaintext block.
To produce the first block of ciphertext, an initialization vector (IV) is XORed with
the first block of plaintext.
The IV is a data block that is the same size as the cipher block.
The IV must be known to both the sender and receiver but be unpredictable by a
third party.
74
CBC MODE…
In CBC mode, a single bit error in ciphertext block Cj during transmission may
create error in most bits in plaintext block Pj during decryption. However, this single
error toggles only one bit in plaintext block Pj+1 (the bit in the same location).
CBC is an appropriate mode for encrypting messages of length greater than b-bits.
CBC mode can be used for achieving confidentiality and authentication.
EXAMPLE
Using the CBC mode of operation, encrypt the given plaintext blocks
using the provided key and IV.
Block size: 16 bits
Initialization Vector (IV): 1011011100110101
Key: 1010101010101010
Plaintext block 1: 1100101011110010
Plaintext block 2: 0011101010101001
CIPHER FEEDBACK MODE
Three modes make it possible to
For AES, DES, or any block cipher, convert a block cipher into a
encryption is performed on a block stream cipher:
of b bits
In the case of DES b = 64 Cipher feedback
In the case of AES b = 128 (CFB) mode
mode
CFB MODE…
As with CBC, the units of plaintext are chained together, so that the ciphertext of
any plaintext unit is a function of all the preceding plaintext.
Rather than blocks of b bits, the plaintext is divided into segments of s bits.
The input to the encryption function is a b-bit shift register that is initially set to
some initialization vector (IV).
Encryption is done by exclusive-or ing an s-bit plaintext block with s-bits of the shift
register.
Decryption is done by exclusive-or ing an s-bit ciphertext block withs bits of the
shift register.
In CFB mode, encipherment and decipherment use the encryption function of the
underlying block cipher.
CFB MODE…
In CFB, a single bit error in ciphertext block Cj during transmission creates a single
bit error (at the same position) in plaintext block Pj.
However, most of the following plaintext blocks are in error (with 50 percent
probability) as long as some bits of Cj are still in the shift register.
CFB MODE…
Advantages
No padding is required
The system does not have to wait until it has received a large block of data (64 bits
or 128 bits) before starting the encryption.
Disadvantages
CFB is less efficient than CBC or ECB, because it needs to apply the encryption
function of the underlying block cipher for each small block of size.
EXAMPLE
Using the CFB mode of operation, encrypt the given plaintext blocks using the
provided key and IV.
Block size: n=16 bits and s=8 bits
Initialization Vector (IV): 1011011100110101
Key: 1010101010101010
Plaintext block 1: 11001011
Plaintext block 2: 10101001
OUTPUT FEEDBACK (OFB) MODE
VIT/SCOPE/BCSE309-CNS/MODULE 2
OFB MODE…
Consider a block cipher with a block size of 16 bits. Using the Output
Feedback (OFB) mode of operation, the encryption process starts with
an Initialization Vector (IV) of 1011011010110110. The key is
1100110011001100. Encrypt the plaintext 1111000011110000
1100101011110010 using the provided IV and key.
COUNTER MODE
In the counter (CTR) mode, there is no feedback.
A counter equal to the plaintext block size is used, counter value must be different
for each plaintext block that is encrypted.
An n-bit counter is initialized to a pre-determined value (IV) and incremented by 1
for subsequent block(mod 2b).
For encryption, the counter is encrypted and then XORed with the plaintext block
to produce the ciphertext block; there is no chaining.
For decryption, the same sequence of counter values is used, with each encrypted
counter XORed with a ciphertext block to recover the corresponding plaintext
block.
As with the OFB mode, the initial counter value must be a nonce
92
VIT/SCOPE/BCSE309-CNS/MODULE 2
COUNTER MODE
A single error in the ciphertext affects only the corresponding bit in the
plaintext.
ADVANTAGES OF CTR MODE
Hardware Software
Preprocessing
efficiency Efficiency
Random Provable
Simplicity
Access Security
EXAMPLE
Using the Counter (CTR) mode of operation, encrypt the given plaintext
using the provided key and IV.
Block size: 8 bits
Key: 01011011
97
RANDOM BIT GENERATION AND STREAM CIPHERS
RANDOM NUMBERS
VIT/SCOPE/BCE309-CNS/MODULE 2 99
REQUIREMENTS OF RANDOM NUMBERS
Randomness
There are two
distinct requirements
for a sequence of
random numbers:
Unpredictability
VIT/SCOPE/BCE309-CNS/MODULE 2 100
RANDOMNESS
VIT/SCOPE/BCE309-CNS/MODULE 2 103
TRUE RANDOM NUMBER GENERATOR (TRNG)
VIT/SCOPE/BCE309-CNS/MODULE 2 105
PSEUDORANDOM NUMBER GENERATOR (PRNG)
Two different forms of PRNG
Takes as input a fixed value, called the seed, and
produces a sequence of output bits using a
deterministic algorithm Pseudorandom Pseudorandom
number function (PRF)
Quite often the seed is generated by a TRNG generator • Used to produce a
• An algorithm that is pseudorandom
string of bits of
The output bit stream is determined solely by the used to produce an
open-ended some fixed length
• Examples are
input value or values, so an adversary who knows sequence of bits
• Input to a symmetric
encryption keys and
the algorithm and the seed can reproduce the symmetric stream
cipher is a common nonces
application for an
entire bit stream open-ended
sequence of bits
Other than the number of bits produced there is
no difference between a PRNG and a PRF 106
VIT/SCOPE/BCE309-CNS/MODULE 2
Source of Context-
true specific
randomness Seed Seed values
VIT/SCOPE/BCE309-CNS/MODULE 2
PRNG REQUIREMENTS
The generated bit stream needs to appear random even though it is deterministic
There is no single test that can determine if a PRNG generates numbers that have
the characteristic of randomness
If the PRNG exhibits randomness based on multiple tests, then it can be assumed
to satisfy the randomness requirement
NIST SP 800-22 specifies that the tests should seek to establish three characteristics:
Uniformity
Scalability
Consistency
VIT/SCOPE/BCE309-CNS/MODULE 2 109
UNPREDICTABILITY
A stream of pseudorandom numbers should exhibit two forms of unpredictability:
Forward unpredictability
If the seed is unknown, the next output bit in the sequence should be unpredictable in spite of any knowledge of
previous bits in the sequence
Backward unpredictability
It should not be feasible to determine the seed from knowledge of any generated values
No correlation between a seed and any value generated from that seed should be evident
Each element of the sequence should appear to be the outcome of an independent random event whose
probability is 1/2
The same set of tests for randomness also provides a test of unpredictability
A random sequence will have no correlation with a fixed value (the seed)
VIT/SCOPE/BCE309-CNS/MODULE 2 111
Entropy
source
SEED REQUIREMENTS
True random
The seed that serves as input to the PRNG number generator
must be secure and unpredictable (TRNG)
Pseudorandom
bit stream 112
113
VIT/SCOPE/BCE309-CNS/MODULE 2
PSEUDORANDOM NUMBER GENERATOR
VIT/SCOPE/BCE309-CNS/MODULE 2 114
ALGORITHM DESIGN
Algorithms fall into two categories:
Purpose-built algorithms
Algorithms designed specifically and solely for the purpose of generating pseudorandom bit
streams
Algorithms based on existing cryptographic algorithms
Have the effect of randomizing input data
Example
Assume that a = 4, b = 5, n = 17, and x0 = 7.
The sequence is 16, 1, 9, 7, 16, 1, 9, 7, …,
This is a poor pseudorandom sequence; the period is only 4.
VIT/SCOPE/BCE309-CNS/MODULE 2 118
BLUM BLUM SHUB (BBS) GENERATOR
Has the strongest public proof of its cryptographic strength of any purpose-
built algorithm
Referred to as a cryptographically secure pseudorandom bit generator (CSPRBG)
A CSPRBG is defined as one that passes the next-bit-test
if there is not a polynomial-time algorithm that, on input of the first k bits of an
output sequence, can predict the (k + 1)st bit with probability significantly greater
than 1/2
The security of BBS is based on the difficulty of factoring n
VIT/SCOPE/BCE309-CNS/MODULE 2 119
BLUM BLUM SHUB (BBS) GENERATOR…
VIT/SCOPE/BCE309-CNS/MODULE 2 120
BLUM BLUM SHUB (BBS) GENERATOR…
1. Find two large primes numbers p and q in the form 4k + 3, where k is an integer
[(or) 𝑝 ≡ 𝑞 ≡ 3(𝑚𝑜𝑑4)]
2. Select the modulus n = p × q.
3. Choose a random integer r which is coprime to n.
Then the BBS generator produces a sequence of bits Bi as:
4. Calculate the seed as x0 = r2 mod n.
5. Generate the sequence as xi+1 = xi2 mod n.
6. Extract the least significant bit of the generated random integer as the random bit.
PRNG USING BLOCK CIPHER MODES OF OPERATION
Two approaches that use a block cipher to build a PNRG have gained
widespread acceptance:
CTR mode- Recommended in NIST SP 800-90, ANSI standard X.82, and RFC 4086
OFB mode- Recommended in X9.82 and RFC 4086
VIT/SCOPE/BCE309-CNS/MODULE 2 124
1
+ V V
K Encrypt K Encrypt
VIT/SCOPE/BCE309-CNS/MODULE 2
PRACTICE
1. Using a multiplier of 57 and modulus 231 - 1, generate five session keys (X1, X2, X3,
X4, X5) using the pseudo-random number generator algorithm. Assume the seed
value is 10135.
2. Select two primes, P and Q, so that P=Q=3 mod 4 of 3 digits each. Assume seed
value as 101355. Using the Blum Blum Shub generator, generate two session keys.
STREAM CIPHERS
VIT/SCOPE/BCE309-CNS/MODULE 2 128
INTRODUCTION TO STREAM CIPHERS
VIT/SCOPE/BCE309-CNS/MODULE 2 129
INTRODUCTION TO STREAM CIPHERS…
VIT/SCOPE/BCE309-CNS/MODULE 2 130
EXAMPLE: ONE TIME PAD
The simplest and the most secure type of synchronous stream cipher
Introduced by AT&T engineer named Gilbert Vernam in 1918.
His system works on binary data rather than letters.
A one-time pad cipher uses a key stream that is randomly chosen for each
encipherment.
The ciphertext is generated by performing the bitwise XOR of the plaintext and the
key
VIT/SCOPE/BCE309-CNS/MODULE 2 131
ONE TIME PAD …
VIT/SCOPE/BCE309-CNS/MODULE 2 132
ONE TIME PAD …
VIT/SCOPE/BCE309-CNS/MODULE 2 133
EXAMPLE
VIT/SCOPE/BCE309-CNS/MODULE 2 135
136
STREAM CIPHERS…
The keystream is combined one byte at a time with the plaintext stream using the bitwise exclusive-
OR (XOR) operation.
Example: If the next byte generated by the generator is 01101100 and the next plaintext byte is
11001100, then the resulting ciphertext byte is
11001100 plaintext
01101100 key stream
10100000 ciphertext
Decryption requires the use of the same pseudorandom sequence:
10100000 ciphertext
01101100 key stream
11001100 plaintext
VIT/SCOPE/BCE309-CNS/MODULE 2 137
STREAM CIPHER DESIGN CONSIDERATIONS
• A pseudorandom number generator uses a function that produces a
The encryption sequence
deterministic stream of bits that eventually repeats; the longer the
should have a large period period of repeat the more difficult it will be to do cryptanalysis
VIT/SCOPE/BCE309-CNS/MODULE 2 139
RC4
Designed in 1987 by Ron Rivest for RSA Security
Variable key-size stream cipher with byte-oriented operations
Based on the use of a random permutation
Eight to sixteen machine operations are required per output byte and the cipher can be
expected to run very quickly in software
RC4 is used in the WiFi Protected Access (WPA) protocol that are part of the IEEE
802.11 wireless LAN standard
It is optional for use in Secure Shell (SSH) and Kerberos
RC4 was kept as a trade secret by RSA Security until September 1994 when the RC4
algorithm was anonymously posted on the Internet on the Cypherpunks anonymous
remailers list
VIT/SCOPE/BCE309-CNS/MODULE 2 140
RC4…
Initial Permutation of S
VIT/SCOPE/BCE309-CNS/MODULE 2 142
RC4…
Stream Generation
143
VIT/SCOPE/BCE309-CNS/MODULE 2
144
VIT/SCOPE/BCE309-CNS/MODULE 2
STRENGTH OF RC4
A fundamental vulnerability was revealed in the RC4 key scheduling algorithm that
reduces the amount of effort to discover the key
Recent cryptanalysis results exploit biases in the RC4 keystream to recover
repeatedly encrypted plaintexts
As a result of the discovered weaknesses the IETF issued RFC 7465 prohibiting the
use of RC4 in TLS
In its latest TLS guidelines, NIST also prohibited the use of RC4 for government use
146
VIT/SCOPE/BCE309-CNS/MODULE 2
EXAMPLE
Consider the following State vector, key, and plaintext values and perform RC4
encryption
S=[0 1 2 3 4 5 6 7]
K=[2 3 4 5]
P= [ 4 5 6 7]
SOLUTION
Initialization
S=[0 1 2 3 4 5 6 7]
T=[ 2 3 4 5 2 3 4 5]
After Initial Permutation of S =[ 5 7 3 0 2 1 4 6 ]
Stream Generation
Key Stream k =[ 1 4 3 2 ]→ 0001 0100 0011 0010
Plaintext P = [ 4 5 6 7] → 0100 0101 0110 0111
Ciphertext = P XOR k → 0101 0001 0101 0101 = [5 1 5 5]