Ci = Mi XOR StreamKeyi
Conceptually a stream cipher is very simple - have a collection of random (or random looking) stream key bits, and just XOR with message (could use other combining operator, but XOR is by far the easiest and most common). If the stream key is indeed random, then no information about the message can leak through.
Emphasize that the Vernam Cipher is the only cipher we know to be unconditionally secure BUT this only holds if the key stream is truly random and used once only! However given these limitations, it IS used for the most sensitive govt/military communications.
C1i = M1i XOR StreamKeyi C2i = M2i XOR StreamKeyi C1i XOR C2i = M1i XOR StreamKeyi XOR M2i XOR StreamKeyi = M1i XOR M2i
Emphasise the limitations of the Vernam cipher - must distribute large
quantities of key material, securely, in advance, and limit messages
to the amount of key available. Also that have to use other methods
to ensure integrity (need a crypto checksum or similar). And most
critically, must ensure key material is never ever recycled (unlike
politicians promises!!!!!)
However, WRT to key distribution, never underestimate the "bandwidth"
(capacity) of a briefcase full of Exabyte tapes or CDROMs (many many GB's)!
Quite a lot of effort has gone into trying to devise some way of "expanding" a small amount of key (randomness) into a much larger amount, which can then be used as the "stream key" in a Vernam-like cipher. The problem is that the "stream key" has to be not just statistically random but also cryptographical strong ie unpredictable. The usual "random number generators" on computers are statistically random, but are highly predictable (for reasons of easy implementation and reproducability of results) - good for lots of purposes, useless for crypto!!!
Ci = Pi XOR Oi Oi = DESK1(Oi-1) O-1 = IV
Ci = Pi XOR Oi Oi = DESK1(i)
Note the obvious PRG is just to use a block cipher. Can use OFB or Counter modes to generate a "stream key" that is independent of the message.
Ci = Pi XOR DESK1 (Ci-1) C-1 = IV
Can use CFB mode to generate a "stream key" that depends on both key and message. All work quite well - but block ciphers are still complex and at least moderately computationally expensive. Would really like a faster, simpler PRG.
LFSR's are the basic building block of the majority of stream ciphers. Compare to general model: shift register is "internal state", feedback polynomial is the "next state function", bumped bit is "output function". See Schneier for details of the fibonacci vs galois configurations, which are cryptographically equivalent, but easier to implement in h/w & s/w respectively. Variations of this are what most computers use for their "random number" function.
p(x) = x32+x7+x5+x3+x2+x
Usually use the key to set the initial register state - if using for the feedback polynomial then have to take care to select "primitive polynomials" (or accept the loss in size & security of not using them). Briefly, "primitive polynomials" are "prime polynomials", that is, they have no factors (cannot be written as the product of) of any other polynomials except 1 and itself. Finding them is similar to finding prime numbers, easy if small, rather harder as they get larger. See Schneier for a description of how to use any "primitive polynomial" to construct an LFSR.
n bit shift register
2n bits is enough to completely predict sequence
The big problem is that superficially LFSR's look good, but underneath they're fundamentally insecure. Its depressing how often this has been overlooked and how often they've been used in "so called" security products (which then get totally broken).
There are lots of general pointers to designing good stream ciphers, but in practise this is very difficult. Note that some of the design criteria are in conflict, have to tradeoff between them.
240
A5 is the algorithm used to encrypt the air interface of GSM phones (note other algs are used for key generation & authentication). Originally designers tried to keep algorithm secret using secrecy agreements between all manufacturers. Initially reverse engineered in early 90's - not quite correct. Completely reverse engineered at Smart Card Developers Conf in 1999 - see www.scard.org.
Sn+17 = 99 x Sn+15 + Sn+4 + 206 x Sn
2136-1
Vn = ROTL(Sn+Sn+16) + Sn+1 + Sn+6 + Sn+13
S forms the internal state of the cipher
k of length l bytes
i = j = 0
initialise array S to {0, 1, 2, ..., 255}
repeat 256 times
j += S[i] + k[i mod l] (mod 256)
swap(S[i], S[j])
increment i
The RC4 key schedule intialises the state S to all number 0..255, and then
walks thru each entry in turn, using its current value plus the next byte
of key to pick another entry in the array, and swaps their values over.
After doing this 256 times, the result is a well and truly shuffled array.
The total number of possible states is 256! - a truly enormous number,
much larger even that the 2048-bit (=256*8) max key allowed
can select.
i = j = 0 for each message byte 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]
RC4 is widely used, in SSL for secure web transactions amongst other uses. Currently its regarded as quite secure, if used correctly. nb. the comment about the first few values, for example S[0] is very likely the first byte of key. Should step past these.
xi+1 = xi2 mod n and use bi the LSB of xi where n=p.q, primes p,q=3 mod 4
Will look at number theory and public key algs next, but note here that like block ciphers, they also can be used as "good" if "extrememy slow" PRGs.