21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.14 Parallelizing Encryption and Decryption in<br />

Arbitrary Modes (Breaking Compatibility)<br />

<strong>Problem</strong><br />

You are using a cipher mode that is not intrinsically parallelizable, but you have a<br />

large data set and want to take advantage of multiple processors at your disposal.<br />

Solution<br />

Treat the data as multiple streams of interleaved data.<br />

Discussion<br />

Parallelizing encryption and decryption does not necessarily result in a<br />

speed improvement. To provide any chance of a speedup, you will certainly<br />

need to ensure that multiple processors are working in parallel.<br />

Even in such an environment, data sets may be too small to run faster<br />

when they are processed in parallel.<br />

Recipe 5.13 demonstrates how to parallelize CTR mode encryption on a per-block<br />

level using a single encryption context. Instead of having spc_pctr_do_even( ) and<br />

spc_pctr_do_odd( ) share a key and nonce, you could use two separate encryption<br />

contexts. In such a case, there is no need to limit your choice of mode to one that is<br />

intrinsically parallelizable. However, note that you won’t get the same results when<br />

using two separate contexts as you do when you use a single context, even if you use<br />

the same key and IV or nonce (remembering that IV/nonce reuse is a bad idea—and<br />

that certainly applies here).<br />

One consideration is how much to interleave. There’s no need to interleave on a block<br />

level. For example, if you are using two parallel encryption contexts, you could encrypt<br />

the first 1,024 bytes of data with the first context, then alternate every 1,024 bytes.<br />

Generally, it is best to use a different key for each context. You can derive multiple<br />

keys from a single base key, as shown in Recipe 4.11.<br />

It’s easiest to consider interleaving only at the plaintext level, particularly if you’re<br />

using a block-based mode, where padding will generally be added for each cipher<br />

context. In such a case, you would send the encrypted data in multiple independent<br />

streams and reassemble it after decryption.<br />

See Also<br />

Recipes 4.11, 5.13<br />

212 | Chapter 5: Symmetric Encryption<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!