0
$\begingroup$

When a stream cipher is used and a keystream is generated to be XOR'ed with the plaintext, is the keystream sent with the ciphertext so that the receiver knows how to decrypt it? Or does the receiver(s) need to already know the keystream?

Absolute noobie to cryptography.

$\endgroup$
2
$\begingroup$

The keystream is as long as the message, so you don't want to send that to the receiver. The keystream is generated by a much shorter key (e.g., 128-bit private key). That is what the receiver needs in order to decrypt the message.

So, how do you get that to the receiver? Well, clearly you can't just send it in the clear or anyone watching the channel would have the key and could decrypt. Typically what we do in cryptography is run a key establishment protocol. This could be as simple as Alice and Bob meet up and exchange the key on a written piece of paper or as complex as using asymmetric crypto, with public/private key pairs, certification authorities, etc.

$\endgroup$
  • $\begingroup$ Does that make the keystream generator the encryption/decryption algorithm in this case? @mikeazo $\endgroup$ – l30n1d45 Apr 3 '15 at 12:51
  • $\begingroup$ @l30n1d45 More or less. Look at the description of RC4. It really just outputs random bytes. Encryption and decryption happen by using a simple XOR. So, some might say RC4, by itself is not the encryption/decryption algorithm since it requires the XOR to really get encryption/decryption. Depends on how pedantic you want to be. $\endgroup$ – mikeazo Apr 3 '15 at 12:55
  • $\begingroup$ Okay so on the sending side it works like this: Secret key is used with the keystream generator to generate a keystream which is then XOR'ed with the plaintext, producing the ciphertext which is sent to the receiver. What then happens at the receiving side? Since every keystream produced is random, how does the key and the keystream generator produce the same keystream to XOR with the ciphertext? @mikeazo $\endgroup$ – l30n1d45 Apr 3 '15 at 12:57
  • $\begingroup$ @l30n1d45 the keystream is random if you do not know the key. If you know the key, however, the keystream is completely deterministic. So, as long as the recipient knows the key, they can produce the exact same keystream. $\endgroup$ – mikeazo Apr 3 '15 at 13:58
  • $\begingroup$ So in context of general symmetric encryption, essentially, there are two instances of the same key (each at a sender and a receiver). These keys are used with encryption or decryption algorithms to encrypt or decrypt plaintext or ciphertext? And in order to get a different keystream, would you need to use a different key? @mikeazo $\endgroup$ – l30n1d45 Apr 3 '15 at 14:10
1
$\begingroup$

Anyone who has the keystream and the ciphertext can trivially calculate the plaintext — it's a xor operation bit by bit. Sending the keystream alongside the ciphertext would completely defeat the purpose of encryption.

The principle of stream ciphers is that the sender and the receiver agree on an algorithm, a secret key and some parameters, and both calculate the keystream from those parameters. The parameters can be something like a way to derive a session key from a shared master key or from a key exchange, an IV (a unique value sent at the beginning of each message that allows using the same key for multiple messages), etc.

The message remains confidential because only the sender and the receiver know the secret key, and thus only they can calculate the keystream.

$\endgroup$
0
$\begingroup$

The keystream is not transmitted - if it were, anyone could decrypt it.

The stream cipher produces a pseudo-random number sequence based on a given key. If you give it the same key twice, it'll produce the same sequence. As such, if the receiver has the same key as the sender, then he can generate the same keystream and decrypt the message.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.