Documentation
¶
Overview ¶
Package veracrypt reads VeraCrypt and TrueCrypt volumes in pure Go.
A VeraCrypt header is indistinguishable from random bytes: nothing on disk names the key derivation or the cipher. Opening a volume therefore tries every allowed KDF on the password (and keyfiles), and every allowed cipher chain on each derived key, until the decrypted header starts with "VERA" (or TrueCrypt's "TRUE") and its CRC-32s match, as cryptsetup's tcrypt support does. Naming the KDF and the cipher in Options skips the others, which matters: one KDF costs about half a second.
dev, err := veracrypt.Open("volume.hc", veracrypt.Options{Password: []byte("pw")})
The decrypted volume starts at its filesystem's first byte. This version reads AES and Twofish (and VeraCrypt's AES-Twofish cascade) in XTS mode, with PBKDF2 over SHA-512, SHA-256, BLAKE2s-256 or RIPEMD-160, or Argon2id; PIM, keyfiles, hidden volumes and backup headers. It does not write.
Untrusted images: the trial costs as much as the caller allows; Limits bounds the number of key derivations, the PBKDF2 iterations and the Argon2id memory a PIM can ask for, and refuses before deriving.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrWrongSecret = errors.New("veracrypt: no KDF and cipher open the header with this secret") ErrCorrupt = errors.New("veracrypt: corrupt volume") ErrUnsupported = errors.New("veracrypt: unsupported volume") ErrLimit = errors.New("veracrypt: limit exceeded") ErrReadOnly = errors.New("veracrypt: read-only") )
Errors. Every refusal of a malformed image wraps ErrCorrupt.
Functions ¶
This section is empty.
Types ¶
type Cipher ¶
type Cipher string
Cipher names an XTS cipher or cascade, as cryptsetup names it: the ciphers in the order of its table, which is the REVERSE of VeraCrypt's display name (VeraCrypt's "AES-Twofish" is "twofish-aes" here).
The ciphers this version decrypts. Serpent, Camellia and Kuznyechik, and the cascades that use them, need implementations the fleet does not have yet (go-fde/fde#28); a volume made with them fails like a wrong password.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is an unlocked volume. ReadAt is safe for concurrent use.
func OpenFrom ¶
func OpenFrom(r ReadAtCloser, size int64, o Options) (*Device, error)
OpenFrom unlocks the volume of size bytes in r. Close on the returned Device closes r.
type Header ¶
type Header struct {
VeraCrypt bool // magic "VERA"; false for TrueCrypt's "TRUE"
Version uint16
MinVersion uint16
HiddenSize uint64
VolumeSize uint64
MKOffset uint64 // the data area's start on the device
MKSize uint64
Flags uint32
SectorSize uint32
KDF string // the variant that opened it, e.g. pbkdf2-sha512-500000
Cipher Cipher
// contains filtered or unexported fields
}
Header is what the decrypted header records, big-endian on disk (cryptsetup TCRYPT_hdr_from_disk).
type KDF ¶
type KDF string
KDF names a header key derivation, as cryptsetup names them.
const ( SHA512 KDF = "sha512" SHA256 KDF = "sha256" BLAKE2s KDF = "blake2s-256" RIPEMD160 KDF = "ripemd160" Argon2id KDF = "argon2id" SHA1 KDF = "sha1" // TrueCrypt legacy only )
The KDFs this version derives with. Whirlpool and Streebog are not implemented yet (no Go implementation in the fleet); a volume made with them fails like a wrong password.
type Limits ¶
type Limits struct {
// MaxKeyDerivations is how many KDFs may run; default: all of them.
MaxKeyDerivations int
// MaxPIM bounds the PIM; default 2000 (2,015,000 PBKDF2 iterations).
MaxPIM int
// MaxIterations bounds the PBKDF2 iterations of one derivation;
// default 2,015,000.
MaxIterations int
// MaxArgon2MemKiB bounds Argon2id's memory; default 1 GiB, the most a
// VeraCrypt PIM asks for.
MaxArgon2MemKiB uint32
}
Limits bounds the work an open may do. Zero fields take the defaults.
type Options ¶
type Options struct {
Password []byte
// Keyfiles are the contents of the keyfiles, in the order VeraCrypt
// was given them; only the first MiB of each counts.
Keyfiles [][]byte
// PIM is VeraCrypt's Personal Iterations Multiplier; 0 is the
// default. A non-zero PIM tries only VeraCrypt KDFs.
PIM int
// KDF and Cipher, when set, are the only ones tried.
KDF KDF
Cipher Cipher
// Hidden opens the hidden volume (its header at 64 KiB).
Hidden bool
// Backup reads the backup header at the end of the device instead.
Backup bool
// TrueCryptOnly refuses VeraCrypt's "VERA" volumes and KDFs.
TrueCryptOnly bool
// Legacy also tries TrueCrypt's oldest KDF (PBKDF2-SHA-1).
Legacy bool
Limits Limits
}
Options says how to open a volume.