We previously said XORing random distributions produces random distributions. Today we explain how that is used with secure "stream ciphers", such as Salsa20. Let’s start with why this is needed, then we explain what they are. 1/n
2
The One-Time Pad (OTP) is a simple cipher. Considering a message m of N bits, and random key k of same length, we simply do k ⊕ m. That’s it! 2/n
3
The OTP has "perfect secrecy" meaning that given any two messages m1, m2 (of the same size) and a ciphertext c, it is impossible to predict if c most likely comes from m1 or m2. 3/n
4
Unfortunately, perfect secrecy is only possible for keys at least as long as messages they are encrypting. Additionally, as the name suggest, the One-Time Pad is secure if the key is only used once! Indeed, let’s say we use the same key k for m1 and m2, guess what happens ... 4/n
5
If an attacker access c1 = k ⊕ m1, and c2 = k ⊕ m2, they can compute c1 ⊕ c2, which is equal to m1 ⊕ m2 without ever knowing the key. Since none of m1 or m2 are random distributions, they are messages after all, it’s possible to decode m1 and m2 with statistical analysis. 5/n
6
So there is no point sending a long key that can only be used once. Because if we can send that key securely, we might as well send the message itself ... Are we doomed? Of course not, that’s where stream ciphers come to the rescue. 6/n
7
Imagine there is a way to generate a very long key from a very short one, in a way that is still sufficiently random. Then we can use that small key to generate the pad that we XOR with our message! This is exactly what we can do with "pseudo random generators" (PRG). 7/n
8
A good PRG for crypto must be "unpredictable", meaning given N generated bits, there is no efficient algorithm able to predict the N+1 bit. This property is super important! In fact this is equivalent to saying that a PRG is secure, as demonstrated by Yao’82. 8/n
9
A PRG is secure if there isn’t any efficient algorithm capable differentiating its distribution from uniformly random. We say there is no "advantage" for any statistical test trying to differentiate both. 9/n
10
We also say that this PRG distribution is "computationally indistinguishable" from the uniform random distribution. 10/n
11
For a one-time key encryption scheme, we say that the algorithm is "semantically secure" if there isn’t any efficient algorithm capable of statistically differentiating two messages. That’s a lot of definitions. Let’s see a concrete example with Salsa20. 11/n
12
First the algorithm initializes a 4x4 matrix of 32-bit words using constants, a key, a nonce (always different so that we can keep the same key) and a counter. Then the core function applies 20 rounds of different types of transformations mixing rows and columns. 12/n
13
Finally the new 512-bit keystream block (4x4 matrix) is added to the previous one and used to XOR a block of the plaintext. More information about the exact algorithm is available on wikipedia for the curious en.wikipedia.org/wiki/Salsa20. 13/n
14
Of course, here is the usual disclaimer. Do not make your own pseudo random generators. Use a secure one such as Salsa20 or ChaCha. Both are highly efficient already. That’s all for today! I hope you liked it. See you in the next episode! 14/14