☕
Pause for minutes until .
Remaining:
Pius Walter
T4INF1202: Kryptologie
Part 4: Block ciphers, stream ciphers and operation modes
2026-04-21
Recap
  • Last week we spoke about authentication functions and authenticated encryption
  • This week we are going to more generally discuss different cipher types and how authenticated encryption works
  • In particular, we'll discuss stream ciphers, block ciphers and their operation modes
Cipher properties
  • Good cipher properties are similar to properties of cryptographically secure hash functions.
  • Encryption exhibits a strong avalanche effect in the input key and, ideally, also under the input plaintext
  • Ciphertext looks statistically uniform and practically random (i.e., it is indistinguishable from a truly random sequence of data)
Stream vs. block ciphers
  • Generally, stream ciphers produce a continuous key stream that is infinite in length
  • This stream is XORed against the plaintext in a bitwise fashion to produce the ciphertext
  • Conversely, the same key stream is XORed against the ciphertext to get back the plaintext
Stream cipher
Stream vs. block ciphers
  • In the typical case, the key stream therefore is independent of the plaintext
  • Typically, encryption and decryption are the same, identical operation
  • Sometimes, encryption and decryption are not identical operations, but the plaintext influences the key stream
  • Viewed abstractly, it does not matter (implementation detail)
Stream vs. block ciphers
  • The other class of ciphers that is commonly used are block ciphers
  • Block ciphers have a block size (typically no less than 128 bit in a modern cipher)
  • The only possible operation of such a cipher is to encrypt or decrypt a full block
  • Encryption and decryption operations are typically not identical
Block cipher encryption
Block cipher decryption
Stream cipher recap
  • Recall that in a stream cipher, Q4mta4Ck5NLHC = S \oplus PZf1qH71g5gJY, where Q4mta4Ck5NLHSZf1qH71g5gJY is the key stream (not the seeding key)
  • We have a function that generates us the infinitely long sequence Q4mta4Ck5NLHSZf1qH71g5gJY from the key Q4mta4Ck5NLHKZf1qH71g5gJY (a CSPRNGCryptographically Secure Pseudo-Random Number Generator)
  • It is critical that Q4mta4Ck5NLHSZf1qH71g5gJY does not only depend on Q4mta4Ck5NLHKZf1qH71g5gJY. Why is that?
Stream cipher recap
  • Imagine two messages being encrypted under the same key Q4mta4Ck5NLHKZf1qH71g5gJY where the key streams Q4mta4Ck5NLHSZf1qH71g5gJY would be identical
  • Q4mta4Ck5NLHC_1 = E_K(P_1) = P_1 \oplus SZf1qH71g5gJY
  • Q4mta4Ck5NLHC_2 = E_K(P_2) = P_2 \oplus SZf1qH71g5gJY
  • Imagine an attacker knows one plaintext/ciphertext pair Q4mta4Ck5NLHP_1, C_1Zf1qH71g5gJY but is unable to decrypt Q4mta4Ck5NLHC_2Zf1qH71g5gJY
Stream cipher recap
  • With knowledge of both Q4mta4Ck5NLHP_1, C_1Zf1qH71g5gJY, recovery of Q4mta4Ck5NLHSZf1qH71g5gJY is simple:
  • Q4mta4Ck5NLHC_1 = P_1 \oplus S \rightarrow S = C_1 \oplus P_1Zf1qH71g5gJY
Stream cipher recap
  • With knowledge of both Q4mta4Ck5NLHP_1, C_1Zf1qH71g5gJY, recovery of Q4mta4Ck5NLHSZf1qH71g5gJY is simple:
  • Q4mta4Ck5NLHC_1 = P_1 \oplus S \rightarrow S = C_1 \oplus P_1Zf1qH71g5gJY
  • With knowledge of Q4mta4Ck5NLHSZf1qH71g5gJY, arbitrary ciphertexts could be decrypted:
  • Q4mta4Ck5NLHP_2 = D_K(C_2) = C_2 \oplus SZf1qH71g5gJY
Stream cipher nonce
  • Similar to the Shannon one-time pad, key streams may never be reused in a stream cipher
  • That is precisely the reason for the nonce (which is publicly transmitted with the ciphertext): to allow encryption of different messages under the same key
  • The nonce ensures that the CSPRNG generates a different sequence for different nonces even when Q4mta4Ck5NLHKZf1qH71g5gJY is identical
Stream cipher nonce
  • It must be ensured that this nonce is always unique, otherwise security guarantees do not hold anymore.
  • How can this be ensured? What do you think a typical implementation looks like?
Stream cipher nonce
  • Typically, the nonce is long enough (e.g. 96 bit) and generated by a CSPRNGCryptographically Secure Pseudo-Random Number Generator
  • Additionally, a monotonic counter is typically concatenated with the random value to produce a 128 bit value
  • Note that the counter may not wrap around, i.e., after Q4mta4Ck5NLH2^{32}Zf1qH71g5gJY operations, a new nonce is needed
Examples
  • RC4 (1987): 8-2048 bit key
  • A5/1 (1989): 54 or 64 bit key
  • Achterbahn-128/80 (2006): 128 bit or 80 bit key
  • ChaCha (2008): 128 bit or 256 bit key (internally always 256 bit)
Block cipher basic construction
  • In contrast to stream ciphers, block ciphers do not have this particular implementation caveat
  • However, they pose a different security challenge
  • Recall that any input block is both a valid ciphertext and a valid plaintext block (i.e., encryption/decryption works for all inputs)
Block cipher encryption
Block cipher basic construction
  • Think about non-salted password hashing for a second.
  • A similar issue occurs in this “plain” usage of a block cipher encryption primitive.
  • Do you know what it is?
Block cipher basic construction
  • Same plaintext blocks always map to the same ciphertext block under a specific key Q4mta4Ck5NLHKZf1qH71g5gJY
  • This breaks one of the most basic assumptions, namely indistinguishability
  • I.e., clearly even for the best block cipher, a constant sequence of any value maps to a pattern that is a multiple of the block size
Block cipher input
Block cipher output
The need for an operation mode
  • Using a block cipher without any additional means of protecting data is, therefore, highly dangerous and discouraged
  • This is called ECBElectronic Codebook, and it is, roughly speaking, the “operation mode of no operation mode”
  • Think about the block cipher as an incredibly large lookup table (e.g., with Q4mta4Ck5NLH2^{128}Zf1qH71g5gJY entries)
ECB in practice
  • If you review cryptography and ever see ECBElectronic Codebook being used directly, this is a huge red flag
  • There are virtually no use-cases in the real world that use ECBElectronic Codebook, it is exclusively used to build better cryptographic constructions
Simple operation modes
  • To mitigate the effects of plain ECBElectronic Codebook, input blocks can be constructed in a particular way that avoids that even identical input blocks make it to the encryption function unmodified
  • Naive approach could be: add a counter value to the plaintext
  • For different blocks Q4mta4Ck5NLHP_1, P_2, \ldots, P_nZf1qH71g5gJY, encryption could be Q4mta4Ck5NLHC_i = E_K(P_i \oplus i)Zf1qH71g5gJY
  • What would be the basic issue with such a construction?
Simple operation modes
  • This would solve the problem of identical blocks being mapped to the same ciphertext blocks
  • However, it would exhibit the exact same phenomenon for slightly related plaintext blocks (i.e., which would differ only in the counter bits)
  • The idea is generally sound, however. We should pad with a pseudo-random sequence. What would be a solid and efficient idea to achieve this?
Cipher block chaining
  • Note that we previously established that the ciphertext output of an ideal cipher looks practically random
  • The simplest operation mode is CBCCipher Block Chaining, the cipher block chaining mode, and it uses that exact property to achieve relatively good robustness
Cipher block chaining
  • Idea: For the first block, XOR a randomly selected block with the plaintext; this is the IVInitialization Vector (initialization vector)
  • IVInitialization Vector is transmitted along with the ciphertext (not secret)
  • For every subsequent block, XOR the previous ciphertext with the plaintext
CBC encryption
CBC encryption
CBC encryption
CBC encryption properties
  • Can still encrypt only integer multiples of the block size
  • Two entirely identical messages encrypted with different IVInitialization Vectors will encrypt to completely different ciphertexts
  • Any bit error has infinite error propagation (i.e., entire stream that follows is broken)
CBC decryption
CBC decryption
CBC decryption
CBC decryption properties
  • Modification of any ciphertext block does two things:
    • It completely destroys the corresponding plaintext block
    • It modifies the subsequent block linearly
  • This is one of the reasons why attacks on CBCCipher Block Chaining, under specific circumstances, can be feasible
CBC message size
  • Typically, we do not want to transmit messages that are an integer multiple of the block size
  • The abstraction should be able to handle arbitrary messages – we don't want to worry about this in the application
  • Otherwise, change of block cipher could have consequences on application layer code (e.g., when the block size changes)
  • How can we achieve this?
CBC message size
  • We could introduce a length field, but that would require that at the time of sending the message, the full length is already known
  • Also needs to be ensured that the message length is authenticated (otherwise truncation attacks could be possible)
  • Typically, unambiguous padding is applied to messages by use of PKCS#7
CBC padding
CBC properties
  • In CBCCipher Block Chaining, we can observe continued error propagation for any different plaintext bit due to the avalanche property of the underlying block cipher
  • This means that as soon as the first different block is encrypted (e.g., different IVInitialization Vector or different plaintext block), all subsequent ciphertext data will be entirely different
CBC properties
Stream cipher operation modes
  • Operation modes can perform powerful transformation on the underlying block cipher primitive
  • Many operation modes (e.g., CCMCounter with CBC-MAC, CTRCounter Mode, GCMGalois/Counter Mode) turn a block cipher into a pseudo stream cipher
  • This construction then has all advantages and disadvantages of an actual stream cipher
Stream cipher operation modes
  • The fundamental trick is to use some form of deterministic plaintext into the encryption
  • Because of the block cipher's avalanche property, we will see greatly varying ciphertexts
  • Those ciphertexts are then used as a key stream which is XORed onto the plaintext
  • The simplest operation mode that does this: CTRCounter Mode
CTR encryption
CTR encryption
CTR encryption
CTR decryption
CTR decryption
CTR decryption
CTR properties
  • There is no continued error propagation (bit errors only affect the respective block)
  • Tampering with ciphertext has linear effects on the corresponding plaintexts
  • Nonce reuse leads to reveal of keystream and breaks security completely
  • Only the block cipher encryption primitive is needed
Examples
  • DES: 56 bit key size, 64 bit block size
  • 3DES: 168 bit key size, 64 bit block size
  • Blowfish: 32-448 bit key size, 64 bit block size
  • AES-128: 128 bit key size, 128 bit block size
  • AES-256: 256 bit key size, 128 bit block size
Conclusion
45
Takeaway
  • You should be able to:
    • Clearly identify block ciphers vs. stream ciphers and their respective underlying properties
    • Identify and explain what an operation mode is and how it can affect the use of the cipher
    • Name some typical candidates of block ciphers, stream ciphers, and operation modes
Thank you!
Any questions?
Acronyms