Overall
Design:
Sha256 hash is used to convert an ascii pass phrase to
a 256 bit encryption key. Pseudorandom data is used as an
initialization vector for AES-256 encryption. Optionally,
a the
encryption key (NOT the passphrase) is encrypted using a
second
master key, and
included in the
file header. This master key can be used as an emergency
data
recovery key, or as a second key to be used by programs to read
encrypted files.
Overall File Format: Consists of a preamble, the
encrypted data, and some padding at the end.
Encrypted files start with an 8
byte preamble, the first 4 bytes are a "magic number" to
identify the file
type (currently 0x04030201) and a 4 byte sub-file type,
(currently
either 0x00000001 or 0x00000002 if the file has a master
key).
The next 16 bytes of the preamble are the initialization
vector for the
AES engine, to be used with the file key. Each file gets a
unique 16
bytes of pseudo random noise.
Next, for master keyed files, is a 16 byte IV for the master
key,
followed by a 32 byte block containing the file key, encrypted
with the
master key, using the master key IV and CBC block chaining.
Next, is the actual file data, encrypted using the file key
and the IV,
and CBC block chaining.
Finally, are 1-16 bytes of padding to round out the last AES
block. Note that there are never 0 bytes of padding.