What is a stream cipher? 🔗
A symmetric-key encryption method that encrypts data bit by bit.
Input: Elements received continuously.
Output: One element at a time.
Faster than a block cipher.
The key is used only once.
Vulnerable to known-plaintext attacks:
M ⊕ C = M ⊕ ( M ⊕ k ) = k M \oplus C = M \oplus (M \oplus k) = k M ⊕ C = M ⊕ ( M ⊕ k ) = k .
Examples: LFSR, RC4, and ChaCha.
Widely used in cryptography:
Private keys in public-key cryptography.
Keys for stream ciphers.
Symmetric keys for temporary sessions.
Requirements:
Randomness.
Uniform distribution: Each number should occur with the same frequency.
Independence: No value can be inferred from another.
Unpredictability.
Each number is statistically independent of the others.
No one should be able to predict future elements from earlier elements in the sequence.
Random vs. pseudorandom numbers 🔗
True random number generator (TRNG):
Expensive to implement.
Uses a nondeterministic source.
Measures unpredictable natural processes such as radioactivity, gas discharge, or leakage in a capacitor.
Increasingly available in recent processors.
Pseudorandom numbers:
Generates sequences that pass statistical randomness tests.
Uses a deterministic source and is therefore more predictable.
RC stands for Rivest Cipher.
A stream cipher with a variable key size, built from byte-level operations.
Expected to be fast in software.
Based on the use of a random permutation.
S: An array of 256 bytes.
Initially contains each number from 0 through 255 once, in ascending order.
T: A temporary vector whose first keylen elements are copied from k.
keylen: Key length.
k: The key, repeated as necessary to fill T.
Use T to permute S.
j = 0
for i= 0 to 255 do
j = (j + S[i] + T[i]) mod 256 ;
Swap(S[i], S[j]);
Traverse the elements of S[i].
i = 0
j = 0
while (true)
i = (i + 1 ) mod 256
j = (j + S[i]) mod 256
Swap(S[i], S[j])
t = (S[i] + S[j]) mod 256
k = S[t]
Encryption: XOR k with the next plaintext byte.
Decryption: XOR k with the next ciphertext byte.
With a reasonable key size, such as 128 bits, RC4 is considered secure.
It is vulnerable in the WEB (Wired Equivalent Privacy) protocol.
What are modes of operation? 🔗
Methods for encrypting messages using a block cipher.
A block cipher's limitation: Fixed-length plaintext blocks.
Modes of operation use a block cipher to encrypt messages of arbitrary length.
ECB (Electronic Codebook).
CBC (Cipher Block Chaining).
CFB (Cipher Feedback).
OFB (Output Feedback).
CTR (Counter).
ECB mode (Electronic Codebook) 🔗
Encryption: Encrypt one block at a time.
At time n, encrypt P n P_n P n → C n C_n C n .
Decryption: Decrypt one block at a time.
At time n, decrypt C n C_n C n → P n P_n P n .
Advantages:
No block synchronization is required.
A transmission error affects only its own block.
Parallel processing is possible.
Disadvantages:
Deterministic encryption.
Vulnerable to substitution attacks: Identical plaintext blocks can become identical ciphertext blocks.
CBC mode (Cipher Block Chaining) 🔗
Encryption: Uses XOR with the previous block's ciphertext and key K.
C n = E K ( P n ⊕ C n − 1 ) C_n = E_K(P_n \oplus C_{n-1}) C n = E K ( P n ⊕ C n − 1 )
Decryption: Uses XOR with the previous block's ciphertext and key K.
P n = D K ( C n ) ⊕ C n − 1 P_n = D_K(C_n) \oplus C_{n-1} P n = D K ( C n ) ⊕ C n − 1
An initialization vector is required.
CFB mode (Cipher Feedback) 🔗
Encryption: A mode that encrypts and uses the initialization vector with key K and XOR…