On 06/08/2012 01:06 PM, Denis Cormier wrote:
> I plan on using a randomly generated 32-byte key provided by a trusted 3rd
> party. I also plan on using a randomly generated 32-byte initialization
> vector generated by NSS within Firefox (to use with the AES Chain Block
> Cipher scheme).
So you are fetching the key off box through some authenticated and
protected channel?
>
> What should I do with the initialization vector? I read that you have to
> keep changing the initialization vector to preserve security. But to
> decrypt the data you need the same initialization vector that you encrypted
> the data with (which might not be the same IV as other files in the profile
> at that given moment). Now, I know that SQLCipher keeps the initialization
> vector at the end of every page it reads/writes to. Should I be doing
> something similar with NSS (keeping the IV at the end or at the start of
> each file)?
There is no problem using a single generated IV to encrypt a full file.
The IV can and should be public, so you can store the IV with the file.
If you make changes to the file, you should generate a New IV and
encrypt the full file again.
If you want random access (writes or reads), you should generate a new
IV per block that you need to read/write (a la SQLCipher's pages). You
only need to change the IV on write, and there is no problem including
the IV with the data for read.
All of this assumes that writes to these files can be triggered by
untrusted 3 parties which do not have access to the key, but do have
access to the file. This is rare, but it's easier just to protect
against the attack than to analyze if you may be vulnerable to attack.
Also don't use a stream cipher to encrypt the files (RC-4, AES-CTR,
AES-OFB, etc).
bob