Skip to content

cipher_chacha20.c: Can reserved == 0 still occur in the ChaCha20 page cipher callbacks? #256

Description

@matbech

In cipher_chacha20.c, both EncryptPageChaCha20Cipher() and DecryptPageChaCha20Cipher() contain:

int nReserved = (reserved == 0 && legacy == 0)
    ? 0
    : GetReservedChaCha20Cipher(cipher);

When nReserved == 0, they use the encryption-only branch, deriving the nonce through sqlite3mcGenerateInitialVector() rather than storing a random nonce and Poly1305 tag.

What supported configuration or API sequence can cause these callbacks to receive reserved == 0?

From tracing the current implementation:

  • GetReservedChaCha20Cipher() always returns 32.
  • Normal cipher initialization configures those 32 reserved bytes.
  • When encrypting an existing plaintext database, the original database may have zero reserved bytes, but its read cipher is disabled.
  • When removing encryption, the destination has zero reserved bytes, but its write cipher is disabled.

Instrumenting a ChaCha20-only WASM build, I have not observed calls to sqlite3mcGenerateInitialVector() during encryption, rekeying, decryption, updates, VACUUM, or VACUUM INTO.

Is the zero-reserve branch still required for a supported scenario, or is it leftover code that could be removed?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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