For example, say you have a client and server. You use asymmetric encryption to securely deliver two seeds from server to client. Each user then seeds two PRNGs (one for incoming data, one for outgoing). Then when they send data over the network, they add a new randomly generated byte (from the outgoing PRNG) to each unencrypted byte. The receiver can decrypt using their incoming PRNG which has the same seed as the senders outgoing PRNG. An HMAC could also be used to verify integrity and authenticate messages.

I was just musing over this idea. I'm a total novice to cryptography, so I'm sure there's something flawed with this. I would just like to know what the flaw is?

(The PRNG I'm looking at is ISAAC which is also a stream cipher, but would this work with any PRNG, disregarding speed?)

EDIT: Also, if not secure by itself, would it be possible to do this on top of AES? Is there no point (AES is already secure enough)? Or would it actually hurt security?

  • 3
    $\begingroup$ You'd be interested in stream cipher. That's basically what your scheme is (except, of course, when specifying a cipher, we usually leave out things like key exchange and authentication). As for the AES comment, you can use AES as a stream cipher with the appropriate mode of operation, e.g. CTR mode. (Indeed, this is a common way to use AES.) $\endgroup$
    – Reid
    Commented Jan 8, 2014 at 6:33
  • $\begingroup$ Ah, I only understand CBC. I'll look into CTR and stream ciphers, thanks! $\endgroup$ Commented Jan 8, 2014 at 7:40
  • $\begingroup$ Two things : First it would be somewhat pointless to do on top of AES-[insert-right-mode-of-operation-here] but as long as the AES layer and the PRNG layer are uncorrolated it won't decrease security. Also what you get from your solution is confidentiality which is great but in many situations not enough. For example what is the consequence of a bit flip by an attacker on ciphertext in transit ? $\endgroup$ Commented Jan 8, 2014 at 9:32
  • $\begingroup$ That's why I suggested an HMAC to be included with messages. Well, it seems by your responses it's overkill and I'll probably never do this. $\endgroup$ Commented Jan 8, 2014 at 10:32

1 Answer 1


A PRNG with a seed $S$ whose output is combined with the plaintext is called a stream cipher with the key $S$. So assuming that the details are filled in correctly, what you're describing is a stream cipher algorithm with two session keys, one used in each direction. Each seed/key must be unique, and the combination must ensure that each output bit has a $1/2$ probability of being flipped (xor is common, but addition of bytes would work too).

If you have an encrypted communication channel, then it's already using a stream cipher, which may be built on AES. (Note that AES is not a stream cipher — it's a family (128, 192, 256) of pairs (encrypt, decrypt) of algorithms that operate on blocks of exactly 128 bits. There are ciphers built on top of AES with a mode of operation, which result in a block cipher or stream cipher.) For example, AES-CTR is a popular stream cipher. AES-CTR is also a popular PRNG, for exactly the same reason.

Combining your scheme with another cipher would mean, in fact, chaining two ciphers. This is hardly ever useful, but is at least as strong as the weakest cipher if the ciphers are not correlated. (Possibly not as strong as the strongest cipher, because the weakest cipher may leak information.) Correlation can lead to catastrophic failures — for example, if you encrypt twice with the same stream cipher with the same key, you get the original stream.

A stream cipher only ensures confidentiality, not integrity or authenticity. For example, AES-CTR is trivial to modify: flipping a bit of ciphertext results in the same flipped bit in the plaintext (this applies to any stream cipher that uses xor as the combination function). HMAC or some other form of MAC can ensure integrity and authenticity. Alternatively, you may use a mode of operation that performs authenticated encryption, such as CCM or EAX which are CTR combined with CBC-MAC or CMAC.

Further reading: Is modern encryption needlessly complicated?

I'm only rehashing what's been said in comments really, just so that this question is answered.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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