Use same kdf_iter as for protocol db

This commit is contained in:
Dmitry 2019-07-31 13:53:51 +03:00 committed by Dmitry Shulyak
parent a3a413b5d9
commit 1a37e6b25a
1 changed files with 10 additions and 0 deletions

View File

@ -8,6 +8,12 @@ import (
_ "github.com/mutecomm/go-sqlcipher" // We require go sqlcipher that overrides default implementation _ "github.com/mutecomm/go-sqlcipher" // We require go sqlcipher that overrides default implementation
) )
// The reduced number of kdf iterations (for performance reasons) which is
// currently used for derivation of the database key
// https://github.com/status-im/status-go/pull/1343
// https://notes.status.im/i8Y_l7ccTiOYq09HVgoFwA
const kdfIterationsNumber = 3200
func openDB(path, key string) (*sql.DB, error) { func openDB(path, key string) (*sql.DB, error) {
db, err := sql.Open("sqlite3", path) db, err := sql.Open("sqlite3", path)
if err != nil { if err != nil {
@ -25,6 +31,10 @@ func openDB(path, key string) (*sql.DB, error) {
return nil, errors.New("failed to set key pragma") return nil, errors.New("failed to set key pragma")
} }
if _, err = db.Exec(fmt.Sprintf("PRAGMA kdf_iter = '%d'", kdfIterationsNumber)); err != nil {
return nil, err
}
// readers do not block writers and faster i/o operations // readers do not block writers and faster i/o operations
// https://www.sqlite.org/draft/wal.html // https://www.sqlite.org/draft/wal.html
// must be set after db is encrypted // must be set after db is encrypted