07. Pseudorandom Numbers and Stream Ciphers

Random Numbers

Randomness: want any specific string of bits is exactly as random as any other string.

True random number generator (TRNG): physical process which outputs each valid string independently with equal probability.

Pseudorandom number generator (PRNG): deterministic algorithm which approximates a TRNG.

For practically, TRNGs are often used to provide a seed for a PRNG.

Pseudorandom Number Generator (PRNG)/Deterministic Random Bit Generator (DRBG)

Entropy source includes:

Periodic health tests required to ensure reliable operation.

Each generator takes a seed as an input, outputting a bit string before updating its state.

The seed should be updated after some number of calls.

DRBGs expose some functions:

The DDRBG should prevent an attacker from being able to reliably distinguish between its output and a truly random string. There are two types of resistance:

CTR_DRBG

Block cipher in counter (CTR) mode - AES with 128-bit keys recommended.

DRBG initialized with seed whose length is equal to key length PLUS block length.

Seed defines a key KK and counter value ctrctr (no separate nonce).

CTR run iteratively with no plaintext.

Update Function

Each request to the DRBG generates up to 2192^{19} bits.

State (K,ctr)(K, ctr) must be updated after each Generate request by generating two blocks using the current key to obtain a new key and counter; provides backtracking resistance.

Up to 2482^{48} requests to the Generate function are allowed before re-seeding is required; provides forwards prediction and backtracking resistance.

Dual_EC_DRBG

Older standard based on elliptic curve discrete logarithm problem and with many flaws.

Much slower than other DRBGs.

Secret deal between NSA and RSA Security to use this as the default PRNG in their software was reported in 2013.

Stream Ciphers

Generates keystream using a short key and initialization vector IVIV.

Each element of the keystream is used to successively encrypt one or more ciphertext characters.

Stream ciphers are usually symmetric.

Synchronous Stream Ciphers

Keystream is generated independently of the plaintext; both the sender and receiver need to generate the same keystream and be synchronized.

Keystream and plaintext are XORed together, so receiver simply needs to XOR the ciphertext with the keystream to decrypt.

Vigenère cipher can be seen as a periodic synchronous stream cipher where each shift is defined by a key letter.

CTR mode of operation for a block cipher can be used to generate a keystream.

Binary Synchronous Stream Ciphers

For each time interval tt:

Encryption: c(t)=p(t)s(t)c(t) = p(t) \oplus s(t).

Decryption: p(t)=c(t)s(t)p(t) = c(t) \oplus s(t).

One-Time Pad

Key is random sequence of characters such that each is independently generated.

Each character in the key is only used once; this provides perfect secrecy.

Alphabet can be of any length but is usually either binary or a natural language alphabet.

Perfect Secrecy

Shannon’s definition:

The ciphertext should be independent of the plaintext

One-Time Pad Perfect Secrecy

Let a ciphertext CjC_j be observed.

The probability that MiM_i was sent given that CjC_j is observed is the probability that MiM_i is chosen, weighted by the probability that the right keystream is chosen.

As each keystream is chosen with equal probability, Pr(MiCj)=Pr(Mi)\mathrm{Pr}(M_i | C_j) = \mathrm{Pr}(M_i).

Any keystream is possible and so given any plaintext, every possible ciphertext is generated with equal probability.

Vernam Binary One-Time Pad

Properties

Shannon showed that any ciphertext with perfect secrecy must have as many keys as there are messages. Hence, one-time pad is the only unbreakable cipher.

However, this requires secure communication between fixed parties and secure key generation, transportation, synchronization, and destruction which are all difficult due to the size of the keys.

Visual Cryptography

Encryption splits an image into two shares, each pixel being shared in a random way (similar to splitting a bit in a one-time pad).

Each share alone reveals no information about the image, but the two images can be overlayed to reveal the plaintext.

Prominent Stream Ciphers

A5 Cipher

Binary synchronous stream cipher applied in most GSM communications. Three variants:

A5/1 Design

Three linear feedback shift registers (LFSRs) whose outputs are combined.

The LFSRs are irregularly clocked, making the overall output non-linear.

It has a 64-bit keystream such that 10 bits are fixed to zero; hence, the effective key length is 54 bits.

RC4 Cipher

Ron’s code #4 . Originally owned by RSA but leaked in 1994. Too weak to use in real systems nowadays, but was was widely deployed in TLS before 2013.

ChaCha Algorithm

Possible replacement of RC4 designed in 2008.

Faster than AES; as few as 4 cycles/byte on x84 processors.