Documentation
¶
Overview ¶
Package xts implements the XTS-AES tweakable block-cipher mode (IEEE P1619/D16, NIST SP 800-38E) used for full-disk encryption.
It is a drop-in replacement for golang.org/x/crypto/xts: the Cipher type exposes the same NewCipher / Encrypt / Decrypt API and produces byte-identical ciphertext. The difference is performance. x/crypto/xts drives the underlying block cipher one 16-byte block at a time through the cipher.Block interface and advances the XTS tweak with a scalar GF(2^128) multiply per block; on a CPU with hardware AES this collapses a ~10 GB/s AES engine to ~600 MB/s because the per-block interface dispatch defeats the pipelined multi-block AES path.
This package instead ships a fused AES-XTS kernel that pipelines four AES blocks at a time and folds the tweak XOR into the round pipeline. On arm64 (ARMv8 AES + NEON) and amd64 (AES-NI) the kernel runs the AESE/AESMC (resp. AESENC) pipeline directly, reaching multi-GB/s per core. On the remaining architectures (riscv64, loong64, ppc64le, s390x) it transparently falls back to the same per-block algorithm as x/crypto/xts, so behaviour is identical everywhere; only the speed differs.
XTS provides confidentiality but no authentication, and does not implement ciphertext stealing, so each sector must be a multiple of 16 bytes. It is intended for disk-sector encryption only.
Index ¶
- type Blocks
- type Cipher
- func (c *Cipher) Decrypt(plaintext, ciphertext []byte, sectorNum uint64)
- func (c *Cipher) DecryptSectors(plaintext, ciphertext []byte, sectorSize int, firstSector uint64)
- func (c *Cipher) Encrypt(ciphertext, plaintext []byte, sectorNum uint64)
- func (c *Cipher) EncryptSectors(ciphertext, plaintext []byte, sectorSize int, firstSector uint64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Blocks ¶ added in v0.3.0
Blocks is implemented by a block cipher that can encrypt or decrypt many 16-byte blocks in one call, as in ECB mode, faster than one Encrypt or Decrypt per block (go-encryptions/twofish interleaves four blocks). dst and src have the same length, a multiple of 16, and overlap entirely or not at all.
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher is an expanded XTS key. It is safe for concurrent use.
func NewCipher ¶
NewCipher creates a Cipher from a function that builds the underlying block cipher (which must have a 16-byte block size) and a key that is twice the underlying cipher's key length. For AES this is a 32-byte key (AES-128-XTS) or a 64-byte key (AES-256-XTS).
func (*Cipher) Decrypt ¶
Decrypt decrypts a sector of ciphertext into plaintext using the given sector number as the XTS tweak. The same overlap and length rules as Encrypt apply.
func (*Cipher) DecryptSectors ¶ added in v0.2.0
DecryptSectors decrypts consecutive sectors of sectorSize bytes: ciphertext[i*sectorSize:(i+1)*sectorSize] is sector firstSector+i. The result is that of calling Decrypt on each sector; on amd64 and arm64 it is faster, because the tweaks of 8 sectors are encrypted together instead of one serial AES per sector. plaintext and ciphertext must overlap entirely or not at all; sectorSize must be a positive multiple of 16 and len(ciphertext) a multiple of sectorSize.
