Skip to content

Cipher::_update_into asserts that all input has been consumed, but that is not necessarily the case #154

Description

@teythoon

Consider:

Testing IDEA/CBC
[openpgp/src/crypto/symmetric.rs:524:13] (self.scratch[..whole_blocks].len(), &buf[..whole_blocks].len()) = (
    5152,
    5152,
)

thread 'crypto::symmetric::tests::roundtrip' panicked at /home/teythoon/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/botan-0.11.1/src/cipher.rs:294:9:
assertion `left == right` failed
  left: 5120
 right: 5152
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.85.0/library/std/src/panicking.rs:692:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.85.0/library/core/src/panicking.rs:75:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /usr/src/rustc-1.85.0/library/core/src/panicking.rs:364:5
   4: botan::cipher::Cipher::_update_into
             at /home/teythoon/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/botan-0.11.1/src/cipher.rs:294:9
   5: botan::cipher::Cipher::update_into
             at /home/teythoon/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/botan-0.11.1/src/cipher.rs:337:9

Relevant part of the function:

        let flags = u32::from(end);
        let mut output_written = 0;
        let mut input_consumed = 0;

        botan_call!(
            botan_cipher_update,
            self.obj,
            flags,
            output.as_mut_ptr(),
            output.len(),
            &mut output_written,
            msg.as_ptr(),
            msg.len(),
            &mut input_consumed
        )?;

        assert_eq!(input_consumed, msg.len());  // This is the failing assertion.

But if flags is 0, then botan_cipher_update will process chunks of the ciphers update granularity, leaving the rest unconsumed.

% qalc
> 5152 // 256 * 256

  trunc(5152 / 256) × 256 = 5120

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions