CNS - Module 2 Updated
CNS - Module 2 Updated
MODULE 2
Block Ciphers and the Data Encryption Standard (DES) algorithm. Differential and linear
cryptanalysis, triple DES. Block cipher design principles, Block cipher modes of operation,
Advanced Encryption Standard (AES), Stream Ciphers: RC4.
❖ A stream cipher is one that encrypts a digital data stream one bit or one byte at a
time. Ex: Vernam Cipher
❖ In the ideal case, a one-time pad version of the Vernam cipher would be used, in
which the keystream is as long as the plaintext bit stream.
❖ If the cryptographic keystream is random, then this cipher is unbreakable.
❖ The keystream must be provided to both users in advance via some independent
and secure channel.
❖ The bit-stream generator must be implemented as an algorithmic procedure, so that
the cryptographic bit stream can be produced by both users as shown in figure 1
❖ In this approach, the bit-stream generator is a key-controlled algorithm and must
produce a bit stream that is cryptographically strong.
❖ Now, the two users need to share only the generating key, and each can produce
the keystream.
DES Encryption
❖ There are two inputs to the encryption function: the plaintext to be encrypted and
the key.
❖ The left and right halves of each 64-bit intermediate value are treated as separate 32-
bit quantities, labeled L (left) and R (right).
❖ The first and last bits of the input to box Si form a 2-bit binary number to select one of
four substitutions defined by the four rows in the table for Si .
❖ The middle four bits select one of the sixteen columns.
❖ The decimal value in the cell selected by the row and column is then converted to its
4-bit representation to produce the output.
❖ For example, in S1, for input 011001, the row is 01 (row 1) and the column is 1100
(column 12).The value in row 1, column 12 is 9, so the output is 1001.
Key Generation
DES Decryption
❖ Decryption uses the same algorithm as encryption, except that the application of the
subkeys is reversed.
1 The Use of 56-bit Keys: With a key length of 56 bits, there are 256 possible keys,
which is approximately 7.2 * 1016 keys. Thus, a brute-force attack is impossible.
With Brute-force on average, a single machine performing one DES encryption per
microsecond would take more than a thousand years to break the cipher.
2 The Nature of the DES algorithm: The cryptanalysis is possible by exploiting the
characteristics of the DES algorithm. The usage of 8 substitution table or S-boxes
that are used in each iteration. The design criteria of these boxes for the entire
algorithm in nor public.
3 Timing Attacks: Information about key or plain text is obtained by observing how
long it takes a given implementation to perform decryption. A timing attack exploits
the fact that an encryption or decryption algorithm often takes slightly different
amounts of time on different inputs.
❖ The primary concern with DES is its vulnerability to brute-force attack because of its
short 56-bits key length
❖ Thus, a cryptanalytic attack on DES has increased
❖ Differential cryptanalysis is the attack that is capable of breaking DES in less than 255
encryptions.
❖ In differential cryptanalysis, we start with two messages, m and m', with a known
XOR difference ∆m =m m' , and consider the difference between the intermediate
message halves: ∆mi mi' .Then we have
then we suspect that all the probable patterns at all the intermediate rounds are
correct.
✔ With that assumption, key bits can be deducted.
✔ This procedure must be repeated many times to determine all the key bits.
❖ For a cipher with n-bit plaintext and ciphertext blocks and an m-bit key, let the
plaintext block be labeled P[1]....P[n], the cipher text block C[1]....C[n], and the key
K[1]....K[m], Then define
❖ The objective of linear cryptanalysis is to find an effective linear equation of the form:
where x=0 or 1;1 ≤a; b ≤n; c ≤m; and where the α, β and γ terms represent fixed, unique
bit locations that holds with probability p ≠ 0.5.
❖ Once a proposed relation is determined, the procedure is to compute the results of the
left-hand side of the preceding equation for a large number of plaintext–ciphertext
pairs.
❖ If the result is 0 more than half the time, assume K[γ1,γ2.....γC]=0 .
❖ If it is 1 most of the time, assume K[γ1,γ2.....γC]=1.
❖ This gives us a linear equation on the key bits
✔ Three critical aspects of block cipher design: the number of rounds, design of the
function F, and the key scheduling.
1 Number of Rounds
✔ The greater the number of rounds, the more difficult it is to perform cryptanalysis,
even for a relatively weak F.
✔ In general, the criterion should be that the number of rounds is chosen so that known
cryptanalytic efforts require greater effort than a simple brute-force key search attack
✔ This criterion was certainly used in the design of DES.
✔ For DES with 16 rounds, a differential cryptanalysis attack is slightly less efficient
than brute force attack
✔ The differential cryptanalysis attack requires 255.1 operations, whereas brute force
requires 255
2 Design of Function F
✔ Design of Function F includes the criteria for F and S-Box Design
✔ The function F should be nonlinear.
✔ The more nonlinear F, the more difficulty for cryptanalysis
✔ General Criteria is a change in one bit of the input should produce a change in many
bits of the output
✔ Several criteria are used for designing function F:
● Strict Avalanche Criterion (SAC): Which states that any output bit j of an S-box
should change with probability 1/2 when any single input bit i is inverted for all i,j.
Although SAC is expressed in terms of S-boxes, a similar criterion could be applied
to F as a whole. This is important when considering designs that do not include S-
boxes.
● Bit Independent Criterion (BIC): Which states that output bits j and k should
change independently when any single input bit i is inverted for all i, j and k.
✔ A block cipher takes a fixed-length block of text of length b bits and a key as input and
produces a b-bit block of ciphertext.
✔ If the amount of plaintext to be encrypted is greater than b bits, then the block cipher
can be used by breaking the plaintext up into b-bit blocks.
✔ When multiple blocks of plaintext are encrypted using the same key, a number of
security issues arise.
✔ To apply a block cipher in a variety of applications, five modes of operation have been
defined.
✔ A mode of operation is a technique for enhancing the effect of a cryptographic
algorithm or adapting the algorithm for an application, such as applying a block cipher
to a sequence of data blocks or a data stream.
✔ These modes are intended for use with any symmetric block cipher, including triple
DES and AES and is shown in table 2.
✔ The ECB method is ideal for a short amount of data, such as an encryption key. Thus,
to transmit a DES or AES key securely, ECB is the appropriate mode to use.
✔ The most significant characteristic of ECB is that 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.
✔ The input to the encryption function for each plaintext block has no fixed relationship
to the plaintext block
✔ The CBC mode requires that the last block be padded to a full b bits if it is a partial
block.
✔ For decryption, each cipher block is passed through the decryption algorithm.
✔ The result is XORed with the preceding ciphertext block to produce the plaintext block.
✔ It can be shown as:
✔ The IV(Initialisation Vector) is a data block that is that same size as the cipher block
✔ To produce the first block of ciphertext, a IV is XORed with the first block of plaintext.
✔ On decryption, the IV is XORed with the output of the decryption algorithm to recover
the first block of plaintext.
✔ CBC mode can be defined as
✔ The IV must be known to both the sender and receiver but be unpredictable by a third
party
✔ For maximum security, the IV should be protected against unauthorized changes. This
could be done by sending the IV using ECB encryption
✔ Block cipher can be converted to stream cipher using one of the 3 modes: Cipher
Feedback(CFB) mode, output feedback(OFB) mode and Counter(CTR) mode
✔ A stream cipher eliminates the need to pad a message to be an integral number of
blocks. It also can operate in real time.
✔ Property of Stream cipher: Ciphertext is of same length of plaintext. Thus, if 8-bit
characters are being transmitted, each character should be encrypted to produce a
ciphertext output of 8 bits
✔ Figure 9 shows the CFB mode.
✔ In the figure 9, it is assumed that the unit of transmission is s bits; a common value
is s=8 .
✔ 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.
✔ In this case, rather than blocks of b bits, the plaintext is divided into segments of s
bits.
✔ For Encryption, the input to the encryption function is a b-bit shift register that is
initially set to some initialization vector (IV).
✔ The leftmost (most significant) s bits of the output of the encryption function are
XORed with the first segment of plaintext P1 to produce the first unit of ciphertext C1,
which is then transmitted.
✔ In addition, the contents of the shift register are shifted left by s bits, and is placed in
the rightmost (least significant) bits of the shift register. This process continues until
all plaintext units have been encrypted.
✔ For Decryption, the same scheme is used, except that the received ciphertext unit is
XORed with the output of the encryption function to produce the plaintext unit.
✔ Let MSBs(X) be defined as the most significant s bits of X .Then
✔ As shown in figure 10, it is the output of the encryption function that is fed back to
the shift register in OFB, whereas in CFB, the ciphertext unit is fed back to the shift
register.
✔ The other difference is that the OFB mode operates on full blocks of plaintext and
ciphertext, not on an s-bit subset
✔ Encryption can be expressed as
Advantages
● Hardware Efficiency: Encryption (or decryption) in CTR mode can be done in
parallel on multiple blocks of plaintext or ciphertext. For the chaining modes, the
algorithm must complete the computation on one block before beginning on the next
block. This limits the maximum throughput of the algorithm to the reciprocal of the
time for one execution of block encryption or decryption. In CTR mode, the
throughput is only limited by the amount of parallelism that is achieved.
● Software Efficiency: Because of the opportunities for parallel execution in CTR
mode, processors that support parallel features, such as aggressive pipelining,
multiple instruction dispatch per clock cycle, a large number of registers, and SIMD
instructions, can be effectively utilized.
● Preprocessing: The execution of the underlying encryption algorithm does not
depend on input of the plaintext or ciphertext. Therefore, if sufficient memory is
available and security is maintained, pre-processing can be used to prepare the
output of the encryption boxes that feed into the XOR functions
● Random Access: The ith block of plaintext or ciphertext can be processed in random-
access fashion. There may be applications in which a ciphertext is stored and it is
ShiftRows Transformation
➢ The first row of State is not altered. For the second row, a 1-byte circular left shift
is performed. For the third row, a 2-byte circular left shift is performed. For the
fourth row, a 3-byte circular left shift is performed
➢ The inverse shift row transformation, called InvShiftRows, performs the circular
shifts in the opposite direction for each of the last three rows, with a 1-byte circular
right shift for the second row, and so on.
➢ The shift row transformation is more substantial than it may first appear.
➢ This is because the State, as well as the cipher input and output, is treated as an
array of four 4-byte columns.
➢ Thus, on encryption, the first 4 bytes of the plaintext are copied to the first column
of State, and so on.
➢ Furthermore, the round key is applied to State column by column. Thus, a row
shift moves an individual byte from one column to another, which is a linear
distance of a multiple of 4 bytes. Also note that the transformation ensures that
the 4 bytes of one column are spread out to four different columns as shown in
figure 16.
➢ Each element in the product matrix is the sum of products of elements of one row
and one column.
AddRoundKey Transformation
➢ In the forward add round key transformation, called AddRoundKey, the 128 bits
of State are bitwise XORed with the 128 bits of the round key.
➢ As shown in Figure 18, the operation is viewed as a column wise operation between
the 4 bytes of a State column and one word of the round key; it can also be viewed
as a byte-level operation.
➢ The inverse add round key transformation is identical to the forward add round
key transformation, because the XOR operation is its own inverse.
➢ The add round key transformation is as simple as possible and affects every bit of
State. The complexity of the round key expansion, plus the complexity of the other
stages of AES, ensure security.
➢ The AES key expansion algorithm takes as input a four-word (16-byte) key and
produces a linear array of 44 words (176 bytes).This is sufficient to provide a four-
word round key for the initial AddRoundKey stage and each of the 10 rounds of the
cipher.
➢ The key is copied into the first four words of the expanded key.
RC4 is a stream cipher and variable length key algorithm. This algorithm encrypt one
byte at a time (or larger units on a time).
A key input is pseudorandom bit generator that produces a stream 8-bit number that
is unpredictable without knowledge of input key, The output of generator is called key-
stream, is combined one byte at a time with the plaintext stream cipher using X-OR
operation.
Example:
RC4 Encryption
RC4 Decryption
Key-Generation Algorithm:
A variable-length key of from 1 to 256 byte is used to initialize a 256-byte state vector
S, with elements S[0] to S[255]. For encryption and decryption, a byte k is generated
from S by selecting one of te 255 entries in systematic fashion, then the entries in S
are permuted again.
● Key-Scheduling Algorithm:
Initialization: The entries of S are set equal to the values from 0 to 255 in ascending
order, a temporary vector T, is created.
for
i = 0 to 255 do S[i] = i;
we use T to produce the initial permutation of S. Starting with S[0] to S[255], and for
each S[i] algorithm swap it with another byte in S according to a scheme dictated by
T[i], but S will still contain values from 0 to 255 :
j = 0;
for
i = 0 to 255 do
Swap(S[i], S[j]);
i, j = 0;
while (true)
i = (i + 1) mod 256;
Swap(S[i], S[j]);