Skip to content

Commit 2e412d0

Browse files
committed
Updated SQLite3MultipleCiphers library to version 2.1.0
1 parent bba71b9 commit 2e412d0

File tree

7 files changed

+54
-399
lines changed

7 files changed

+54
-399
lines changed

QSQLite3MultipleCiphers/SQLite3MultipleCiphers/src/aegis/aegis128x2/aegis128x2_common.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ AEGIS_mac_nr(uint8_t *mac, size_t maclen, uint64_t adlen, AEGIS_AES_BLOCK_T*stat
216216
tmp = AEGIS_AES_BLOCK_XOR(tmp, AEGIS_AES_BLOCK_XOR(state[1], state[0]));
217217
AEGIS_AES_BLOCK_STORE(t, tmp);
218218
for (i = 0; i < d / 2; i++) {
219-
memcpy(r, t + i * 32, 32);
219+
memcpy(r, t + i * 32, 16);
220+
memcpy(r + AEGIS_RATE / 2, t + i * 32 + 16, 16);
220221
AEGIS_absorb(r, state);
221222
}
222223
tmp = AEGIS_AES_BLOCK_LOAD_64x2(maclen << 3, d);
@@ -240,7 +241,7 @@ AEGIS_mac_nr(uint8_t *mac, size_t maclen, uint64_t adlen, AEGIS_AES_BLOCK_T*stat
240241
AEGIS_AES_BLOCK_STORE(t + AES_BLOCK_LENGTH, tmp);
241242
for (i = 1; i < d; i++) {
242243
memcpy(r, t + i * 16, 16);
243-
memcpy(r + 16, t + AES_BLOCK_LENGTH + i * 16, 16);
244+
memcpy(r + AEGIS_RATE / 2, t + AES_BLOCK_LENGTH + i * 16, 16);
244245
AEGIS_absorb(r, state);
245246
}
246247
tmp = AEGIS_AES_BLOCK_LOAD_64x2(maclen << 3, d);

QSQLite3MultipleCiphers/SQLite3MultipleCiphers/src/aegis/aegis128x4/aegis128x4_common.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ AEGIS_mac_nr(uint8_t *mac, size_t maclen, uint64_t adlen, AEGIS_AES_BLOCK_T *sta
231231
tmp = AEGIS_AES_BLOCK_XOR(tmp, AEGIS_AES_BLOCK_XOR(state[1], state[0]));
232232
AEGIS_AES_BLOCK_STORE(t, tmp);
233233
for (i = 0; i < d / 2; i++) {
234-
memcpy(r, t + i * 32, 32);
234+
memcpy(r, t + i * 32, 16);
235+
memcpy(r + AEGIS_RATE / 2, t + i * 32 + 16, 16);
235236
AEGIS_absorb(r, state);
236237
}
237238
tmp = AEGIS_AES_BLOCK_LOAD_64x2(maclen << 3, d);
@@ -255,7 +256,7 @@ AEGIS_mac_nr(uint8_t *mac, size_t maclen, uint64_t adlen, AEGIS_AES_BLOCK_T *sta
255256
AEGIS_AES_BLOCK_STORE(t + AES_BLOCK_LENGTH, tmp);
256257
for (i = 1; i < d; i++) {
257258
memcpy(r, t + i * 16, 16);
258-
memcpy(r + 16, t + AES_BLOCK_LENGTH + i * 16, 16);
259+
memcpy(r + AEGIS_RATE / 2, t + AES_BLOCK_LENGTH + i * 16, 16);
259260
AEGIS_absorb(r, state);
260261
}
261262
tmp = AEGIS_AES_BLOCK_LOAD_64x2(maclen << 3, d);

QSQLite3MultipleCiphers/SQLite3MultipleCiphers/src/sqlite3mc.c

+26-32
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** Purpose: Amalgamation of the SQLite3 Multiple Ciphers encryption extension for SQLite
44
** Author: Ulrich Telle
55
** Created: 2020-02-28
6-
** Copyright: (c) 2006-2024 Ulrich Telle
6+
** Copyright: (c) 2006-2025 Ulrich Telle
77
** License: MIT
88
*/
99

@@ -37,19 +37,6 @@
3737
#endif
3838
#endif
3939

40-
/*
41-
** Define function for extra initialization and extra shutdown
42-
**
43-
** The extra initialization function registers an extension function
44-
** which will be automatically executed for each new database connection.
45-
**
46-
** The extra shutdown function will be executed on the invocation of sqlite3_shutdown.
47-
** All created multiple ciphers VFSs will be unregistered and destroyed.
48-
*/
49-
50-
#define SQLITE_EXTRA_INIT sqlite3mc_initialize
51-
#define SQLITE_EXTRA_SHUTDOWN sqlite3mc_shutdown
52-
5340
/*
5441
** Declare all internal functions as 'static' unless told otherwise
5542
*/
@@ -538,8 +525,6 @@ sqlite3mcRegisterCipher(const CipherDescriptor* desc, const CipherParams* params
538525
if (!cipherParams)
539526
return SQLITE_NOMEM;
540527

541-
sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MAIN));
542-
543528
/* Check for */
544529
if (globalCipherCount < CODEC_COUNT_MAX)
545530
{
@@ -589,8 +574,6 @@ sqlite3mcRegisterCipher(const CipherDescriptor* desc, const CipherParams* params
589574
rc = SQLITE_NOMEM;
590575
}
591576

592-
sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MAIN));
593-
594577
return rc;
595578
}
596579

@@ -602,7 +585,10 @@ sqlite3mc_register_cipher(const CipherDescriptor* desc, const CipherParams* para
602585
rc = sqlite3_initialize();
603586
if (rc) return rc;
604587
#endif
605-
return sqlite3mcRegisterCipher(desc, params, makeDefault);
588+
sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MAIN));
589+
rc = sqlite3mcRegisterCipher(desc, params, makeDefault);
590+
sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MAIN));
591+
return rc;
606592
}
607593

608594
SQLITE_PRIVATE int
@@ -718,84 +704,92 @@ sqlite3mc_initialize(const char* arg)
718704
{
719705
rc = sqlite3mc_vfs_create(NULL, 1);
720706
}
707+
return rc;
708+
}
709+
710+
SQLITE_PRIVATE int
711+
sqlite3mc_builtin_extensions(sqlite3* db)
712+
{
713+
char* errmsg = NULL;
714+
int rc = SQLITE_OK;
721715

722716
/*
723717
** Register Multi Cipher extension
724718
*/
725719
if (rc == SQLITE_OK)
726720
{
727-
rc = sqlite3_auto_extension((void(*)(void)) mcRegisterCodecExtensions);
721+
rc = mcRegisterCodecExtensions(db, &errmsg, NULL);
728722
}
729723
#ifdef SQLITE_ENABLE_EXTFUNC
730724
if (rc == SQLITE_OK)
731725
{
732-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_extfunc_init);
726+
rc = sqlite3_extfunc_init(db, &errmsg, NULL);
733727
}
734728
#endif
735729
#ifdef SQLITE_ENABLE_CSV
736730
if (rc == SQLITE_OK)
737731
{
738-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_csv_init);
732+
rc = sqlite3_csv_init(db, &errmsg, NULL);
739733
}
740734
#endif
741735
#ifdef SQLITE_ENABLE_VSV
742736
if (rc == SQLITE_OK)
743737
{
744-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_vsv_init);
738+
rc = sqlite3_vsv_init(db, &errmsg, NULL);
745739
}
746740
#endif
747741
#ifdef SQLITE_ENABLE_SHA3
748742
if (rc == SQLITE_OK)
749743
{
750-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_shathree_init);
744+
rc = sqlite3_shathree_init(db, &errmsg, NULL);
751745
}
752746
#endif
753747
#ifdef SQLITE_ENABLE_CARRAY
754748
if (rc == SQLITE_OK)
755749
{
756-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_carray_init);
750+
rc = sqlite3_carray_init(db, &errmsg, NULL);
757751
}
758752
#endif
759753
#ifdef SQLITE_ENABLE_FILEIO
760754
if (rc == SQLITE_OK)
761755
{
762-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_fileio_init);
756+
rc = sqlite3_fileio_init(db, &errmsg, NULL);
763757
}
764758
#endif
765759
#ifdef SQLITE_ENABLE_SERIES
766760
if (rc == SQLITE_OK)
767761
{
768-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_series_init);
762+
rc = sqlite3_series_init(db, &errmsg, NULL);
769763
}
770764
#endif
771765
#ifdef SQLITE_ENABLE_UUID
772766
if (rc == SQLITE_OK)
773767
{
774-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_uuid_init);
768+
rc = sqlite3_uuid_init(db, &errmsg, NULL);
775769
}
776770
#endif
777771
#ifdef SQLITE_ENABLE_REGEXP
778772
if (rc == SQLITE_OK)
779773
{
780-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_regexp_init);
774+
rc = sqlite3_regexp_init(db, &errmsg, NULL);
781775
}
782776
#endif
783777
#ifdef SQLITE_ENABLE_COMPRESS
784778
if (rc == SQLITE_OK)
785779
{
786-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_compress_init);
780+
rc = sqlite3_compress_init(db, &errmsg, NULL);
787781
}
788782
#endif
789783
#ifdef SQLITE_ENABLE_SQLAR
790784
if (rc == SQLITE_OK)
791785
{
792-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_sqlar_init);
786+
rc = sqlite3_sqlar_init(db, &errmsg, NULL);
793787
}
794788
#endif
795789
#ifdef SQLITE_ENABLE_ZIPFILE
796790
if (rc == SQLITE_OK)
797791
{
798-
rc = sqlite3_auto_extension((void(*)(void)) sqlite3_zipfile_init);
792+
rc = sqlite3_zipfile_init(db, &errmsg, NULL);
799793
}
800794
#endif
801795
return rc;

QSQLite3MultipleCiphers/SQLite3MultipleCiphers/src/sqlite3mc_config.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** Purpose: Header file for SQLite3 Multiple Ciphers compile-time configuration
44
** Author: Ulrich Telle
55
** Created: 2021-09-27
6-
** Copyright: (c) 2019-2024 Ulrich Telle
6+
** Copyright: (c) 2019-2025 Ulrich Telle
77
** License: MIT
88
*/
99

@@ -72,6 +72,18 @@
7272
#define HAVE_CIPHER_ASCON128 1
7373
#endif
7474

75+
/*
76+
** Disable AEGIS cipher scheme for MSVC 2015 and below
77+
** MSVC versions below MSVC 2017 can't compile the AEGIS cipher code
78+
** due to not supporting to pass aligned parameters by value
79+
*/
80+
#if defined(_MSC_VER) && _MSC_VER < 1910
81+
#ifdef HAVE_CIPHER_AEGIS
82+
#undef HAVE_CIPHER_AEGIS
83+
#endif
84+
#define HAVE_CIPHER_AEGIS 0
85+
#endif
86+
7587
#ifndef HAVE_CIPHER_AEGIS
7688
#define HAVE_CIPHER_AEGIS 1
7789
#endif

QSQLite3MultipleCiphers/SQLite3MultipleCiphers/src/sqlite3mc_version.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#define SQLITE3MC_VERSION_H_
1414

1515
#define SQLITE3MC_VERSION_MAJOR 2
16-
#define SQLITE3MC_VERSION_MINOR 0
17-
#define SQLITE3MC_VERSION_RELEASE 4
16+
#define SQLITE3MC_VERSION_MINOR 1
17+
#define SQLITE3MC_VERSION_RELEASE 0
1818
#define SQLITE3MC_VERSION_SUBRELEASE 0
19-
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 2.0.4"
19+
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 2.1.0"
2020

2121
#endif /* SQLITE3MC_VERSION_H_ */

QSQLite3MultipleCiphers/SQLite3MultipleCiphers/src/sqlite3patched.c

+6
Original file line numberDiff line numberDiff line change
@@ -14045,6 +14045,7 @@ SQLITE_PRIVATE int sqlite3mcPagerHasCodec(PagerMC* pPager);
1404514045
SQLITE_PRIVATE void sqlite3mcInitMemoryMethods();
1404614046
SQLITE_PRIVATE int sqlite3mcIsBackupSupported(sqlite3*, const char*, sqlite3*, const char*);
1404714047
SQLITE_PRIVATE void sqlite3mcCodecGetKey(sqlite3* db, int nDb, void** zKey, int* nKey);
14048+
SQLITE_PRIVATE int sqlite3mc_builtin_extensions(sqlite3* db);
1404814049

1404914050
/************** End of sqlite3.h *********************************************/
1405014051
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -181668,6 +181669,7 @@ static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {
181668181669
#ifdef SQLITE_EXTRA_AUTOEXT
181669181670
SQLITE_EXTRA_AUTOEXT,
181670181671
#endif
181672+
sqlite3mc_builtin_extensions,
181671181673
};
181672181674

181673181675
#ifndef SQLITE_AMALGAMATION
@@ -181885,6 +181887,8 @@ SQLITE_API int sqlite3_initialize(void){
181885181887
if( rc==SQLITE_OK ){
181886181888
sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
181887181889
sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
181890+
int sqlite3mc_initialize(const char*);
181891+
rc = sqlite3mc_initialize(0);
181888181892
sqlite3MemoryBarrier();
181889181893
sqlite3GlobalConfig.isInit = 1;
181890181894
#ifdef SQLITE_EXTRA_INIT
@@ -181959,6 +181963,8 @@ SQLITE_API int sqlite3_shutdown(void){
181959181963
void SQLITE_EXTRA_SHUTDOWN(void);
181960181964
SQLITE_EXTRA_SHUTDOWN();
181961181965
#endif
181966+
void sqlite3mc_shutdown(void);
181967+
sqlite3mc_shutdown();
181962181968
sqlite3_os_end();
181963181969
sqlite3_reset_auto_extension();
181964181970
sqlite3GlobalConfig.isInit = 0;

0 commit comments

Comments
 (0)