I am currently working on a project where I am trying to replicate the header encryption and decryption logic of TrueCrypt in Java. I have some uncertainties regarding the key generation, distribution, and usage of the XTS mode. Notice that my understanding so far is based on the documentation, which in my opinion can be quite ambiguous at times.
Further Background (Technical specifications)
File Format Structure: https://www.andryou.com/truecrypt_orig/docs/volume-format-specification/
Encryption: https://www.truecrypt71a.com/documentation/technical-details/encryption-scheme/
Header Key Derivation: https://www.truecrypt71a.com/documentation/technical-details/header-key-derivation-salt-and-iteration-count/
Cascades: https://www.truecrypt71a.com/documentation/encryption-algorithms/cascades/
XTS-mode: https://www.truecrypt71a.com/documentation/technical-details/modes-of-operation/
My understanding so far:
- Assuming there are no key files the PBKDF2 function (Password-Based Key Derivation Function 2) uses the user password and a salt to generate a header key. Depending on the chosen hash algorithm (HMAC-SHA-512, HMAC-RIPEMD-160, HMAC-Whirlpool), PBKDF2 is executed either 1000 or 2000 times.
- For the simple cascade (e.g., just AES), I understand that a 512-bit key is generated, which is then split into two 256-bit keys. The primary and secondary keys respectively.
- Notice XTS mode, means for each algorithm a primary and secondary key of 256-bit each are needed.
My questions:
For triple cascades (e.g., AES-Twofish-Serpent) in XTS mode: Is a single 1536-bit key generated by PBKDF2 and then split into two 768-bit keys (primary and secondary key) which are further divided into three 256-bit keys per algorithm? Or are two separate 768-bit keys (primary and secondary key) independently generated by PBKDF2 and then those two are split into three three 256-bit keys per algorithm? I would appreciate any help or pointers
Furthermore, based on the file structure specification in the documentation listed above, the 64-byte salt is not encrypted but the rest of the header (which goes up to and including byte 511) is. But the XTS mode says that it always works on a 512-byte data unit. If it starts after the salt, the encryption will cut into the middle of the reserved field, which could be encrypted or not (but this refers to the entire field, not just a part of it). So does encryption and decryption work on the first 512 bytes, including Salt or does it start after Salt. In other words, at what offset (0 or 64 or something else) is the first plaintext block encrypted and until when (511 or 576 or something else) is encryption done?