Cryptography
Cryptography
Symmetric key cryptography: Block ciphers and its components, Stream cipher, Blowfish, DES, AES,
RC4, Key distribution
1. A block cipher takes a block of plaintext bits and generates a block of ciphertext bits, generally of same size.
The size of block is fixed in the given scheme. The choice of block size does not directly affect to the
strength of encryption scheme. The strength of cipher depends up on the key length.
2. A modern block cipher is a cipher which encrypts m-bit block of plaintext and decrypts m-bit block of
ciphertext. For encryption or decryption, modern block cipher facilitate a K bit key and the decryption
algorithm should be inverse of encryption algorithms and for both encryption and decryption similar key is
used.
3. A block cipher works on a plaintext block of n bits to make a cipher text block of n bits. There are possible
multiple plaintext blocks and, for the encryption to be reversible (i.e., for decryption to be applicable), each
should create a unique cipher text block. Such transformation is known as reversible, or non-singular.
4. Block cipher modes of operation have been produced to delete the chance of encrypting identical blocks of
text the similar method, the ciphertext formed from the previous encrypted block is used to the next block.
A block of bits is known as an initialization vector (IV).
There are various components of Modern Block Cipher which are as follows −
D-boxes − A D-box is a permutation box having similar features as traditional transposition ciphers.
D-boxes transpose bits. There are three types of D-boxes which are as follows −
Straight D-box − It creates n inputs, permutes them and supports n outputs. In this, the second input after
permutation is the first to be outputted. The first letter in input is permuted to second place, third on fourth place
and fourth on third place. There are n! Possible way of mapping in D-box.
Compression D-box − This is a D-box with n inputs and m outputs, where m<n. There are various inputs are
blocked and do not reach the output. Compression D-boxes are used when it is required to permute bits and at
the similar time reduce the number of bits for the next stage.
Expansion D-box − This is a D-box with n inputs and m outputs, where m >n i.e., there are various inputs are
connected to more than one output it is used when it is required to transpose bits and the same increase the
multiple bits for the next stage.
Circular Shift − It can also discovered in modern block ciphers, it can be such as leftshift or right-shift.
In the circular left shift, shift each bit in n-bit word with m position to the left and the leftmost m-bits are
deleted from the left and become the rightmost bits.
❖ Stream cipher
1. A stream cipher is an encryption technique that works byte by byte to transform plain text into code that's
unreadable to anyone without the proper key.
2. Stream ciphers are linear, so the same key both encrypts and decrypts messages. And while cracking them
can be difficult, hackers have managed to do it.
3. A typical stream cipher encrypts plaintext one byte at a time, although a stream cipher may be designed to
operate on one bit at a time or on units larger than a byte at a time.
4. Figure 6.8 is a representative diagram of stream cipher structure. In this structure a key is input to a
pseudorandom bit generator that produces a stream of 8-bit numbers that are apparently random.
5. For now, we simply say that a pseudorandom stream is one that is unpredictable without knowledge of the
input key. The output of the generator, called a keystream, is combined one byte at a time with the plaintext
stream using the bitwise exclusive-OR (XOR) operation.
6. For example, if the next byte generated by the generator is 01101100 and the next plaintext byte is 11001100,
then the resulting ciphertext byte is
3. The complexity of block cipher is simple. While stream cipher is more complex.
4. Block cipher Uses confusion as well as diffusion. While stream cipher uses only confusion.
The algorithm modes which are used in block The algorithm modes which are used in stream
6. cipher are ECB (Electronic Code Book) and CBC cipher are CFB (Cipher Feedback) and OFB
(Cipher Block Chaining). (Output Feedback).
Block cipher works on transposition techniques like While stream cipher works on substitution
7. rail-fence technique, columnar transposition techniques like Caesar cipher, polygram
technique, etc. substitution cipher, etc.
Block cipher is slow as compared to a stream While stream cipher is fast in comparison to
8.
cipher. block cipher.
9. Suitable for applications that require strong Suitable for applications that require strong
encryption, such as file storage and internet encryption, such as file storage and internet
communications communications
More secure than stream ciphers when the same Less secure than block ciphers when the same
10.
key is used multiple times key is used multiple times
11. key length is Typically 128 or 256 bits key length is Typically 128 or 256 bits
12. Operates on fixed-length blocks of data Encrypts data one bit or byte at a time
-------------------------------------------------------------------------------------------------------------- Blowfish
Now each of the subkey is changed with respect to the input key as:
P[0] = P[0] xor 1st 32-bits of input key
P[1] = P[1] xor 2nd 32-bits of input key
.
.
.
P[i] = P[i] xor (i+1)th 32-bits of input key
(roll over to 1st 32-bits depending on the key length)
.
.
.
P[17] = P[17] xor 18th 32-bits of input key
(roll over to 1st 32-bits depending on key length)
The resultant P-array holds 18 subkeys that is used during the entire encryption process
Step2: initialise Substitution Boxes:
4 Substitution boxes(S-boxes) are needed{S[0]…S[4]} in both encryption aswell as decryption process
with each S-box having 256 entries{S[i][0]…S[i][255], 0&lei&le4} where each entry is 32-bit.
Prepared By : Mrs.Anuradha Hiwase 8
It is initialized with the digits of pi(?) after initializing the P-array. You may find the s-boxes in here!
Step3: Encryption:
The encryption function consists of two parts:
a. Rounds: The encryption consists of 16 rounds with each round(Ri) taking inputs the plainText(P.T.)
from previous round and corresponding subkey(Pi). The description of each round is as follows:
We have mentioned that DES uses a 56-bit key. Actually, the initial key consists of 64 bits. However, before
the DES process even starts, every 8th bit of the key is discarded to produce a 56-bit key. That is bit positions
8, 16, 24, 32, 40, 48, 56, and 64 are discarded.
Thus, the discarding of every 8th bit of the key produces a 56-bit key from the original 64-bit key.
DES is based on the two fundamental attributes of cryptography: substitution (also called confusion) and
transposition (also called diffusion). DES consists of 16 steps, each of which is called a round. Each round
performs the steps of substitution and transposition. Let us now discuss the broad-level steps in DES.
In the first step, the 64-bit plain text block is handed over to an initial Permutation (IP) function.
a) The initial permutation is performed on plain text.
b) Next, the initial permutation (IP) produces two halves of the permuted block; saying Left Plain Text (LPT)
and Right Plain Text (RPT).
c) Now each LPT and RPT go through 16 rounds of the encryption process.
d) In the end, LPT and RPT are rejoined and a Final Permutation (FP) is performed on the combined block
ciphertext.
As we have noted after IP is done, the resulting 64-bit permuted text block is divided into two half blocks.
Each half-block consists of 32 bits, and each of the 16 rounds, in turn, consists of the broad-level steps
outlined in the figure.
We have noted initial 64-bit key is transformed into a 56-bit key by discarding every 8th bit of the initial key.
Thus, for each a 56-bit key is available. From this 56-bit key, a different 48-bit Sub Key is generated during
each round using a process called key transformation. For this, the 56-bit key is divided into two halves, each
of 28 bits. These halves are circularly shifted left by one or two positions, depending on the round.
For example: if the round numbers 1, 2, 9, or 16 the shift is done by only one position for other rounds, the
circular shift is done by two positions. The number of key bits shifted per round is shown in the figure.
After an appropriate shift, 48 of the 56 bits are selected. for selecting 48 of the 56 bits the table is shown in the
figure given below. For instance, after the shift, bit number 14 moves to the first position, bit number 17
moves to the second position, and so on. If we observe the table carefully, we will realize that it contains only
48-bit positions. Bit number 18 is discarded (we will not find it in the table), like 7 others, to reduce a 56-bit
key to a 48-bit key. Since the key transformation process involves permutation as well as a selection of a 48-bit
subset of the original 56-bit key it is called Compression Permutation.
Because of this compression permutation technique, a different subset of key bits is used in each round. That
makes DES not easy to crack.
Recall that after the initial permutation, we had two 32-bit plain text areas called Left Plain Text(LPT) and
Right Plain Text(RPT). During the expansion permutation, the RPT is expanded from 32 bits to 48 bits. Bits
are permuted as well hence called expansion permutation. This happens as the 32-bit RPT is divided into 8
blocks, with each block consisting of 4 bits. Then, each 4-bit block of the previous step is then expanded to a
corresponding 6-bit block, i.e., per 4-bit block, 2 more bits are added.
------------------------------------------------------------------------------------------------------------------------------------
Advanced Encryption Standard (AES) is a specification for the encryption of electronic data established by
the U.S National Institute of Standards and Technology (NIST) in 2001. AES is widely used today as it is a
much stronger than DES and triple DES despite being harder to implement.
Points to remember
AES is a block cipher.
The key size can be 128/192/256 bits.
Encrypts data in blocks of 128 bits each.
That means it takes 128 bits as input and outputs 128 bits of encrypted cipher text as output. AES relies on
substitution-permutation network principle which means it is performed using a series of linked operations
which involves replacing and shuffling of the input data.
Working of the cipher :
AES performs operations on bytes of data rather than in bits. Since the block size is 128 bits, the cipher
processes 128 bits (or 16 bytes) of the input data at a time.
The number of rounds depends on the key length as follows :
128 bit key – 10 rounds
192 bit key – 12 rounds
256 bit key – 14 rounds
Creation of Round keys :
A Key Schedule algorithm is used to calculate all the round keys from the key. So the initial key is used to
create many different round keys which will be used in the corresponding round of the encryption.
After all these rounds 128 bits of encrypted data is given back as output. This process is repeated until all the
data to be encrypted undergoes this process.
Decryption :
The stages in the rounds can be easily undone as these stages have an opposite to it which when performed
reverts the changes.Each 128 blocks goes through the 10,12 or 14 rounds depending on the key size.
The stages of each round in decryption is as follows :
Add round key
Inverse MixColumns
ShiftRows
Inverse SubByte
The decryption process is the encryption process done in reverse so i will explain the steps with notable
differences.
Inverse MixColumns :
This step is similar to the MixColumns step in encryption, but differs in the matrix used to carry out the
operation.
Inverse SubBytes :
Inverse S-box is used as a lookup table and using which the bytes are substituted during decryption.
AES and DES are both examples of symmetric block ciphers but have certain dissimilarities.
1. AES stands for Advanced Encryption Standard DES stands for Data Encryption Standard
3. Byte-Oriented. Bit-Oriented.
4. Key length can be 128-bits, 192-bits, and The key length is 56 bits in DES.
256-bits.
7. The design rationale for AES is open. The design rationale for DES is closed.
8. The selection process for this is secret but The selection process for this is secret.
accepted for open public comment.
9. AES is more secure than the DES cipher and is DES can be broken easily as it has known
the de facto world standard. vulnerabilities. 3DES(Triple DES) is a
variation of DES which is secure than the
usual DES.
10. The rounds in AES are: Byte Substitution, Shift The rounds in DES are: Expansion, XOR
Row, Mix Column and Key Addition operation with round key, Substitution
and Permutation
11. AES can encrypt 128 bits of plaintext. DES can encrypt 64 bits of plaintext.
12. It can generate Ciphertext of 128, 192, 256 bits. It generates Ciphertext of 64 bits.
13. AES cipher is derived from an aside-channel DES cipher is derived from Lucifer
square cipher. cipher.
18. It is efficient with both hardware and software. It is efficient only with hardware.
Working of RC4
Encryption Procedure
1. The user inputs a plain text file and a secret key.
2. The encryption engine then generates the keystream by using KSA and PRGA Algorithm.
3. This keystream is now XOR with the plain text, this XORing is done byte by byte to produce the
encrypted text.
4. The encrypted text is then sent to the intended receiver, the intended receiver will then decrypted the
text and after decryption, the receiver will get the original plain text.
Decryption Procedure
Decryption is achieved by doing the same byte-wise X-OR operation on the Ciphertext.
Example: Let A be the plain text and B be the keystream (A xor B) xor B = A
Advantages
Disadvantages
1. If RC4 is not used with strong MAC then encryption is vulnerable to a bit-flipping attack.
2. RC4 stream ciphers do not provide authentication.
3. RC4 algorithm requires additional analysis before including new systems.
4. RC4 stream ciphers cannot be implemented on small streams of data.
5. RC4 fails to discard the beginning of output keystream or fails to use non-random or related keys for the
algorithm.
Key Management and Distribution
KEY POINTS
◆ Key distribution is the function that delivers a key to two parties who wish to exchange secure encrypted
data. Some sort of mechanism or protocol is needed to provide for the secure distribution of keys.
◆ Key distribution often involves the use of master keys, which are infre- quently used and are long lasting,
and session keys, which are generated and distributed for temporary use between two parties.
◆ Public-key encryption schemes are secure only if the authenticity of the public key is assured. A public-key
certificate scheme provides the neces- sary security.
◆ X.509 defines the format for public-key certificates. This format is widely used in a variety of applications.