AES & RC4
Advanced Encryption Standard
& Rivest Cipher 4
• 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.
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.
Encryption :
• AES considers each block as a 16 byte (4 byte x 4 byte =
128 ) grid in a column major arrangement.
[ b0 | b4 | b8 | b12 |
• Each round comprises of 4 steps : | b1 | b5 | b9 | b13 |
| b2 | b6 | b10| b14 |
• SubBytes | b3 | b7 | b11| b15 ]
• ShiftRows
• MixColumns
• Add Round Key
• The last round doesn’t have the MixColumns round.
The SubBytes does the substitution and ShiftRows and
MixColumns performs the permutation in the algorithm.
SubBytes :
• This step implements the substitution.
• In this step each byte is substituted by another byte. Its performed
using a lookup table also called the S-box.
• This substitution is done in a way that a byte is never substituted by itself and
also not substituted by another byte which is a compliment of the current byte.
The result of this step is a 16 byte (4 x 4 ) matrix like before.
• This step is just as it sounds. Each row is shifted
a particular number of times.
ShiftRows : • The first row is not shifted
• The second row is shifted once to the left.
• The third row is shifted twice to the left.
• The fourth row is shifted thrice to the left.
(A left circular shift is performed.)
• This step is basically a matrix multiplication.
Each column is multiplied with a specific
MixColumns : matrix and thus the position of each byte in the
column is changed as a result.
• This step is skipped in the last round.
Add Round Keys :
• 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.
• Now the resultant output of the previous
stage is XOR-ed with the corresponding
round key. Here, the 16 bytes is not
considered as a grid but just as 128 bits of
data.
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
• the steps with notable differences will be highligted.
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.
Applications:
• AES is widely used in many applications which require secure data storage and transmission. Some common use cases
include:
• Wireless security:
• AES is used in securing wireless networks, such as Wi-Fi networks, to ensure data confidentiality and prevent unauthorized access.
• Database Encryption:
• AES can be applied to encrypt sensitive data stored in databases. This helps protect personal information, financial records, and other
confidential data from unauthorized access in case of a data breach.
• Secure communications:
• AES is widely used in protocols like such as internet communications, email, instant messaging, and voice/video calls.It ensures that
the data remains confidential.
• Data storage:
• AES is used to encrypt sensitive data stored on hard drives, USB drives, and other storage media, protecting it from unauthorized
access in case of loss or theft.
• Virtual Private Networks (VPNs):
• AES is commonly used in VPN protocols to secure the communication between a user’s device and a remote server. It ensures that
data sent and received through the VPN remains private and cannot be deciphered by eavesdroppers.
• Secure Storage of Passwords:
• AES encryption is commonly employed to store passwords securely. Instead of storing plaintext passwords, the encrypted version is
stored. This adds an extra layer of security and protects user credentials in case of unauthorized access to the storage.
• File and Disk Encryption:
• AES is used to encrypt files and folders on computers, external storage devices, and cloud storage. It protects sensitive data stored on
devices or during data transfer to prevent unauthorized access.
Stream ciphers
• In a stream cipher, encryption and decryption are done one symbol at a time.
• P= p1,p2,p3,… C= c1,c2,c3,…
• K= k1,k2,…..
• c1=Ek1(p1) c2=Ek2(p2)…….
• Characters in the PT are fed into the encryption algo, one at a time; the cipher
characters are generated one at a time.
• The key stream , can be created in many ways.
• It may be a stream of predetermined values
• it may be created one value at a time using an algo
• The values may depend on PT or CT characters
• The values may also depend on the previous key values.
Stream Ciphers
Pure stream ciphers can encipher small units of data such as
characters or bits.
Stream ciphers are more efficient for real-time processing.
RC4
RC4 is a stream cipher that was designed in 1984 by Ronald
Rivest for RSA Data Security. RC4 is used in many data
communication and networking protocols, including
SSL/TLS and IEEE802.11 wireless LAN standard.
RC4 is a byte-oriented stream cipher in which a byte of a
plaintext is exclusive-ored with a byte of key to produce a byte of
a ciphertext. The secret key, from which the one-byte keys in the
key stream are generated, can contain anywhere from 1 to 256
bytes.
State
RC4 is based on the concept of a state. At each moment, a state of
256 bytes is active from which one of the bytes is randomly
selected to serve as the key for encryption.
S[0] S[1] … S[255]
Note that the indices of the elements range between 0 and 255.
The contents of each element is also a byte (8 bits) that can be
interpreted as an integer between 0 to 255.
State and key initialization
Initial State permutation
Done only once
Done only once
0 1 2 … 255 0 1 2 … 255
Key
Mix with key bytes and permute
… …
K[0] K[1] K[2] K[255] K[0] K[1] K[2] K[255]
State permutation for key stream generation State permutation for key stream generation State permutation for key stream generation
… … …
Permute state values Permute state values Permute state values
…
…
… … …
K 8 bits K 8 bits K 8 bits
8 bits + 8 bits 8 bits + 8 bits 8 bits + 8 bits
P C P C P C
Encryption (first byte) Encryption (second byte) Encryption (last byte)
Initialization
is done in two steps
1. State is initialized to values 0,1,.. .255. A key array, K[0],K[1]
… K[255] is also created. If the secret key has exactly 256
bytes, the bytes are copied to the K array, otherwise, the
bytes are repeated until the K array is filled.
for ( i=0 to 255 )
{
S[i] i
K[i] Key[ i mod KeyLength]
} 0 1 2 … 255
Key
…
State and key initialization K[0] K[1] K[2] K[255]
Done only once
2) The initialized state goes through a permutation
( swapping the elements ) based on the value of the
bytes in K[i]. The key byte is used only in this step to
define which elements are to be swapped. After this
step , the state bytes are completely shuffled.
J←0
for ( i=0 to 255 )
{
j ← ( j+S[i]+K[i])mod 256
swap(S[i],S[j]) 0 1 2 … 255
} Mix with key bytes and permute
…
Initial State permutation K[0] K[1] K[2] K[255]
Done only once
• Key stream generation
The keys in the key stream, the k’s, are generated , one by one.
-First , the state is permuted based on the values of state elements
and the values of two individual variables, i and j.
- Second , the values of state elements in position i and j are used
to define the index of the state element that serves as K.
- The following code is repeated for each byte of the PT to create
a new key element in the key stream. The variables i and j are
initialized to 0 before the first iteration, but the values are
copied from one iteration to the next.
i←(i+1)mod256
j ←(j+S[i])mod256
swap ( S[i],S[j])
k ← S[S[i]+S[j])mod256]
Encryption or Decryption
After k has been created, the PT byte is encrypted with
k to create the CT byte. Decryption is the reverse
process.
State permutation for key stream generation State permutation for key stream generation State permutation for key stream generation
… … …
Permute state values Permute state values Permute state values
…
…
… … …
K 8 bits K 8 bits K 8 bits
8 bits + 8 bits 8 bits + 8 bits 8 bits + 8 bits
P C P C P C
Encryption (first byte) Encryption (second byte) Encryption (last byte)
RC4_Encryption(K) //continuously permuting state bytes,
//generating keys, and encrypting
{ i←0
for ( i=0 to 255 )
// creation of initial state and key j←0
bytes
{ while( more byte to encrypt)
S[i] I {
K[i] Key[ i mod i←(i+1)mod256
KeyLength]
} j ←(j+S[i])mod256
J←0 swap ( S[i],S[j])
// Permuting state bytes k ← S[S[i]+S[j])mod256]
//based on values of key bytes
// key is ready for encryption input P
for ( i=0 to 255 )
{ C ← P k
j ← ( j+S[i]+K[i])mod 256
output C
swap(S[i],S[j])
} }
}
• Advantages
1.RC4 stream ciphers are simple to use.
2.The speed of operation in RC4 is fast as compared to other
ciphers.
3.RC4 stream ciphers are strong in coding and easy to
implement.
4.RC4 stream ciphers do not require more memory.
5.RC4 stream ciphers are implemented on large streams of data.
• Disadvantages
• If RC4 is not used with strong MAC then encryption is
vulnerable to a bit-flipping attack.
• RC4 stream ciphers do not provide authentication.
• RC4 algorithm requires additional analysis before including
new systems.
• RC4 stream ciphers cannot be implemented on small streams of
data.
• RC4 fails to discard the beginning of output keystream or fails
to use non-random or related keys for the algorithm.
Security issues
The cipher is secure if the key size is atleast 128 bits
(16 bytes).
It is recommended to use different keys for different
sessions.
Beyond Syllabus
Modes of operation of block ciphers
The DES is the basic building block for providing data
security. To apply DES in a variety of applications,
four modes of operation have been defined.
These four modes are intended to cover virtually
all possible applications for which DES could be
used.
They are:
1. Electronic code book mode (ECB)
2. Cipher Block Chaining(CBC)
3. Cipher Feedback(CFB), Output Feedback (OFB)
4. Counter(CTR)
Cipher Block Chaining Mode (CBC)
s-bit Cipher Feedback (CFB) Mode