Skip to content

[SES-3593] - Disable KDF for sqlcipher #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

SessionHero01
Copy link
Collaborator

@SessionHero01 SessionHero01 commented Apr 10, 2025

This PR effectively disables the kdf in sqlcipher. The reason we want to do this:

  1. The key used in sqlcipher is a securely generated key rather than a passphrase. There is no need for further key derivation.
  2. The sqlcipher's builtin kdf adds significant time on start up: as we spawn many db connection on app start-up, and each connection needs to go for 256000 iteration of kdf and it adds significant time on cold start. I believe this is where most of our ANRs come from.

For reference document on kdf, see https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter

This PR also moves the initilisation of SQLCipherOpenHelper to a lazy loading fashion so that the expensive migration will only happen when database access is required. This means all the database classes shouldn't access to the helper directly, they should all use the getReadableDatabase/getWritableDatabase from the base class.

@SessionHero01 SessionHero01 marked this pull request as draft April 10, 2025 07:19
@SessionHero01 SessionHero01 marked this pull request as ready for review April 14, 2025 05:54
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.

2 participants