Skip to content

perf(crypto): reuse derived AES keys for consecutive operations - #65401

Open
RobinDev wants to merge 2 commits into
nextcloud:masterfrom
RobinDev:perf/crypto-key-reuse
Open

RobinDev wants to merge 2 commits into
nextcloud:masterfrom
RobinDev:perf/crypto-key-reuse

Conversation

@RobinDev

@RobinDev RobinDev commented Oct 11, 2026 •

Copy link
Copy Markdown

Summary

The Passwords app decrypts six fields consecutively with the same key material. Each field currently repeats the same PBKDF2 derivation. Reuse the current derived AES key while its input is unchanged, keeping just one fingerprint per Crypto instance. A different input derives a new key. Ciphertext formats, KDF parameters, per-field IV handling and HMAC checks remain unchanged.

A deployment on Nextcloud 35.0.3 with Passwords 2026.11.20 and PHP 8.5.12 produced these measurements:

Measurement Before After
Full password/list response, 344 items, median of five Chrome requests 1,637.4 ms 663.8 ms
Synthetic decryption, 344 revisions × six fields, median of three runs on that host 1,112.83 ms 213.38 ms
Key derivations for that synthetic lot 2,064 344

All five requests before and ten requests after returned HTTP 200. The complete responses after the change matched the baseline response exactly, compared only in browser memory. No vault contents, keys or identifiers were exported. The final after series ran without the synthetic benchmark in parallel; shared-host and network load still vary, so these timings are observations rather than a latency guarantee. Measurements were performed with agent assistance. The contributor has independently tested the deployed change and confirmed that the vault works correctly.

Validation:

  • Native Nextcloud SQLite test runner: 23 tests, 482 assertions, PHP 8.5.12 and PHPUnit 11.5.56. Coverage includes historical Nextcloud/ownCloud ciphertexts, default/explicit keys, key changes, distinct IVs, tampering, malformed inputs and binary/boundary values.
  • tests/benchmarks/crypto.php reproduces the repeated-field workload without loading instance configuration or accessing a database/vault. Before/after source can be selected in separate processes with the same dependencies; every plaintext is checked. All three runs reproduced 2,064 → 344 derivations for 344 revisions. See tests/benchmarks/README.md for commands and limits.
  • Focused coding-style check, PHP syntax and build/autoloaderchecker.sh pass.

TODO

  • Contributor review of the final diff — confirmed by the contributor.
  • Contributor independent live-instance validation — tested and confirmed by the contributor.
  • Human DCO sign-off for both commits — added by the contributor; the DCO check passes.
  • Maintainer review of the key-reuse lifecycle and compatibility before merging — reviews requested from leftybournes and CarlSchwan; approval still pending.

Checklist

  • Code is properly formatted
  • Sign-off message is added to all commits — certified by the contributor.
  • Tests (unit, integration, api and/or acceptance) are included
  • Screenshots before/after for front-end changes — not applicable; no front-end changes.
  • Documentation (manuals or wiki) has been updated or is not required — benchmark instructions included; no user-facing configuration change.
  • Backports requested where applicable (ex: critical bugfixes) — desired target: stable35 after merge into master. An eligible collaborator/contributor needs to queue /backport to stable35; the PR author is not eligible to invoke the bot yet.
  • Labels added where applicable (ex: bug/enhancement, 3. to review, feature component) — feedback-requested is present. Suggested additional triage labels: performance 🚀 and 3. to review; the author cannot assign repository labels.
  • Milestone added for target branch/version (ex: 32.x for stable32) — suggested milestone: Nextcloud 36 (master); assignment requires maintainer triage.

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

AI-assisted implementation, tests, benchmarking and documentation. I reviewed the changes and tested them on a live Nextcloud instance.

@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@RobinDev RobinDev changed the title perf(crypto): reuse the key for consecutive operations perf(crypto): reuse derived AES keys for consecutive operations Nov 18, 2026
Assisted-by: Codex:GPT-6
Signed-off-by: Robin Delattre <contact@piedweb.com>
Make the repeated-field workload independently reproducible without accessing instance configuration or vault data, and cover malformed input and key/field boundaries.

Assisted-by: Codex:GPT-6
Signed-off-by: Robin Delattre <contact@piedweb.com>
@RobinDev
RobinDev force-pushed the perf/crypto-key-reuse branch from aca97d6 to 2d5ebe9 Compare November 18, 2026 20:14
@RobinDev
RobinDev marked this pull request as ready for review November 18, 2026 20:15
@RobinDev
RobinDev requested a review from a team as a code owner November 18, 2026 20:15
@RobinDev
RobinDev requested review from CarlSchwan and leftybournes and removed request for a team November 18, 2026 20:15

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant