Complete module3
Complete module3
. STREAM CIPHER:
In stream cipher, one byte is encrypted at a time while in block cipher ~128 bits are encrypted at a time.
Initially, a key(k) will be supplied as input to pseudorandom bit generator and then it produces a
random 8-bit output which is treated as keystream. The resulted keystream will be of size 1 byte, i.e., 8
bits.
l 3.By making the key more longer it is also safe against brute force attacks.
4.The longer the key the stronger security is achieved, preventing any attack.
5.Keystream can be designed more efficiently by including more number of 1s and 0s, for making
e
cryptanalysis more difficult.
Encryption : For Encryption,
•Plain Text and Keystream produces Cipher Text (Same keystream will be used for decryption.).
c
•The Plaintext will undergo XOR operation with keystream bit-by-bit and produces the Cipher
Text.
Example –
Plain Text : 10011001
t Keystream : 11000011
`````````````````````
Cipher Text : 01011010
r
Decryption : For Decryption,
•Cipher Text and Keystream gives the original Plain Text (Same keystream will be used for
encryption.).
o
•The Ciphertext will undergo XOR operation with keystream bit-by-bit and produces the actual
Plain Text.
Example –
Cipher Text : 01011010
n
Keystream : 11000011
``````````````````````
Plain Text : 10011001
i
Decryption is just the reverse process of Encryption i.e. performing XOR with Cipher Text.
BLOCK CIPHER:
➢ With block ciphers, the plaintext is split into fixed size chunks called blocks, and each
block is encrypted separately.
➢ Typically all blocks in the plaintext are encrypted using the same key.
➢ Block ciphers include DES, AES, RSA, and ECC.
➢ Block sizes used in secret key cryptography are usually smaller — 64 bits in DES and
128 bits in AES.
➢ The block size in RSA is much larger — 768 or more bits, while the block size in ECC is
about 200 bits.
DATA ENCRYPTION STANDARD( DES):
History:
• IBM developed Lucifer cipher
• by team led by Feistel
• used 64-bit data blocks with 128-bit key
• then redeveloped as a commercial cipher with input from NSA and others
• in 1973 NBS issued request for proposals for a national cipher standard
• IBM submitted their revised Lucifer which was eventually accepted as the DES
DES ENCRYPTION:
DES Round Structure:
plain text of 64-bit is split into two 32-bit L & R halves
Li = Ri–1
Ri = Li–1 xor F(Ri–1 , Ki )
takes 32-bit R half and 48-bit subkey and expands R to 48-bits using Expansion Permutation
and then adds to subkey then the reult passes through 8 S-boxes to get 32-bit result and finally
permutes this using 32-bit Permutation Function P.
DES Decryption
As with any Feistel cipher, decryption uses the same algorithm as encryption, except that the
application of the sub keys is reversed. Additionally, the initial and final permutations are reversed
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 −
Add round key
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 algorithm needs to be separately implemented, although they are very closely related.
RC4 Decryption
11001000 ? 01010000 = 10011000
Key-Generation Algorithm –A variable-length key from 1 to 256 bytes is used to initialize a 256-byte
state vector S, with elements S[0] to S[255]. For encryption and decryption, a byte k is generated from
S by selecting one of the 255 entries in a systematic fashion, then the entries in S are permuted again.
Key-Scheduling Algorithm: Initialization: The entries of S are set equal to the values from 0 to 255 in
ascending order, a temporary vector T, is created. If the length of the key k is 256 bytes, then k is
assigned to T. Otherwise, for a key with length(k-len) bytes, the first k-len elements of T as copied
from K, and then K is repeated as many times as necessary to fill T.
Advantages:
1.Fast and efficient:RC4 is a very fast and efficient encryption algorithm, which makes it suitable
for use in applications where speed and efficiency are critical.
2.Simple to implement:RC4 is a relatively simple algorithm to implement, which means that it can
be easily implemented in software or hardware.
3.Variable key size:RC4 supports variable key sizes, which makes it flexible and adaptable for
different security requirements.
4.Widely used:RC4 has been widely used in various applications, including wireless networks,
secure sockets layer (SSL), virtual private networks (VPN), and file encryption.
Disadvantages:
1.Vulnerabilities:RC4 has several known vulnerabilities that make it unsuitable for new
applications. For example, there is a bias in the first few bytes of the keystream, which can be
exploited to recover the key.
2.Security weaknesses:RC4 has some inherent weaknesses in its design, which make it less secure
than other encryption algorithms, such as AES or ChaCha20.
3.Limited key length:The maximum key length for RC4 is 2048 bits, which may not be sufficient
for some applications that require stronger encryption.
4.Not recommended for new applications:Due to its vulnerabilities and weaknesses, RC4 is no
longer recommended for use in new applications. Other more secure stream cipher algorithms, such
as AES-CTR or ChaCha20, should be used instead
2. A5/1: A5/1 is a stream cipher used in GSM (Global System for Mobile Communications) to provide
encryption for data transmission over the air interface. It's designed to ensure privacy and
confidentiality in GSM networks.
Here's a brief overview of how the A5/1 stream cipher works:
• R1 is a 19-bit register.
• R2 is an 22-bit register.
• R3 is an 23-bit register.
2. Clocking : The clocking mechanism involves clocking the registers and generating a key
sequence:
• The bits in the registers are clocked based on a clocking bit generated by the
combination of certain bits from the three registers.
• Based on the clocking bit, the registers are shifted to produce a keystream bit.
3. Keystream Generation :
• The keystream is generated by the combination of bits from the three registers.
• For each clock cycle, the outputs of the three registers are combined (usually using
bitwise XOR operations) to produce a keystream bit.
4. Key Initialization :
• The registers are initialized with a secret key (Kc) and an initialization vector (IV) at the
start of a communication session.
5. Key Stream Utilization :
• The keystream generated by A5/1 is XORed with the plaintext data to produce the
ciphertext.
• At the receiver's end, the same keystream (generated using the same key and IV) is
XORed with the ciphertext to retrieve the original plaintext.
A5/1 has been subject to various attacks due to its design weaknesses, which have implications for the
security of GSM communications. Therefore, newer standards like A5/3 have been developed to
address these vulnerabilities.
3. Grain Family: The Grain family of stream ciphers is a series of cryptographic algorithms designed
for efficient and secure encryption of data streams. These ciphers belong to the category of stream
ciphers, which generate a pseudorandom keystream to be combined (typically via XOR) with plaintext
to produce ciphertext. The Grain ciphers are known for their compact design, good performance in
software and hardware implementations, and strong security properties.
Grain-128 :
• Structure : Grain-128 is a stream cipher designed by Martin Hell and Thomas Johansson. It
operates with a 128-bit key and a 96-bit IV (Initialization Vector).
• Feedback Mechanism : Grain-128 uses a shift register-based feedback mechanism to produce
pseudorandom keystream bits.
• Nonlinear Operations : The cipher includes nonlinear operations (such as bitwise XOR and
rotations) to generate the keystream efficiently.
Features :
• Efficiency : Grain ciphers are designed to be efficient in terms of both speed and memory
usage, making them suitable for resource-constrained environments such as embedded systems.
• Security : The Grain family of ciphers is designed to provide strong security against various
cryptographic attacks, including linear and differential cryptanalysis.
Design Principles :
• Grain ciphers have been used in various applications, including wireless communication
systems, RFID (Radio Frequency Identification) devices, and other embedded systems
requiring lightweight cryptographic solutions.
4. Salsa20 : The Salsa20 stream cipher is a widely recognized and extensively used cryptographic
algorithm known for its speed, security, and flexibility. It was designed by Daniel J. Bernstein to
efficiently provide encryption for a variety of applications, including secure communication protocols,
disk encryption, and more. Here's an overview of the Salsa20 stream cipher:
Key Features:
1. Structure :
• Salsa20 is designed with a strong security foundation and has withstood extensive
cryptanalysis.
• The use of a large key size (256 bits) and a well-designed core function contribute to its
robustness against various types of attacks, including differential and linear
cryptanalysis.
4. Performance :
• Salsa20 is highly versatile and supports different variants, including Salsa20/12 (which
uses 12 rounds instead of 20 for reduced computational cost) and XSalsa20 (which
extends the nonce size to 192 bits for applications requiring a larger nonce space).
6. Applications :
5. ChaCha: ChaCha is a stream cipher developed by Daniel J. Bernstein, known for its simplicity,
efficiency, and strong security properties. It is a variant of the Salsa20 stream cipher and is designed to
provide high-speed encryption suitable for a wide range of applications, including secure
communication protocols, disk encryption, and more. ChaCha has gained popularity and widespread
adoption in various cryptographic systems and protocols due to its excellent performance and
robustness.
Key Features of ChaCha:
1. Structure :
• ChaCha uses a 256-bit secret key and a 64-bit nonce to initialize its internal state.
• The key and nonce are combined to set up the initial state of the ChaCha cipher.
3. Keystream Generation :
• ChaCha generates a keystream by repeatedly applying its core function, which consists
of a specified number of rounds (e.g., 20 rounds for ChaCha20).
• Each round involves a series of quarter-round operations that mix the state matrix to
produce pseudorandom output.
4. Security :
• ChaCha has different variants, including ChaCha8, ChaCha12, and ChaCha20, which
specify the number of rounds used in the core function (e.g., 8, 12, or 20 rounds).
• The number of rounds can be adjusted based on specific performance and security
requirements.
Modes of Operation for Block Ciphers
There are five different modes in which a block
cipher, such as DES or AES, can be used:
1. Electronic Code Book (ECB)
2. Cipher Block Chaining Mode (CBC)
3. Cipher Feedback Mode (CFB)
4. Output Feedback Mode (OFB)
5. Counter Mode (CTR)
12
Information Security Sufyan Al-Janabi 2015
Electronic Code Book (ECB)
Each block of plaintext is coded independently. Not very
secure for long segments of plaintext, especially plaintext
containing repetitive information.
Used primarily for secure transmission of short pieces of
information, such as an encryption key.
Another shortcoming of ECB is that the length of the
plaintext message must be integral multiple of the block
size. When that condition is not met, the plaintext message
must be padded appropriately.
The rest of the modes discussed below provide enhanced
security by making the ciphertext for any block a function
of all the blocks seen previously.
13
Information Security Sufyan Al-Janabi 2015
ECB Encryption
14
Information Security Sufyan Al-Janabi 2015
CIPHER BLOCK CHAINING MODE (CBC)
The input to the encryption algorithm is the XOR of the
next block of plaintext and the previous block of ciphertext.
This is obviously more secure for long segments of
plaintext.
This mode also requires that length of the plaintext message
be an integral multiple of the block size. When that
condition is not satisfied, the message must be suitably
padded.
To get started, the chaining scheme obviously needs what is
known as the initialization vector for the first invocation of
the encryption algorithm.
With this chaining scheme, the ciphertext block for any
given plaintext block becomes a function of all the previous
ciphertext blocks.
15
Information Security Sufyan Al-Janabi 2015
CBC Encryption
16
Information Security Sufyan Al-Janabi 2015
Cipher Feedback Mode (CFB)
Whereas the CBC mode uses all of the previous
ciphertext block to compute the next ciphertext block,
the CFB mode uses only a fraction thereof.
Also, whereas in the CBC mode the encryption system
digests b bits of plaintext at a time (where b is the
block size used by the block cipher), now the encryption
system digests only s < b number of plaintext bits at a
time even though the encryption algorithm itself carries
out a b-bits to b-bits transformation. Since s can be
any number, including one byte, that makes CFB suitable
as a stream cipher.
CFB uses only the encryption algorithm in both
encryption and decryption.
17
Information Security Sufyan Al-Janabi 2015
18
Information Security Sufyan Al-Janabi 2015 CFB Encryption
Output Feedback Mode (OFB)
The basic logic here is the same as in CFB, only the
nature of what gets fed from stage to stage is different. In
CFB, you feed s < b number of ciphertext bits from the
current stage into the b-bits to b-bits transformation
carried out by the next-stage encryption. But in OFB, you
feed s bits from the output of the transformation itself.
This mode of operation is also suitable if you want to use
a block cipher as a stream cipher.
Similarly to CFB, OFB uses only the encryption
algorithm in both encryption and decryption.
OFB is more resistant to transmission bit errors.
19
Information Security Sufyan Al-Janabi 2015
20
Information Security Sufyan Al-Janabi 2015 OFB Encryption
COUNTER MODE (CTR)
Whereas the previous four modes for using a block cipher are
intuitively plausible, this new mode at first seems strange and
seemingly not secure. But it has been theoretically established
that this mode is at least as secure as the other modes.
As for CFB and OFB, an interesting property of this mode is
that only the encryption algorithm is used at both the
encryption end and at the decryption end.
The basic idea consists of applying the encryption algorithm
not to the plaintext directly, but to a b-bit number (and its
increments modulo 2b for successive blocks) that is chosen
beforehand. The ciphertext consists of what is obtained by
XORing the encryption of the number with a b-bit block of
plaintext.
21
Information Security Sufyan Al-Janabi 2015
22
Information Security Sufyan Al-Janabi 2015 CTR Encryption
Advantages of CTR
1. Fast encryption and decryption. If memory is not a
constraint, we can pre-compute the encryptions for as
many counter values as needed. Then, at the transmit
time, we only have to XOR the plaintext blocks with
the pre-computed b-bit blocks. The same applies to fast
decryption.
2. It has been shown that the CTR is at least as secure as
the other four modes for using block ciphers.
3. Because there is no block-to-block feedback, the
algorithm is highly amenable to implementation on
parallel machines.
4. For the same reason, any block can be decrypted with
random access.
23
Information Security Sufyan Al-Janabi 2015
Chapter 9: Message Authentication and Hash Functions
A hash function H accepts a variable-length block of data M as input and produces a fixed-size hash value
h = H(M). A “good” hash function has the property that the results of applying the function to a large set
of inputs will produce outputs that are evenly distributed and apparently random. In general terms, the
principal object of a hash function is data integrity. A change to any bit or bits in M results, with high
probability, in a change to the hash value.
The kind of hash function needed for security applications is referred to as a cryptographic hash function.
A cryptographic hash function is an algorithm for which it is computationally infeasible (because no attack
is significantly more efficient than brute force) to find either
(a) a data object that maps to a pre-specified hash result (the one-way property) or
(b) two data objects that map to the same hash result (the collision-free property).
Because of these characteristics, hash functions are often used to determine whether or not data has
changed.
Message Authentication:
Figure below illustrates a variety of ways in which a hash code can be used to provide message
authentication, as follows.
a) The message plus concatenated hash code is encrypted using symmetric encryption. Because only
A and B share the secret key, the message must have come from A and has not been altered. The
hash code provides the structure or redundancy required to achieve authentication. Because
encryption is applied to the entire message plus hash code, confidentiality is also provided.
When confidentiality is not required, method (b) has an advantage over methods (a) and (d), which
encrypts the entire message, in that less computation is required. Nevertheless, there has been growing
interest in techniques that avoid encryption.
• Encryption software is relatively slow. Even though the amount of data to be encrypted per
message is small, there may be a steady stream of messages into and out of a system.
• Encryption hardware costs are not negligible. Low-cost chip implementations of DES are available,
but the cost adds up if all nodes in a network must have this capability.
• Encryption hardware is optimized toward large data sizes. For small blocks of data, a high
proportion of the time is spent in initialization/invocation overhead.
• Encryption algorithms may be covered by patents, and there is a cost associated with licensing
their use.
The message authentication function is concerned with the types of functions that may be used to pro-
duce an authenticator. These may be grouped into three classes:
• Hash function: A function that maps a message of any length into a fixed- length hash value, which
serves as the authenticator.
• Message encryption: The ciphertext of the entire message serves as its authenticator.
• Message authentication code (MAC): A function of the message and a secret key that produces a
fixed-length value that serves as the authenticator.
A authentication technique that involves the use of a secret key to generate a small fixed-size block of
data that is appended to the message is known as Message Authentication Code (MAC). This technique
assumes that two communicating parties, say A and B, share a common secret key K. When A has a
message to send to B, it calculates the MAC as a function of the message and the key:
MAC = C (K, M)
where
M = input message
C = MAC function
The message plus MAC are transmitted to the intended recipient. The recipient performs the same
calculation on the received message, using the same secret key, to generate a new MAC. The received
MAC is compared to the calculated MAC.
• The receiver is assured that the message has not been altered. If an attacker alters the message
but does not alter the MAC, then the receiver’s calculation of the MAC will differ from the received
MAC. Because the attacker is assumed not to know the secret key, the attacker cannot alter the
MAC to correspond to the alterations in the message.
• The receiver is assured that the message is from the alleged sender. Because no one else knows
the secret key, no one else could prepare a message with a proper MAC.
• If the message includes a sequence number (such as is used with TCP), then the receiver can be
assured of the proper sequence because an attacker cannot successfully alter the sequence
number.
A MAC function is similar to encryption. One difference is that the MAC algorithm need not be reversible,
as it must be for decryption. In general, the MAC function is a many-to-one function. The domain of the
function consists of messages of some arbitrary length, whereas the range consists of all possible MACs
and all possible keys.
• A cryptographic hash function (CHF) is a hash function that is suitable for use in cryptography.
• It is a mathematical algorithm that maps data of arbitrary size (often called the "message") to a
bit string of a fixed size (the "hash value", "hash", or "message digest") and is a one-way function,
that is, a function which is practically infeasible to invert.
• Ideally, the only way to find a message that produces a given hash is to attempt a brute-force
search of possible inputs to see if they produce a match, or use a table of matched hashes.
• Cryptographic hash functions are a basic tool of modern cryptography.
The process depicted in Figure (a) provides authentication but not confidentiality, because the message
as a whole is transmitted in the clear.
Confidentiality can be provided by performing message encryption either after (Figure b) or before
(Figure c) the MAC algorithm.
In both these cases, two separate keys are needed, each of which is shared by the sender and the receiver.
In the first case, the MAC is calculated with the message as input and is then concatenated to the message.
The entire block is then encrypted. In the second case, the message is encrypted first.
Then the MAC is calculated using the resulting ciphertext and is concatenated to the ciphertext to form
the transmitted block.
Typically, it is preferable to tie the authentication directly to the plaintext, so the method of Figure b is
used.
MACs based on hash functions: HMAC
HMAC Design Objectives
RFC 2104 lists the following design objectives for HMAC.
• To use, without modifications, available hash functions. In particular, to use hash functions that perform
well in software and for which code is freely and widely available.
• To allow for easy replaceability of the embedded hash function in case faster or more secure hash
functions are found or required.
• To preserve the original performance of the hash function without incurring a significant degradation.
• To use and handle keys in a simple way.
• To have a well understood cryptographic analysis of the strength of the authentication mechanism based
on reasonable assumptions about the embedded hash function.
HMAC Algorithm
H = embedded hash function (e.g., MD5, SHA-1, RIPEMD-160)
IV = initial value input to hash function
Information Technology II Year II Semester
Unit-5:EM-IV [19BS1403] Number Theory & Cryptography
M = message input to HMAC (including the padding specified in the embedded
hash function)
Yi _ i th block of M, 0 ≤i ≤(L – 1)
L _ number of blocks in M
b _ number of bits in a block
n _ length of hash code produced by embedded hash function
K _ secret key; recommended length is ≥n; if key length is greater than b, the key is input to the hash function
to produce an n-bit key
K+ _ K padded with zeros on the left so that the result is b bits in length
ipad _ 00110110 (36 in hexadecimal) repeated b/8 times
opad _ 01011100 (5C in hexadecimal) repeated b/8 times