Skip to content

Commit 54d03b9

Browse files
committed
Resolve issue #233
Add support for specifying plaintext header size in non-legacy mode of the SQLCipher cipher scheme. This option was supported only for legacy mode version 4 (legacy=4), but there is no reason to not support it for non-legacy mode.
1 parent 22e55dc commit 54d03b9

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/cipher_sqlcipher.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ AllocateSQLCipherCipher(sqlite3* db)
140140
sqlCipherCipher->m_kdfAlgorithm = sqlite3mcGetCipherParameter(cipherParams, "kdf_algorithm");
141141
sqlCipherCipher->m_hmacAlgorithm = sqlite3mcGetCipherParameter(cipherParams, "hmac_algorithm");
142142
sqlCipherCipher->m_hmacAlgorithmCompat = sqlite3mcGetCipherParameter(cipherParams, "hmac_algorithm_compat");
143-
if (sqlCipherCipher->m_legacy >= SQLCIPHER_VERSION_4)
143+
if (sqlCipherCipher->m_legacy == 0 || sqlCipherCipher->m_legacy >= SQLCIPHER_VERSION_4)
144144
{
145145
sqlCipherCipher->m_plaintextHeaderSize = sqlite3mcGetCipherParameter(cipherParams, "plaintext_header_size");
146146
}
@@ -363,9 +363,12 @@ EncryptPageSQLCipherCipher(void* cipher, int page, unsigned char* data, int len,
363363
if (plaintextHeaderSize > 0)
364364
{
365365
usePlaintextHeader = 1;
366-
if (sqlCipherCipher->m_legacy >= SQLCIPHER_VERSION_4)
366+
if (sqlCipherCipher->m_legacy == 0 || sqlCipherCipher->m_legacy >= SQLCIPHER_VERSION_4)
367367
{
368-
offset = plaintextHeaderSize;
368+
if (plaintextHeaderSize > offset)
369+
{
370+
offset = plaintextHeaderSize;
371+
}
369372
}
370373
}
371374
}
@@ -446,9 +449,12 @@ DecryptPageSQLCipherCipher(void* cipher, int page, unsigned char* data, int len,
446449
if (plaintextHeaderSize > 0)
447450
{
448451
usePlaintextHeader = 1;
449-
if (sqlCipherCipher->m_legacy >= SQLCIPHER_VERSION_4)
452+
if (sqlCipherCipher->m_legacy == 0 || sqlCipherCipher->m_legacy >= SQLCIPHER_VERSION_4)
450453
{
451-
offset = plaintextHeaderSize;
454+
if (plaintextHeaderSize > offset)
455+
{
456+
offset = plaintextHeaderSize;
457+
}
452458
}
453459
}
454460
}

0 commit comments

Comments
 (0)