Skip to content

Commit ea29ea4

Browse files
committed
Fix issue #226: raw key+salt not handled properly
In case a database is encrypted with the _SQLCipher_ scheme using _raw key and salt material_ and the _plaintext header_ feature, opening an existing database failed. The reason was that the salt part was erroneously ignored on reading the raw key and salt material. This has been fixed. The same fix has been applied to other cipher schemes, namely AEGIS, Ascon, and ChaCha20. Actually, this fix is currently not absolutely required for these schemes, because the salt is only used for key derivation, which is not performed when raw key and salt material is used. However, behaviour of the schemes may change in the future.
1 parent c519b34 commit ea29ea4

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

src/cipher_aegis.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ GenerateKeyAegisCipher(void* cipher, char* userPassword, int passwordLength, int
262262
else
263263
{
264264
memcpy(aegisCipher->m_salt, cipherSalt, SALTLENGTH_AEGIS);
265+
if (aegisCipher->m_plaintextHeaderSize > 0)
266+
keyOnly = 0;
265267
}
266268

267269
/* Bypass key derivation, if raw key (and optionally salt) are given */

src/cipher_ascon.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ GenerateKeyAscon128Cipher(void* cipher, char* userPassword, int passwordLength,
131131
else
132132
{
133133
memcpy(ascon128Cipher->m_salt, cipherSalt, SALTLENGTH_ASCON128);
134+
if (ascon128Cipher->m_plaintextHeaderSize > 0)
135+
keyOnly = 0;
134136
}
135137

136138
/* Bypass key derivation, if raw key (and optionally salt) are given */

src/cipher_chacha20.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ GenerateKeyChaCha20Cipher(void* cipher, char* userPassword, int passwordLength,
157157
else
158158
{
159159
memcpy(chacha20Cipher->m_salt, cipherSalt, SALTLENGTH_CHACHA20);
160+
if (chacha20Cipher->m_plaintextHeaderSize > 0)
161+
keyOnly = 0;
160162
}
161163

162164
/* Bypass key derivation, if raw key (and optionally salt) are given */

src/cipher_sqlcipher.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ GenerateKeySQLCipherCipher(void* cipher, char* userPassword, int passwordLength,
252252
else
253253
{
254254
memcpy(sqlCipherCipher->m_salt, cipherSalt, SALTLENGTH_SQLCIPHER);
255+
if (sqlCipherCipher->m_plaintextHeaderSize > 0)
256+
keyOnly = 0;
255257
}
256258

257259
/* Bypass key derivation, if raw key (and optionally salt) are given */

0 commit comments

Comments
 (0)