21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.15 Performing File or Disk Encryption<br />

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

You want to encrypt a file or a disk.<br />

Solution<br />

If you’re willing to use a nonce or an initialization vector, standard modes such as<br />

CBC and CTR are acceptable. For file-at-a-time encryption, you can avoid the use of<br />

a nonce or IV altogether by using the LION construction, described in the “Discussion”<br />

section.<br />

Generally, keys will be generated from a password. For that, use PKCS #5, as discussed<br />

in Recipe 4.10.<br />

Discussion<br />

Disk encryption is usually done in fixed-size chunks at the operating system level.<br />

File encryption can be performed in chunks so that random access to an encrypted<br />

file doesn’t require decrypting the entire file. This also has the benefit that part of a<br />

file can be changed without reencrypting the entire file.<br />

CBC mode is commonly used for this purpose, and it is used on chunks that are a<br />

multiple of the block size of the underlying block cipher, so that padding is never<br />

necessary. This eliminates any message expansion that one would generally expect<br />

with CBC mode.<br />

However, when people are doing disk or file encryption with CBC mode, they often<br />

use a fixed initialization vector. That’s a bad idea because an initialization vector is<br />

expected to be random for CBC mode to obtain its security goals. Using a fixed IV<br />

leads to dictionary-like attacks that can often lead to recovering, at the very least, the<br />

beginning of a file.<br />

Other modes that require only a nonce (not an initialization vector) tend to be<br />

streaming modes. These fail miserably when used for disk encryption if the nonce<br />

does not change every single time the contents associated with that nonce change.<br />

Keys for disk encryption are generally created from a password. Such<br />

keys will be only as strong as the password. See Recipe 4.10 for a discussion<br />

of turning a password into a cryptographic key.<br />

For example, if you’re encrypting file-by-file in 8,192-byte chunks, you need a separate<br />

nonce for each 8,192-byte chunk, and you need to select a new nonce every sin-<br />

Performing File or Disk Encryption | 213<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!