Skip to content

refactor: encrypt EMWP with native Go XTS instead of cryptsetup#20

Merged
milesdai merged 1 commit into
mainfrom
milesdai/native-xts
Jun 17, 2026
Merged

refactor: encrypt EMWP with native Go XTS instead of cryptsetup#20
milesdai merged 1 commit into
mainfrom
milesdai/native-xts

Conversation

@milesdai

@milesdai milesdai commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Replace the cryptsetup/device-mapper EMWP encryption path with a pure-Go AES-XTS-plain64 implementation (new crypt package) that streams the ciphertext directly into the GPT image.

Encrypting in userspace lets the packer drop:

  • the --privileged container (no loop device or device-mapper at pack time)
  • the derived volume key written to a temp file in the output dir
  • the global /dev/mapper name and its cleanup/collision races

VerifyEMWP now decrypts in Go and runs veritysetup verify over the plaintext.

To maintain parity with the kernel, we keep a golden test vector and add a kernel round-trip test that ensures the encrypted volume can be opened with dmcrypt.


Summary by cubic

Encrypt EMWP with a native Go AES-XTS-plain64 implementation that streams directly into the GPT image, replacing cryptsetup/device-mapper. Pack and verify now run unprivileged, avoid loop/dev-mapper and on-disk keys, and remain byte-identical to dm-crypt.

  • Refactors

    • Added crypt package: pure-Go AES-XTS-plain64 (4096-byte sectors) with streaming Encrypt/Decrypt using golang.org/x/crypto/xts; pads trailing partial sector on encrypt and enforces alignment on decrypt.
    • wrap.encryptEMWP streams ciphertext into the payload partition; VerifyEMWP decrypts in Go to a temp file and runs verity over plaintext.
    • Removed device-mapper path: no /dev/mapper, no temp volume key file, and no --privileged in launcher/CLI/e2e; tests assert this.
    • Tests: dm-crypt golden vector and streaming parity; kernel round-trip opens Go-encrypted volumes with cryptsetup, compares plaintext bytes, and verifies dm-verity.
  • Migration

    • If running the packer in Docker, remove --privileged. No loop devices or device-mapper are required at pack time.

Written for commit 407e961. Summary will update on new commits.

Review in cubic

@milesdai milesdai force-pushed the milesdai/native-xts branch from 34018c6 to 5aea818 Compare June 11, 2026 20:36
@milesdai milesdai marked this pull request as ready for review June 11, 2026 20:36

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 13 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread crypt/crypt.go
Replace the cryptsetup/device-mapper EMWP encryption path with a pure-Go
AES-XTS-plain64 implementation (new crypt package) that streams the
ciphertext directly into the GPT image.

Encrypting in userspace lets the packer drop:

- the --privileged container (no loop device or device-mapper at pack
  time)
- the derived volume key written to a temp file in the output dir
- the global /dev/mapper name and its cleanup/collision races

VerifyEMWP now decrypts in Go and runs veritysetup verify over the
plaintext.

To maintain parity with the kernel, we keep a golden test vector and add
a kernel round-trip test that ensures the encrypted volume can be opened
with dmcrypt.
@milesdai milesdai force-pushed the milesdai/native-xts branch from 5aea818 to 407e961 Compare June 11, 2026 21:13
@milesdai milesdai requested a review from jdrean June 11, 2026 21:23
@milesdai milesdai merged commit d0be5b4 into main Jun 17, 2026
2 checks passed
@milesdai milesdai deleted the milesdai/native-xts branch June 17, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant