Cns Module2
Cns Module2
Virtually, all symmetric block encryption algorithms in current use are based on a structure referred to as
Fiestel block cipher. For that reason, it is important to examine the design principles of the Fiestel cipher.
We begin with a comparison of stream cipher with 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.
• 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 bitsis used.
most symmetric block ciphers are based on a Feistel Cipher Structure needed since must be able to decrypt
ciphertext to recover messages efficiently. block ciphers look like an extremely large substitution
• would need table of 264 entries for a 64-bit block • Instead create from smaller building blocks
• using idea of a product cipher in 1949 Claude Shannon introduced idea of substitution- permutation (S-P) networks
called modern substitution-transposition product cipher these form the basis of modern block ciphers
• S-P networks are based on the two primitive cryptographic operations we have seen before:
• substitution (S-box)
• permutation (P-box)
• The inputs to the encryption algorithm are a plaintext block of length 2w bits and a key K.
• The plaintext block is divided into two halves, L0 and R0. T
• he two halves of the data pass through n rounds of processing and then combine toproduce the
ciphertext block.
• Each round i has as inputs Li-1 and Ri-1, derived from the previous round, as well as asubkey Ki, derived
from the overall K.
• In general, the subkeys Ki are different from K
and from each other.
Description:
• All rounds have the same structure.
The 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 achievedby greater diffusion
Traditionally, a block size of 64 bits has been considered a reasonable tradeoff and was nearly universal in block
cipher design.
● Key size: Larger key size means greater security but may decrease encryption/decryptionspeed. 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 16rounds.
DES Encryption
DES, data are encrypted in 64-bit blocks using a 56-bit key. The algorithm transforms 64-bitinput in a
series of steps into a 64-bit output. The same steps, with the same key, are used to reverse the
encryption
1. The right-hand portion of Figure 3.4 shows the way in which the 56-bit key isused. Initially, the
key is passed through a permutation function.
Initial Permutation
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 alsoconsists of 64 bits.
To see that these two permutation functions are indeed the inverse of each other, considerthe
following 64-bit input M:
If we then take the inverse permutation Y = IP-1(X) = IP-1(IP(M)), it can be seen that theoriginal ordering of the bits
is restored
3. The left and right halves of each 64-bit intermediate value are treated as separate 32-bit quantities, labeled
L (left) and R (right).
4. As in any classic Feistel cipher, the overall processing at each round can besummarized in the
following formulas
Differential Cryptanalysis:
One of the most significant advances in cryptanalysis in recent years is differential
cryptanalysis.
The differential cryptanalysis attack is complex;provides a complete description. The rationalebehind
differential cryptanalysis is to observe the behavior of pairs of text blocks evolving along each round of the
cipher, instead of observing the evolution of a single text block
Linear Cryptanalysis
We now give a brief summary of the principle on which linear cryptanalysis is based. For acipher with
nbit plaintext and ciphertext blocks and an m-bit key, let the plaintext block belabeled P[1], ... P[n], the
cipher text block C[1], ... C[n], and the key K[1], ... K[m]. Thendefine
Block Cipher Modes of Operation
A block cipher algorithm is a basic building block for providing data security The modes
1. The simplest mode is the electronic codebook (ECB) mode, in which plaintext is handled one block at a
time and each block of plaintext is encrypted using the samekey (Figure 6.3).
2. The term codebook is used because, for a given key, there is a unique ciphertext forevery b-bit block of
plaintext.
3. Therefore, we can imagine a gigantic codebook in which there is an entry for every possible b-bit
plaintext pattern showing its corresponding ciphertext
4. For a message longer than b bits, the procedure is simply to break the message into b-bit blocks, padding
the last block if necessary. Decryption is performed one block at a time, always using the same key.
5. The ECB method is ideal for a short amount of data, such as an encryption key. Thus,if you want to
transmit a DES key securely, ECB is the appropriate mode to use.
6. The most significant characteristic of ECB is that the same b-bit block of plaintext, if itappears more than
once in the message, always produces the same ciphertext.
To overcome the security deficiencies of ECB, we would like a technique in which the same plaintext
block, if repeated, produces different ciphertext blocks.
A simple way to satisfy this requirement is the cipher block chaining (CBC) mode
In this scheme, 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 eachblock.
In effect, we have chained together the processing of the sequence of plaintext blocks. Theinput to the
encryption function for each plaintext block bears no fixed relationship to the plaintext block.
Therefore, repeating patterns of b bits are not exposed.
Cipher Feedback Mode :
Figure 6.5 depicts the CFB scheme. In the figure, 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 units of b bits, the
plaintext is divided into segments of s bits.
Encryption.
1. The input to the encryption function is a b-bit shift register that is initially set to someinitialization vector
(IV).
2. 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 leftby s bits and C1 is placed in the rightmost (least significant) s
bits of the shift register.
3. This process continues until all plaintext units have been encrypted.
Decryption
The same scheme is used, except that the received ciphertext unit is XORed with the outputof the
encryption function to produce the plaintext unit.
Output Feedback Mode:
The output feedback (OFB) mode is similar in structure to that of CFB, as illustrated in Figure
As can be seen, 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.
One advantage of the OFB method is that bit errors in transmission do not propagate.
The disadvantage of OFB is that it is more vulnerable to a message stream modification attack than is
CFB.
Counter Mode:
Although interest in the counter mode (CTR) has increased recently, with applications to ATM
(asynchronous transfer mode) network security and IPSec (IP security).
2. Typically, the counter is initialized to some value and then incremented by 1 for eachsubsequent block
(modulo 2b where b is the block size).
3. For encryption, the counter is encrypted and then XORed with the plaintext block toproduce the
ciphertext block; there is no chaining.
4. For decryption, the same sequence of counter values is used, with each encryptedcounter XORed with a
ciphertext block to recover the corresponding plaintext block.
Advantages of CTR mode:
Hardware efficiency :
in CTR mode can be done in parallel on multiple blocks of plaintext or ciphertext.
Software efficiency :
Because of the opportunities for parallel execution.
Preprocessing:
The execution of the underlying encryption algorithm does not depend on input of theplaintext or
ciphertext
Random access:
The ith block of plaintext or ciphertext can be processed in random-accessFashion
Simplicity:
Unlike ECB and CBC modes, CTR mode requires only the implementation of theencryption
algorithm and not the decryption algorithm
Advanced Encryption Standard (AES).
The more popular and widely adopted symmetric encryption algorithm likely to be encountered nowadays
is the Advanced Encryption Standard (AES). It is found at least six time faster than triple DES.
A replacement for DES was needed as its key size was too small. With increasing computing power, it was
considered vulnerable against exhaustive key search attack. Triple DES was designed to overcome this
drawback but it was found slow.
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 arrangedin 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 result is a new matrix consisting of the same 16 bytes but shifted with respectto each other.
MixColumns
Each column of four bytes is now transformed using a special mathematical function. This function takes as
input the four bytes of one column and outputs four completely new bytes, which replace the original
column. The result is another new matrix consisting of 16 new bytes. It should be noted that this step is not
performed in the last round.
Addroundkey
The 16 bytes of the matrix are now considered as 128 bits and are XORed to the 128 bits of the round key.
If this is the last round then the output is the ciphertext. Otherwise, the resulting 128 bits are interpreted
as 16 bytes and we begin another similar round.
Decryption Process
The process of decryption of an AES ciphertext is similar to the encryption process in the reverse order.
Each round consists of the four processes conducted in the reverse order −
• Mix columns
• Shift rows
• Byte substitution
Since sub-processes in each round are in reverse manner, unlike for a Feistel Cipher, the encryption and
decryption algorithms needs to be separately implemented,although they are very closely related.
AES Analysis
In present day cryptography, AES is widely adopted and supported in both hardware and software. Till date,
no practical cryptanalytic attacks against AES has been discovered. Additionally, AES has built-in flexibility
of key length, which allows a degree of ‘future-proofing’ against progress in the ability to perform
exhaustive key searches.
However, just as for DES, the AES security is assured only if it is correctly implemented and good key
management is employed.
Blow Fish
⚫ Blowfish is a keyed, symmetric block cipher, designed in 1993 by Bruce Schneier and included in a large number
of cipher suites and encryption products.
⚫ Blowfish is a symmetric block cipher that can be used as a drop-in replacement for DES or IDEA.
⚫ Blowfish was designed in 1993 by Bruce Schneier as a fast, free alternative to existing encryption algorithms.
⚫ It takes a variable-length key, from 32 bits to 448 bits, making it ideal for both domestic and exportable use.
⚫ Blowfish is unpatented and license-free, and is available free for all uses.
⚫ While no effective cryptanalysis of Blowfish has been found to date, more attention is now given to block ciphers
with a larger block size, such as AES or Twofish.
⚫ The expansion of the key: break the original key into a set of subkeys. Specifically, a key of no more than 448
bits is separated into 4168 bytes. There is a P-array and four 32-bit S-boxes. The P-array contains 18 32-bit
subkeys, while each S-box contains 256 entries.
⚫ The encryption of the data: 64-bit input is denoted with an x, while the P-array is denoted with a Pi (where i is
the iteration).
⚫ Blowfish has a 64-bit block size and a key length of anywhere from 32 bits to 448 bits (32-448 bits in steps of 8
bits; default 128 bits).
⚫ It is a 16-round Feistel cipher and uses large key-dependent S-boxes. It is similar in structure to CAST-128, which
uses fixed S-boxes.
⚫ From the above diagram each line represents 32 bits. The algorithm keeps two subkey arrays: the 18-entry P-array
and four 256-entry S-boxes.
⚫ The S-boxes accept 8-bit input and produce 32-bit output. One entry of the P-array is used every round, and after
the final round, each half of the data block is XORed with one of the two remaining unused P-entries.
Working Principle
⚫ Initialize the P-array and S-boxes
⚫ XOR P-array with the key bits. For example, P1 XOR (first 32 bits of key), P2 XOR (second 32 bits of key), ...
⚫ Repeat 521 times in order to calculate new subkeys for the P-array and the four S-boxes
Fig Blowfish’s F function
⚫ The above diagram shows Blowfish's F-function. The function splits the 32-bit input into four eight-bit quarters,
and uses the quarters as input to the S-boxes. The outputs are added modulo 232 and XORed to produce the final
32-bit output.
⚫ Since Blowfish is a Feistel network, it can be inverted simply by XORing P17 and P18 to the ciphertext block,
then using the P-entries in reverse order.
⚫ Blowfish's key schedule starts by initializing the P-array and S-boxes with values derived from the hexadecimal
digits of pi, which contain no obvious pattern.
⚫ The secret key is then XORed with the P-entries in order (cycling the key if necessary). A 64-bit all-zero block is
then encrypted with the algorithm as it stands.
⚫ The resultant ciphertext replaces P1 and P2. The ciphertext is then encrypted again with the new subkeys, and P3
and P4 are replaced by the new ciphertext. This continues, replacing the entire P-array and all the S-box entries.
⚫ In all, the Blowfish encryption algorithm will run 521 times to generate all the subkeys - about 4KB of data is
processed.
RC4:
RC4 is an encryption algorithm that was created by Ronald Rivest of RSA Security. Itis used in WEP and
WPA, which are encryption protocols commonly used on wireless routers. The workings of RC4 used to be a
secret, but its code was leaked onto the internet in 1994. RC4 was originally very widely used due to its
simplicity and speed. Typically 16 byte keys are used for strong encryption, but shorter key lengths are also
widely used due to export restrictions. Over time this code was shown to produce biased outputs towards
certain sequences, mostly in first few bytes of the keystream generated.
To begin the process of RC4 encryption, you need a key, which is often user-defined and between 40-bits
and 256-bits. A 40-bit key represents a five character ASCII code that gets translated into its 40 character
binary equivalent (for example, the ASCII key "pwd12" is equivalent to
0111000001110111011001000011000100110010
in binary). The next part of RC4 is the key-scheduling algorithm (KSA), listed below.
KSA creates an array S that contains 256 entries with the digits 0 through 255, as
inthe table below.
where j is the previous j value (which is initially zero). S[i] is the value of the current entry
in
S. key[i mod keylength] is either a zero or a one.
For example, if we are at the 52th entry in S and the keylength was 40-bit, then 52 mod
40
= 12. The 13th element (because numbering for arrays begins at zero) in the
binary versionof "pwd12" is 0. For example, consider the first iteration of KSA with
key "pwd12".
Then, since i = 0, i mod 256 = 0. So, the element at the index 0 of the key is p, and
its asciivalue is 112. So, the new j is computed as
So, swapping the i-th and the j-th elements, we obtain the following array after the
firstiteration:
The next part of RC4 is the pseudo-random generation algorithm (PRGA). The PRGA is
below:
In PRGA, we begin with the array S that was swapped in the KSA. In PRGA, an element
in S (at index i) is swapped with another element in S (at index j). Then, the next
element in the encrypted text is the element of S at the index calculated by (S[i]
+ S[j] mod 256). At each iteration, i is recalculated as (i + 1) mod 256, and j is
recalculated as (j + S[i]) mod 256. The number of iterations performed is the length
of the key, and every value of S is swapped at least once beyond 256 iterations (due
to the fact that i and j are calculated by some number n mod 256).
● Asymmetric encryption transforms plaintext into ciphertext using a one of two keys and
an encryption algorithm. Using the paired key and a decryption algorithm, the plaintext is
recovered from the ciphertext.
● The most widely used public-key cryptosystem is RSA. The difficulty of attacking RSA
is based on the difficulty of finding the prime factors of a composite number.
• Plaintext: This is the readable message or data that is fed into the algorithm as input.
• Encryption algorithm: The encryption algorithm performs various transformations on the
plaintext.
• Public and private keys: This is a pair of keys that have been selected so that if one is used for
encryption, the other is used for decryption. The exact transformations performed by the
algorithm depend on the public or private key that is provided as input.
• Ciphertext: This is the scrambled message produced as output. It depends on the plaintext
and the key. For a given message, two different keys will produce two different ciphertexts.
• Decryption algorithm: This algorithm accepts the ciphertext and the matching key and
produces the original plaintext.
1. Each user generates a pair of keys to be used for the encryption and decryption of messages.
2. Each user places one of the two keys in a public register or other accessible file. This is the public
key. The companion key is kept private. As Figure suggests, each user maintains a collection of
public keys obtained from others.
3. If Bob wishes to send a confidential message to Alice, Bob encrypts the message using Alice's
public key.
4. When Alice receives the message, she decrypts it using her private key. No other recipient can
decrypt the message because only Alice knows Alice's private key.
With this approach, all participants have access to public keys, and private keys are generated locally
by each participant and therefore need never be distributed. As long as a user's private key remains
protected and secret, incoming communication is secure. At any time, a system can change its private
key and publish the companion public key to replace its old public key.
2. The sender and receiver must share the 2. The sender and receiver must each have
algorithm and the key. one of the matched pair of keys (not the
same one).
3. The key must be kept secret. 3. One of the two keys must be kept secret.
In broad terms, we can classify the use of public-key cryptosystems into three
categories:
• Encryption/decryption: The sender encrypts a message with the recipient's public key.
• Digital signature: The sender "signs" a message with its private key. Signing is achieved
by a cryptographic algorithm applied to the message or to a small block of data that is a
function of the message.
• Key exchange: Two sides cooperate to exchange a session key. Several different
approaches are possible, involving the private key(s) of one or both parties.
• Select e = 5, which is a valid choice since there is no number that is common factor
of 5 and (p − 1)(q − 1) = 6 × 12 = 72, except for 1.
• The pair of numbers (n, e) = (91, 5) forms the public key and can be made available
to anyone whom we wish to be able to send us encrypted messages.
• Input p = 7, q = 13, and e = 5 to the Extended Euclidean Algorithm. The output will
be d = 29.
de = 29 × 5 = 145 = 1 mod 72
• Hence, public key is (91, 5) and private keys is (91, 29).
The Algorithm
Assume two communication Parties A for (Anu) and B for (Banu):
Example
Assume Anu generated the values as n =11 and g= 7 and communicated to Banu over a channel.
Man-In-The-Middle Attack (MIMA)
In cryptography and computer security, a man-in-the-middle attack is an attack where the attacker
secretly relays and possibly alters the communication between two parties who believe they are
directly communicating with each other.
Elliptic Curve Cryptographic algorithm ( ECC )
• Elliptic Curve Cryptography (ECC) was discovered in 1985 by Victor Miller (IBM) and Neil Koblitz
(University of Washington) as an alternative mechanism for implementing public-key
cryptography.
• Elliptical curve cryptography is a public key encryption technique which is based on the theory of
elliptical curves.
• This encryption technique uses the properties of elliptic curve in order to generate keys instead
of using the traditional methodology of generation of keys using the product of two very large
prime numbers.
• ECC is a public key cryptosystem which is used to generate the public key and the private key in
order to encrypt and decrypt the data.
• It is based on the mathematical complexity of solving the elliptic curve discrete logarithm problem
which deals with the problem of calculating the number of steps or hops it takes to move from
one point to another point on the elliptic curve.
• Elliptic curves are the binary curves and are symmetrical over x- axis. These are defined by the
function:
Encryption
• Let ‘M’ be the message that we are sending. We have to represent this message on
the curve.
• Randomly select ‘k’ from [1 – (n-1)].
• Two cipher texts will be generated let it be C1 and C2.
C1 = k*P
C2 = M + k*Q
C1 and C2 will be send.
Decryption
• We have to get back the message ‘m’ that was send to us,
• M = C2 – d * C1
• M is the original message that we have send.
Proof
How do we get back the message,
• C2 – d * C1 = (M + k * Q) – d * ( k * P ) ( C2 = M + k * Q and C1 = k * P )
• = M + k * d * P – d * k *P ( Since Q =d * p)
• = M ( Original Message )