[BUG] CBC ciphertext stealing differs from CBC-CS3 #10

Closed
opened 2026-11-13 03:45:10 +01:00 by erikinkinen · 1 comment
Owner

Summary

The CTS functions do not produce the stated CBC-CS3 format. Partial blocks use the wrong chaining block; aligned inputs of at least two blocks omit the required final-block exchange. Encryption and decryption mirror these errors, so their round-trip test passes while independent ciphertext answers fail.

Reproduction

Use the AES-256 key and IV from NIST SP 800-38A F.2.5, with its first 17 plaintext bytes. The independent controls also cover every byte length through 64. On revision 52c81b0760f4646f3e38fee1eea5c4b6334e5d40, both directions fail for partial and aligned ciphertext, consistently.

To run the independent controls against the previous implementation in a disposable checkout:

git fetch origin feature/cbc-cs3
git switch --detach 52c81b0760f4646f3e38fee1eea5c4b6334e5d40
git show FETCH_HEAD:src/cbc_cs3_tests.rs > src/cbc_cs3_tests.rs
printf '\n#[cfg(test)]\nmod cbc_cs3_tests;\n' >> src/lib.rs
cargo test cbc_cs3_tests

Expected and actual behavior

For the 17-byte input, expected ciphertext is 29d372a201f3b07d72f459881d34e62ef5; actual ciphertext is 38ea91680df3dcf7fcf02234b9dd9dc7cf5. For 32 bytes, the implementation returns ordinary CBC instead of exchanging the final complete blocks. NIST SP 800-38A Addendum section 4 defines the required ordering.

Environment and identity

  • Component: lib-aes 52c81b0760f4646f3e38fee1eea5c4b6334e5d40.
  • Host x86-64; Rust 1.93.1; independent ordinary-CBC oracle OpenSSL 4.0.3.
  • Public NIST fixture key/IV/plaintext; no image, endpoint, session or capability is required.
  • No known working revision. Native filesystem behavior has not been established by this host reproduction.

Evidence and prior checks

The four independent encryption/decryption controls fail on the preceding source and pass after the correction. They use 49 fixed answers derived from independent CBC output and the NIST CS3 specification. The old round-trip control passes on the defective source.

Tracking

The filename consumer is lib-fs-crypto. Correcting this format changes previously nonstandard ciphertext; stored data needs an explicit owner-managed migration rather than an automatic alternate-mode fallback.

## Summary The CTS functions do not produce the stated CBC-CS3 format. Partial blocks use the wrong chaining block; aligned inputs of at least two blocks omit the required final-block exchange. Encryption and decryption mirror these errors, so their round-trip test passes while independent ciphertext answers fail. ## Reproduction Use the AES-256 key and IV from NIST SP 800-38A F.2.5, with its first 17 plaintext bytes. The [independent controls](https://git.erikinkinen.fi/erix/lib-aes/src/branch/feature/cbc-cs3/src/cbc_cs3_tests.rs) also cover every byte length through 64. On revision `52c81b0760f4646f3e38fee1eea5c4b6334e5d40`, both directions fail for partial and aligned ciphertext, consistently. To run the independent controls against the previous implementation in a disposable checkout: ```sh git fetch origin feature/cbc-cs3 git switch --detach 52c81b0760f4646f3e38fee1eea5c4b6334e5d40 git show FETCH_HEAD:src/cbc_cs3_tests.rs > src/cbc_cs3_tests.rs printf '\n#[cfg(test)]\nmod cbc_cs3_tests;\n' >> src/lib.rs cargo test cbc_cs3_tests ``` ## Expected and actual behavior For the 17-byte input, expected ciphertext is `29d372a201f3b07d72f459881d34e62ef5`; actual ciphertext is `38ea91680df3dcf7fcf02234b9dd9dc7cf5`. For 32 bytes, the implementation returns ordinary CBC instead of exchanging the final complete blocks. NIST SP 800-38A Addendum section 4 defines the required ordering. ## Environment and identity - Component: lib-aes `52c81b0760f4646f3e38fee1eea5c4b6334e5d40`. - Host x86-64; Rust 1.93.1; independent ordinary-CBC oracle OpenSSL 4.0.3. - Public NIST fixture key/IV/plaintext; no image, endpoint, session or capability is required. - No known working revision. Native filesystem behavior has not been established by this host reproduction. ## Evidence and prior checks The four independent encryption/decryption controls fail on the preceding source and pass after the correction. They use 49 fixed answers derived from independent CBC output and the [NIST CS3 specification](https://doi.org/10.6028/NIST.SP.800-38A-Add). The old round-trip control passes on the defective source. ## Tracking The filename consumer is lib-fs-crypto. Correcting this format changes previously nonstandard ciphertext; stored data needs an explicit owner-managed migration rather than an automatic alternate-mode fallback.
erikinkinen added this to the Alpha 1 milestone 2026-11-13 03:45:10 +01:00
Author
Owner

The correction is now on main through #6, including the independent CBC-CS3 answers and key-schedule ownership checks. The filesystem filename consumer also passed its original debug/release checks against the corrected AES main and is merged. The explicit migration requirement for earlier prototype ciphertext still applies.

The correction is now on `main` through [#6](https://git.erikinkinen.fi/erix/lib-aes/pulls/6), including the independent CBC-CS3 answers and key-schedule ownership checks. The [filesystem filename consumer](https://git.erikinkinen.fi/erix/lib-fs-crypto/pulls/5) also passed its original debug/release checks against the corrected AES main and is merged. The explicit migration requirement for earlier prototype ciphertext still applies.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
erix/lib-aes#10
No description provided.