Skip to content

feat(encryption): implement key reading from file and update verification options for encrypted containers - #16

Merged
zombocoder merged 2 commits into
mainfrom
bugfix/crc32c-sse42-verify-encrypted
Oct 23, 2026
Merged

zombocoder merged 2 commits into
mainfrom
bugfix/crc32c-sse42-verify-encrypted

Conversation

@zombocoder

@zombocoder zombocoder commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Fixes found while preparing the FreeBSD port, and bumps the version to 1.4.1 so the port can pin a release that includes them.

Changes

bfc verify works on encrypted containers

verify --deep on an encrypted container always failed: the library returns BFC_E_PERM without a key, and the CLI had no way to pass one.

  • New options --password PASS and -K, --keyfile FILE (same meaning as in extract). There is no short -p for the password because verify already uses -p for --progress, and that stays as it is.
  • Without a key, verify now says the content is encrypted and that --password or --keyfile is needed, instead of a bare "Permission denied".
  • With a key or password supplied, a checksum mismatch is reported as "wrong password/key or data corruption".
  • read_key_from_file moved to cli_util.c. Before, create and extract each had their own copy.

SSE4.2 limited to the hardware CRC32C function

-msse4.2 -mcrc32 was applied to the whole library. At -O3 the compiler can put SSE4.2 instructions anywhere, so a generic x86_64 package could crash with SIGILL on CPUs without SSE4.2, even though the runtime cpuid check exists. The flags are removed, and only crc32c_hw_x86 gets __attribute__((target("sse4.2"))). objdump confirms crc32 instructions appear only in that function.

Software CRC32C matches the hardware paths

The SSE4.2 and ARMv8 paths compute CRC32C with initial value 0 and no final XOR. crc32c_sw inverted the value on input and output, so on "123456789" it gave 0xE3069283 while the hardware paths gave 0x58E3FA20. A container written on a machine with hardware CRC failed verification on a machine without it (i386, powerpc64, riscv64, armv7), and the other way round.

The software path now matches the hardware paths. Containers written on x86_64 or arm64, which is almost all of them, stay valid. The checksum definition is now written down in docs/format.md, and a unit test pins the value 0x58E3FA20.

Version

1.4.0 → 1.4.1.

Testing

  • Unit tests: 10/10 on macOS arm64 (Debug, ASan/UBSan, zstd + libsodium) and on FreeBSD 14.3 amd64
  • Hardware vs software CRC: 11,200 cases (offsets 0–15, lengths up to 4.9 KB, including chaining from a hardware prefix into a software tail) on arm64, x86_64 (Rosetta) and FreeBSD amd64, no mismatches
  • Software-only path on i386 (-m32) gives 0x58E3FA20
  • A container created on macOS arm64 passes verify --deep on FreeBSD amd64
  • Containers created by 1.4.0 pass verify --deep with 1.4.1, and the other way round
  • verify with a password, a key file, a wrong password, no key, -p together with --password, and --password with no argument
  • clang-format --dry-run -Werror clean, no warnings with -Werror

@zombocoder
zombocoder merged commit 058a36a into main Oct 23, 2026
11 checks passed
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