Unit II
Unit II
Since the cryptanalysis concepts are highly specialized and complex, we concentrate
here only on some of the key mathematical concepts behind cryptography.
To do this, certain mathematical equations are used, which are very difficult to solve
unless certain strict criteria are met. The level of difficulty of solving a given
equation is known as its intractability. These types of equations form the basis of
cryptography.
A symmetric algorithm uses the same key to encrypt data as it does to decrypt data.
The study of symmetric cryptosystems is referred to as symmetric cryptography.
2.2Algebraic structures
Cryptography requires sets of integers and specific operations that are defined for
those sets. The combination of the set and the operations that are applied to the
elements of the set is called an algebraic structure. Figure 2.1 shows the common
algebraic structures.
Figure 2.1 Common Algebraic Structures
2.2.1 Groups
A group is an algebraic structure conssting of a set of elements together with an
operation that combines any two elements to form a third element.
A group G, sometimes denoted by {G, .} is a set of elements with a binary
Example 1:
Four cyclic subgroups can be made from the group G = <Z6, +>. There are H1 = < {0}, + >,
H2 = <{0, 2, 4}, +>, H3 = <{ 0, 3}, +> and H4 = G.
Example 2:
Three cyclic subgroups can be made from the group G = <Z 10 *, x>. G has only four
elements: 1, 3, 7 and 9. The Cyclic sub groups are H1 = <{1}, x >, H2 = <{1, 9}, x>, H3 = G.
2.2.2 Rings
A ring R, sometimes denoted by {R, +, x}, is a set of elements with two binary
operations, called addition and multiplication, such that for all a, b, c in R the
following axioms are obeyed:
Closure under multiplication: If a and b belong to R, then ab is also in R.
Associativity of multiplication: a(bc) = (ab)c for all a, b, c in R.
Distributive laws:
a (b + c) = ab + ac for all a, b, c in R.
(a + b) c = ac + bc for all a, b, c in R.
A ring is said to be commutative if it satisfies the following additional condition:
An integral domain, which is a commutative ring that obeys the following axioms:
2.2.3 Fields
A field F, sometimes denoted by {F, +, x}, is a set of elements with two binary
operations, called addition and multiplication, such that for all a, b, c in F the
following axioms are obeyed:
F is an integral domain; that is, F satisfies axioms of Groups and Rings.
Multiplicative inverse: For each a in F, except 0, there is an element a -1 in F
such that aa-1 = (a-1) a = 1.
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)
2.3 Finite Fields
Finite Fields, also known as Galois Fields, are cornerstones for understanding
any cryptography.
A field can be defined as a set of numbers that we can add, subtract, multiply and
divide together and only ever end up with a result that exists in our set of numbers.
Galois showed that for a field to be finite, the number of elements should be p n, where
p is a prime and n is a positive integer.
A Galois field, GF(pn), is a finite field with pn elements.
2.3.1 Finite Fields of Order p
For a given prime, p, the finite field of order p, GF(p) is defined as the set Zp of
integers {0, 1,..., p- 1}, together with the arithmetic operations modulo p.
A very common field in this category is GF(2) with the set {0, 1} and two operations,
addition and multiplication, as shown in Figure 2.2
Figure 2.2 GF(2) field
We can define GF(5) on the set Z5 (5 is a prime) with addition and multiplication
operators as shown in Figure 2.3.
Because 38 − 14 = 24, which is a multiple of 12, or, equivalently, because both 38 and
14 have the same remainder 2 when divided by 12.
The same rule holds for negative values:
-8 ≡ 7 (mod 5)
2 ≡ -3 (mod 5)
-3 ≡ -8 (mod 5)
Examples:
Find the GCD
GCD (12, 8)
GCD (200, 1000)
GCD (7, 122)
The S-DES decryption algorithm takes an 8-bit block of ciphertext and the same 10-
bit key used to produce that ciphertext as input and produces the original 8-bit block
of plaintext.
The function fk takes as input not only the data passing through the encryption
algorithm, but also an 8-bit key. Here a 10-bit key is used from which two 8-bit
subkeys are generated.
The key is first subjected to a permutation (P10). Then a shift operation is performed.
The output of the shift operation then passes through a permutation function that
produces an 8-bit output (P8) for the first subkey (K1).
The output of the shift operation also feeds into another shift and another instance of
P8 to produce the second subkey (K2).
Where
Decryption can be shown as Plaintext = IP-1 (fK1 (SW (fk2 (IP (ciphertext)))))
S-DES depends on the use of a 10-bit key shared between sender and receiver. From
this key, two 8-bit subkeys are produced for use in particular stages of the encryption
and decryption algorithm.(Figure 2.6)
Figure 2.6 S-DES Key Generation
First, permute the key in the following fashion. Let the 10-bit key be designated as
(k1, K2, k3, k4, k5, k6, k7, k8, k9, k10). Then the permutation P10 is defined as:
P10 (k1, K2, k3, k4, k5, k6, k7, k8, k9, k10) = (k3, k5, K2, k7, k4, k10 10, k1, k9, k8,
k6).
This table is read from left to right; each position in the table gives the identity of the
input bit that produces the output bit in that position. So, the first output bit is bit 3 of
the input; the second output bit is bit 5 of the input, and so on.
Example
The 10 bit key is (1010000010), now find the permutation from P10 for this key so it
becomes (10000 01100).
Next, perform a circular left shift (LS-1), or rotation, separately on the first five bits
and the second five bits. In our example, the result is (00001 11000).
Next, apply P8, which picks out and permutes 8 of the 10 bits according to the
following rule:
So, The result is subkey 1 (K1). In our example, this yield (10100100).
Then go back to the pair of 5-bit strings produced by the two LS-1 functions and
performs a circular left shift of 2 bit positions on each string. In our example, the
value (00001 11000) becomes (00100 00011).
Finally, P8 is applied again to produce K2. In our example, the result is (01000011).
1. Initial Permutations
The input to the algorithm is an 8-bit block of plaintext, which we first permute using
the IP function
2. The Function fk
The most complex component of S-DES is the function f k, which consists of a
combination of permutation and substitution functions. The functions can be
expressed as follows. Let L and R be the leftmost 4 bits and rightmost 4 bits of the 8-
bit input to f K, and let F be a mapping (not necessarily one to one) from 4-bit strings
to 4-bit strings. Then we let
Now, describe the mapping F. The input is a 4-bit number (n1 n2 n3 n4). The first
operation is an expansion/permutation operation:
E/P = 01111101
The first 4 bits (first row of the preceding matrix) are fed into the S-box S0 to
produce a 2- bit output, and the remaining 4 bits (second row) are fed into S1 to
produce another 2-bit output.
The S-boxes operate as follows. The first and fourth input bits are treated as a 2-bit
number that specify a row of the S-box, and the second and third input bits specify a
column of the S-box. Each s box gets 4-bit input and produce 2 bits as output. It
follows 00- 0, 01-1, 10-2, 11-3 scheme.
11 - > 3 11 -> 3
Now, find P4
The switch function (sw) interchanges the left and right 4 bits.
1100 1110
1110 1100
4. Second function fk
First, do E/P function and XOR with K2, the value is 01101001⊕01000011, the
answer is 00101010
Value is 0000
After P4 => 0000 ⊕ 1110 = 1110, then concatenate last 4 bits after
interchange in sw.
5. Find IP-1
1. Find IP
After IP, value is 11101100
2. Function fk
3. Swift
4. Second fk
5. Find IP-1
All symmetric block encryption algorithms in current use are based on a structure
referred to as Fiestel block cipher.
A stream cipher is one that encrypts a digital data stream one bit or one byte at a
time. E.g, vigenere cipher. Figure (2.8a)
A block cipher is one in which a block of plaintext is treated as a whole and used to
produce a cipher text block of equal length. Typically, a block size of 64 or 128 bits
is used. Figure (2.8b)
Figure 2.8 Stream Cipher and Block Cipher
Many block ciphers have a Feistel structure. Such a structure consists of a number of
identical rounds of processing.
In each round, a substitution is performed on one half of the data being processed,
followed by a permutation that interchanges the two halves.
The original key is expanded so that a different key is used for each round.
The Data Encryption Standard (DES) has been the most widely used encryption
algorithm. It exhibits the classic Feistel structure.
The DES uses a 64-bit block and a 56-bit key. Two important methods of
cryptanalysis are differential cryptanalysis and linear cryptanalysis. DES has been
shown to be highly resistant to these two types of attack.
A block cipher operates on a plaintext block of n bits to produce a ciphertext block of
n bits. There are possible different plaintext blocks and, for the encryption to be
reversible (i.e., for decryption to be possible), each must produce a unique ciphertext
block. Such a transformation is called reversible, or nonsingular
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.
Two methods for frustrating statistical cryptanalysis are:
Diffusion – Each plaintext digit affects many ciphertext digits, or each
ciphertext digit is affected by many plaintext digits.
Confusion – Make the statistical relationship between a plaintext and the
corresponding ciphertext as complex as possible in order to thread attempts to
deduce the key.
The left-hand side of figure 2.9 depicts the structure proposed by Feistel.
The input to the encryption algorithm is a plaintext block of length 2w bits and a key
K. the plaintext block is divided into two halves L0 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 inputs Li-1 and Ri-1, derived from the
previous round, as well as the subkey Ki, derived from the overall key K.
In general, the subkeys Ki are different from K and from each other. All rounds have
the same structure.
A substitution is performed on the left half of the data (as similar to S-DES). This is
done by applying a round function F to the right half of the data and then taking the
XOR 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. Following this substitution, a permutation is performed that
consists of the interchange of the two halves of the data.
Key size - Increasing size improves security, makes exhaustive key searching
harder, but may slow cipher
Subkey generation - Greater complexity can make analysis harder, but slows
cipher
Round function - Greater complexity can make analysis harder, but slows
cipher
The rule is as follows: use the cipher text as input to the algorithm, but use the subkey
ki in reverse order. i.e., kn in the first round, kn-1 in second round and so on.
For clarity, we use the notation LE i and REi for data traveling through the decryption
algorithm and LDi and RDi.
The above diagram indicates that, at each round, the intermediate value of the
decryption process is same (equal) to the corresponding value of the encryption
process with two halves of the value swapped.
After the last iteration of the encryption process, the two halves of the output are
swapped, so that the cipher text is RE16 || LE16.
The output of that round is the cipher text. Now take the cipher text and use it as input
to the same algorithm.
The input to the first round is RE 16 || LE16, which is equal to the 32-bit swap of the
output of the sixteenth round of the encryption process.
Now we will see how the output of the first round of the decryption process is equal
to a 32-bit swap of the input to the sixteenth round of the encryption process.
The general Structure of DES is depicted in the following illustration −Figure 2.10
Figure 2.10 General Structure of DES Encryption Algorithm
If we then take the inverse permutation, Y = IP-1(X) = IP-1(IP(M)) it can be seen that the
original ordering of the bits is restored.
Table 2.1 Permutation Tables for DES
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
2.2a.
The key is first subjected to a permutation governed by a table labeled Permuted
Choice One (Table 2.2b).
The resulting 56-bit key is then treated as two 28-bit quantities, labelled C0 and D0.
At each round, and are separately subjected to a circular left shift or (rotation) of 1 or
2 bits, as governed by Table 2.2d.
These shifted values serve as input to the next round.
They also serve as input to the part labeled Permuted Choice Two (Table 2.2c), which
produces a 48-bit output that serves as input to the function F(Ri-1, Ki)
Table 2.2 DES Key Calculation
2.10.4 S Boxes
The substitution consists of a set of eight S-boxes (Figure 2.12), each of which
accepts 6 bits as input and produces 4 bits as output.
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.
Figure 2.12 Calculation of F (R. K)
2.10.5 Avalanche Effect
A desirable property of any encryption algorithm is that a small change in either the
plaintext or the key should produce a significant change in the ciphertext.
In particular, a change in one bit of the plaintext or one bit of the key should produce
a change in many bits of the ciphertext. Figure 2.13 shows the avalanche effect.
The criteria used in the design of DES, focused on the design of the S-boxes and on
the P function that takes the output of the S-boxes. The criteria for the S-boxes are as
follows.
No output bit of any S-box should be too close a linear function of the input
bits. Specifically, if we select any output bit and any subset of the six input
bits, the fraction of inputs for which this output bit equals the XOR of these
input bits should not be close to 0 or 1, but rather should be near 1/2.
Each row of an S-box (determined by a fixed value of the leftmost and
rightmost input bits) should include all 16 possible output bit combinations.
If two inputs to an S-box differ in exactly one bit, the outputs must differ in at
least two bits.
If two inputs to an S-box differ in the two middle bits exactly, the outputs
must differ in at least two bits.
If two inputs to an S-box differ in their first two bits and are identical in their
last two bits, the two outputs must not be the same.
For any nonzero 6-bit difference between inputs, no more than eight of the 32
pairs of inputs exhibiting that difference may result in the same output
difference.
This is a criterion similar to the previous one, but for the case of three S-
boxes.
The S-boxes are the only nonlinear part of DES. If the S-boxes were linear (i.e., each
output bit is a linear combination of the input bits), the entire algorithm would be
linear and easily broken.
random digits to generate the entries in the S-boxes. This may lead to boxes
Random with testing: Choose S-box entries randomly, then test the results
against various criteria.
Human-made: This is a more or less manual approach with only simple
For the last plaintext block, which may be a partial block of bits, the most significant
bits of the last output block are used for the XOR operation; the remaining bits are
discarded.
Figure 2.18 Counter
Advantages
Hardware efficiency
Software efficiency
Preprocessing
Random access
Provable security
Simplicity
Interestingly, AES performs all its computations on bytes rather than bits. Hence,
AES treats the 128 bits of a plaintext block as 16 bytes. These 16 bytes are arranged
in four columns and four rows for processing as a matrix.
Unlike DES, the number of rounds in AES is variable and depends on the length of
the key. AES uses 10 rounds for 128-bit keys, 12 rounds for 192-bit keys and 14
rounds for 256-bit keys. Each of these rounds uses a different 128-bit round key,
which is calculated from the original AES key.
The overall structure of AES (figure 2.19) focus particularly on the four steps used in
each round of AES:
Byte Substitution
Shift Rows
Mix Columns
MixColumns Transformation
It operates on each column individually. Each byte of a column is mapped into a new
value that is a function of all four bytes in that column. The transformation can be
defined by the following matrix multiplication on State (Figure 2.22)
Figure 2.22 MixColumns Transformation
AddRoundKey Transormation
It is a simple bitwise XOR of the current block with a portion of the expanded key.
The 128 bits of State are bitwise XORed with the 128 bits of the round key. As
shown in Figure 2.23, the operation is viewed as a columnwise 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.
Example of AddRoundKey
2.16.2 AES Key Expansion Algorithm
This 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. The remainder of the
expanded key is filled in four words at a time. Each added word w[i] depends on the
immediately preceding word w[i-1], and the word four positions back, w[i-4].
In three out of four cases, a simple XOR is used. For a word whose position in the w
array is a multiple of 4, a more complex function is used. Figure 2.24 illustrates the
generation of the expanded key, using the symbol g to represent that complex
function.
Figure 2.24 AES Key Expansion
2.17 RC4
RC4 is an encryption algorithm created in 1987 by Ronald Rivest of RSA Security. It
is a stream cipher (figure 2.25), which means that each digit or character is encrypted
one at a time. A cipher is a message that has been encoded.
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 the generator is called key-stream, is combined one byte at a time with
the plaintext stream cipher using X-OR operation.
Figure 2.25 Stream Cipher Diagram
Example
2. A third party can select the key and physically deliver it to A and B.
3. If A and B have previously and recently used a key, one party can transmit
the new key to the other, encrypted using the old key.
4. If A and B each has an encrypted connection to a third-party C, C can deliver
a key on the encrypted links to A and B.
Physical delivery (1 & 2) is simplest - but only applicable when there is personal
contact between recipient and key issuer. This is fine for link encryption where
devices & keys occur in pairs, but does not scale as number of parties who wish to
communicate grows. 3 is mostly based on 1 or 2 occurring first.
A third party, whom all parties trust, can be used as a trusted intermediary to mediate
the establishment of secure communications between them (4). Must trust
intermediary not to abuse the knowledge of all session keys. As number of parties
grow, some variant of 4 is only practical solution to the huge growth in number of
keys potentially needed.
Key Distribution Centre
The use of a key distribution center is based on the use of a hierarchy of keys. At a
minimum, two levels of keys are used.
Communication between end systems is encrypted using a temporary key, often
referred to as a Session key.
Typically, the session key is used for the duration of a logical connection and then
discarded
Master key is shared by the key distribution center and an end system or user and
used to encrypt the session key.
Key Distribution Scenario
Let us assume that user A wishes to establish a logical connection with B and
requires a one-time session key to protect the data transmitted over the connection.
A has a master key, Ka, known only to itself and the KDC; similarly, B shares the
master key Kb with the KDC(Figure 2.27). The following steps occur:
Figure 2.27 Key Distribution Scenario
1. An issue a request to the KDC for a session key to protect a logical connection to B.
The message includes the identity of A and B and a unique identifier, N 1, for this
transaction, which we refer to as a nonce. The nonce may be a timestamp, a
counter, or a random number; the minimum requirement is that it differs with each
request. Also, to prevent masquerade, it should be difficult for an opponent to guess
the nonce. Thus, a random number is a good choice for a nonce.
2. The KDC responds with a message encrypted using Ka Thus, A is the only one who
can successfully read the message, and A knows that it originated at the KDC. The
message includes two items intended for A:
The original request message, including the nonce, to enable A to match this
response with the appropriate request
Thus, A can verify that its original request was not altered before reception by the
KDC and, because of the nonce, that this is not a replay of some previous request.
In addition, the message includes two items intended for B:
The one-time session key, Ks to be used for the session
The distribution of session keys delays the start of any exchange and places a
burden on network capacity. A security manager must try to balance these
competing considerations in determining the lifetime of a particular session key.
For connection-oriented protocols, one obvious choice is to use the same session
key for the length of time that the connection is open, using a new session key
for each new session.
If a logical connection has a very long lifetime, then it would be prudent to
change the session key periodically, perhaps every time the PDU (protocol data
unit) sequence number cycles.
For a connectionless protocol, such as a transaction-oriented protocol, there is no
explicit connection initiation or termination.
Thus, it is not obvious how often one needs to change the session key. The most
secure approach is to use a new session key for each exchange.
A better strategy is to use a given session key for a certain fixed period only or for a
certain number of transactions.