3
$\begingroup$

As the title says, I would like to know which one is faster. I read in some book it indicates the stream is faster since it encrypts one bit at a time; the others show block is faster since it is using "block".

Thanks

$\endgroup$
3
$\begingroup$

It depends on what you're trying to do.

In general, block ciphers are more versatile: anything you can do with a stream cipher can also be done with a block cipher in a suitable mode of operation. So if there was no other advantage to "pure" stream ciphers (i.e. ones that are not based on block ciphers), everybody would just be using block ciphers.

The main advantages of pure stream ciphers over block ciphers are usually 1) raw speed, and 2) code / circuit size. The versatility of block ciphers tends to come with some overhead cost, and if you're targeting a very low-end device, you can often squeeze some extra speed out and/or save some memory by only using a purpose-built stream cipher.

(Of course, that only really works if all you need is a stream cipher. In the past few decades people have gradually woken up to the fact that in many — if not most — cases it's not enough to just hide the data by encrypting it, but you also need to protect it against tampering. Block ciphers can do that, when used in a suitable mode, but most traditional stream ciphers can't. So either you need to implement an extra integrity protection layer on top of the stream cipher encryption, or use an "authenticated stream cipher" that has it built in. Either way, that adds extra complexity.)

So, at least in some situations, stream ciphers can be faster than block ciphers — and, in fact, that's their main selling point.

That said, there are also several situations where block ciphers can beat stream ciphers in speed:

  • Many modern high-end CPUs provide hardware acceleration for the AES block cipher. If you're using such a CPU, using that is almost certainly going to be faster than any encryption you could implement purely in software.

    (Of course, a similarly hardware-accelerated stream cipher might be even faster yet, and would likely require less space on the CPU chip, but it wouldn't be useful for nearly as many purposes as a block cipher like AES is. So if you're only going to add extra hardware for one crypto primitive to your general purpose CPU, it might as well be a block cipher.)

  • Stream ciphers typically generate a sequential keystream, always starting from the beginning of the stream. So even if you only need to decrypt, say, the last kilobyte of a multi-megabyte message, you still need to generate all those megabytes of keystream first.

    There are various ways to work around that, such as splitting long messages into smaller chunks and encrypting those separately. But many block cipher operating modes offer something even better: the ability to decrypt any block (of, say, 16 bytes for AES) of the ciphertext independently of the others. If you need fast random access to small pieces of the encrypted data (e.g. to query an encrypted database), a block-cipher-based encryption scheme is probably the way to go.

  • The same features of many block cipher modes that allow random access also allow decryption (and in some cases also encryption) to be done in parallel by as many processor cores as you happen to have available. Stream ciphers tend to be limited by their sequential nature to a single core per keystream. Again, on modern multicore processors, that can make block ciphers significantly faster even without hardware acceleration.


Ps. For more information, you might also want to take a look at this earlier answer I wrote about the differences between block ciphers and stream ciphers, as well as the answers and wiki pages linked from it.

$\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.