Skip to content

Commit 161bc01

Browse files
committed
Add legacy_page_size option.
1 parent e691c79 commit 161bc01

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

sqlitecipher/sqlitecipher.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,19 +832,23 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
832832
int cipher = -1;
833833
// AES128CBC
834834
bool aes128cbcLegacy = false;
835+
int aes128cbcLegacyPageSize = 0;
835836
// AES256CBC
836837
bool aes256cbcLegacy = false;
837838
int aes256cbcKdfIter = 4001;
839+
int aes256cbcLegacyPageSize = 0;
838840
// CHACHA20
839841
bool chacha20Legacy = false;
840842
int chacha20KdfIter = 64007;
843+
int chacha20LegacyPageSize = 4096;
841844
// SQLCIPHER
842845
bool sqlcipherLegacy = false;
843846
int sqlcipherKdfIter = 64000;
844847
int sqlcipherFastKdfIter = 2;
845848
bool sqlcipherHmacUse = true;
846849
int sqlcipherHmacPgno = 1;
847850
int sqlcipherHmacSaltMask = 0x3a;
851+
int sqlcipherLegacyPageSize = 1024;
848852

849853
#ifdef REGULAR_EXPRESSION_ENABLED
850854
static const QLatin1String regexpConnectOption = QLatin1String("QSQLITE_ENABLE_REGEXP");
@@ -876,13 +880,37 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
876880
aes128cbcLegacy = nl;
877881
}
878882
}
883+
if (option.startsWith(QLatin1String("AES128CBC_LEGACY_PAGE_SIZE="))) {
884+
bool ok;
885+
const int np = option.mid(27).toInt(&ok);
886+
if (ok) {
887+
aes128cbcLegacyPageSize = np;
888+
if (aes128cbcLegacyPageSize < 0) {
889+
aes128cbcLegacyPageSize = 0;
890+
} else if (aes128cbcLegacyPageSize > 65536) {
891+
aes128cbcLegacyPageSize = 65536;
892+
}
893+
}
894+
}
879895
if (option.startsWith(QLatin1String("AES256CBC_LEGACY="))) {
880896
bool ok;
881897
const int nl = option.mid(17).toInt(&ok);
882898
if (ok) {
883899
aes256cbcLegacy = nl;
884900
}
885901
}
902+
if (option.startsWith(QLatin1String("AES256CBC_LEGACY_PAGE_SIZE="))) {
903+
bool ok;
904+
const int np = option.mid(27).toInt(&ok);
905+
if (ok) {
906+
aes256cbcLegacyPageSize = np;
907+
if (aes256cbcLegacyPageSize < 0) {
908+
aes256cbcLegacyPageSize = 0;
909+
} else if (aes256cbcLegacyPageSize > 65536) {
910+
aes256cbcLegacyPageSize = 65536;
911+
}
912+
}
913+
}
886914
if (option.startsWith(QLatin1String("AES256CBC_KDF_ITER="))) {
887915
bool ok;
888916
const int nk = option.mid(19).toInt(&ok);
@@ -900,6 +928,18 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
900928
chacha20Legacy = nl;
901929
}
902930
}
931+
if (option.startsWith(QLatin1String("CHACHA20_LEGACY_PAGE_SIZE="))) {
932+
bool ok;
933+
const int np = option.mid(26).toInt(&ok);
934+
if (ok) {
935+
chacha20LegacyPageSize = np;
936+
if (chacha20LegacyPageSize < 0) {
937+
chacha20LegacyPageSize = 0;
938+
} else if (chacha20LegacyPageSize > 65536) {
939+
chacha20LegacyPageSize = 65536;
940+
}
941+
}
942+
}
903943
if (option.startsWith(QLatin1String("CHACHA20_KDF_ITER="))) {
904944
bool ok;
905945
const int nk = option.mid(18).toInt(&ok);
@@ -917,6 +957,18 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
917957
sqlcipherLegacy = nl;
918958
}
919959
}
960+
if (option.startsWith(QLatin1String("SQLCIPHER_LEGACY_PAGE_SIZE="))) {
961+
bool ok;
962+
const int np = option.mid(27).toInt(&ok);
963+
if (ok) {
964+
sqlcipherLegacyPageSize = np;
965+
if (sqlcipherLegacyPageSize < 0) {
966+
sqlcipherLegacyPageSize = 0;
967+
} else if (sqlcipherLegacyPageSize > 65536) {
968+
sqlcipherLegacyPageSize = 65536;
969+
}
970+
}
971+
}
920972
if (option.startsWith(QLatin1String("SQLCIPHER_KDF_ITER="))) {
921973
bool ok;
922974
const int nk = option.mid(19).toInt(&ok);
@@ -1025,23 +1077,27 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
10251077
case AES_128_CBC:
10261078
{
10271079
wxsqlite3_config_cipher(d->access, "aes128cbc", "legacy", aes128cbcLegacy ? 1 : 0);
1080+
wxsqlite3_config_cipher(d->access, "aes128cbc", "legacy_page_size", aes128cbcLegacyPageSize);
10281081
break;
10291082
}
10301083
case AES_256_CBC:
10311084
{
10321085
wxsqlite3_config_cipher(d->access, "aes256cbc", "legacy", aes256cbcLegacy ? 1 : 0);
1086+
wxsqlite3_config_cipher(d->access, "aes256cbc", "legacy_page_size", aes256cbcLegacyPageSize);
10331087
wxsqlite3_config_cipher(d->access, "aes256cbc", "kdf_iter", aes256cbcKdfIter);
10341088
break;
10351089
}
10361090
case CHACHA20:
10371091
{
10381092
wxsqlite3_config_cipher(d->access, "chacha20", "legacy", chacha20Legacy ? 1 : 0);
1093+
wxsqlite3_config_cipher(d->access, "chacha20", "legacy_page_size", chacha20LegacyPageSize);
10391094
wxsqlite3_config_cipher(d->access, "chacha20", "kdf_iter", chacha20KdfIter);
10401095
break;
10411096
}
10421097
case SQLCIPHER:
10431098
{
10441099
wxsqlite3_config_cipher(d->access, "sqlcipher", "legacy", sqlcipherLegacy ? 1 : 0);
1100+
wxsqlite3_config_cipher(d->access, "sqlcipher", "legacy_page_size", sqlcipherLegacyPageSize);
10451101
wxsqlite3_config_cipher(d->access, "sqlcipher", "kdf_iter", sqlcipherKdfIter);
10461102
wxsqlite3_config_cipher(d->access, "sqlcipher", "fast_kdf_iter", sqlcipherFastKdfIter);
10471103
wxsqlite3_config_cipher(d->access, "sqlcipher", "hmac_use", sqlcipherHmacUse ? 1 : 0);

0 commit comments

Comments
 (0)