Documentation
¶
Overview ¶
Package luks provides pure-Go support for LUKS1 and LUKS2 full-disk encryption.
Supported:
- LUKS version 1 (key derivation: PBKDF2; ciphers: aes-xts-plain64, aes-cbc-essiv:sha256)
- LUKS version 2 (key derivation: PBKDF2 and Argon2id/i; ciphers: aes-xts-plain64)
Usage:
dev, err := luks.Open("/dev/sdb", []byte("passphrase"))
if err != nil { log.Fatal(err) }
defer dev.Close()
// use dev.ReadAt / dev.WriteAt to access plaintext payload
Index ¶
- Variables
- func Detect(path string) (bool, error)
- type Device
- func Format(path string, passphrase []byte) (*Device, error)
- func FormatOn(rw blockRW, passphrase []byte) (*Device, error)
- func Open(path string, passphrase []byte) (*Device, error)
- func OpenFrom(rw blockRW, passphrase []byte) (*Device, error)
- func OpenFromLimited(rw blockRW, passphrase []byte, lim Limits) (*Device, error)
- func OpenLimited(path string, passphrase []byte, lim Limits) (*Device, error)
- type Limits
Constants ¶
This section is empty.
Variables ¶
var DefaultLimits = Limits{
MaxPBKDF2Iterations: 1 << 26,
MaxArgon2Time: 1000,
MaxArgon2MemoryKiB: argon2MaxMemoryKiB,
}
DefaultLimits are what Open and OpenFrom use.
var ErrLimit = errors.New("luks: the header asks for more than the limits allow")
ErrLimit is a key slot or digest whose parameters a Limits refuses.
Functions ¶
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is an unlocked LUKS device. Its ReadAt and WriteAt methods transparently decrypt/encrypt the payload using the volume key.
func Format ¶
Format creates a new LUKS1 container at path, protecting it with passphrase. The file must already exist. Returns an opened Device ready for payload I/O.
func FormatOn ¶
FormatOn creates a new LUKS1 container on rw, protecting it with passphrase. Returns an opened Device ready for payload I/O.
func Open ¶
Open opens the LUKS1 or LUKS2 container at path and unlocks it using passphrase. Returns a Device that exposes the plaintext payload.
func OpenFrom ¶
OpenFrom unlocks a LUKS container from any read-write-closable block device. This allows LUKS to be layered on top of e.g. a QCOW2 device. The caller is responsible for ensuring that rw remains valid for the lifetime of the returned Device; Close on the Device also closes rw.
func OpenFromLimited ¶
OpenFromLimited is OpenFrom with lim instead of DefaultLimits.
func OpenLimited ¶
OpenLimited is Open with lim instead of DefaultLimits.
func (*Device) PayloadOffset ¶ added in v0.2.0
PayloadOffset returns the byte offset of the payload in the device: the payload's offset 0 is the device's PayloadOffset.
func (*Device) ReadAt ¶
ReadAt reads decrypted data from the plaintext payload starting at off. off is relative to the start of the payload (sector 0 of the plaintext).
func (*Device) Size ¶
Size returns the size of the plaintext payload in bytes, as the header states it. It is 0 when the payload runs to the end of the device -- every LUKS1 header, and a LUKS2 segment of size "dynamic", which is what cryptsetup writes -- and the payload is then the device's size minus PayloadOffset.
type Limits ¶
type Limits struct {
// MaxPBKDF2Iterations bounds a PBKDF2 key slot's iterations and a
// master-key digest's.
MaxPBKDF2Iterations uint32
// MaxArgon2Time bounds an Argon2 key slot's passes.
MaxArgon2Time uint32
// MaxArgon2MemoryKiB bounds an Argon2 key slot's memory; at most
// argon2MaxMemoryKiB whatever it says.
MaxArgon2MemoryKiB uint32
}
Limits bound the work a header may make Open do. A header is read from the image, so it is untrusted: without bounds a key slot can ask for 2^32 PBKDF2 iterations (hours), 4 TiB of Argon2 memory (2^32 KiB), or zero Argon2 rounds or threads (a panic in golang.org/x/crypto/argon2).
Two kinds of bound:
- Structural, always enforced, from cryptsetup's own limits for the KDFs it writes (lib/crypto_backend/pbkdf_check.c, crypt_pbkdf_get_limits): Argon2 memory at most 4 GiB and 1 to 4 threads (and Argon2's own floor of 8 KiB per thread); at least one iteration; and the anti-forensic split of a key slot at most 4000 stripes (LUKS1 and LUKS2 headers use 4000) of a key of at most 128 bytes.
- Cost, chosen by the caller: cryptsetup accepts up to 2^32 iterations because it trusts headers it wrote; a program opening images from elsewhere -- an upload, a browser -- should not. DefaultLimits are generous enough for headers calibrated on fast machines.
