CNS Unit-2
CNS Unit-2
UNIT-2
Secret Key Cryptography
◆ Symmetric encryption transforms plaintext into ciphertext using a secret key and an
encryption algorithm. Using the same key and a decryption algorithm, the plaintext is
recovered from the ciphertext.
◆ The two types of attack on an encryption algorithm are cryptanalysis, based on properties
of the encryption algorithm, and brute-force, which involves trying all possible keys.
Feistel proposed [FEIS73] that we can approximate the ideal block cipher by utilizing
the concept of a product cipher, which is the execution of two or more simple ciphers in
sequence in such a way that the final result or product is cryptographically stronger than any
of the component ciphers.The essence of the approach is to develop a block cipher with a key
length of k bits and a block length of n bits, allowing a total of 2 k possible transformations,
rather than the 2n! transformations available with the ideal block cipher.
In particular, Feistel proposed the use of a cipher that alternates substitutions and
permutations, where these terms are defined as follows:
Substitution: Each plaintext element or group of elements is uniquely replaced by a
corresponding ciphertext element or group of elements.
Permutation: A sequence of plaintext elements is replaced by a permutation of that
sequence. That is, no elements are added or deleted or replaced in the sequence, rather
the order in which the elements appear in the sequence is changed.
FEISTEL CIPHER STRUCTURE The left-hand side of Figure 3.3 depicts the structure
proposed by Feistel.The inputs to the encryption algorithm are a plaintext block of length 2w
bits and a key . The plaintext block is divided into two halves, L 0 and R0. The two halves of
the data pass through n rounds of processing and then combine to produce the ciphertext
block. Each round i has as inputs Li-1 and Ri-1 derived from the previous round, as well as a
subkey Ki derived from the overall K. In general, the subkeys Ki are different from K and
from each othe.
All rounds have the same structure. A substitution is performed on the left half of the data.
This is done by applying a round function F to the right half of the data and then taking the
exclusive-OR of the output of that function and the left half of the data. The round function
has the same general structure for each round but is parameterized by the round subkey Ki.
Permutation is performed that consists of the interchange of the two halves of the data. This
structure is a particular form of the substitution-permutation network (SPN) proposed by
Shannon.
Te exact realization of a Feistel network depends on the choice of the following parameters
and design features:
Block size: Larger block sizes mean greater security (all other things being equal) but
reduced encryption/decryption speed for a given algorithm. The greater security is
achieved by greater diffusion. Traditionally, a block size of 64 bits has been
considered a reasonable tradeoff and was nearly universal in block cipher design.
However, the new AES uses a 128-bit block size.
Key size: Larger key size means greater security but may decrease encryption/
decryption speed. The greater security is achieved by greater resistance to brute-force
attacks and greater confusion. Key sizes of 64 bits or less are now widely considered
to be inadequate, and 128 bits has become a common size.
Number of rounds: The essence of the Feistel cipher is that a single round offers
inadequate security but that multiple rounds offer increasing security. A typical size is
16 rounds.
Subkey generation algorithm: Greater complexity in this algorithm should lead to
greater difficulty of cryptanalysis.
DES (and most of the other major symmetric ciphers) is based on a cipher known as the
Feistel block cipher. This was a block cipher developed by the IBM cryptography researcher
Horst Feistel in the early 70’s. It consists of a number of rounds where each round contains
bit-shuffling, non-linear substitutions (S-boxes) and exclusive OR operations. Most
symmetric encryption schemes today are based on this structure (known as a feistel network).
Overall structure
DES (and most of the other major symmetric ciphers) is based on a cipher known as the
Feistel block cipher.
Looking at the left-hand side of the figure, we can see that the processing of the plaintext
proceeds in three phases.
First, the 64-bit plaintext passes through an initial permutation (IP) that rearranges the
bits to produce the permuted input.
This is followed by a phase consisting of sixteen rounds of the same function, which
involves both permutation and substitution functions. The output of the last
(sixteenth) round consists of 64 bits that are a function of the input plaintext and the
key. The left and right halves of the output are swapped to produce the preoutput.
Finally, the preoutput is passed through a permutation that is the inverse of the initial
permutation function, to produce the 64-bit cipher text. With the exception of the
initial and final permutations, DES has the exact structure of a Feistel cipher,
The right-hand portion of below shows the way in which the 56-bit key is used. Initially, the
key is passed through a permutation function. Then, for each of the sixteen rounds, a subkey
(Ki ) is produced by the combination of a left circular shift and a permutation. The
permutation function is the same for each round, but a different subkey is produced because
of the repeated shifts of the key bits.
Initial Permutation: The initial permutation and its inverse are defined by tables, as shown
in Tables 3.2a and 3.2b, respectively. The tables are to be interpreted as follows. The input to
a table consists of 64 bits numbered from 1 to 64. The 64 entries in the permutation table
contain a permutation of the numbers from 1 to 64. Each entry in the permutation table
indicates the position of a numbered input bit in the output, which also consists of 64 bits.
To see that these two permutation functions are indeed the inverse of each other, consider the
following 64-bit input M:
Below figure shows the internal structure of a single round. Again, begin by focusing on the
left-hand side of the diagram. The left and right halves of each 64-bit intermediate value are
treated as separate 32-bit quantities, labeled L (left) and R (right). As in any classic Feistel
cipher, the overall processing at each round can be summarized in the following formulas:
The round key Ki is 48 bits. The R input is 32 bits. This R input is first expanded to 48 bits by
using a table that defines a permutation plus an expansion that involves duplication of 16 of
the R bits (Table 3.2c).The resulting 48 bits are XORed with K i . This 48-bit result passes
through a substitution function that produces a 32-bit output, which is permuted as defined by
Table 3.2d. The role of the S-boxes in the function F is illustrated in Figure 3.7.The
substitution consists of a set of eight S-boxes, each of which accepts 6 bits as input and
produces 4 bits as output. These transformations are defined in Table 3.3, which is interpreted
as follows : 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 . 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. Each row of an S-box defines a
general reversible substitution. Figure 3.2 may be useful in understanding the mapping. The
figure shows the substitution for row 0 of box S 1. The operation of the S-boxes is worth
further comment. Ignore for the moment the contribution of the key (Ki). If you examine the
expansion table, you see that the 32 bits of input are split into groups of 4 bits and then
become groups of 6 bits by taking the outer bits from the two adjacent groups. For example,
if part of the input word is
... efgh ijkl mnop ...
This becomes ... defghi hijklm lmnopq ...
The outer two bits of each group select one of four possible substitutions (one row of an S-
box). Then a 4-bit output value is substituted for the particular 4-bit input (the middle four
input bits). The 32-bit output from the eight S-boxes is then permuted, so that on the next
round, the output from each S-box immediately affects as many others as possible.
Substitution Boxes S: Have eight S-boxes which map 6 to 4 bits. Each S-box is actually 4
little 4 bit boxes. Outer bits 1 & 6 (row bits) select one rows. inner bits 2-5 (col bits) are
substituted. Result is 8 lots of 4 bits, or 32 bits. Row selection depends on both data & key
KEY GENERATION Returning to above all figures, we see that a 64-bit key is used as
input to the algorithm.The bits of the key are numbered from 1 through 64; every eighth bit is
ignored, as indicated by the lack of shading in Table 3.4a.The key is first subjected to a
permutation governed by a table labeled Permuted Choice One (Table 3.4b)
The resulting 56-bit key is then treated as two 28-bit quantities, labelled C0 and D0. At each
round, Ci-1 and Di-1 are separately subjected to a circular left shift or (rotation) of 1 or 2 bits,
as governed by Table 3.4d.These shifted values serve as input to the next round. They also
serve as input to the part labeled Permuted Choice Two (Table 3.4c), which produces a 48-bit
output that serves as input to the Function F(Ri-1, Ki).
DES DECRYPTION:
Whatever process we following in the encryption that process is used for decryption also but
the order of key is changed on input message (cipher text).
Reverse order of keys are K16, K15 ,……, K1.
Strengths of DES:
The DES is a symmetric key block cipher which takes 64bits cipher text and 56 bit
key as an input and produce 64 bits cipher text as output.
The DES function is made up of P & S boxes
P-boxes transpose bits
S-boxes Substitution bits to generating the cipher text.
The use of 56bits keys: 56 bit key is used in encryption, there are 256 possible keys.
256=7.2×1016 keys, by this a brute force attack on such number of keys is impractical. A
machine performing one DES encryption per microsecond would take more than a thousand
years to break the cipher.
Avalanche Effect:
• key desirable property of an encryption algorithm
• where a change of one input or key bit results in changing approx half output bits
• making attempts to “home-in” by guessing keys impossible
• DES exhibits strong avalanche
Timing Attacks
• attacks actual implementation of cipher
• use knowledge of consequences of implementation to derive knowledge of some/all
subkey bits
• specifically use fact that calculations can take varying times depending on the value
of the inputs to it
• particularly problematic on smartcards
Analytic Attacks
• now have several analytic attacks on DES
Triple DES:
Double DES:
The simplest form of multiple encryption has two encryption stages and two keys (Figure
4.la). Given a plaintext P and two encryption keys K, and K,, ciphertext C is generated as
For DES, this scheme apparently involves a key length of 56 * 2 = 112 bits, resulting in a
dramatic increase in cryptographic strength. But we need to examine the algorithm more
closely.
Reduction to A Single Stage: Suppose it were true for DES, for all 56-bit key values, that
given any two keys K1 and K2, it would be possible to find a key K3 such that
If this were the case, then double encryption, and indeed any number of stages of
multiple encryption with DES, would be useless because the result would be equivalent
to a single encryption with a single 56-bit key.
MEET-IN-THE-MIDDLE ATTACK Thus, the use of double DES results in a mapping that
is not equivalent to a single DES encryption. But there is a way to attack this scheme, one
that does not depend on any particular property of DES but that will work against any block
encryption cipher.
meet-in-the-middle attack is based on the observation that, if we have
Given a known pair, (P, C) the attack proceeds as follows. First, encrypt for all 2 56 possible
values of K1. Store these results in a table and then sort the table by the values of .
Next, decrypt C using all 256 possible values of K2. As each decryption is produced, check the
result against the table for a match. If a match occurs, then test the two resulting keys against
a new known plaintext–ciphertext pair. If the two keys produce the correct ciphertext, accept
them as the correct keys.
For any given plaintext P, there are 2 64 possible ciphertext values that could be produced by
double DES. Double DES uses, in effect, a 112-bit key, so that there are 2 112 possible keys.
Therefore, on average, for a given plaintext , the number of different 112-bit keys that will
produce a given ciphertext C is 2112/ 264=248 Thus, the foregoing procedure will produce about
248 false alarms on the first (P, C)
General-purpose
Each block of plaintext is XORed with blockoriented
an encrypted counter. The counter is
Counter (CTR) Transmission.
incremented for each subsequent
block. Useful for high-speed
requirements
● Applications
– secure transmission of single values
– Databases (retrieval of single fields)
– however if IV is sent in the clear, an attacker can change bits of the first block, and change
IV to compensate
– hence either IV must be a fixed value - or it must be sent encrypted in ECB mode before
rest of message
● Message is treated as a
stream of bits
● Added to the output of the
block cipher
● Result is feed back for
next stage (hence name)
● Standard allows any
number of bit (1,8 or 64 or
whatever) to be feed back
– denoted CFB-1, CFB-8,
CFB-64 etc
● CFB-64 is used most often
(most efficient)
● Applications: stream data
encryption, authentication
COUNTER MODE
● A “new” mode, though proposed in '79
● Similar to OFB but encrypts counter value rather than any feedback value
● Must have a different key & counter value for every plaintext block (never reused)
● Applications: high-speed network encryptions
● Efficiency
– can do parallel encryptions
– in advance of need
– good for bursty high speed links
● Random access to encrypted data blocks
● Provable security (good as other modes)
– must ensure key/counter values are not reused
IDEA operates with 64 bit plain text and cipher text blocks and is controlled b a 128
bit key.
It avoids substitution boxes & lookup tables used in the block cipher.
The algorithm structure has been chosen such that different key sub-blocks are used;
the encryption process is identical to the decryption process.
The design principle behind IDEA is mixing of arithmetical operations form different
algebraic groups.
The arithmetical operations are easily implemented both in hardware and software.
The underling operations are
a. Exclusive-OR.
b. Addition of integers modulo 216
c. Multiplication modulo 210+1
The algorithm structure has been chosen such that when different key sub-blocks are
used, the encryption process is identical to the decryption process
The IDEA algorithm consists of eight rounds followed by a final transformation
function. The algorithm divides the input into four 16-bit subblocks. Each of the
rounds takes four 16-bit subblocks as input and produces four 16-bit output blocks.
The final transformation also produces four %-bit blocks, which are concatenated to
form the 64-bit ciphertext.
Each of the rounds also makes use of six 16-bit subkeys, whereas the final
transformation uses four subkeys, for a total of 52 subkeys
The 128-bit key is expanded into 52 16-bit keys: K1, K2, ....K52. (in diagram we represented
these keys with Z1 to z52)
Step 1: Keys K1….K8 are generated by taking 8 chunks of 16-bits each
Step 2: Keys K9…K16 are generated by starting from the 25 th bit, wrapping around the first
25 bits at the end, and taking 16-bit chunks.
Step 3: Wrap around 25 more bits to the end, and generate keys K17…K24. This process is
repeated until all keys K1…K52 are generated
64 bit data is divided into 4 16bit data blocks. These 4 blocks are processed through 8 rounds
and transformed by the above arithmetical operations among each other and with 6 16 bit
subkeys.
Blow fish:
Blow fish is a symmetric block cipher developed by bruce schner in year 1993.
Blow fish is designed to have following characteristics
Speed: Blowfish encrypts data on 32 bit microprocessor at a rate of 18 clock
cycles per byte.
Compact: it can run in less than 5k memory.
Simple: very easy to implements.
Variably secure: the key length is variable and can be as long as 448 bits. This
allows a trade off between higher speed and higher security.
Blowfish is a feistal type model.
BLOWFISH ALGORITHM:
That key is used to generate 18 “32 bit” subkeys & four “8*32”bits S-boxes.
The subkeys are stored in the p-array
P1,P2,-------P18
There are four s-boxes(each s-box size is 8*32 bits) each with 256 32bit entries.
S1,0, S1,1,-------------------S1,255
S2,0, S2,1,-------------------S2,255
S3,0, S3,1,-------------------S3,255
S4,0, S4,1,-------------------S4,255
The steps in generating the P-array & S-boxes as follows.
Step1 initialize first the P-array and then 4 s-boxes in order using the bits of fractional part
of the constant п.
Step 2 Perform a bitwise xor of the P-array & k-array, reusing words from the k-array as
needed.
Example P1=P1 K1, P1=P2 K2, -------- P14=P14 K14,
P15=P15 K1, P16=P1 K2, P17=P1 K3, P18=P1 K4,
Step 3 Encrypt the 64 bit block of all zeros using the current P & S-arrays, Replace P1&P2
with the output of the encryption.
Step 4 Encrypt the output of step 3 using the current P- and S-arrays and replace P3, and
P4, with the resulting ciphertext.
Step 5Continue this process to update all elements of P and then, in order, all elements of
S, using at each step the output of the continuously changing Blowfish algorithm.
Where Ep,s[Y] is the ciphertext produced by encrypting Y using Blowfish with the arrays S
and P.
In the above figure the encryption operation. The plaintext is divided into two 32-bit halves
LE, and RE,. We use the variables LE, and RE, to refer to the left and right half of the data
after round i has completed. The algorithm can be defined by the following pseudocode:
The function F is shown in below Figure. The 32-bit input to F is divided into 4 bytes. If we
label those bytes a, b, c, and d, then the function can be defined as follows:
Blowfish Decryption:
Blowfish decryption occurs in the same algorithmic direction as encryption. Rather
than the reverse. The algorithm can be defined as follows:
A brute-force attack is even more difficult than may be apparent from the key length
because of the time-consuming subkey-generation process. A total of 522 executions
of the encryption algorithm are required to test a single key.
The function F gives Blowfish the best possible avalanche affect for a Feistel
network: In round i, every bit of Li-1, affects every bit of Ri-1. In addition . every
subkey bit is affected by every key bit. and therefore F has a perfect avalanche effect
between the key (P,) and the right half of the data (R,) after every round.
Every bit of the input to F is only used as input to one S-box. In contrast. In DES,
many bits are used as inputs to two S-boxes. which strengthens the algorithm
considerably against differential attacks. Schneier felt that this added complexity was
not necessary with key-dependent S-boxes.
Unlike in CAST, the function F in Blowfish is not round dependent. Schneier felt that
such dependency did not add any cryptographic merit, given that the P-array
substitution is already round dependent.
CAST-128
CAST-128 is a 12- or 16-round Feistel network with a 64-bit block size and a key
size of between 40 to 128 bits (but only in 8-bit increments). The full 16 rounds are
used when the key size is longer than 80 bits.
CAST-128 Encryption
CAST-128 uses four primitive operations:
Addition and subtraction: Addition of words, denoted by +, is performed modulo
232. The inverse operation, denoted by -, is subtraction modulo 232.
Bitwise exclusive-OR: This operation is denoted by
Left circular rotation: The cyclic rotation of word x left by y bits is denoted by x
<<< y.
The CAST-128 encryption algorithm can be defined by the following pseudocode. The
plaintext is divided into two 32-bit halves L0, and R0. We use the variables Li and Ri, to refer
to the left and right half of the data after round i has completed. The ciphertext is formed by
swapping the output of the sixteenth round; that is, the ciphertext is the concatenation of R16
and L16.
Decryption is the same as encryption, with the keys employed in reverse order. Figure 4.14
depicts the details of a single round. The F function includes the use of four 8 x 32 S-boxes,
the left circular rotation function, and four functions that vary depending on the round
number; we label these functions f1, f2,, f3,, and f4,. We use I to refer to the intermediate 32-
bit value after the left circular rotation function, and the labels Ia, Ib, Ic, and Id to refer to the
4 bytes of I, where Ia is the most significant and Id is the least significant. With these
conventions, F is defined as follows:
FEATURES OF CAST-128:
There are several notable features of CAST worthy of comment.,
CAST makes use of fixed S-boxes. The designers felt that fixed S-boxes with good
nonlinearity characteristics are preferable to random S-boxes as might be obtained if the S-
boxes were key dependent. The subkey-generation process used in CAST-128 is different
from that employed in other symmetric encryption algorithms described in the literature.
The
CAST designers were concerned to make subkeys as resistant to known cryptanalytic attacks
as possible and felt that the use of highly nonlinear S-boxes provided this strength. We have
seen other approaches with the same goal.
For example. Blowfish uses the encryption algorithm itself to generate the subkeys.
The function F is designed to have good confusion, diffusion. and avalanche properties. It
uses S-box substitutions, mod 2 addition and subtraction, exclusive- OR operations, and key-
dependent rotation.
The strength of the F function is based primarily on the strength of the S-boxes, but the
further use of these arithmetic. Boolean, and rotate operators adds to its strength. Finally, F is
not uniform from round to round, as was described. This dependence of F on round number
may provide.
The Advanced Encryption Standard (AES) was published by the National Institute of
Standards and Technology (NIST) in 2001.
AES is a block cipher intended to replace DES for commercial applications.
It uses a 128-bit block size and a key size of 128, 192, or 256 bits.
AES does not use a Feistel structure. Instead, each full round consists of four separate
functions: byte substitution, permutation, arithmetic operations over a finite field, and
XOR with a key.
AES parameters:
Key size(words/bytes/bits) 4/16/128 6/24/192 8/32/256
Number of rounds 10 12 14
Again, the tenth round simply leaves out the Inverse Mix Columns stage. Each of these
stages will now be considered in more detail.
Substitute Bytes
This stage (known as SubBytes) is simply a table lookup using a 16×16 matrix of byte values
called an s-box. This matrix consists of all the possible combinations of an 8 bit sequence (2 8
= 16 × 16 = 256). However, the s-box is not just a random permutation of these values and
there is a well defined method for creating the s-box tables. The designers of Rijndael showed
how this was done unlike the s-boxes in DES for which no rationale was given. We will not
be too concerned here how the s-boxes are made up and can simply take them as table
lookups.
Again the matrix that gets operated upon throughout the encryption is known as state. We
will be concerned with how this matrix is effected in each round. For this particular round
each byte is mapped into a new byte in the following way: the leftmost nibble of the byte is
used to specify a particular row of the s-box and the rightmost nibble specifies a column. For
example, the byte {95} (curly brackets represent hex values in FIPS PUB 197) selects row
9 column 5 which turns out to contain the value {2A}.
This is then used to update the state matrix. Figure 7.3 depicts this idea.
The Inverse substitute byte transformation (known as InvSubBytes) makes use of an inverse
s-box. In this case what is desired is to select the value {2A} and get the value {95}. Table
7.4 shows the two s-boxes and it can be verified that this is in fact the case.