A cipher (KG,E,D) with message space M and ciphertext space C is perfectly secret if
∀m0,m1∈M,c∈C:Pr[E(m0)=c]=Pr[E(m1)=c]or, equivalently, if
Pr[M=m0∣C=c]=Pr[M=m0]The shift cipher is not perfectly secret.
Imagine 2 possible messages:
m0=OKm1=NOThe ciphertext c=QM cannot have been generated by m1, for the amount of shift applied to the letters is different.
The one-time pad is a perfectly secret cipher.
KG→{0,1}nE(k,m)=k⊕mD(k,c)=k⊕cwhere k is a random key of length n.
Pros | Cons |
---|---|
Perfect secrecy | Key must be as long as the message |
Simple and fast | Key must be truly random |
Key must be shared securely | |
Key must only be used once |
A stream cipher is a symmetric key cipher where the plaintext is encrypted using a pseudorandom stream of bit originating from a short seed.
Loading diagram...E(k,m)=PRG(k)⊕mD(k,c)=PRG(k)⊕c
A nonce is a unique value that must be used only once. It must be included in the encryption and decryption processes to prevent replay attacks.
If we only rely on the key, two subsequent encryptions will reveal information about the plaintext.
E(k,m1)=PRG(k)⊕m1=c1E(k,m1)=PRG(k)⊕m2=c2c1⊕c2=m1⊕m2Stream cipher must also consider the nonce in the encryption and decryption processes. The nonce is not secret and can be sent in the clear.
E(k,n,m)=PRG(k,n)⊕mD(k,n,c)=PRG(k,n)⊕cThe combination (key, nonce) must be unique for each encryption request.
True randomness is difficult to achieve for computers. Instead, we rely on pseudorandom generators (PRGs) which expand a short seed into a long pseudorandom sequence of bits.
PRG:{0,1}k→{0,1}nA linear feedback shift register (LFSR) is a simple PRG that generates a sequence of bits by shifting the bits of a register, producing a bit from the right and introducing a new one from the left.
Can be used to generate a pseudorandom stream of bits.
Loading diagram...
Not all bits of the state contribute in generating the next bit. They are determined by the connection polynomial.
For example, the polynomial
x3+x2+1determines that only bits s3, s2, and s0 participate in generating the next bit.
Loading diagram...
Consider the LFSR with polynomial x2+1 and initial state s=0100. What appears at the output after 3 ticks?
Loading diagram...
The sequence of bits generated by a LFSR repeats after a certain number of ticks.
For an l-bit LFSR, the maximum period is 2l−1.
The period is determined by the irreducibility of its polynomial C(x) and the smallest value l such that C(x) divides the polynomial xl+1.
LFSR are not secure for cryptographic purposes, as the output can be predicted by just observing the output.