CYS406 · Annotated SlidesChapter 6 — PRNGs, RC4 and Block-Cipher Modes of Operation
Chapter 6 · Annotated slides

PRNGs, RC4 and Block-Cipher Modes of Operation

Random vs. pseudorandom numbers, PRNGs, stream ciphers and RC4 (key schedule, encryption, security), then the modes of operation: ECB, CBC, CFB, OFB and CTR with their advantages and limitations.

Slide text Study notes Highlight: key words Tips, tricks & traps Seen again elsewhere How it can come up
Slide 1: Slide 1
Exam weight Low

    Outline

    Stream Cipher & RC4 Modes Of Operation

    2
    Exam weight Low

      Pseudorandom

      Number Generators (PRNGs)

      3
      Exam weight Low
        Slide 4: Random Numbers
        Exam weight Low
          Slide 5: Pseudorandom Number Generators (PRNGs)
          Exam weight Low
          1. PRNG: a deterministic algorithm that produces random-looking numbers from a seed.
          Slide 6: Random & Pseudorandom Number Generators
          Exam weight Low

            Stream Ciphers and rc4

            7
            Exam weight Low
              Slide 8: Stream Cipher Structure
              Exam weight High
              1. Stream cipher: keystream XOR plaintext. Never reuse a keystream (same key + IV).
              🎯 How this can come up · 1 question
              True / False

              Reusing the same keystream for two messages is safe if the messages differ.

              Stream Cipher Properties

              properly designed, can be as secure as a block cipher with same key length but usually simpler & faster however must never reuse same key

              • otherwise cryptanalysis is quite simple

              Example: RC4

              9
              Exam weight Low

                3. RC4

                a proprietary cipher owned by RSA DSI

                • another Ron Rivest design, simple but effective
                • variable key size, byte-oriented stream cipher
                • widely used (web SSL/TLS, wireless WEP/WPA)
                • key forms random permutation of all 8-bit values
                • uses that permutation to scramble input info
                • processed a byte at a time
                10
                Exam weight Low
                1. RC4: variable-length key, byte-oriented stream cipher, simple and fast. Used in WEP and old TLS; now considered broken.
                Slide 11: RC4 Key Schedule
                Exam weight Low
                1. RC4 key schedule (KSA) permutes the 256-byte state S using the key; the PRGA then outputs keystream bytes.

                RC4 Encryption

                encryption continues shuffling array values sum of shuffled pair selects "stream key" value from permutation (k=S[t]) XOR S[t] with next byte of message to en/decrypt

                i = j = 0 for each message byte M

                i

                i = (i + 1) (mod 256) j = (j + S[i]) (mod 256) swap(S[i], S[j]) t = (S[i] + S[j]) (mod 256) C = M XOR S[t]

                i

                i

                12
                Exam weight Low
                  Slide 13: RC4 Example
                  Exam weight Low
                    Slide 14: RC4 Example
                    Exam weight Low
                      Slide 15: RC4 Example
                      Exam weight Low
                        Slide 16: RC4 Example
                        Exam weight Low
                          Slide 17: RC4 Example
                          Exam weight Low

                            RC4 Overview

                            18
                            Exam weight Low

                              RC4 Security

                              claimed secure against known attacks

                              • have some analysis, but none practical since RC4 is a stream cipher, must never reuse a key have a concern with WEP, but due to the way keys are generated for use as input to RC4 rather than RC4 algorithm itself
                              19
                              Exam weight Low

                                Modes of Operation

                                20
                                Exam weight Low

                                  Modes of Operation

                                  block ciphers encrypt fixed size blocks

                                  • eg. DES encrypts 64-bit blocks with 56-bit key need some way to en/decrypt arbitrary amounts of data in practise e.g. a message of 1000 bytes ⚫

                                  NIST SP 800-38A defines 5 modes have block and stream modes to cover a wide variety of applications can be used with any block cipher

                                  21
                                  Exam weight Low

                                    Message Padding

                                    at end of message must handle a possible last short block

                                    • which is not as large as blocksize of cipher
                                    • pad either with known non-data value (eg nulls)
                                    • or pad last block along with count of pad size
                                      • eg. [ b1 b2 b3 0 0 0 0 5]
                                      • means have 3 data bytes, then 5 bytes pad+count
                                    • this may require an extra entire block over those in message there are other modes, which avoid the need for an extra block
                                    22
                                    Exam weight Low

                                      Electronic Codebook Book (ECB)

                                      message is broken into independent blocks which are encrypted Each block encrypted using the same key each block is a value which is substituted, like a codebook, hence name each block is encoded independently of the other blocks

                                      C = E (P)

                                      i K i

                                      uses

                                      : secure transmission of single values

                                      23
                                      Exam weight High
                                      1. ECB: each block encrypted independently. Identical plaintext blocks → identical ciphertext blocks (patterns leak).
                                      Exam trapECB leaks patterns (the "ECB penguin"); never use it for more than one block.
                                      🎯 How this can come up · 1 question
                                      MCQ

                                      Which mode produces identical ciphertext for identical plaintext blocks?

                                      Electronic Codebook Book (ECB)

                                      24
                                      Exam weight Low

                                        Advantages and Limitations of ECB

                                        message repetitions may show in ciphertext

                                        • if aligned with message block
                                        • particularly with data such graphics
                                        • or with messages that change very little, which become a code-book analysis problem weakness is due to the encrypted message blocks being independent main use is sending a few blocks of data. e.g. Session encryption keys
                                        25
                                        Exam weight Low

                                          Cipher Block Chaining (CBC)

                                          message is broken into blocks linked together in encryption operation each previous cipher blocks is chained with current plaintext block, hence name use Initial Vector (IV) to start process

                                          C = E (P XOR C)

                                          i K i

                                          i-1

                                          C = IV

                                          -1

                                          uses: bulk data encryption, authentication

                                          26
                                          Exam weight High
                                          1. CBC: each plaintext block is XORed with the previous ciphertext block (first with an IV) before encryption. Sequential encryption; an error affects two blocks.
                                          🎯 How this can come up · 1 question
                                          MCQ

                                          In CBC, the first plaintext block is XORed with:

                                          Cipher Block Chaining (CBC)

                                          27
                                          Exam weight Low

                                            Advantages and Limitations of CBC

                                            a ciphertext block depends on all blocks before it any change to a block affects all following ciphertext blocks need Initialization Vector (IV)

                                            • which must be known to sender & receiver
                                            • if sent in clear, attacker can change bits of first block, and change IV to compensate
                                            • hence IV must either be a fixed value
                                            • (as in EFTPOS Electronic Funds Transfer at Point Of Sale)
                                            • or must be sent encrypted in ECB mode before rest of message
                                            28
                                            Exam weight Low

                                              Stream Modes of Operation

                                              block modes encrypt entire block may need to operate on smaller units

                                              • real time data convert block cipher into stream cipher
                                              • cipher feedback (CFB) mode
                                              • output feedback (OFB) mode
                                              • counter (CTR) mode use block cipher as some form of pseudo-random number generator
                                              29
                                              Exam weight Low
                                                Slide 30: Using Block Ciphers as PRNGs
                                                Exam weight Low

                                                  Cipher FeedBack (CFB)

                                                  message is treated as a stream of bits added to the output of the block cipher result is feed back for next stage (hence name) standard allows any number of bit (1,8, 64 or 128 etc) to be feed back

                                                  • denoted CFB-1, CFB-8, CFB-64, CFB-128 etc most efficient to use all bits in block (64 or 128)

                                                  C = P XOR E (C)

                                                  i

                                                  i

                                                  K i-1

                                                  C = IV

                                                  -1

                                                  uses

                                                  : stream data encryption, authentication

                                                  31
                                                  Exam weight Low
                                                  1. CFB: turns a block cipher into a self-synchronizing stream cipher.

                                                  s-bit Cipher Feed Back (CFB-s)

                                                  32
                                                  Exam weight Low

                                                    Advantages and Limitations of CFB

                                                    appropriate when data arrives in bits/bytes most common stream mode errors propagate for several blocks after the error

                                                    33
                                                    Exam weight Low

                                                      Output FeedBack (OFB)

                                                      message is treated as a stream of bits output of cipher is added to message output is then feed back (hence name) feedback is independent of message can be computed in advance

                                                      O = E (O)

                                                      i

                                                      K i-1

                                                      C = P XOR O

                                                      i

                                                      i

                                                      i

                                                      O = IV

                                                      -1

                                                      : stream encryption on noisy channels

                                                      uses

                                                      34
                                                      Exam weight Low
                                                      1. OFB: keystream from repeatedly encrypting the IV; bit errors don’t propagate.

                                                      Output FeedBack (OFB)

                                                      35
                                                      Exam weight Low

                                                        Advantages and Limitations of OFB

                                                        needs an IV which is unique for each use

                                                        • if ever reuse attacker can recover outputs

                                                        Advantage: bit errors do not propagate Disadvantage: more vulnerable to message stream modification sender & receiver must remain in sync only use with full block feedback

                                                        • subsequent research has shown that only full block feedback (ie CFB-64 or CFB-128) should ever be used
                                                        36
                                                        Exam weight Low

                                                          Counter (CTR)

                                                          a “new” mode, though proposed early on similar to OFB but encrypts counter value rather than any feedback value must have a different key & counter value for every plaintext block (never reused)

                                                          O = E (i)

                                                          i K

                                                          C = P XOR O

                                                          i i

                                                          i

                                                          uses: high-speed network encryptions

                                                          37
                                                          Exam weight High
                                                          1. CTR: encrypt a counter for each block and XOR. Parallel, random access, needs a unique nonce per message.
                                                          🎯 How this can come up · 1 question
                                                          MCQ

                                                          Which mode allows parallel encryption and random access to blocks?

                                                          Counter (CTR)

                                                          38
                                                          Exam weight Low

                                                            Advantages and Limitations of CTR

                                                            efficiency

                                                            • can do parallel encryptions in h/w or s/w
                                                            • can preprocess in advance of need
                                                            • can process blocks of plaintext or ciphertext in a random-access fashion provable security (good as other modes) but must ensure never reuse key/counter values, otherwise could break (cf OFB)
                                                            39
                                                            Exam weight Low

                                                              References

                                                              Network Security Essentials: Applications and Standards, chapter 2.

                                                              Network Security: Private Communication in a Public World, chapter 3.

                                                              40
                                                              Exam weight Low