better-sqlite3-multiple-ciphers 11.0.0-beta.0 → 11.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/deps/setup.ps1 +1 -1
- package/deps/sqlite3/sqlite3.c +668 -488
- package/deps/sqlite3/sqlite3.h +4 -3
- package/package.json +1 -1
- package/src/better_sqlite3.cpp +29 -29
- package/src/better_sqlite3.hpp +75 -77
package/deps/sqlite3/sqlite3.c
CHANGED
|
@@ -51,8 +51,15 @@
|
|
|
51
51
|
#define SQLITE_EXTRA_INIT sqlite3mc_initialize
|
|
52
52
|
#define SQLITE_EXTRA_SHUTDOWN sqlite3mc_shutdown
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
/*
|
|
55
|
+
** Declare all internal functions as 'static' unless told otherwise
|
|
56
|
+
*/
|
|
57
|
+
#ifndef SQLITE_PRIVATE
|
|
58
|
+
#define SQLITE_PRIVATE static
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
SQLITE_PRIVATE int sqlite3mc_initialize(const char* arg);
|
|
62
|
+
SQLITE_PRIVATE void sqlite3mc_shutdown(void);
|
|
56
63
|
|
|
57
64
|
/*
|
|
58
65
|
** To enable the extension functions define SQLITE_ENABLE_EXTFUNC on compiling this module
|
|
@@ -113,13 +120,13 @@ void sqlite3mc_shutdown(void);
|
|
|
113
120
|
#include <windows.h>
|
|
114
121
|
|
|
115
122
|
/* SQLite functions only needed on Win32 */
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
SQLITE_API void sqlite3_win32_write_debug(const char*, int);
|
|
124
|
+
SQLITE_API char *sqlite3_win32_unicode_to_utf8(LPCWSTR);
|
|
125
|
+
SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char*);
|
|
126
|
+
SQLITE_API char *sqlite3_win32_mbcs_to_utf8_v2(const char*, int);
|
|
127
|
+
SQLITE_API char *sqlite3_win32_utf8_to_mbcs(const char*);
|
|
128
|
+
SQLITE_API char *sqlite3_win32_utf8_to_mbcs_v2(const char*, int);
|
|
129
|
+
SQLITE_API LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
|
|
123
130
|
#endif
|
|
124
131
|
|
|
125
132
|
/*
|
|
@@ -11288,7 +11295,7 @@ SQLITE_API int sqlite3_deserialize(
|
|
|
11288
11295
|
} /* End of the 'extern "C"' block */
|
|
11289
11296
|
#endif
|
|
11290
11297
|
#endif /* SQLITE3_H */
|
|
11291
|
-
|
|
11298
|
+
|
|
11292
11299
|
/* Function prototypes of SQLite3 Multiple Ciphers */
|
|
11293
11300
|
SQLITE_PRIVATE int sqlite3mcCheckVfs(const char*);
|
|
11294
11301
|
SQLITE_PRIVATE int sqlite3mcFileControlPragma(sqlite3*, const char*, int, void*);
|
|
@@ -11299,6 +11306,7 @@ SQLITE_PRIVATE void* sqlite3mcPagerCodec(PgHdrMC* pPg);
|
|
|
11299
11306
|
typedef struct Pager PagerMC;
|
|
11300
11307
|
SQLITE_PRIVATE int sqlite3mcPagerHasCodec(PagerMC* pPager);
|
|
11301
11308
|
SQLITE_PRIVATE void sqlite3mcInitMemoryMethods();
|
|
11309
|
+
SQLITE_PRIVATE int sqlite3mcIsBackupSupported(sqlite3*, const char*, sqlite3*, const char*);
|
|
11302
11310
|
|
|
11303
11311
|
/******** Begin file sqlite3rtree.h *********/
|
|
11304
11312
|
/*
|
|
@@ -25026,8 +25034,8 @@ static const struct {
|
|
|
25026
25034
|
/* 1 */ { 6, "minute", 7.7379e+12, 60.0 },
|
|
25027
25035
|
/* 2 */ { 4, "hour", 1.2897e+11, 3600.0 },
|
|
25028
25036
|
/* 3 */ { 3, "day", 5373485.0, 86400.0 },
|
|
25029
|
-
/* 4 */ { 5, "month", 176546.0,
|
|
25030
|
-
/* 5 */ { 4, "year", 14713.0,
|
|
25037
|
+
/* 4 */ { 5, "month", 176546.0, 2592000.0 },
|
|
25038
|
+
/* 5 */ { 4, "year", 14713.0, 31536000.0 },
|
|
25031
25039
|
};
|
|
25032
25040
|
|
|
25033
25041
|
/*
|
|
@@ -82315,6 +82323,12 @@ SQLITE_API sqlite3_backup *sqlite3_backup_init(
|
|
|
82315
82323
|
}
|
|
82316
82324
|
#endif
|
|
82317
82325
|
|
|
82326
|
+
/* Check whether databases are compatible with backup */
|
|
82327
|
+
if (!sqlite3mcIsBackupSupported(pSrcDb, zSrcDb, pDestDb, zDestDb)){
|
|
82328
|
+
sqlite3ErrorWithMsg(pDestDb, SQLITE_ERROR, "backup is not supported with incompatible source and target databases");
|
|
82329
|
+
return NULL;
|
|
82330
|
+
}
|
|
82331
|
+
|
|
82318
82332
|
/* Lock the source database handle. The destination database
|
|
82319
82333
|
** handle is not locked in this routine, but it is locked in
|
|
82320
82334
|
** sqlite3_backup_step(). The user is required to ensure that no
|
|
@@ -257839,7 +257853,7 @@ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
|
|
|
257839
257853
|
|
|
257840
257854
|
|
|
257841
257855
|
/*
|
|
257842
|
-
** Include SQLite3MultiCipher components
|
|
257856
|
+
** Include SQLite3MultiCipher components
|
|
257843
257857
|
*/
|
|
257844
257858
|
/* #include "sqlite3mc_config.h" */
|
|
257845
257859
|
/*** Begin of #include "sqlite3mc_config.h" ***/
|
|
@@ -258052,9 +258066,9 @@ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
|
|
|
258052
258066
|
|
|
258053
258067
|
#define SQLITE3MC_VERSION_MAJOR 1
|
|
258054
258068
|
#define SQLITE3MC_VERSION_MINOR 8
|
|
258055
|
-
#define SQLITE3MC_VERSION_RELEASE
|
|
258069
|
+
#define SQLITE3MC_VERSION_RELEASE 6
|
|
258056
258070
|
#define SQLITE3MC_VERSION_SUBRELEASE 0
|
|
258057
|
-
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.8.
|
|
258071
|
+
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.8.6"
|
|
258058
258072
|
|
|
258059
258073
|
#endif /* SQLITE3MC_VERSION_H_ */
|
|
258060
258074
|
/*** End of #include "sqlite3mc_version.h" ***/
|
|
@@ -271564,7 +271578,7 @@ SQLITE_API int sqlite3_user_add(
|
|
|
271564
271578
|
** The sqlite3_user_change() interface can be used to change a users
|
|
271565
271579
|
** login credentials or admin privilege. Any user can change their own
|
|
271566
271580
|
** login credentials. Only an admin user can change another users login
|
|
271567
|
-
** credentials or admin privilege setting. No user may change their own
|
|
271581
|
+
** credentials or admin privilege setting. No user may change their own
|
|
271568
271582
|
** admin privilege setting.
|
|
271569
271583
|
*/
|
|
271570
271584
|
SQLITE_API int sqlite3_user_change(
|
|
@@ -271798,6 +271812,7 @@ extern "C" {
|
|
|
271798
271812
|
#ifndef SQLITE_PRIVATE
|
|
271799
271813
|
#define SQLITE_PRIVATE
|
|
271800
271814
|
#endif
|
|
271815
|
+
|
|
271801
271816
|
SQLITE_PRIVATE int sqlite3mcCheckVfs(const char* zVfs);
|
|
271802
271817
|
|
|
271803
271818
|
SQLITE_API int sqlite3mc_vfs_create(const char* zVfsReal, int makeDefault);
|
|
@@ -271918,19 +271933,19 @@ static void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
|
|
271918
271933
|
* architectures that lack an AND-NOT instruction, just like in Colin Plumb's
|
|
271919
271934
|
* implementation.
|
|
271920
271935
|
*/
|
|
271921
|
-
#define F(x, y, z)
|
|
271922
|
-
#define G(x, y, z)
|
|
271923
|
-
#define H(x, y, z)
|
|
271924
|
-
#define H2(x, y, z)
|
|
271925
|
-
#define I(x, y, z)
|
|
271936
|
+
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
|
271937
|
+
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
|
|
271938
|
+
#define H(x, y, z) (((x) ^ (y)) ^ (z))
|
|
271939
|
+
#define H2(x, y, z) ((x) ^ ((y) ^ (z)))
|
|
271940
|
+
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
|
|
271926
271941
|
|
|
271927
271942
|
/*
|
|
271928
271943
|
* The MD5 transformation for all four rounds.
|
|
271929
271944
|
*/
|
|
271930
271945
|
#define STEP(f, a, b, c, d, x, t, s) \
|
|
271931
|
-
|
|
271932
|
-
|
|
271933
|
-
|
|
271946
|
+
(a) += f((b), (c), (d)) + (x) + (t); \
|
|
271947
|
+
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
|
|
271948
|
+
(a) += (b);
|
|
271934
271949
|
|
|
271935
271950
|
/*
|
|
271936
271951
|
* SET reads 4 input bytes in little-endian byte order and stores them
|
|
@@ -271942,18 +271957,18 @@ static void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
|
|
271942
271957
|
*/
|
|
271943
271958
|
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
|
271944
271959
|
#define SET(n) \
|
|
271945
|
-
|
|
271960
|
+
(*(MD5_u32plus *)&ptr[(n) * 4])
|
|
271946
271961
|
#define GET(n) \
|
|
271947
|
-
|
|
271962
|
+
SET(n)
|
|
271948
271963
|
#else
|
|
271949
271964
|
#define SET(n) \
|
|
271950
|
-
|
|
271951
|
-
|
|
271952
|
-
|
|
271953
|
-
|
|
271954
|
-
|
|
271965
|
+
(ctx->block[(n)] = \
|
|
271966
|
+
(MD5_u32plus)ptr[(n) * 4] | \
|
|
271967
|
+
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
|
271968
|
+
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
|
271969
|
+
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
|
|
271955
271970
|
#define GET(n) \
|
|
271956
|
-
|
|
271971
|
+
(ctx->block[(n)])
|
|
271957
271972
|
#endif
|
|
271958
271973
|
|
|
271959
271974
|
/*
|
|
@@ -272181,10 +272196,10 @@ Still 100% Public Domain
|
|
|
272181
272196
|
|
|
272182
272197
|
Corrected a problem which generated improper hash values on 16 bit machines
|
|
272183
272198
|
Routine SHA1Update changed from
|
|
272184
|
-
|
|
272199
|
+
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int
|
|
272185
272200
|
len)
|
|
272186
272201
|
to
|
|
272187
|
-
|
|
272202
|
+
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned
|
|
272188
272203
|
long len)
|
|
272189
272204
|
|
|
272190
272205
|
The 'len' parameter was declared an int which works fine on 32 bit machines.
|
|
@@ -272277,7 +272292,7 @@ typedef unsigned long long uint64_t;
|
|
|
272277
272292
|
#define UINT8_MAX 255
|
|
272278
272293
|
#define UINT16_MAX 65535
|
|
272279
272294
|
#define UINT32_MAX 0xffffffffU /* 4294967295U */
|
|
272280
|
-
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
|
|
272295
|
+
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
|
|
272281
272296
|
#else
|
|
272282
272297
|
#include <stdint.h>
|
|
272283
272298
|
#endif
|
|
@@ -272296,6 +272311,10 @@ typedef unsigned long long uint64_t;
|
|
|
272296
272311
|
#ifndef SHA1_H_
|
|
272297
272312
|
#define SHA1_H_ (1)
|
|
272298
272313
|
|
|
272314
|
+
#ifndef SQLITE_PRIVATE
|
|
272315
|
+
#define SQLITE_PRIVATE
|
|
272316
|
+
#endif
|
|
272317
|
+
|
|
272299
272318
|
/** SHA-1 Context */
|
|
272300
272319
|
typedef struct {
|
|
272301
272320
|
uint32_t h[5];
|
|
@@ -272309,13 +272328,13 @@ typedef struct {
|
|
|
272309
272328
|
/** SHA-1 Digest size in bytes */
|
|
272310
272329
|
#define SHA1_DIGEST_SIZE 20
|
|
272311
272330
|
|
|
272312
|
-
void sha1_init(sha1_ctx *context);
|
|
272331
|
+
SQLITE_PRIVATE void sha1_init(sha1_ctx *context);
|
|
272313
272332
|
|
|
272314
|
-
void sha1_update(sha1_ctx *context, const void *p, size_t len);
|
|
272333
|
+
SQLITE_PRIVATE void sha1_update(sha1_ctx *context, const void *p, size_t len);
|
|
272315
272334
|
|
|
272316
|
-
void sha1_final(sha1_ctx *context, uint8_t digest[SHA1_DIGEST_SIZE]);
|
|
272335
|
+
SQLITE_PRIVATE void sha1_final(sha1_ctx *context, uint8_t digest[SHA1_DIGEST_SIZE]);
|
|
272317
272336
|
|
|
272318
|
-
void sha1_transform(sha1_ctx *context, const uint8_t buffer[64]);
|
|
272337
|
+
SQLITE_PRIVATE void sha1_transform(sha1_ctx *context, const uint8_t buffer[64]);
|
|
272319
272338
|
|
|
272320
272339
|
#endif /* SHA1_H_ */
|
|
272321
272340
|
/*** End of #include "sha1.h" ***/
|
|
@@ -272370,6 +272389,7 @@ void sha1_transform(sha1_ctx *context, const uint8_t buffer[64]);
|
|
|
272370
272389
|
z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=ror(w,2);
|
|
272371
272390
|
|
|
272372
272391
|
/* Hash a single 512-bit block. This is the core of the algorithm. */
|
|
272392
|
+
SQLITE_PRIVATE
|
|
272373
272393
|
void sha1_transform(sha1_ctx *context, const uint8_t buffer[64])
|
|
272374
272394
|
{
|
|
272375
272395
|
uint32_t a, b, c, d, e;
|
|
@@ -272434,6 +272454,7 @@ void sha1_transform(sha1_ctx *context, const uint8_t buffer[64])
|
|
|
272434
272454
|
*
|
|
272435
272455
|
* @param context SHA1-Context
|
|
272436
272456
|
*/
|
|
272457
|
+
SQLITE_PRIVATE
|
|
272437
272458
|
void sha1_init(sha1_ctx *context)
|
|
272438
272459
|
{
|
|
272439
272460
|
/* SHA1 initialization constants */
|
|
@@ -272453,6 +272474,7 @@ void sha1_init(sha1_ctx *context)
|
|
|
272453
272474
|
* @param p Buffer to run SHA1 on
|
|
272454
272475
|
* @param len Number of bytes
|
|
272455
272476
|
*/
|
|
272477
|
+
SQLITE_PRIVATE
|
|
272456
272478
|
void sha1_update(sha1_ctx *context, const void *p, size_t len)
|
|
272457
272479
|
{
|
|
272458
272480
|
const uint8_t *data = p;
|
|
@@ -272488,6 +272510,7 @@ void sha1_update(sha1_ctx *context, const void *p, size_t len)
|
|
|
272488
272510
|
* @param digest Generated message digest
|
|
272489
272511
|
* @param context SHA1-Context
|
|
272490
272512
|
*/
|
|
272513
|
+
SQLITE_PRIVATE
|
|
272491
272514
|
void sha1_final(sha1_ctx *context, uint8_t digest[SHA1_DIGEST_SIZE])
|
|
272492
272515
|
{
|
|
272493
272516
|
uint32_t i;
|
|
@@ -272599,6 +272622,10 @@ void sha1_final(sha1_ctx *context, uint8_t digest[SHA1_DIGEST_SIZE])
|
|
|
272599
272622
|
#ifndef SHA2_H
|
|
272600
272623
|
#define SHA2_H
|
|
272601
272624
|
|
|
272625
|
+
#ifndef SQLITE_PRIVATE
|
|
272626
|
+
#define SQLITE_PRIVATE
|
|
272627
|
+
#endif
|
|
272628
|
+
|
|
272602
272629
|
#define SHA224_DIGEST_SIZE ( 224 / 8)
|
|
272603
272630
|
#define SHA256_DIGEST_SIZE ( 256 / 8)
|
|
272604
272631
|
#define SHA384_DIGEST_SIZE ( 384 / 8)
|
|
@@ -272620,7 +272647,7 @@ typedef sqlite3_uint64 uint64;
|
|
|
272620
272647
|
#define li_64(h) 0x##h##ui64
|
|
272621
272648
|
#else
|
|
272622
272649
|
#define li_64(h) 0x##h##ull
|
|
272623
|
-
#endif
|
|
272650
|
+
#endif
|
|
272624
272651
|
|
|
272625
272652
|
#if 0 /* Start of original int64 defines */
|
|
272626
272653
|
|
|
@@ -272692,35 +272719,27 @@ typedef struct {
|
|
|
272692
272719
|
typedef sha512_ctx sha384_ctx;
|
|
272693
272720
|
typedef sha256_ctx sha224_ctx;
|
|
272694
272721
|
|
|
272695
|
-
void sha224_init(sha224_ctx *ctx);
|
|
272696
|
-
void sha224_update(sha224_ctx *ctx, const unsigned char *message,
|
|
272697
|
-
|
|
272698
|
-
void
|
|
272699
|
-
void sha224(const unsigned char *message, unsigned int len,
|
|
272700
|
-
unsigned char *digest);
|
|
272722
|
+
SQLITE_PRIVATE void sha224_init(sha224_ctx *ctx);
|
|
272723
|
+
SQLITE_PRIVATE void sha224_update(sha224_ctx *ctx, const unsigned char *message, unsigned int len);
|
|
272724
|
+
SQLITE_PRIVATE void sha224_final(sha224_ctx *ctx, unsigned char *digest);
|
|
272725
|
+
SQLITE_PRIVATE void sha224(const unsigned char *message, unsigned int len, unsigned char *digest);
|
|
272701
272726
|
|
|
272702
|
-
void sha256_init(sha256_ctx * ctx);
|
|
272703
|
-
void sha256_update(sha256_ctx *ctx, const unsigned char *message,
|
|
272704
|
-
|
|
272705
|
-
void
|
|
272706
|
-
void
|
|
272707
|
-
void sha256(const unsigned char *message, unsigned int len,
|
|
272708
|
-
unsigned char *digest);
|
|
272727
|
+
SQLITE_PRIVATE void sha256_init(sha256_ctx * ctx);
|
|
272728
|
+
SQLITE_PRIVATE void sha256_update(sha256_ctx *ctx, const unsigned char *message, unsigned int len);
|
|
272729
|
+
SQLITE_PRIVATE void sha256_final(sha256_ctx *ctx, unsigned char *digest);
|
|
272730
|
+
SQLITE_PRIVATE void sha256_transform(sha256_ctx *ctx, const unsigned char *message);
|
|
272731
|
+
SQLITE_PRIVATE void sha256(const unsigned char *message, unsigned int len, unsigned char *digest);
|
|
272709
272732
|
|
|
272710
|
-
void sha384_init(sha384_ctx *ctx);
|
|
272711
|
-
void sha384_update(sha384_ctx *ctx, const unsigned char *message,
|
|
272712
|
-
|
|
272713
|
-
void
|
|
272714
|
-
void sha384(const unsigned char *message, unsigned int len,
|
|
272715
|
-
unsigned char *digest);
|
|
272733
|
+
SQLITE_PRIVATE void sha384_init(sha384_ctx *ctx);
|
|
272734
|
+
SQLITE_PRIVATE void sha384_update(sha384_ctx *ctx, const unsigned char *message, unsigned int len);
|
|
272735
|
+
SQLITE_PRIVATE void sha384_final(sha384_ctx *ctx, unsigned char *digest);
|
|
272736
|
+
SQLITE_PRIVATE void sha384(const unsigned char *message, unsigned int len, unsigned char *digest);
|
|
272716
272737
|
|
|
272717
|
-
void sha512_init(sha512_ctx *ctx);
|
|
272718
|
-
void sha512_update(sha512_ctx *ctx, const unsigned char *message,
|
|
272719
|
-
|
|
272720
|
-
void
|
|
272721
|
-
void
|
|
272722
|
-
void sha512(const unsigned char *message, unsigned int len,
|
|
272723
|
-
unsigned char *digest);
|
|
272738
|
+
SQLITE_PRIVATE void sha512_init(sha512_ctx *ctx);
|
|
272739
|
+
SQLITE_PRIVATE void sha512_update(sha512_ctx *ctx, const unsigned char *message, unsigned int len);
|
|
272740
|
+
SQLITE_PRIVATE void sha512_final(sha512_ctx *ctx, unsigned char *digest);
|
|
272741
|
+
SQLITE_PRIVATE void sha512_transform(sha512_ctx *ctx, const unsigned char *message);
|
|
272742
|
+
SQLITE_PRIVATE void sha512(const unsigned char *message, unsigned int len, unsigned char *digest);
|
|
272724
272743
|
|
|
272725
272744
|
#ifdef __cplusplus
|
|
272726
272745
|
}
|
|
@@ -272823,27 +272842,27 @@ void sha512(const unsigned char *message, unsigned int len,
|
|
|
272823
272842
|
wv[h] = t1 + t2; \
|
|
272824
272843
|
}
|
|
272825
272844
|
|
|
272826
|
-
uint32 sha224_h0[8] =
|
|
272845
|
+
static uint32 sha224_h0[8] =
|
|
272827
272846
|
{0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
|
272828
272847
|
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4};
|
|
272829
272848
|
|
|
272830
|
-
uint32 sha256_h0[8] =
|
|
272849
|
+
static uint32 sha256_h0[8] =
|
|
272831
272850
|
{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
272832
272851
|
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
|
|
272833
272852
|
|
|
272834
|
-
uint64 sha384_h0[8] =
|
|
272853
|
+
static uint64 sha384_h0[8] =
|
|
272835
272854
|
{li_64(cbbb9d5dc1059ed8), li_64(629a292a367cd507),
|
|
272836
272855
|
li_64(9159015a3070dd17), li_64(152fecd8f70e5939),
|
|
272837
272856
|
li_64(67332667ffc00b31), li_64(8eb44a8768581511),
|
|
272838
272857
|
li_64(db0c2e0d64f98fa7), li_64(47b5481dbefa4fa4)};
|
|
272839
272858
|
|
|
272840
|
-
uint64 sha512_h0[8] =
|
|
272859
|
+
static uint64 sha512_h0[8] =
|
|
272841
272860
|
{li_64(6a09e667f3bcc908), li_64(bb67ae8584caa73b),
|
|
272842
272861
|
li_64(3c6ef372fe94f82b), li_64(a54ff53a5f1d36f1),
|
|
272843
272862
|
li_64(510e527fade682d1), li_64(9b05688c2b3e6c1f),
|
|
272844
272863
|
li_64(1f83d9abfb41bd6b), li_64(5be0cd19137e2179)};
|
|
272845
272864
|
|
|
272846
|
-
uint32 sha256_k[64] =
|
|
272865
|
+
static uint32 sha256_k[64] =
|
|
272847
272866
|
{0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
|
272848
272867
|
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
272849
272868
|
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
@@ -272861,7 +272880,7 @@ uint32 sha256_k[64] =
|
|
|
272861
272880
|
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
272862
272881
|
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
|
|
272863
272882
|
|
|
272864
|
-
uint64 sha512_k[80] =
|
|
272883
|
+
static uint64 sha512_k[80] =
|
|
272865
272884
|
{li_64(428a2f98d728ae22), li_64(7137449123ef65cd),
|
|
272866
272885
|
li_64(b5c0fbcfec4d3b2f), li_64(e9b5dba58189dbbc),
|
|
272867
272886
|
li_64(3956c25bf348b538), li_64(59f111f1b605d019),
|
|
@@ -273021,11 +273040,13 @@ void sha256_transf(sha256_ctx *ctx, const unsigned char *message,
|
|
|
273021
273040
|
}
|
|
273022
273041
|
}
|
|
273023
273042
|
|
|
273043
|
+
SQLITE_PRIVATE
|
|
273024
273044
|
void sha256_transform(sha256_ctx *ctx, const unsigned char *message)
|
|
273025
273045
|
{
|
|
273026
273046
|
sha256_transf(ctx, message, 1);
|
|
273027
273047
|
}
|
|
273028
273048
|
|
|
273049
|
+
SQLITE_PRIVATE
|
|
273029
273050
|
void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
|
|
273030
273051
|
{
|
|
273031
273052
|
sha256_ctx ctx;
|
|
@@ -273035,6 +273056,7 @@ void sha256(const unsigned char *message, unsigned int len, unsigned char *diges
|
|
|
273035
273056
|
sha256_final(&ctx, digest);
|
|
273036
273057
|
}
|
|
273037
273058
|
|
|
273059
|
+
SQLITE_PRIVATE
|
|
273038
273060
|
void sha256_init(sha256_ctx *ctx)
|
|
273039
273061
|
{
|
|
273040
273062
|
#ifndef UNROLL_LOOPS
|
|
@@ -273053,6 +273075,7 @@ void sha256_init(sha256_ctx *ctx)
|
|
|
273053
273075
|
ctx->tot_len = 0;
|
|
273054
273076
|
}
|
|
273055
273077
|
|
|
273078
|
+
SQLITE_PRIVATE
|
|
273056
273079
|
void sha256_update(sha256_ctx *ctx, const unsigned char *message,
|
|
273057
273080
|
unsigned int len)
|
|
273058
273081
|
{
|
|
@@ -273087,6 +273110,7 @@ void sha256_update(sha256_ctx *ctx, const unsigned char *message,
|
|
|
273087
273110
|
ctx->tot_len += (block_nb + 1) << 6;
|
|
273088
273111
|
}
|
|
273089
273112
|
|
|
273113
|
+
SQLITE_PRIVATE
|
|
273090
273114
|
void sha256_final(sha256_ctx *ctx, unsigned char *digest)
|
|
273091
273115
|
{
|
|
273092
273116
|
unsigned int block_nb;
|
|
@@ -273223,11 +273247,13 @@ void sha512_transf(sha512_ctx *ctx, const unsigned char *message,
|
|
|
273223
273247
|
}
|
|
273224
273248
|
}
|
|
273225
273249
|
|
|
273250
|
+
SQLITE_PRIVATE
|
|
273226
273251
|
void sha512_transform(sha512_ctx *ctx, const unsigned char *message)
|
|
273227
273252
|
{
|
|
273228
273253
|
sha512_transf(ctx, message, 1);
|
|
273229
273254
|
}
|
|
273230
273255
|
|
|
273256
|
+
SQLITE_PRIVATE
|
|
273231
273257
|
void sha512(const unsigned char *message, unsigned int len,
|
|
273232
273258
|
unsigned char *digest)
|
|
273233
273259
|
{
|
|
@@ -273238,6 +273264,7 @@ void sha512(const unsigned char *message, unsigned int len,
|
|
|
273238
273264
|
sha512_final(&ctx, digest);
|
|
273239
273265
|
}
|
|
273240
273266
|
|
|
273267
|
+
SQLITE_PRIVATE
|
|
273241
273268
|
void sha512_init(sha512_ctx *ctx)
|
|
273242
273269
|
{
|
|
273243
273270
|
#ifndef UNROLL_LOOPS
|
|
@@ -273256,6 +273283,7 @@ void sha512_init(sha512_ctx *ctx)
|
|
|
273256
273283
|
ctx->tot_len = 0;
|
|
273257
273284
|
}
|
|
273258
273285
|
|
|
273286
|
+
SQLITE_PRIVATE
|
|
273259
273287
|
void sha512_update(sha512_ctx *ctx, const unsigned char *message,
|
|
273260
273288
|
unsigned int len)
|
|
273261
273289
|
{
|
|
@@ -273290,6 +273318,7 @@ void sha512_update(sha512_ctx *ctx, const unsigned char *message,
|
|
|
273290
273318
|
ctx->tot_len += (block_nb + 1) << 7;
|
|
273291
273319
|
}
|
|
273292
273320
|
|
|
273321
|
+
SQLITE_PRIVATE
|
|
273293
273322
|
void sha512_final(sha512_ctx *ctx, unsigned char *digest)
|
|
273294
273323
|
{
|
|
273295
273324
|
unsigned int block_nb;
|
|
@@ -273330,6 +273359,7 @@ void sha512_final(sha512_ctx *ctx, unsigned char *digest)
|
|
|
273330
273359
|
|
|
273331
273360
|
/* SHA-384 functions */
|
|
273332
273361
|
|
|
273362
|
+
SQLITE_PRIVATE
|
|
273333
273363
|
void sha384(const unsigned char *message, unsigned int len,
|
|
273334
273364
|
unsigned char *digest)
|
|
273335
273365
|
{
|
|
@@ -273340,6 +273370,7 @@ void sha384(const unsigned char *message, unsigned int len,
|
|
|
273340
273370
|
sha384_final(&ctx, digest);
|
|
273341
273371
|
}
|
|
273342
273372
|
|
|
273373
|
+
SQLITE_PRIVATE
|
|
273343
273374
|
void sha384_init(sha384_ctx *ctx)
|
|
273344
273375
|
{
|
|
273345
273376
|
#ifndef UNROLL_LOOPS
|
|
@@ -273358,6 +273389,7 @@ void sha384_init(sha384_ctx *ctx)
|
|
|
273358
273389
|
ctx->tot_len = 0;
|
|
273359
273390
|
}
|
|
273360
273391
|
|
|
273392
|
+
SQLITE_PRIVATE
|
|
273361
273393
|
void sha384_update(sha384_ctx *ctx, const unsigned char *message,
|
|
273362
273394
|
unsigned int len)
|
|
273363
273395
|
{
|
|
@@ -273392,6 +273424,7 @@ void sha384_update(sha384_ctx *ctx, const unsigned char *message,
|
|
|
273392
273424
|
ctx->tot_len += (block_nb + 1) << 7;
|
|
273393
273425
|
}
|
|
273394
273426
|
|
|
273427
|
+
SQLITE_PRIVATE
|
|
273395
273428
|
void sha384_final(sha384_ctx *ctx, unsigned char *digest)
|
|
273396
273429
|
{
|
|
273397
273430
|
unsigned int block_nb;
|
|
@@ -273430,6 +273463,7 @@ void sha384_final(sha384_ctx *ctx, unsigned char *digest)
|
|
|
273430
273463
|
|
|
273431
273464
|
/* SHA-224 functions */
|
|
273432
273465
|
|
|
273466
|
+
SQLITE_PRIVATE
|
|
273433
273467
|
void sha224(const unsigned char *message, unsigned int len,
|
|
273434
273468
|
unsigned char *digest)
|
|
273435
273469
|
{
|
|
@@ -273440,6 +273474,7 @@ void sha224(const unsigned char *message, unsigned int len,
|
|
|
273440
273474
|
sha224_final(&ctx, digest);
|
|
273441
273475
|
}
|
|
273442
273476
|
|
|
273477
|
+
SQLITE_PRIVATE
|
|
273443
273478
|
void sha224_init(sha224_ctx *ctx)
|
|
273444
273479
|
{
|
|
273445
273480
|
#ifndef UNROLL_LOOPS
|
|
@@ -273458,6 +273493,7 @@ void sha224_init(sha224_ctx *ctx)
|
|
|
273458
273493
|
ctx->tot_len = 0;
|
|
273459
273494
|
}
|
|
273460
273495
|
|
|
273496
|
+
SQLITE_PRIVATE
|
|
273461
273497
|
void sha224_update(sha224_ctx *ctx, const unsigned char *message,
|
|
273462
273498
|
unsigned int len)
|
|
273463
273499
|
{
|
|
@@ -273492,6 +273528,7 @@ void sha224_update(sha224_ctx *ctx, const unsigned char *message,
|
|
|
273492
273528
|
ctx->tot_len += (block_nb + 1) << 6;
|
|
273493
273529
|
}
|
|
273494
273530
|
|
|
273531
|
+
SQLITE_PRIVATE
|
|
273495
273532
|
void sha224_final(sha224_ctx *ctx, unsigned char *digest)
|
|
273496
273533
|
{
|
|
273497
273534
|
unsigned int block_nb;
|
|
@@ -273655,7 +273692,6 @@ int main()
|
|
|
273655
273692
|
}
|
|
273656
273693
|
|
|
273657
273694
|
#endif /* TEST_VECTORS */
|
|
273658
|
-
|
|
273659
273695
|
/*** End of #include "sha2.c" ***/
|
|
273660
273696
|
|
|
273661
273697
|
|
|
@@ -273695,6 +273731,10 @@ int main()
|
|
|
273695
273731
|
#ifndef FASTPBKDF2_H
|
|
273696
273732
|
#define FASTPBKDF2_H
|
|
273697
273733
|
|
|
273734
|
+
#ifndef SQLITE_PRIVATE
|
|
273735
|
+
#define SQLITE_PRIVATE
|
|
273736
|
+
#endif
|
|
273737
|
+
|
|
273698
273738
|
#include <stdlib.h>
|
|
273699
273739
|
/* #include "mystdint.h" */
|
|
273700
273740
|
|
|
@@ -273712,6 +273752,7 @@ extern "C" {
|
|
|
273712
273752
|
*
|
|
273713
273753
|
* This function cannot fail; it does not report errors.
|
|
273714
273754
|
*/
|
|
273755
|
+
SQLITE_PRIVATE
|
|
273715
273756
|
void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw,
|
|
273716
273757
|
const uint8_t *salt, size_t nsalt,
|
|
273717
273758
|
uint32_t iterations,
|
|
@@ -273726,6 +273767,7 @@ void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw,
|
|
|
273726
273767
|
*
|
|
273727
273768
|
* This function cannot fail; it does not report errors.
|
|
273728
273769
|
*/
|
|
273770
|
+
SQLITE_PRIVATE
|
|
273729
273771
|
void fastpbkdf2_hmac_sha256(const uint8_t *pw, size_t npw,
|
|
273730
273772
|
const uint8_t *salt, size_t nsalt,
|
|
273731
273773
|
uint32_t iterations,
|
|
@@ -273740,6 +273782,7 @@ void fastpbkdf2_hmac_sha256(const uint8_t *pw, size_t npw,
|
|
|
273740
273782
|
*
|
|
273741
273783
|
* This function cannot fail; it does not report errors.
|
|
273742
273784
|
*/
|
|
273785
|
+
SQLITE_PRIVATE
|
|
273743
273786
|
void fastpbkdf2_hmac_sha512(const uint8_t *pw, size_t npw,
|
|
273744
273787
|
const uint8_t *salt, size_t nsalt,
|
|
273745
273788
|
uint32_t iterations,
|
|
@@ -273749,6 +273792,7 @@ void fastpbkdf2_hmac_sha512(const uint8_t *pw, size_t npw,
|
|
|
273749
273792
|
*
|
|
273750
273793
|
* This function cannot fail; it does not report errors.
|
|
273751
273794
|
*/
|
|
273795
|
+
SQLITE_PRIVATE
|
|
273752
273796
|
void sqlcipher_hmac(int algorithm,
|
|
273753
273797
|
unsigned char* key, int nkey,
|
|
273754
273798
|
unsigned char* in, int in_sz,
|
|
@@ -274142,6 +274186,7 @@ DECL_PBKDF2(sha512,
|
|
|
274142
274186
|
sha512_extract,
|
|
274143
274187
|
sha512_xor)
|
|
274144
274188
|
|
|
274189
|
+
SQLITE_PRIVATE
|
|
274145
274190
|
void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw,
|
|
274146
274191
|
const uint8_t *salt, size_t nsalt,
|
|
274147
274192
|
uint32_t iterations,
|
|
@@ -274153,6 +274198,7 @@ void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw,
|
|
|
274153
274198
|
#endif
|
|
274154
274199
|
}
|
|
274155
274200
|
|
|
274201
|
+
SQLITE_PRIVATE
|
|
274156
274202
|
void fastpbkdf2_hmac_sha256(const uint8_t *pw, size_t npw,
|
|
274157
274203
|
const uint8_t *salt, size_t nsalt,
|
|
274158
274204
|
uint32_t iterations,
|
|
@@ -274161,6 +274207,7 @@ void fastpbkdf2_hmac_sha256(const uint8_t *pw, size_t npw,
|
|
|
274161
274207
|
PBKDF2(sha256)(pw, npw, salt, nsalt, iterations, out, nout);
|
|
274162
274208
|
}
|
|
274163
274209
|
|
|
274210
|
+
SQLITE_PRIVATE
|
|
274164
274211
|
void fastpbkdf2_hmac_sha512(const uint8_t *pw, size_t npw,
|
|
274165
274212
|
const uint8_t *salt, size_t nsalt,
|
|
274166
274213
|
uint32_t iterations,
|
|
@@ -274169,6 +274216,7 @@ void fastpbkdf2_hmac_sha512(const uint8_t *pw, size_t npw,
|
|
|
274169
274216
|
PBKDF2(sha512)(pw, npw, salt, nsalt, iterations, out, nout);
|
|
274170
274217
|
}
|
|
274171
274218
|
|
|
274219
|
+
SQLITE_PRIVATE
|
|
274172
274220
|
void sqlcipher_hmac(int algorithm, unsigned char* key, int nkey, unsigned char* in, int in_sz, unsigned char* in2, int in2_sz, unsigned char* out)
|
|
274173
274221
|
{
|
|
274174
274222
|
switch (algorithm)
|
|
@@ -274218,10 +274266,10 @@ void sqlcipher_hmac(int algorithm, unsigned char* key, int nkey, unsigned char*
|
|
|
274218
274266
|
|
|
274219
274267
|
|
|
274220
274268
|
/* Prototypes for several crypto functions to make pedantic compilers happy */
|
|
274221
|
-
void chacha20_xor(void* data, size_t n, const uint8_t key[32], const uint8_t nonce[12], uint32_t counter);
|
|
274222
|
-
void poly1305(const uint8_t* msg, size_t n, const uint8_t key[32], uint8_t tag[16]);
|
|
274223
|
-
int poly1305_tagcmp(const uint8_t tag1[16], const uint8_t tag2[16]);
|
|
274224
|
-
void chacha20_rng(void* out, size_t n);
|
|
274269
|
+
SQLITE_PRIVATE void chacha20_xor(void* data, size_t n, const uint8_t key[32], const uint8_t nonce[12], uint32_t counter);
|
|
274270
|
+
SQLITE_PRIVATE void poly1305(const uint8_t* msg, size_t n, const uint8_t key[32], uint8_t tag[16]);
|
|
274271
|
+
SQLITE_PRIVATE int poly1305_tagcmp(const uint8_t tag1[16], const uint8_t tag2[16]);
|
|
274272
|
+
SQLITE_PRIVATE void chacha20_rng(void* out, size_t n);
|
|
274225
274273
|
|
|
274226
274274
|
/* #include "chacha20poly1305.c" */
|
|
274227
274275
|
/*** Begin of #include "chacha20poly1305.c" ***/
|
|
@@ -274302,6 +274350,7 @@ static void chacha20_block(uint32_t x[16])
|
|
|
274302
274350
|
#undef CC20QR
|
|
274303
274351
|
}
|
|
274304
274352
|
|
|
274353
|
+
SQLITE_PRIVATE
|
|
274305
274354
|
void chacha20_xor(void* buffer, size_t n, const uint8_t key[32],
|
|
274306
274355
|
const uint8_t nonce[12], uint32_t counter)
|
|
274307
274356
|
{
|
|
@@ -274369,6 +274418,7 @@ void chacha20_xor(void* buffer, size_t n, const uint8_t key[32],
|
|
|
274369
274418
|
/*
|
|
274370
274419
|
* Poly1305 authentication tags
|
|
274371
274420
|
*/
|
|
274421
|
+
SQLITE_PRIVATE
|
|
274372
274422
|
void poly1305(const uint8_t* msg, size_t n, const uint8_t key[32],
|
|
274373
274423
|
uint8_t tag[16])
|
|
274374
274424
|
{
|
|
@@ -274438,6 +274488,7 @@ process_block:
|
|
|
274438
274488
|
s4 = d4; STORE32_LE(tag + 12, s4);
|
|
274439
274489
|
}
|
|
274440
274490
|
|
|
274491
|
+
SQLITE_PRIVATE
|
|
274441
274492
|
int poly1305_tagcmp(const uint8_t tag1[16], const uint8_t tag2[16])
|
|
274442
274493
|
{
|
|
274443
274494
|
uint8_t d = 0;
|
|
@@ -274514,7 +274565,7 @@ static size_t entropy(void* buf, size_t n)
|
|
|
274514
274565
|
}
|
|
274515
274566
|
|
|
274516
274567
|
#else
|
|
274517
|
-
|
|
274568
|
+
|
|
274518
274569
|
#include <windows.h>
|
|
274519
274570
|
#define RtlGenRandom SystemFunction036
|
|
274520
274571
|
BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
|
|
@@ -274633,6 +274684,7 @@ static size_t entropy(void* buf, size_t n)
|
|
|
274633
274684
|
/*
|
|
274634
274685
|
* ChaCha20 random number generator
|
|
274635
274686
|
*/
|
|
274687
|
+
SQLITE_PRIVATE
|
|
274636
274688
|
void chacha20_rng(void* out, size_t n)
|
|
274637
274689
|
{
|
|
274638
274690
|
static uint8_t key[32], nonce[12], buffer[64] = { 0 };
|
|
@@ -274926,7 +274978,7 @@ SQLITE_API int sqlite3_user_add(
|
|
|
274926
274978
|
if( db->auth.authLevel<UAUTH_Admin ) return SQLITE_AUTH;
|
|
274927
274979
|
if( !userTableExists(db, "main") ){
|
|
274928
274980
|
if( !isAdmin ) return SQLITE_AUTH;
|
|
274929
|
-
pStmt = sqlite3UserAuthPrepare(db,
|
|
274981
|
+
pStmt = sqlite3UserAuthPrepare(db,
|
|
274930
274982
|
"CREATE TABLE sqlite_user(\n"
|
|
274931
274983
|
" uname TEXT PRIMARY KEY,\n"
|
|
274932
274984
|
" isAdmin BOOLEAN,\n"
|
|
@@ -274937,7 +274989,7 @@ SQLITE_API int sqlite3_user_add(
|
|
|
274937
274989
|
rc = sqlite3_finalize(pStmt);
|
|
274938
274990
|
if( rc ) return rc;
|
|
274939
274991
|
}
|
|
274940
|
-
pStmt = sqlite3UserAuthPrepare(db,
|
|
274992
|
+
pStmt = sqlite3UserAuthPrepare(db,
|
|
274941
274993
|
"INSERT INTO sqlite_user(uname,isAdmin,pw)"
|
|
274942
274994
|
" VALUES(%Q,%d,sqlite_crypt(?1,NULL))",
|
|
274943
274995
|
zUsername, isAdmin!=0);
|
|
@@ -274957,7 +275009,7 @@ SQLITE_API int sqlite3_user_add(
|
|
|
274957
275009
|
** The sqlite3_user_change() interface can be used to change a users
|
|
274958
275010
|
** login credentials or admin privilege. Any user can change their own
|
|
274959
275011
|
** login credentials. Only an admin user can change another users login
|
|
274960
|
-
** credentials or admin privilege setting. No user may change their own
|
|
275012
|
+
** credentials or admin privilege setting. No user may change their own
|
|
274961
275013
|
** admin privilege setting.
|
|
274962
275014
|
*/
|
|
274963
275015
|
SQLITE_API int sqlite3_user_change(
|
|
@@ -275121,6 +275173,10 @@ mcRegisterCodecExtensions(sqlite3* db, char** pzErrMsg, const sqlite3_api_routin
|
|
|
275121
275173
|
#ifndef _RIJNDAEL_H_
|
|
275122
275174
|
#define _RIJNDAEL_H_
|
|
275123
275175
|
|
|
275176
|
+
#ifndef SQLITE_PRIVATE
|
|
275177
|
+
#define SQLITE_PRIVATE
|
|
275178
|
+
#endif
|
|
275179
|
+
|
|
275124
275180
|
/*
|
|
275125
275181
|
// File : rijndael.h
|
|
275126
275182
|
// Creation date : Sun Nov 5 2000 03:21:05 CEST
|
|
@@ -275219,16 +275275,16 @@ typedef unsigned short UINT16;
|
|
|
275219
275275
|
*/
|
|
275220
275276
|
|
|
275221
275277
|
typedef struct _Rijndael
|
|
275222
|
-
{
|
|
275223
|
-
|
|
275224
|
-
|
|
275225
|
-
|
|
275226
|
-
|
|
275227
|
-
|
|
275228
|
-
|
|
275278
|
+
{
|
|
275279
|
+
int m_state;
|
|
275280
|
+
int m_mode;
|
|
275281
|
+
int m_direction;
|
|
275282
|
+
UINT8 m_initVector[MAX_IV_SIZE];
|
|
275283
|
+
UINT32 m_uRounds;
|
|
275284
|
+
UINT8 m_expandedKey[_MAX_ROUNDS+1][4][4];
|
|
275229
275285
|
} Rijndael;
|
|
275230
275286
|
|
|
275231
|
-
void RijndaelCreate(Rijndael* rijndael);
|
|
275287
|
+
SQLITE_PRIVATE void RijndaelCreate(Rijndael* rijndael);
|
|
275232
275288
|
|
|
275233
275289
|
/*
|
|
275234
275290
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
@@ -275250,7 +275306,7 @@ void RijndaelCreate(Rijndael* rijndael);
|
|
|
275250
275306
|
// keyLen : Rijndael::Key16Bytes , Rijndael::Key24Bytes or Rijndael::Key32Bytes
|
|
275251
275307
|
// initVector: initialization vector, you will usually use 0 here
|
|
275252
275308
|
*/
|
|
275253
|
-
int RijndaelInit(Rijndael* rijndael, int mode, int dir, UINT8* key, int keyLen, UINT8* initVector);
|
|
275309
|
+
SQLITE_PRIVATE int RijndaelInit(Rijndael* rijndael, int mode, int dir, UINT8* key, int keyLen, UINT8* initVector);
|
|
275254
275310
|
|
|
275255
275311
|
/*
|
|
275256
275312
|
// Encrypts the input array (can be binary data)
|
|
@@ -275261,7 +275317,7 @@ int RijndaelInit(Rijndael* rijndael, int mode, int dir, UINT8* key, int keyLen,
|
|
|
275261
275317
|
// outBuffer must be at least inputLen / 8 bytes long.
|
|
275262
275318
|
// Returns the encrypted buffer length in BITS or an error code < 0 in case of error
|
|
275263
275319
|
*/
|
|
275264
|
-
int RijndaelBlockEncrypt(Rijndael* rijndael, UINT8 *input, int inputLen, UINT8 *outBuffer);
|
|
275320
|
+
SQLITE_PRIVATE int RijndaelBlockEncrypt(Rijndael* rijndael, UINT8 *input, int inputLen, UINT8 *outBuffer);
|
|
275265
275321
|
|
|
275266
275322
|
/*
|
|
275267
275323
|
// Encrypts the input array (can be binary data)
|
|
@@ -275270,7 +275326,7 @@ int RijndaelBlockEncrypt(Rijndael* rijndael, UINT8 *input, int inputLen, UINT8 *
|
|
|
275270
275326
|
// outBuffer must be at least (inputLen + 16) bytes long
|
|
275271
275327
|
// Returns the encrypted buffer length in BYTES or an error code < 0 in case of error
|
|
275272
275328
|
*/
|
|
275273
|
-
int RijndaelPadEncrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8 *outBuffer);
|
|
275329
|
+
SQLITE_PRIVATE int RijndaelPadEncrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8 *outBuffer);
|
|
275274
275330
|
|
|
275275
275331
|
/*
|
|
275276
275332
|
// Decrypts the input vector
|
|
@@ -275278,7 +275334,7 @@ int RijndaelPadEncrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8
|
|
|
275278
275334
|
// outBuffer must be at least inputLen / 8 bytes long
|
|
275279
275335
|
// Returns the decrypted buffer length in BITS and an error code < 0 in case of error
|
|
275280
275336
|
*/
|
|
275281
|
-
int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8 *input, int inputLen, UINT8 *outBuffer);
|
|
275337
|
+
SQLITE_PRIVATE int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8 *input, int inputLen, UINT8 *outBuffer);
|
|
275282
275338
|
|
|
275283
275339
|
/*
|
|
275284
275340
|
// Decrypts the input vector
|
|
@@ -275286,14 +275342,14 @@ int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8 *input, int inputLen, UINT8 *
|
|
|
275286
275342
|
// outBuffer must be at least inputLen bytes long
|
|
275287
275343
|
// Returns the decrypted buffer length in BYTES and an error code < 0 in case of error
|
|
275288
275344
|
*/
|
|
275289
|
-
int RijndaelPadDecrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8 *outBuffer);
|
|
275345
|
+
SQLITE_PRIVATE int RijndaelPadDecrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8 *outBuffer);
|
|
275346
|
+
|
|
275347
|
+
SQLITE_PRIVATE void RijndaelInvalidate(Rijndael* rijndael);
|
|
275348
|
+
SQLITE_PRIVATE void RijndaelKeySched(Rijndael* rijndael, UINT8 key[_MAX_KEY_COLUMNS][4]);
|
|
275349
|
+
SQLITE_PRIVATE void RijndaelKeyEncToDec(Rijndael* rijndael);
|
|
275350
|
+
SQLITE_PRIVATE void RijndaelEncrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16]);
|
|
275351
|
+
SQLITE_PRIVATE void RijndaelDecrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16]);
|
|
275290
275352
|
|
|
275291
|
-
void RijndaelInvalidate(Rijndael* rijndael);
|
|
275292
|
-
void RijndaelKeySched(Rijndael* rijndael, UINT8 key[_MAX_KEY_COLUMNS][4]);
|
|
275293
|
-
void RijndaelKeyEncToDec(Rijndael* rijndael);
|
|
275294
|
-
void RijndaelEncrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16]);
|
|
275295
|
-
void RijndaelDecrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16]);
|
|
275296
|
-
|
|
275297
275353
|
#endif /* _RIJNDAEL_H_ */
|
|
275298
275354
|
/*** End of #include "rijndael.h" ***/
|
|
275299
275355
|
|
|
@@ -275535,7 +275591,7 @@ aesGenKeyEncrypt(const unsigned char* userKey, const int bits, unsigned char* ke
|
|
|
275535
275591
|
{
|
|
275536
275592
|
int numberOfRounds = (bits == 128) ? 10 : (bits == 192) ? 12 : (bits == 256) ? 14 : 0;
|
|
275537
275593
|
int rc = (!userKey || !keyData) ? -1 : (numberOfRounds > 0) ? 0 : -2;
|
|
275538
|
-
|
|
275594
|
+
|
|
275539
275595
|
if (rc == 0)
|
|
275540
275596
|
{
|
|
275541
275597
|
__m128i tempKey[_MAX_ROUNDS + 1];
|
|
@@ -275684,7 +275740,7 @@ aesDecryptCBC(const unsigned char* in,
|
|
|
275684
275740
|
int offset;
|
|
275685
275741
|
--numBlocks;
|
|
275686
275742
|
offset = numBlocks * 16;
|
|
275687
|
-
|
|
275743
|
+
|
|
275688
275744
|
/* Decrypt the last plain block. */
|
|
275689
275745
|
last_in = _mm_loadu_si128(&((__m128i*) in)[numBlocks]);
|
|
275690
275746
|
data = _mm_xor_si128(last_in, key[numberOfRounds - 0]);
|
|
@@ -275814,7 +275870,7 @@ aesGenKeyEncryptInternal(const unsigned char* userKey, const int bits, uint8x16_
|
|
|
275814
275870
|
int i;
|
|
275815
275871
|
int j;
|
|
275816
275872
|
int numberOfRounds = (bits == 128) ? 10 : (bits == 192) ? 12 : (bits == 256) ? 14 : 0;
|
|
275817
|
-
int keyWords = bits / 32;
|
|
275873
|
+
int keyWords = bits / 32;
|
|
275818
275874
|
int schedWords = (numberOfRounds + 1) * 4;
|
|
275819
275875
|
|
|
275820
275876
|
/*
|
|
@@ -275875,7 +275931,7 @@ aesGenKeyEncrypt(const unsigned char* userKey, const int bits, unsigned char* ke
|
|
|
275875
275931
|
{
|
|
275876
275932
|
int numberOfRounds = (bits == 128) ? 10 : (bits == 192) ? 12 : (bits == 256) ? 14 : 0;
|
|
275877
275933
|
int rc = (!userKey || !keyData) ? -1 : (numberOfRounds > 0) ? 0 : -2;
|
|
275878
|
-
|
|
275934
|
+
|
|
275879
275935
|
if (rc == 0)
|
|
275880
275936
|
{
|
|
275881
275937
|
uint8x16_t tempKey[_MAX_ROUNDS + 1];
|
|
@@ -275985,7 +276041,7 @@ aesEncryptCBC(const unsigned char* in,
|
|
|
275985
276041
|
}
|
|
275986
276042
|
feedback = vaeseq_u8(feedback, key[numberOfRounds-1]);
|
|
275987
276043
|
feedback = veorq_u8(feedback, key[numberOfRounds]); \
|
|
275988
|
-
|
|
276044
|
+
|
|
275989
276045
|
vst1q_u8(&out[(numBlocks-1)*16], feedback);
|
|
275990
276046
|
|
|
275991
276047
|
memcpy(&out[numBlocks*16], lastblock, lenFrag);
|
|
@@ -276026,7 +276082,7 @@ aesDecryptCBC(const unsigned char* in,
|
|
|
276026
276082
|
int offset;
|
|
276027
276083
|
--numBlocks;
|
|
276028
276084
|
offset = numBlocks * 16;
|
|
276029
|
-
|
|
276085
|
+
|
|
276030
276086
|
/* Decrypt the last plain block. */
|
|
276031
276087
|
last_in = vld1q_u8(&in[numBlocks*16]);
|
|
276032
276088
|
|
|
@@ -276122,21 +276178,21 @@ aesHardwareAvailable()
|
|
|
276122
276178
|
|
|
276123
276179
|
static UINT8 S[256]=
|
|
276124
276180
|
{
|
|
276125
|
-
99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118,
|
|
276126
|
-
202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192,
|
|
276127
|
-
183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21,
|
|
276128
|
-
4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117,
|
|
276129
|
-
9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132,
|
|
276130
|
-
83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207,
|
|
276131
|
-
208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168,
|
|
276132
|
-
81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210,
|
|
276133
|
-
205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115,
|
|
276134
|
-
96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219,
|
|
276135
|
-
224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121,
|
|
276136
|
-
231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8,
|
|
276137
|
-
186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138,
|
|
276138
|
-
112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158,
|
|
276139
|
-
225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223,
|
|
276181
|
+
99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118,
|
|
276182
|
+
202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192,
|
|
276183
|
+
183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21,
|
|
276184
|
+
4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117,
|
|
276185
|
+
9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132,
|
|
276186
|
+
83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207,
|
|
276187
|
+
208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168,
|
|
276188
|
+
81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210,
|
|
276189
|
+
205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115,
|
|
276190
|
+
96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219,
|
|
276191
|
+
224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121,
|
|
276192
|
+
231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8,
|
|
276193
|
+
186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138,
|
|
276194
|
+
112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158,
|
|
276195
|
+
225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223,
|
|
276140
276196
|
140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22
|
|
276141
276197
|
};
|
|
276142
276198
|
|
|
@@ -276207,7 +276263,7 @@ static UINT8 T1[256][4]=
|
|
|
276207
276263
|
{0x82,0x41,0x41,0xc3}, {0x29,0x99,0x99,0xb0}, {0x5a,0x2d,0x2d,0x77}, {0x1e,0x0f,0x0f,0x11},
|
|
276208
276264
|
{0x7b,0xb0,0xb0,0xcb}, {0xa8,0x54,0x54,0xfc}, {0x6d,0xbb,0xbb,0xd6}, {0x2c,0x16,0x16,0x3a}
|
|
276209
276265
|
};
|
|
276210
|
-
|
|
276266
|
+
|
|
276211
276267
|
static UINT8 T2[256][4]=
|
|
276212
276268
|
{
|
|
276213
276269
|
{0xa5,0xc6,0x63,0x63}, {0x84,0xf8,0x7c,0x7c}, {0x99,0xee,0x77,0x77}, {0x8d,0xf6,0x7b,0x7b},
|
|
@@ -276819,7 +276875,7 @@ static UINT8 U1[256][4]=
|
|
|
276819
276875
|
{0xa7,0x79,0xb4,0x92}, {0xa9,0x70,0xb9,0x99}, {0xbb,0x6b,0xae,0x84}, {0xb5,0x62,0xa3,0x8f},
|
|
276820
276876
|
{0x9f,0x5d,0x80,0xbe}, {0x91,0x54,0x8d,0xb5}, {0x83,0x4f,0x9a,0xa8}, {0x8d,0x46,0x97,0xa3}
|
|
276821
276877
|
};
|
|
276822
|
-
|
|
276878
|
+
|
|
276823
276879
|
static UINT8 U2[256][4]=
|
|
276824
276880
|
{
|
|
276825
276881
|
{0x00,0x00,0x00,0x00}, {0x0b,0x0e,0x09,0x0d}, {0x16,0x1c,0x12,0x1a}, {0x1d,0x12,0x1b,0x17},
|
|
@@ -277025,7 +277081,7 @@ static UINT8 U4[256][4]=
|
|
|
277025
277081
|
};
|
|
277026
277082
|
|
|
277027
277083
|
static UINT32 rcon[30]=
|
|
277028
|
-
{
|
|
277084
|
+
{
|
|
277029
277085
|
0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
|
|
277030
277086
|
0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8,
|
|
277031
277087
|
0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc,
|
|
@@ -277039,11 +277095,13 @@ static UINT32 rcon[30]=
|
|
|
277039
277095
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
277040
277096
|
*/
|
|
277041
277097
|
|
|
277098
|
+
SQLITE_PRIVATE
|
|
277042
277099
|
void RijndaelCreate(Rijndael* rijndael)
|
|
277043
277100
|
{
|
|
277044
277101
|
rijndael->m_state = RIJNDAEL_State_Invalid;
|
|
277045
277102
|
}
|
|
277046
277103
|
|
|
277104
|
+
SQLITE_PRIVATE
|
|
277047
277105
|
int RijndaelInit(Rijndael* rijndael, int mode, int dir, UINT8* key, int keyLen, UINT8* initVector)
|
|
277048
277106
|
{
|
|
277049
277107
|
UINT32 uKeyLenInBytes;
|
|
@@ -277128,7 +277186,7 @@ int RijndaelInit(Rijndael* rijndael, int mode, int dir, UINT8* key, int keyLen,
|
|
|
277128
277186
|
#endif
|
|
277129
277187
|
}
|
|
277130
277188
|
}
|
|
277131
|
-
#ifndef TEST_AES_HW
|
|
277189
|
+
#ifndef TEST_AES_HW
|
|
277132
277190
|
else
|
|
277133
277191
|
#endif
|
|
277134
277192
|
#endif
|
|
@@ -277140,7 +277198,7 @@ int RijndaelInit(Rijndael* rijndael, int mode, int dir, UINT8* key, int keyLen,
|
|
|
277140
277198
|
if (rijndael->m_direction == RIJNDAEL_Direction_Decrypt) RijndaelKeyEncToDec(rijndael);
|
|
277141
277199
|
}
|
|
277142
277200
|
|
|
277143
|
-
#ifdef TEST_AES_HW
|
|
277201
|
+
#ifdef TEST_AES_HW
|
|
277144
277202
|
{
|
|
277145
277203
|
int cmpkeyexp = memcmp((unsigned char*) rijndael->m_expandedKey, aesKeySched, (rijndael->m_uRounds+1)*16);
|
|
277146
277204
|
int datalen = (rijndael->m_uRounds + 1) * 16;
|
|
@@ -277170,10 +277228,10 @@ int RijndaelBlockEncrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277170
277228
|
|
|
277171
277229
|
numBlocks = inputLen/128;
|
|
277172
277230
|
lenFrag = (inputLen % 128) / 8;
|
|
277173
|
-
|
|
277231
|
+
|
|
277174
277232
|
switch (rijndael->m_mode)
|
|
277175
277233
|
{
|
|
277176
|
-
case RIJNDAEL_Direction_Mode_ECB:
|
|
277234
|
+
case RIJNDAEL_Direction_Mode_ECB:
|
|
277177
277235
|
for(i = numBlocks;i > 0;i--)
|
|
277178
277236
|
{
|
|
277179
277237
|
RijndaelEncrypt(rijndael, input, outBuffer);
|
|
@@ -277185,7 +277243,7 @@ int RijndaelBlockEncrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277185
277243
|
#if HAS_AES_HARDWARE
|
|
277186
277244
|
if (aesHardwareAvailable())
|
|
277187
277245
|
{
|
|
277188
|
-
#ifndef TEST_AES_HW
|
|
277246
|
+
#ifndef TEST_AES_HW
|
|
277189
277247
|
aesEncryptCBC(input, outBuffer, rijndael->m_initVector, inputLen/8, (unsigned char*) (rijndael->m_expandedKey), rijndael->m_uRounds);
|
|
277190
277248
|
#else
|
|
277191
277249
|
TEST_AES_HW_DEBUG_LOG("aes enc: hw enabled\n");
|
|
@@ -277231,8 +277289,8 @@ int RijndaelBlockEncrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277231
277289
|
}
|
|
277232
277290
|
break;
|
|
277233
277291
|
case RIJNDAEL_Direction_Mode_CFB1:
|
|
277234
|
-
#if STRICT_ALIGN
|
|
277235
|
-
memcpy(iv,rijndael->m_initVector,16);
|
|
277292
|
+
#if STRICT_ALIGN
|
|
277293
|
+
memcpy(iv,rijndael->m_initVector,16);
|
|
277236
277294
|
#else /* !STRICT_ALIGN */
|
|
277237
277295
|
*((UINT32*)iv[0]) = *((UINT32*)(rijndael->m_initVector ));
|
|
277238
277296
|
*((UINT32*)iv[1]) = *((UINT32*)(rijndael->m_initVector + 4));
|
|
@@ -277276,7 +277334,7 @@ int RijndaelBlockEncrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277276
277334
|
break;
|
|
277277
277335
|
}
|
|
277278
277336
|
|
|
277279
|
-
#ifdef TEST_AES_HW
|
|
277337
|
+
#ifdef TEST_AES_HW
|
|
277280
277338
|
{
|
|
277281
277339
|
int cmpdata = memcmp((unsigned char*) outOrig, outBuffer2, inputLen/8);
|
|
277282
277340
|
TEST_AES_HW_DEBUG_LOG("aes enc: cmp=%d\n", cmpdata);
|
|
@@ -277284,10 +277342,11 @@ int RijndaelBlockEncrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277284
277342
|
TEST_AES_HW_DEBUG_HEX("aes enc HW:", outBuffer2, 16);
|
|
277285
277343
|
}
|
|
277286
277344
|
#endif
|
|
277287
|
-
|
|
277345
|
+
|
|
277288
277346
|
return 128 * numBlocks;
|
|
277289
277347
|
}
|
|
277290
277348
|
|
|
277349
|
+
SQLITE_PRIVATE
|
|
277291
277350
|
int RijndaelPadEncrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8 *outBuffer)
|
|
277292
277351
|
{
|
|
277293
277352
|
int i, numBlocks, padLen;
|
|
@@ -277302,7 +277361,7 @@ int RijndaelPadEncrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8
|
|
|
277302
277361
|
|
|
277303
277362
|
switch (rijndael->m_mode)
|
|
277304
277363
|
{
|
|
277305
|
-
case RIJNDAEL_Direction_Mode_ECB:
|
|
277364
|
+
case RIJNDAEL_Direction_Mode_ECB:
|
|
277306
277365
|
for(i = numBlocks; i > 0; i--)
|
|
277307
277366
|
{
|
|
277308
277367
|
RijndaelEncrypt(rijndael, input, outBuffer);
|
|
@@ -277342,10 +277401,11 @@ int RijndaelPadEncrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8
|
|
|
277342
277401
|
return -1;
|
|
277343
277402
|
break;
|
|
277344
277403
|
}
|
|
277345
|
-
|
|
277404
|
+
|
|
277346
277405
|
return 16*(numBlocks + 1);
|
|
277347
277406
|
}
|
|
277348
|
-
|
|
277407
|
+
|
|
277408
|
+
SQLITE_PRIVATE
|
|
277349
277409
|
int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8* outBuffer)
|
|
277350
277410
|
{
|
|
277351
277411
|
int i, k, numBlocks, lenFrag;
|
|
@@ -277365,7 +277425,7 @@ int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277365
277425
|
|
|
277366
277426
|
switch (rijndael->m_mode)
|
|
277367
277427
|
{
|
|
277368
|
-
case RIJNDAEL_Direction_Mode_ECB:
|
|
277428
|
+
case RIJNDAEL_Direction_Mode_ECB:
|
|
277369
277429
|
for (i = numBlocks; i > 0; i--)
|
|
277370
277430
|
{
|
|
277371
277431
|
RijndaelDecrypt(rijndael, input, outBuffer);
|
|
@@ -277420,8 +277480,8 @@ int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277420
277480
|
}
|
|
277421
277481
|
}
|
|
277422
277482
|
}
|
|
277423
|
-
#if STRICT_ALIGN
|
|
277424
|
-
memcpy(iv,rijndael->m_initVector,16);
|
|
277483
|
+
#if STRICT_ALIGN
|
|
277484
|
+
memcpy(iv,rijndael->m_initVector,16);
|
|
277425
277485
|
#else
|
|
277426
277486
|
*((UINT32*)iv[0]) = *((UINT32*)(rijndael->m_initVector ));
|
|
277427
277487
|
*((UINT32*)iv[1]) = *((UINT32*)(rijndael->m_initVector+ 4));
|
|
@@ -277450,8 +277510,8 @@ int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277450
277510
|
}
|
|
277451
277511
|
break;
|
|
277452
277512
|
case RIJNDAEL_Direction_Mode_CFB1:
|
|
277453
|
-
#if STRICT_ALIGN
|
|
277454
|
-
memcpy(iv, rijndael->m_initVector, 16);
|
|
277513
|
+
#if STRICT_ALIGN
|
|
277514
|
+
memcpy(iv, rijndael->m_initVector, 16);
|
|
277455
277515
|
#else
|
|
277456
277516
|
*((UINT32*)iv[0]) = *((UINT32*)(rijndael->m_initVector));
|
|
277457
277517
|
*((UINT32*)iv[1]) = *((UINT32*)(rijndael->m_initVector+ 4));
|
|
@@ -277495,7 +277555,7 @@ int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277495
277555
|
break;
|
|
277496
277556
|
}
|
|
277497
277557
|
|
|
277498
|
-
#ifdef TEST_AES_HW
|
|
277558
|
+
#ifdef TEST_AES_HW
|
|
277499
277559
|
{
|
|
277500
277560
|
int cmpdata = memcmp((unsigned char*) outOrig, outBuffer2, inputLen/8);
|
|
277501
277561
|
TEST_AES_HW_DEBUG_LOG("aes dec: cmp=%d\n", cmpdata);
|
|
@@ -277503,10 +277563,11 @@ int RijndaelBlockDecrypt(Rijndael* rijndael, UINT8* input, int inputLen, UINT8*
|
|
|
277503
277563
|
TEST_AES_HW_DEBUG_HEX("aes dec HW:", outBuffer2, 16);
|
|
277504
277564
|
}
|
|
277505
277565
|
#endif
|
|
277506
|
-
|
|
277566
|
+
|
|
277507
277567
|
return 128*numBlocks;
|
|
277508
277568
|
}
|
|
277509
277569
|
|
|
277570
|
+
SQLITE_PRIVATE
|
|
277510
277571
|
int RijndaelPadDecrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8 *outBuffer)
|
|
277511
277572
|
{
|
|
277512
277573
|
int i, numBlocks, padLen;
|
|
@@ -277540,7 +277601,7 @@ int RijndaelPadDecrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8
|
|
|
277540
277601
|
if (block[i] != padLen) return RIJNDAEL_CORRUPTED_DATA;
|
|
277541
277602
|
}
|
|
277542
277603
|
memcpy(outBuffer, block, 16 - padLen);
|
|
277543
|
-
break;
|
|
277604
|
+
break;
|
|
277544
277605
|
case RIJNDAEL_Direction_Mode_CBC:
|
|
277545
277606
|
memcpy(iv, rijndael->m_initVector, 16);
|
|
277546
277607
|
/* all blocks but last */
|
|
@@ -277570,12 +277631,12 @@ int RijndaelPadDecrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8
|
|
|
277570
277631
|
}
|
|
277571
277632
|
memcpy(outBuffer, block, 16 - padLen);
|
|
277572
277633
|
break;
|
|
277573
|
-
|
|
277634
|
+
|
|
277574
277635
|
default:
|
|
277575
277636
|
return -1;
|
|
277576
277637
|
break;
|
|
277577
277638
|
}
|
|
277578
|
-
|
|
277639
|
+
|
|
277579
277640
|
return 16*numBlocks - padLen;
|
|
277580
277641
|
}
|
|
277581
277642
|
|
|
@@ -277585,6 +277646,7 @@ int RijndaelPadDecrypt(Rijndael* rijndael, UINT8 *input, int inputOctets, UINT8
|
|
|
277585
277646
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
277586
277647
|
*/
|
|
277587
277648
|
|
|
277649
|
+
SQLITE_PRIVATE
|
|
277588
277650
|
void RijndaelKeySched(Rijndael* rijndael, UINT8 key[_MAX_KEY_COLUMNS][4])
|
|
277589
277651
|
{
|
|
277590
277652
|
int j,rconpointer = 0;
|
|
@@ -277621,7 +277683,7 @@ void RijndaelKeySched(Rijndael* rijndael, UINT8 key[_MAX_KEY_COLUMNS][4])
|
|
|
277621
277683
|
t = 0;
|
|
277622
277684
|
}
|
|
277623
277685
|
}
|
|
277624
|
-
|
|
277686
|
+
|
|
277625
277687
|
while(r <= rijndael->m_uRounds)
|
|
277626
277688
|
{
|
|
277627
277689
|
tempKey[0][0] ^= S[tempKey[uKeyColumns-1][1]];
|
|
@@ -277662,9 +277724,10 @@ void RijndaelKeySched(Rijndael* rijndael, UINT8 key[_MAX_KEY_COLUMNS][4])
|
|
|
277662
277724
|
t = 0;
|
|
277663
277725
|
}
|
|
277664
277726
|
}
|
|
277665
|
-
}
|
|
277727
|
+
}
|
|
277666
277728
|
}
|
|
277667
277729
|
|
|
277730
|
+
SQLITE_PRIVATE
|
|
277668
277731
|
void RijndaelKeyEncToDec(Rijndael* rijndael)
|
|
277669
277732
|
{
|
|
277670
277733
|
UINT32 r;
|
|
@@ -277681,8 +277744,9 @@ void RijndaelKeyEncToDec(Rijndael* rijndael)
|
|
|
277681
277744
|
w = rijndael->m_expandedKey[r][3];
|
|
277682
277745
|
*((UINT32*)w) = *((UINT32*)U1[w[0]]) ^ *((UINT32*)U2[w[1]]) ^ *((UINT32*)U3[w[2]]) ^ *((UINT32*)U4[w[3]]);
|
|
277683
277746
|
}
|
|
277684
|
-
}
|
|
277747
|
+
}
|
|
277685
277748
|
|
|
277749
|
+
SQLITE_PRIVATE
|
|
277686
277750
|
void RijndaelEncrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16])
|
|
277687
277751
|
{
|
|
277688
277752
|
UINT32 r;
|
|
@@ -277694,19 +277758,19 @@ void RijndaelEncrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16])
|
|
|
277694
277758
|
*((UINT32*)temp[3]) = *((UINT32*)(a+12)) ^ *((UINT32*)rijndael->m_expandedKey[0][3]);
|
|
277695
277759
|
*((UINT32*)(b )) = *((UINT32*)T1[temp[0][0]])
|
|
277696
277760
|
^ *((UINT32*)T2[temp[1][1]])
|
|
277697
|
-
^ *((UINT32*)T3[temp[2][2]])
|
|
277761
|
+
^ *((UINT32*)T3[temp[2][2]])
|
|
277698
277762
|
^ *((UINT32*)T4[temp[3][3]]);
|
|
277699
277763
|
*((UINT32*)(b + 4)) = *((UINT32*)T1[temp[1][0]])
|
|
277700
277764
|
^ *((UINT32*)T2[temp[2][1]])
|
|
277701
|
-
^ *((UINT32*)T3[temp[3][2]])
|
|
277765
|
+
^ *((UINT32*)T3[temp[3][2]])
|
|
277702
277766
|
^ *((UINT32*)T4[temp[0][3]]);
|
|
277703
277767
|
*((UINT32*)(b + 8)) = *((UINT32*)T1[temp[2][0]])
|
|
277704
277768
|
^ *((UINT32*)T2[temp[3][1]])
|
|
277705
|
-
^ *((UINT32*)T3[temp[0][2]])
|
|
277769
|
+
^ *((UINT32*)T3[temp[0][2]])
|
|
277706
277770
|
^ *((UINT32*)T4[temp[1][3]]);
|
|
277707
277771
|
*((UINT32*)(b +12)) = *((UINT32*)T1[temp[3][0]])
|
|
277708
277772
|
^ *((UINT32*)T2[temp[0][1]])
|
|
277709
|
-
^ *((UINT32*)T3[temp[1][2]])
|
|
277773
|
+
^ *((UINT32*)T3[temp[1][2]])
|
|
277710
277774
|
^ *((UINT32*)T4[temp[2][3]]);
|
|
277711
277775
|
for(r = 1; r < rijndael->m_uRounds-1; r++)
|
|
277712
277776
|
{
|
|
@@ -277717,19 +277781,19 @@ void RijndaelEncrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16])
|
|
|
277717
277781
|
|
|
277718
277782
|
*((UINT32*)(b )) = *((UINT32*)T1[temp[0][0]])
|
|
277719
277783
|
^ *((UINT32*)T2[temp[1][1]])
|
|
277720
|
-
^ *((UINT32*)T3[temp[2][2]])
|
|
277784
|
+
^ *((UINT32*)T3[temp[2][2]])
|
|
277721
277785
|
^ *((UINT32*)T4[temp[3][3]]);
|
|
277722
277786
|
*((UINT32*)(b + 4)) = *((UINT32*)T1[temp[1][0]])
|
|
277723
277787
|
^ *((UINT32*)T2[temp[2][1]])
|
|
277724
|
-
^ *((UINT32*)T3[temp[3][2]])
|
|
277788
|
+
^ *((UINT32*)T3[temp[3][2]])
|
|
277725
277789
|
^ *((UINT32*)T4[temp[0][3]]);
|
|
277726
277790
|
*((UINT32*)(b + 8)) = *((UINT32*)T1[temp[2][0]])
|
|
277727
277791
|
^ *((UINT32*)T2[temp[3][1]])
|
|
277728
|
-
^ *((UINT32*)T3[temp[0][2]])
|
|
277792
|
+
^ *((UINT32*)T3[temp[0][2]])
|
|
277729
277793
|
^ *((UINT32*)T4[temp[1][3]]);
|
|
277730
277794
|
*((UINT32*)(b +12)) = *((UINT32*)T1[temp[3][0]])
|
|
277731
277795
|
^ *((UINT32*)T2[temp[0][1]])
|
|
277732
|
-
^ *((UINT32*)T3[temp[1][2]])
|
|
277796
|
+
^ *((UINT32*)T3[temp[1][2]])
|
|
277733
277797
|
^ *((UINT32*)T4[temp[2][3]]);
|
|
277734
277798
|
}
|
|
277735
277799
|
*((UINT32*)temp[0]) = *((UINT32*)(b )) ^ *((UINT32*)rijndael->m_expandedKey[rijndael->m_uRounds-1][0]);
|
|
@@ -277758,11 +277822,12 @@ void RijndaelEncrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16])
|
|
|
277758
277822
|
*((UINT32*)(b+12)) ^= *((UINT32*)rijndael->m_expandedKey[rijndael->m_uRounds][3]);
|
|
277759
277823
|
}
|
|
277760
277824
|
|
|
277825
|
+
SQLITE_PRIVATE
|
|
277761
277826
|
void RijndaelDecrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16])
|
|
277762
277827
|
{
|
|
277763
277828
|
int r;
|
|
277764
277829
|
UINT8 temp[4][4];
|
|
277765
|
-
|
|
277830
|
+
|
|
277766
277831
|
*((UINT32*)temp[0]) = *((UINT32*)(a )) ^ *((UINT32*)rijndael->m_expandedKey[rijndael->m_uRounds][0]);
|
|
277767
277832
|
*((UINT32*)temp[1]) = *((UINT32*)(a+ 4)) ^ *((UINT32*)rijndael->m_expandedKey[rijndael->m_uRounds][1]);
|
|
277768
277833
|
*((UINT32*)temp[2]) = *((UINT32*)(a+ 8)) ^ *((UINT32*)rijndael->m_expandedKey[rijndael->m_uRounds][2]);
|
|
@@ -277770,19 +277835,19 @@ void RijndaelDecrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16])
|
|
|
277770
277835
|
|
|
277771
277836
|
*((UINT32*)(b )) = *((UINT32*)T5[temp[0][0]])
|
|
277772
277837
|
^ *((UINT32*)T6[temp[3][1]])
|
|
277773
|
-
^ *((UINT32*)T7[temp[2][2]])
|
|
277838
|
+
^ *((UINT32*)T7[temp[2][2]])
|
|
277774
277839
|
^ *((UINT32*)T8[temp[1][3]]);
|
|
277775
277840
|
*((UINT32*)(b+ 4)) = *((UINT32*)T5[temp[1][0]])
|
|
277776
277841
|
^ *((UINT32*)T6[temp[0][1]])
|
|
277777
|
-
^ *((UINT32*)T7[temp[3][2]])
|
|
277842
|
+
^ *((UINT32*)T7[temp[3][2]])
|
|
277778
277843
|
^ *((UINT32*)T8[temp[2][3]]);
|
|
277779
277844
|
*((UINT32*)(b+ 8)) = *((UINT32*)T5[temp[2][0]])
|
|
277780
277845
|
^ *((UINT32*)T6[temp[1][1]])
|
|
277781
|
-
^ *((UINT32*)T7[temp[0][2]])
|
|
277846
|
+
^ *((UINT32*)T7[temp[0][2]])
|
|
277782
277847
|
^ *((UINT32*)T8[temp[3][3]]);
|
|
277783
277848
|
*((UINT32*)(b+12)) = *((UINT32*)T5[temp[3][0]])
|
|
277784
277849
|
^ *((UINT32*)T6[temp[2][1]])
|
|
277785
|
-
^ *((UINT32*)T7[temp[1][2]])
|
|
277850
|
+
^ *((UINT32*)T7[temp[1][2]])
|
|
277786
277851
|
^ *((UINT32*)T8[temp[0][3]]);
|
|
277787
277852
|
for(r = rijndael->m_uRounds-1; r > 1; r--)
|
|
277788
277853
|
{
|
|
@@ -277792,22 +277857,22 @@ void RijndaelDecrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16])
|
|
|
277792
277857
|
*((UINT32*)temp[3]) = *((UINT32*)(b+12)) ^ *((UINT32*)rijndael->m_expandedKey[r][3]);
|
|
277793
277858
|
*((UINT32*)(b )) = *((UINT32*)T5[temp[0][0]])
|
|
277794
277859
|
^ *((UINT32*)T6[temp[3][1]])
|
|
277795
|
-
^ *((UINT32*)T7[temp[2][2]])
|
|
277860
|
+
^ *((UINT32*)T7[temp[2][2]])
|
|
277796
277861
|
^ *((UINT32*)T8[temp[1][3]]);
|
|
277797
277862
|
*((UINT32*)(b+ 4)) = *((UINT32*)T5[temp[1][0]])
|
|
277798
277863
|
^ *((UINT32*)T6[temp[0][1]])
|
|
277799
|
-
^ *((UINT32*)T7[temp[3][2]])
|
|
277864
|
+
^ *((UINT32*)T7[temp[3][2]])
|
|
277800
277865
|
^ *((UINT32*)T8[temp[2][3]]);
|
|
277801
277866
|
*((UINT32*)(b+ 8)) = *((UINT32*)T5[temp[2][0]])
|
|
277802
277867
|
^ *((UINT32*)T6[temp[1][1]])
|
|
277803
|
-
^ *((UINT32*)T7[temp[0][2]])
|
|
277868
|
+
^ *((UINT32*)T7[temp[0][2]])
|
|
277804
277869
|
^ *((UINT32*)T8[temp[3][3]]);
|
|
277805
277870
|
*((UINT32*)(b+12)) = *((UINT32*)T5[temp[3][0]])
|
|
277806
277871
|
^ *((UINT32*)T6[temp[2][1]])
|
|
277807
|
-
^ *((UINT32*)T7[temp[1][2]])
|
|
277872
|
+
^ *((UINT32*)T7[temp[1][2]])
|
|
277808
277873
|
^ *((UINT32*)T8[temp[0][3]]);
|
|
277809
277874
|
}
|
|
277810
|
-
|
|
277875
|
+
|
|
277811
277876
|
*((UINT32*)temp[0]) = *((UINT32*)(b )) ^ *((UINT32*)rijndael->m_expandedKey[1][0]);
|
|
277812
277877
|
*((UINT32*)temp[1]) = *((UINT32*)(b+ 4)) ^ *((UINT32*)rijndael->m_expandedKey[1][1]);
|
|
277813
277878
|
*((UINT32*)temp[2]) = *((UINT32*)(b+ 8)) ^ *((UINT32*)rijndael->m_expandedKey[1][2]);
|
|
@@ -277834,6 +277899,7 @@ void RijndaelDecrypt(Rijndael* rijndael, UINT8 a[16], UINT8 b[16])
|
|
|
277834
277899
|
*((UINT32*)(b+12)) ^= *((UINT32*)rijndael->m_expandedKey[0][3]);
|
|
277835
277900
|
}
|
|
277836
277901
|
|
|
277902
|
+
SQLITE_PRIVATE
|
|
277837
277903
|
void RijndaelInvalidate(Rijndael* rijndael)
|
|
277838
277904
|
{
|
|
277839
277905
|
rijndael->m_state = RIJNDAEL_State_Invalid;
|
|
@@ -277944,6 +278010,7 @@ typedef struct _Codec
|
|
|
277944
278010
|
unsigned char m_page[SQLITE_MAX_PAGE_SIZE + 24];
|
|
277945
278011
|
int m_pageSize;
|
|
277946
278012
|
int m_reserved;
|
|
278013
|
+
int m_lastError;
|
|
277947
278014
|
int m_hasKeySalt;
|
|
277948
278015
|
unsigned char m_keySalt[KEYSALT_LENGTH];
|
|
277949
278016
|
} Codec;
|
|
@@ -278015,6 +278082,9 @@ SQLITE_PRIVATE int sqlite3mcGetReservedWriteCipher(Codec* codec);
|
|
|
278015
278082
|
|
|
278016
278083
|
SQLITE_PRIVATE int sqlite3mcReservedEqual(Codec* codec);
|
|
278017
278084
|
|
|
278085
|
+
SQLITE_PRIVATE void sqlite3mcSetCodecLastError(Codec* codec, int error);
|
|
278086
|
+
SQLITE_PRIVATE int sqlite3mcGetCodecLastError(Codec* codec);
|
|
278087
|
+
|
|
278018
278088
|
SQLITE_PRIVATE unsigned char* sqlite3mcGetSaltWriteCipher(Codec* codec);
|
|
278019
278089
|
|
|
278020
278090
|
SQLITE_PRIVATE int sqlite3mcCodecCopy(Codec* codec, Codec* other);
|
|
@@ -278239,7 +278309,7 @@ sqlite3mcAES128(Rijndael* aesCtx, int page, int encrypt, unsigned char encryptio
|
|
|
278239
278309
|
{
|
|
278240
278310
|
len = RijndaelBlockDecrypt(aesCtx, datain, datalen*8, dataout);
|
|
278241
278311
|
}
|
|
278242
|
-
|
|
278312
|
+
|
|
278243
278313
|
/* It is a good idea to check the error code */
|
|
278244
278314
|
if (len < 0)
|
|
278245
278315
|
{
|
|
@@ -278293,7 +278363,7 @@ sqlite3mcAES256(Rijndael* aesCtx, int page, int encrypt, unsigned char encryptio
|
|
|
278293
278363
|
{
|
|
278294
278364
|
len = RijndaelBlockDecrypt(aesCtx, datain, datalen*8, dataout);
|
|
278295
278365
|
}
|
|
278296
|
-
|
|
278366
|
+
|
|
278297
278367
|
/* It is a good idea to check the error code */
|
|
278298
278368
|
if (len < 0)
|
|
278299
278369
|
{
|
|
@@ -279166,7 +279236,8 @@ EncryptPageChaCha20Cipher(void* cipher, int page, unsigned char* data, int len,
|
|
|
279166
279236
|
return rc;
|
|
279167
279237
|
}
|
|
279168
279238
|
|
|
279169
|
-
|
|
279239
|
+
static int
|
|
279240
|
+
chacha20_ismemset(const void* v, unsigned char value, int len)
|
|
279170
279241
|
{
|
|
279171
279242
|
const unsigned char* a = v;
|
|
279172
279243
|
int i = 0, result = 0;
|
|
@@ -279616,6 +279687,8 @@ GetHmacSizeSQLCipherCipher(int algorithm)
|
|
|
279616
279687
|
hmacSize = SHA1_DIGEST_SIZE;
|
|
279617
279688
|
break;
|
|
279618
279689
|
case SQLCIPHER_HMAC_ALGORITHM_SHA256:
|
|
279690
|
+
hmacSize = SHA256_DIGEST_SIZE;
|
|
279691
|
+
break;
|
|
279619
279692
|
case SQLCIPHER_HMAC_ALGORITHM_SHA512:
|
|
279620
279693
|
default:
|
|
279621
279694
|
hmacSize = SHA512_DIGEST_SIZE;
|
|
@@ -279634,7 +279707,7 @@ EncryptPageSQLCipherCipher(void* cipher, int page, unsigned char* data, int len,
|
|
|
279634
279707
|
int n = len - nReserved;
|
|
279635
279708
|
int offset = (page == 1) ? (sqlCipherCipher->m_legacy != 0) ? 16 : 24 : 0;
|
|
279636
279709
|
int blen;
|
|
279637
|
-
unsigned char iv[
|
|
279710
|
+
unsigned char iv[128];
|
|
279638
279711
|
int usePlaintextHeader = 0;
|
|
279639
279712
|
|
|
279640
279713
|
/* Check whether a plaintext header should be used */
|
|
@@ -279651,10 +279724,10 @@ EncryptPageSQLCipherCipher(void* cipher, int page, unsigned char* data, int len,
|
|
|
279651
279724
|
}
|
|
279652
279725
|
|
|
279653
279726
|
/* Generate nonce (64 bytes) */
|
|
279654
|
-
memset(iv, 0,
|
|
279727
|
+
memset(iv, 0, 128);
|
|
279655
279728
|
if (nReserved > 0)
|
|
279656
279729
|
{
|
|
279657
|
-
chacha20_rng(iv,
|
|
279730
|
+
chacha20_rng(iv, 128);
|
|
279658
279731
|
}
|
|
279659
279732
|
else
|
|
279660
279733
|
{
|
|
@@ -280003,7 +280076,7 @@ SQLITE_PRIVATE const CipherDescriptor mcRC4Descriptor =
|
|
|
280003
280076
|
/*** Begin of #include "ascon/prolog.h" ***/
|
|
280004
280077
|
/*
|
|
280005
280078
|
** Name: prolog.h
|
|
280006
|
-
** Purpose: Include important header files, before
|
|
280079
|
+
** Purpose: Include important header files, before
|
|
280007
280080
|
** Based on: Public domain Ascon reference implementation
|
|
280008
280081
|
** and optimized variants for 32- and 64-bit
|
|
280009
280082
|
** (see https://github.com/ascon/ascon-c)
|
|
@@ -280103,6 +280176,8 @@ typedef union {
|
|
|
280103
280176
|
|
|
280104
280177
|
#define ASCON_U64TOWORD(x) ASCON_U64BIG(x)
|
|
280105
280178
|
#define ASCON_WORDTOU64(x) ASCON_U64BIG(x)
|
|
280179
|
+
#define ASCON_LOAD(b, n) ASCON_LOADBYTES(b, n)
|
|
280180
|
+
#define ASCON_STORE(b, w, n) ASCON_STOREBYTES(b, w, n)
|
|
280106
280181
|
|
|
280107
280182
|
forceinline uint64_t ASCON_ROR(uint64_t x, int n) { return x >> n | x << (-n & 63); }
|
|
280108
280183
|
|
|
@@ -280120,6 +280195,8 @@ forceinline int ASCON_NOTZERO(uint64_t a, uint64_t b) {
|
|
|
280120
280195
|
|
|
280121
280196
|
forceinline uint64_t ASCON_PAD(int i) { return 0x80ull << (56 - 8 * i); }
|
|
280122
280197
|
|
|
280198
|
+
forceinline uint64_t ASCON_DSEP() { return 0x01; }
|
|
280199
|
+
|
|
280123
280200
|
forceinline uint64_t ASCON_PRFS_MLEN(uint64_t len) { return len << 51; }
|
|
280124
280201
|
|
|
280125
280202
|
forceinline uint64_t ASCON_CLEAR(uint64_t w, int n) {
|
|
@@ -280133,16 +280210,6 @@ forceinline uint64_t ASCON_MASK(int n) {
|
|
|
280133
280210
|
return ~0ull >> (64 - 8 * n);
|
|
280134
280211
|
}
|
|
280135
280212
|
|
|
280136
|
-
forceinline uint64_t ASCON_LOAD(const uint8_t* bytes, int n) {
|
|
280137
|
-
uint64_t x = *(uint64_t*)bytes & ASCON_MASK(n);
|
|
280138
|
-
return ASCON_U64TOWORD(x);
|
|
280139
|
-
}
|
|
280140
|
-
|
|
280141
|
-
forceinline void ASCON_STORE(uint8_t* bytes, uint64_t w, int n) {
|
|
280142
|
-
*(uint64_t*)bytes &= ~ASCON_MASK(n);
|
|
280143
|
-
*(uint64_t*)bytes |= ASCON_WORDTOU64(w);
|
|
280144
|
-
}
|
|
280145
|
-
|
|
280146
280213
|
forceinline uint64_t ASCON_LOADBYTES(const uint8_t* bytes, int n) {
|
|
280147
280214
|
uint64_t x = 0;
|
|
280148
280215
|
memcpy(&x, bytes, n);
|
|
@@ -280305,6 +280372,10 @@ void ascon_squeeze(ascon_state_t* s, uint8_t* out, uint64_t outlen);
|
|
|
280305
280372
|
#ifndef CRYPTO_AEAD_H
|
|
280306
280373
|
#define CRYPTO_AEAD_H
|
|
280307
280374
|
|
|
280375
|
+
#ifndef SQLITE_PRIVATE
|
|
280376
|
+
#define SQLITE_PRIVATE
|
|
280377
|
+
#endif
|
|
280378
|
+
|
|
280308
280379
|
#include <stddef.h>
|
|
280309
280380
|
|
|
280310
280381
|
/*
|
|
@@ -280319,6 +280390,7 @@ void ascon_squeeze(ascon_state_t* s, uint8_t* out, uint64_t outlen);
|
|
|
280319
280390
|
** \param nonce Buffer with nonce data
|
|
280320
280391
|
** \param k Buffer with key data
|
|
280321
280392
|
*/
|
|
280393
|
+
SQLITE_PRIVATE
|
|
280322
280394
|
int ascon_aead_encrypt(uint8_t* ctext, uint8_t tag[ASCON_AEAD_TAG_LEN],
|
|
280323
280395
|
const uint8_t* mtext, uint64_t mlen,
|
|
280324
280396
|
const uint8_t* ad, uint64_t adlen,
|
|
@@ -280337,6 +280409,7 @@ int ascon_aead_encrypt(uint8_t* ctext, uint8_t tag[ASCON_AEAD_TAG_LEN],
|
|
|
280337
280409
|
** \param nonce Buffer with nonce data
|
|
280338
280410
|
** \param k Buffer with key data
|
|
280339
280411
|
*/
|
|
280412
|
+
SQLITE_PRIVATE
|
|
280340
280413
|
int ascon_aead_decrypt(uint8_t* mtext, const uint8_t* ctext, uint64_t clen,
|
|
280341
280414
|
const uint8_t* ad, uint64_t adlen,
|
|
280342
280415
|
const uint8_t tag[ASCON_AEAD_TAG_LEN],
|
|
@@ -280773,7 +280846,7 @@ forceinline void ascon_adata(ascon_state_t* s, const uint8_t* ad,
|
|
|
280773
280846
|
ASCON_P(s, nr);
|
|
280774
280847
|
}
|
|
280775
280848
|
/* domain separation */
|
|
280776
|
-
s->x[4] ^=
|
|
280849
|
+
s->x[4] ^= ASCON_DSEP();
|
|
280777
280850
|
ascon_printstate("domain separation", s);
|
|
280778
280851
|
}
|
|
280779
280852
|
|
|
@@ -280882,6 +280955,7 @@ forceinline void ascon_final(ascon_state_t* s, const ascon_key_t* key) {
|
|
|
280882
280955
|
ascon_printstate("final 2nd key xor", s);
|
|
280883
280956
|
}
|
|
280884
280957
|
|
|
280958
|
+
SQLITE_PRIVATE
|
|
280885
280959
|
int ascon_aead_encrypt(uint8_t* ctext,
|
|
280886
280960
|
uint8_t tag[ASCON_AEAD_TAG_LEN],
|
|
280887
280961
|
const uint8_t* mtext, uint64_t mlen,
|
|
@@ -280905,6 +280979,7 @@ int ascon_aead_encrypt(uint8_t* ctext,
|
|
|
280905
280979
|
return 0;
|
|
280906
280980
|
}
|
|
280907
280981
|
|
|
280982
|
+
SQLITE_PRIVATE
|
|
280908
280983
|
int ascon_aead_decrypt(uint8_t* mtext,
|
|
280909
280984
|
const uint8_t* ctext, uint64_t clen,
|
|
280910
280985
|
const uint8_t* ad, uint64_t adlen,
|
|
@@ -280969,6 +281044,10 @@ int ascon_aead_decrypt(uint8_t* mtext,
|
|
|
280969
281044
|
#ifndef CRYPTO_HASH_H
|
|
280970
281045
|
#define CRYPTO_HASH_H
|
|
280971
281046
|
|
|
281047
|
+
#ifndef SQLITE_PRIVATE
|
|
281048
|
+
#define SQLITE_PRIVATE
|
|
281049
|
+
#endif
|
|
281050
|
+
|
|
280972
281051
|
#include <stddef.h>
|
|
280973
281052
|
|
|
280974
281053
|
/*
|
|
@@ -280978,6 +281057,7 @@ int ascon_aead_decrypt(uint8_t* mtext,
|
|
|
280978
281057
|
** \param in Buffer with input data
|
|
280979
281058
|
** \param passwordlen Length of input data in bytes
|
|
280980
281059
|
*/
|
|
281060
|
+
SQLITE_PRIVATE
|
|
280981
281061
|
int ascon_hash(uint8_t* out, const uint8_t* in, uint64_t inlen);
|
|
280982
281062
|
|
|
280983
281063
|
#endif
|
|
@@ -281061,6 +281141,7 @@ forceinline void ascon_squeeze(ascon_state_t* s, uint8_t* out,
|
|
|
281061
281141
|
ascon_printstate("squeeze output", s);
|
|
281062
281142
|
}
|
|
281063
281143
|
|
|
281144
|
+
SQLITE_PRIVATE
|
|
281064
281145
|
int ascon_hash(uint8_t* out, const uint8_t* in, uint64_t inlen)
|
|
281065
281146
|
{
|
|
281066
281147
|
ascon_state_t s;
|
|
@@ -281093,6 +281174,7 @@ int ascon_hash(uint8_t* out, const uint8_t* in, uint64_t inlen)
|
|
|
281093
281174
|
#define ASCON_HASH_SIZE 32
|
|
281094
281175
|
#define ASCON_PBKDF2_SIZE 32
|
|
281095
281176
|
|
|
281177
|
+
SQLITE_PRIVATE
|
|
281096
281178
|
void ascon_pbkdf2_init(ascon_state_t* state, const char* functionName,
|
|
281097
281179
|
const unsigned char* custom, uint32_t customlen, uint32_t outlen)
|
|
281098
281180
|
{
|
|
@@ -281138,10 +281220,11 @@ void ascon_pbkdf2_init(ascon_state_t* state, const char* functionName,
|
|
|
281138
281220
|
* Note: Instead of HMAC like in RFC 8018, use the following PRF:
|
|
281139
281221
|
* PRF(P, X) = ASCON-cXOF(X, 256, "PBKDF2", P)
|
|
281140
281222
|
*/
|
|
281141
|
-
static
|
|
281142
|
-
|
|
281143
|
-
|
|
281144
|
-
|
|
281223
|
+
static
|
|
281224
|
+
void ascon_pbkdf2_f(ascon_state_t* state,
|
|
281225
|
+
uint8_t* T, /*uint8_t* U,*/
|
|
281226
|
+
const uint8_t* salt, uint32_t saltlen,
|
|
281227
|
+
uint32_t count, uint32_t blocknum)
|
|
281145
281228
|
{
|
|
281146
281229
|
uint32_t asconSaltLen = (saltlen < ASCON_SALT_LEN) ? saltlen : ASCON_SALT_LEN;
|
|
281147
281230
|
uint8_t temp[ASCON_SALT_LEN+4];
|
|
@@ -281151,7 +281234,7 @@ static void ascon_pbkdf2_f(ascon_state_t* state,
|
|
|
281151
281234
|
memset(temp, 0, ASCON_SALT_LEN);
|
|
281152
281235
|
memcpy(temp, salt, asconSaltLen);
|
|
281153
281236
|
STORE32_BE(temp+ASCON_SALT_LEN, blocknum);
|
|
281154
|
-
|
|
281237
|
+
|
|
281155
281238
|
/* Copy initial state */
|
|
281156
281239
|
for (j = 0; j < 5; ++j) state2.x[j] = state->x[j];
|
|
281157
281240
|
|
|
@@ -281187,6 +281270,7 @@ static void ascon_pbkdf2_f(ascon_state_t* state,
|
|
|
281187
281270
|
sqlite3mcSecureZeroMemory(&state2, sizeof(ascon_state_t));
|
|
281188
281271
|
}
|
|
281189
281272
|
|
|
281273
|
+
SQLITE_PRIVATE
|
|
281190
281274
|
void ascon_pbkdf2(uint8_t* out, uint32_t outlen,
|
|
281191
281275
|
const uint8_t* password, uint32_t passwordlen,
|
|
281192
281276
|
const uint8_t* salt, uint32_t saltlen, uint32_t count)
|
|
@@ -281760,6 +281844,7 @@ sqlite3mcCodecInit(Codec* codec)
|
|
|
281760
281844
|
memset(codec->m_page, 0, sizeof(codec->m_page));
|
|
281761
281845
|
codec->m_pageSize = 0;
|
|
281762
281846
|
codec->m_reserved = 0;
|
|
281847
|
+
codec->m_lastError = SQLITE_OK;
|
|
281763
281848
|
codec->m_hasKeySalt = 0;
|
|
281764
281849
|
memset(codec->m_keySalt, 0, sizeof(codec->m_keySalt));
|
|
281765
281850
|
}
|
|
@@ -281967,7 +282052,7 @@ sqlite3mcGetLegacyWriteCipher(Codec* codec)
|
|
|
281967
282052
|
SQLITE_PRIVATE int
|
|
281968
282053
|
sqlite3mcGetPageSizeReadCipher(Codec* codec)
|
|
281969
282054
|
{
|
|
281970
|
-
int pageSize = (codec->m_hasReadCipher && codec->m_readCipher != NULL) ? globalCodecDescriptorTable[codec->m_readCipherType - 1].m_getPageSize(codec->m_readCipher) :
|
|
282055
|
+
int pageSize = (codec->m_hasReadCipher && codec->m_readCipher != NULL) ? globalCodecDescriptorTable[codec->m_readCipherType - 1].m_getPageSize(codec->m_readCipher) : -1;
|
|
281971
282056
|
return pageSize;
|
|
281972
282057
|
}
|
|
281973
282058
|
|
|
@@ -282000,6 +282085,21 @@ sqlite3mcReservedEqual(Codec* codec)
|
|
|
282000
282085
|
return (readReserved == writeReserved);
|
|
282001
282086
|
}
|
|
282002
282087
|
|
|
282088
|
+
SQLITE_PRIVATE void
|
|
282089
|
+
sqlite3mcSetCodecLastError(Codec* codec, int error)
|
|
282090
|
+
{
|
|
282091
|
+
if (codec)
|
|
282092
|
+
{
|
|
282093
|
+
codec->m_lastError = error;
|
|
282094
|
+
}
|
|
282095
|
+
}
|
|
282096
|
+
|
|
282097
|
+
SQLITE_PRIVATE int
|
|
282098
|
+
sqlite3mcGetCodecLastError(Codec* codec)
|
|
282099
|
+
{
|
|
282100
|
+
return codec ? codec->m_lastError : SQLITE_OK;
|
|
282101
|
+
}
|
|
282102
|
+
|
|
282003
282103
|
SQLITE_PRIVATE unsigned char*
|
|
282004
282104
|
sqlite3mcGetSaltWriteCipher(Codec* codec)
|
|
282005
282105
|
{
|
|
@@ -282053,6 +282153,9 @@ sqlite3mcCodecCopy(Codec* codec, Codec* other)
|
|
|
282053
282153
|
codec->m_bt = other->m_bt;
|
|
282054
282154
|
#endif
|
|
282055
282155
|
codec->m_btShared = other->m_btShared;
|
|
282156
|
+
|
|
282157
|
+
codec->m_lastError = SQLITE_OK;
|
|
282158
|
+
|
|
282056
282159
|
return rc;
|
|
282057
282160
|
}
|
|
282058
282161
|
|
|
@@ -282163,7 +282266,7 @@ sqlite3mcConfigureSQLCipherVersion(sqlite3* db, int configDefault, int legacyVer
|
|
|
282163
282266
|
static char* defNames[] = { "default:legacy_page_size", "default:kdf_iter", "default:hmac_use", "default:kdf_algorithm", "default:hmac_algorithm", NULL };
|
|
282164
282267
|
static int versionParams[SQLCIPHER_VERSION_MAX][5] =
|
|
282165
282268
|
{
|
|
282166
|
-
{ 1024, 4000, 0, SQLCIPHER_KDF_ALGORITHM_SHA1, SQLCIPHER_HMAC_ALGORITHM_SHA1 },
|
|
282269
|
+
{ 1024, 4000, 0, SQLCIPHER_KDF_ALGORITHM_SHA1, SQLCIPHER_HMAC_ALGORITHM_SHA1 },
|
|
282167
282270
|
{ 1024, 4000, 1, SQLCIPHER_KDF_ALGORITHM_SHA1, SQLCIPHER_HMAC_ALGORITHM_SHA1 },
|
|
282168
282271
|
{ 1024, 64000, 1, SQLCIPHER_KDF_ALGORITHM_SHA1, SQLCIPHER_HMAC_ALGORITHM_SHA1 },
|
|
282169
282272
|
{ 4096, 256000, 1, SQLCIPHER_KDF_ALGORITHM_SHA512, SQLCIPHER_HMAC_ALGORITHM_SHA512 }
|
|
@@ -282217,7 +282320,7 @@ SQLITE_PRIVATE void sqlite3mcConfigTable(sqlite3_context* context, int argc, sql
|
|
|
282217
282320
|
SQLITE_PRIVATE CodecParameter* sqlite3mcGetCodecParams(sqlite3* db);
|
|
282218
282321
|
|
|
282219
282322
|
/* Forward declaration */
|
|
282220
|
-
|
|
282323
|
+
SQLITE_PRIVATE unsigned char* sqlite3mcGetSaltWriteCipher(Codec* codec);
|
|
282221
282324
|
|
|
282222
282325
|
SQLITE_PRIVATE void sqlite3mcCodecDataSql(sqlite3_context* context, int argc, sqlite3_value** argv);
|
|
282223
282326
|
SQLITE_PRIVATE void sqlite3mcConfigParams(sqlite3_context* context, int argc, sqlite3_value** argv);
|
|
@@ -282410,6 +282513,21 @@ sqlite3mc_cipher_name(int cipherIndex)
|
|
|
282410
282513
|
return cipherName;
|
|
282411
282514
|
}
|
|
282412
282515
|
|
|
282516
|
+
static
|
|
282517
|
+
int checkParameterValue(const char* paramName, int value)
|
|
282518
|
+
{
|
|
282519
|
+
int ok = 1;
|
|
282520
|
+
if (sqlite3_stricmp(paramName, "legacy_page_size") == 0 && value > 0)
|
|
282521
|
+
{
|
|
282522
|
+
ok = value >= 512 && value <= SQLITE_MAX_PAGE_SIZE && ((value - 1) & value) == 0;
|
|
282523
|
+
}
|
|
282524
|
+
if (ok && sqlite3_stricmp(paramName, "plaintext_header_size") == 0 && value > 0)
|
|
282525
|
+
{
|
|
282526
|
+
ok = value % 16 == 0;
|
|
282527
|
+
}
|
|
282528
|
+
return ok;
|
|
282529
|
+
}
|
|
282530
|
+
|
|
282413
282531
|
SQLITE_API int
|
|
282414
282532
|
sqlite3mc_config_cipher(sqlite3* db, const char* cipherName, const char* paramName, int newValue)
|
|
282415
282533
|
{
|
|
@@ -282516,7 +282634,8 @@ sqlite3mc_config_cipher(sqlite3* db, const char* cipherName, const char* paramNa
|
|
|
282516
282634
|
value = (hasDefaultPrefix) ? param->m_default : (hasMinPrefix) ? param->m_minValue : (hasMaxPrefix) ? param->m_maxValue : param->m_value;
|
|
282517
282635
|
if (!hasMinPrefix && !hasMaxPrefix)
|
|
282518
282636
|
{
|
|
282519
|
-
if (newValue >= 0 && newValue >= param->m_minValue && newValue <= param->m_maxValue
|
|
282637
|
+
if (newValue >= 0 && newValue >= param->m_minValue && newValue <= param->m_maxValue &&
|
|
282638
|
+
checkParameterValue(paramName, newValue))
|
|
282520
282639
|
{
|
|
282521
282640
|
if (hasDefaultPrefix)
|
|
282522
282641
|
{
|
|
@@ -283769,7 +283888,7 @@ sqlite3_activate_see(const char *info)
|
|
|
283769
283888
|
|
|
283770
283889
|
/*
|
|
283771
283890
|
** Free the encryption data structure associated with a pager instance.
|
|
283772
|
-
** (called from the modified code in pager.c)
|
|
283891
|
+
** (called from the modified code in pager.c)
|
|
283773
283892
|
*/
|
|
283774
283893
|
SQLITE_PRIVATE void
|
|
283775
283894
|
sqlite3mcCodecFree(void *pCodecArg)
|
|
@@ -283799,12 +283918,15 @@ mcReportCodecError(BtShared* pBt, int error)
|
|
|
283799
283918
|
{
|
|
283800
283919
|
pBt->pPager->eState = PAGER_ERROR;
|
|
283801
283920
|
}
|
|
283802
|
-
setGetterMethod(pBt->pPager);
|
|
283803
283921
|
if (error == SQLITE_OK)
|
|
283804
283922
|
{
|
|
283805
283923
|
/* Clear cache to force reread of database after a new passphrase has been set */
|
|
283806
283924
|
sqlite3PagerClearCache(pBt->pPager);
|
|
283925
|
+
/* unlock required?
|
|
283926
|
+
pager_unlock(pBt->pPager);
|
|
283927
|
+
*/
|
|
283807
283928
|
}
|
|
283929
|
+
setGetterMethod(pBt->pPager);
|
|
283808
283930
|
}
|
|
283809
283931
|
|
|
283810
283932
|
/*
|
|
@@ -283823,6 +283945,7 @@ sqlite3mcCodec(void* pCodecArg, void* data, Pgno nPageNum, int nMode)
|
|
|
283823
283945
|
codec = (Codec*) pCodecArg;
|
|
283824
283946
|
if (!sqlite3mcIsEncrypted(codec))
|
|
283825
283947
|
{
|
|
283948
|
+
sqlite3mcSetCodecLastError(codec, rc);
|
|
283826
283949
|
return data;
|
|
283827
283950
|
}
|
|
283828
283951
|
|
|
@@ -283836,7 +283959,11 @@ sqlite3mcCodec(void* pCodecArg, void* data, Pgno nPageNum, int nMode)
|
|
|
283836
283959
|
if (sqlite3mcHasReadCipher(codec))
|
|
283837
283960
|
{
|
|
283838
283961
|
rc = sqlite3mcDecrypt(codec, nPageNum, (unsigned char*) data, pageSize);
|
|
283839
|
-
if (rc != SQLITE_OK)
|
|
283962
|
+
if (rc != SQLITE_OK)
|
|
283963
|
+
{
|
|
283964
|
+
mcReportCodecError(sqlite3mcGetBtShared(codec), rc);
|
|
283965
|
+
memset(data, 0, pageSize);
|
|
283966
|
+
}
|
|
283840
283967
|
}
|
|
283841
283968
|
break;
|
|
283842
283969
|
|
|
@@ -283870,6 +283997,7 @@ sqlite3mcCodec(void* pCodecArg, void* data, Pgno nPageNum, int nMode)
|
|
|
283870
283997
|
}
|
|
283871
283998
|
break;
|
|
283872
283999
|
}
|
|
284000
|
+
sqlite3mcSetCodecLastError(codec, rc);
|
|
283873
284001
|
return data;
|
|
283874
284002
|
}
|
|
283875
284003
|
|
|
@@ -283879,6 +284007,9 @@ sqlite3mcGetMainCodec(sqlite3* db);
|
|
|
283879
284007
|
SQLITE_PRIVATE void
|
|
283880
284008
|
sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const char* zFileName, Codec* codec);
|
|
283881
284009
|
|
|
284010
|
+
SQLITE_PRIVATE int
|
|
284011
|
+
sqlite3mcIsEncryptionSupported(sqlite3* db, const char* zDbName);
|
|
284012
|
+
|
|
283882
284013
|
static int
|
|
283883
284014
|
mcAdjustBtree(Btree* pBt, int nPageSize, int nReserved, int isLegacy)
|
|
283884
284015
|
{
|
|
@@ -283894,11 +284025,12 @@ mcAdjustBtree(Btree* pBt, int nPageSize, int nReserved, int isLegacy)
|
|
|
283894
284025
|
/* Adjust the page size and the reserved area */
|
|
283895
284026
|
if (pager->pageSize != pagesize || pager->nReserve != nReserved)
|
|
283896
284027
|
{
|
|
284028
|
+
int reserved = (nReserved >= 0) ? nReserved : 0;
|
|
283897
284029
|
if (isLegacy != 0)
|
|
283898
284030
|
{
|
|
283899
284031
|
pBt->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
|
|
283900
284032
|
}
|
|
283901
|
-
rc = sqlite3BtreeSetPageSize(pBt, pagesize,
|
|
284033
|
+
rc = sqlite3BtreeSetPageSize(pBt, pagesize, reserved, 0);
|
|
283902
284034
|
}
|
|
283903
284035
|
return rc;
|
|
283904
284036
|
}
|
|
@@ -284036,6 +284168,11 @@ SQLITE_API int
|
|
|
284036
284168
|
sqlite3_key_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
284037
284169
|
{
|
|
284038
284170
|
int rc = SQLITE_ERROR;
|
|
284171
|
+
if (!sqlite3mcIsEncryptionSupported(db, zDbName))
|
|
284172
|
+
{
|
|
284173
|
+
sqlite3ErrorWithMsg(db, rc, "Setting key failed. Encryption is not supported by the VFS.");
|
|
284174
|
+
return rc;
|
|
284175
|
+
}
|
|
284039
284176
|
if (zKey != NULL && nKey < 0)
|
|
284040
284177
|
{
|
|
284041
284178
|
/* Key is zero-terminated string */
|
|
@@ -284088,7 +284225,15 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
284088
284225
|
int nReserved;
|
|
284089
284226
|
Pager* pPager;
|
|
284090
284227
|
Codec* codec;
|
|
284228
|
+
int codecAllocated = 0;
|
|
284091
284229
|
int rc = SQLITE_ERROR;
|
|
284230
|
+
char* err = NULL;
|
|
284231
|
+
|
|
284232
|
+
if (!sqlite3mcIsEncryptionSupported(db, zDbName))
|
|
284233
|
+
{
|
|
284234
|
+
sqlite3ErrorWithMsg(db, rc, "Rekeying failed. Encryption is not supported by the VFS.");
|
|
284235
|
+
return rc;
|
|
284236
|
+
}
|
|
284092
284237
|
if (zKey != NULL && nKey < 0)
|
|
284093
284238
|
{
|
|
284094
284239
|
/* Key is zero-terminated string */
|
|
@@ -284121,10 +284266,10 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
284121
284266
|
sqlite3ErrorWithMsg(db, rc, "Rekeying is not supported in WAL journal mode.");
|
|
284122
284267
|
return rc;
|
|
284123
284268
|
}
|
|
284124
|
-
|
|
284269
|
+
|
|
284125
284270
|
if ((zKey == NULL || nKey == 0) && (codec == NULL || !sqlite3mcIsEncrypted(codec)))
|
|
284126
284271
|
{
|
|
284127
|
-
/* Database not encrypted and key not specified, therefore do nothing
|
|
284272
|
+
/* Database not encrypted and key not specified, therefore do nothing */
|
|
284128
284273
|
return SQLITE_OK;
|
|
284129
284274
|
}
|
|
284130
284275
|
|
|
@@ -284132,9 +284277,10 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
284132
284277
|
|
|
284133
284278
|
if (codec == NULL || !sqlite3mcIsEncrypted(codec))
|
|
284134
284279
|
{
|
|
284135
|
-
/* Database not encrypted, but key specified, therefore encrypt database
|
|
284280
|
+
/* Database not encrypted, but key specified, therefore encrypt database */
|
|
284136
284281
|
if (codec == NULL)
|
|
284137
284282
|
{
|
|
284283
|
+
codecAllocated = 1;
|
|
284138
284284
|
codec = (Codec*) sqlite3_malloc(sizeof(Codec));
|
|
284139
284285
|
rc = (codec != NULL) ? sqlite3mcCodecInit(codec) : SQLITE_NOMEM;
|
|
284140
284286
|
}
|
|
@@ -284158,14 +284304,9 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
284158
284304
|
if (nReserved != nReservedWriteCipher)
|
|
284159
284305
|
{
|
|
284160
284306
|
/* Use VACUUM to change the number of reserved bytes */
|
|
284161
|
-
char* err = NULL;
|
|
284162
284307
|
sqlite3mcSetReadReserved(codec, nReserved);
|
|
284163
284308
|
sqlite3mcSetWriteReserved(codec, nReservedWriteCipher);
|
|
284164
284309
|
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, NULL, nReservedWriteCipher);
|
|
284165
|
-
if (rc != SQLITE_OK && err != NULL)
|
|
284166
|
-
{
|
|
284167
|
-
sqlite3ErrorWithMsg(db, rc, err);
|
|
284168
|
-
}
|
|
284169
284310
|
goto leave_rekey;
|
|
284170
284311
|
}
|
|
284171
284312
|
}
|
|
@@ -284173,12 +284314,17 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
284173
284314
|
{
|
|
284174
284315
|
/* Pagesize cannot be changed for an encrypted database */
|
|
284175
284316
|
rc = SQLITE_ERROR;
|
|
284176
|
-
|
|
284317
|
+
err = "Rekeying failed. Pagesize cannot be changed for an encrypted database.";
|
|
284177
284318
|
goto leave_rekey;
|
|
284178
284319
|
}
|
|
284179
284320
|
}
|
|
284180
284321
|
else
|
|
284181
284322
|
{
|
|
284323
|
+
sqlite3_mutex_leave(db->mutex);
|
|
284324
|
+
if (codecAllocated)
|
|
284325
|
+
{
|
|
284326
|
+
sqlite3mcCodecFree(codec);
|
|
284327
|
+
}
|
|
284182
284328
|
return rc;
|
|
284183
284329
|
}
|
|
284184
284330
|
}
|
|
@@ -284194,10 +284340,6 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
284194
284340
|
sqlite3mcSetReadReserved(codec, nReserved);
|
|
284195
284341
|
sqlite3mcSetWriteReserved(codec, 0);
|
|
284196
284342
|
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, NULL, 0);
|
|
284197
|
-
if (rc != SQLITE_OK && err != NULL)
|
|
284198
|
-
{
|
|
284199
|
-
sqlite3ErrorWithMsg(db, rc, err);
|
|
284200
|
-
}
|
|
284201
284343
|
goto leave_rekey;
|
|
284202
284344
|
}
|
|
284203
284345
|
}
|
|
@@ -284219,10 +284361,6 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
284219
284361
|
sqlite3mcSetReadReserved(codec, nReserved);
|
|
284220
284362
|
sqlite3mcSetWriteReserved(codec, nReservedWriteCipher);
|
|
284221
284363
|
rc = sqlite3mcRunVacuumForRekey(&err, db, dbIndex, NULL, nReservedWriteCipher);
|
|
284222
|
-
if (rc != SQLITE_OK && err != NULL)
|
|
284223
|
-
{
|
|
284224
|
-
sqlite3ErrorWithMsg(db, rc, err);
|
|
284225
|
-
}
|
|
284226
284364
|
goto leave_rekey;
|
|
284227
284365
|
}
|
|
284228
284366
|
}
|
|
@@ -284230,14 +284368,14 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
284230
284368
|
{
|
|
284231
284369
|
/* Pagesize cannot be changed for an encrypted database */
|
|
284232
284370
|
rc = SQLITE_ERROR;
|
|
284233
|
-
|
|
284371
|
+
err = "Rekeying failed. Pagesize cannot be changed for an encrypted database.";
|
|
284234
284372
|
goto leave_rekey;
|
|
284235
284373
|
}
|
|
284236
284374
|
}
|
|
284237
284375
|
else
|
|
284238
284376
|
{
|
|
284239
284377
|
/* Setup of write cipher failed */
|
|
284240
|
-
|
|
284378
|
+
err = "Rekeying failed. Setup of write cipher failed.";
|
|
284241
284379
|
goto leave_rekey;
|
|
284242
284380
|
}
|
|
284243
284381
|
}
|
|
@@ -284288,8 +284426,15 @@ leave_rekey:
|
|
|
284288
284426
|
/* Set read key equal to write key if necessary */
|
|
284289
284427
|
if (sqlite3mcHasWriteCipher(codec))
|
|
284290
284428
|
{
|
|
284429
|
+
/* Set Read cipher equal to Write cipher */
|
|
284291
284430
|
sqlite3mcCopyCipher(codec, 0);
|
|
284292
284431
|
sqlite3mcSetHasReadCipher(codec, 1);
|
|
284432
|
+
|
|
284433
|
+
/* Enforce page size and number of reserved bytes per page */
|
|
284434
|
+
int pageSize = sqlite3mcGetPageSizeWriteCipher(codec);
|
|
284435
|
+
int reserved = sqlite3mcGetReservedWriteCipher(codec);
|
|
284436
|
+
mcAdjustBtree(pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
|
|
284437
|
+
sqlite3mcCodecSizeChange(codec, pageSize, reserved);
|
|
284293
284438
|
}
|
|
284294
284439
|
else
|
|
284295
284440
|
{
|
|
@@ -284317,6 +284462,10 @@ leave_rekey:
|
|
|
284317
284462
|
/* Remove codec for unencrypted database */
|
|
284318
284463
|
sqlite3mcSetCodec(db, zDbName, dbFileName, NULL);
|
|
284319
284464
|
}
|
|
284465
|
+
if (rc != SQLITE_OK && err != NULL)
|
|
284466
|
+
{
|
|
284467
|
+
sqlite3ErrorWithMsg(db, rc, err);
|
|
284468
|
+
}
|
|
284320
284469
|
return rc;
|
|
284321
284470
|
}
|
|
284322
284471
|
|
|
@@ -284588,7 +284737,7 @@ Usage instructions for the sqlite3 program:
|
|
|
284588
284737
|
security measure; see "Security Considerations" in
|
|
284589
284738
|
http://www.sqlite.org/cvstrac/wiki?p=LoadableExtensions.
|
|
284590
284739
|
If the sqlite3 program and library are built this
|
|
284591
|
-
way, you cannot use these functions from the program, you
|
|
284740
|
+
way, you cannot use these functions from the program, you
|
|
284592
284741
|
must write your own program using the sqlite3 API, and call
|
|
284593
284742
|
sqlite3_enable_load_extension as described above, or else
|
|
284594
284743
|
rebuilt the sqlite3 program to allow loadable extensions.
|
|
@@ -284659,7 +284808,7 @@ Original code 2006 June 05 by relicoder.
|
|
|
284659
284808
|
#define HAVE_ISBLANK 1
|
|
284660
284809
|
#endif
|
|
284661
284810
|
#define SQLITE_SOUNDEX 1
|
|
284662
|
-
#define HAVE_TRIM 1
|
|
284811
|
+
#define HAVE_TRIM 1 /* LMH 2007-03-25 if sqlite has trim functions */
|
|
284663
284812
|
|
|
284664
284813
|
#ifdef COMPILE_SQLITE_EXTENSIONS_AS_LOADABLE_MODULE
|
|
284665
284814
|
/* #include "sqlite3ext.h" */
|
|
@@ -284678,7 +284827,7 @@ Original code 2006 June 05 by relicoder.
|
|
|
284678
284827
|
** This header file defines the SQLite interface for use by
|
|
284679
284828
|
** shared libraries that want to be imported as extensions into
|
|
284680
284829
|
** an SQLite instance. Shared libraries that intend to be loaded
|
|
284681
|
-
** as extensions by SQLite should #include this file instead of
|
|
284830
|
+
** as extensions by SQLite should #include this file instead of
|
|
284682
284831
|
** sqlite3.h.
|
|
284683
284832
|
*/
|
|
284684
284833
|
#ifndef SQLITE3EXT_H
|
|
@@ -285369,14 +285518,14 @@ typedef int (*sqlite3_loadext_entry)(
|
|
|
285369
285518
|
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
|
|
285370
285519
|
|
|
285371
285520
|
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
|
285372
|
-
/* This case when the file really is being compiled as a loadable
|
|
285521
|
+
/* This case when the file really is being compiled as a loadable
|
|
285373
285522
|
** extension */
|
|
285374
285523
|
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
|
|
285375
285524
|
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
|
|
285376
285525
|
# define SQLITE_EXTENSION_INIT3 \
|
|
285377
285526
|
extern const sqlite3_api_routines *sqlite3_api;
|
|
285378
285527
|
#else
|
|
285379
|
-
/* This case when the file is being statically linked into the
|
|
285528
|
+
/* This case when the file is being statically linked into the
|
|
285380
285529
|
** application */
|
|
285381
285530
|
# define SQLITE_EXTENSION_INIT1 /*no-op*/
|
|
285382
285531
|
# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
|
|
@@ -285397,7 +285546,7 @@ SQLITE_EXTENSION_INIT1
|
|
|
285397
285546
|
#include <math.h>
|
|
285398
285547
|
#include <string.h>
|
|
285399
285548
|
#include <stdio.h>
|
|
285400
|
-
#include <errno.h>
|
|
285549
|
+
#include <errno.h> /* LMH 2007-03-25 */
|
|
285401
285550
|
|
|
285402
285551
|
#include <stdlib.h>
|
|
285403
285552
|
#include <assert.h>
|
|
@@ -285577,7 +285726,7 @@ static int sqlite3ReadUtf8(const unsigned char *z){
|
|
|
285577
285726
|
** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
|
|
285578
285727
|
** return the number of unicode characters in pZ up to (but not including)
|
|
285579
285728
|
** the first 0x00 byte. If nByte is not less than zero, return the
|
|
285580
|
-
** number of unicode characters in the first nByte of pZ (or up to
|
|
285729
|
+
** number of unicode characters in the first nByte of pZ (or up to
|
|
285581
285730
|
** the first 0x00, whichever comes first).
|
|
285582
285731
|
*/
|
|
285583
285732
|
static int sqlite3Utf8CharLen(const char *z, int nByte){
|
|
@@ -285612,7 +285761,7 @@ static int sqlite3Utf8CharLen(const char *z, int nByte){
|
|
|
285612
285761
|
**
|
|
285613
285762
|
** Could have been implemented using pointers to functions but this way it's inline
|
|
285614
285763
|
** and thus more efficient. Lower * ranking though...
|
|
285615
|
-
**
|
|
285764
|
+
**
|
|
285616
285765
|
** Parameters:
|
|
285617
285766
|
** name: function name to de defined (eg: sinFunc)
|
|
285618
285767
|
** function: function defined in math.h to wrap (eg: sin)
|
|
@@ -285658,7 +285807,7 @@ GEN_MATH_WRAP_DOUBLE_1(atanFunc, atan)
|
|
|
285658
285807
|
|
|
285659
285808
|
/*
|
|
285660
285809
|
** Many of systems don't have inverse hyperbolic trig functions so this will emulate
|
|
285661
|
-
** them on those systems in terms of log and sqrt (formulas are too trivial to demand
|
|
285810
|
+
** them on those systems in terms of log and sqrt (formulas are too trivial to demand
|
|
285662
285811
|
** written proof here)
|
|
285663
285812
|
*/
|
|
285664
285813
|
|
|
@@ -285830,7 +285979,7 @@ static void squareFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
|
|
|
285830
285979
|
** (see sqrt just before this). Here the result is always double
|
|
285831
285980
|
*/
|
|
285832
285981
|
/* LMH 2007-03-25 Changed to use errno; no pre-checking for errors. Also removes
|
|
285833
|
-
but that was present in the pre-checking that called sqlite3_result_error on
|
|
285982
|
+
but that was present in the pre-checking that called sqlite3_result_error on
|
|
285834
285983
|
a non-positive first argument, which is not always an error. */
|
|
285835
285984
|
static void powerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
285836
285985
|
double r1 = 0.0;
|
|
@@ -285838,9 +285987,9 @@ static void powerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
285838
285987
|
double val;
|
|
285839
285988
|
|
|
285840
285989
|
assert( argc==2 );
|
|
285841
|
-
|
|
285990
|
+
|
|
285842
285991
|
if( sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL ){
|
|
285843
|
-
sqlite3_result_null(context);
|
|
285992
|
+
sqlite3_result_null(context);
|
|
285844
285993
|
}else{
|
|
285845
285994
|
r1 = sqlite3_value_double(argv[0]);
|
|
285846
285995
|
r2 = sqlite3_value_double(argv[1]);
|
|
@@ -285848,9 +285997,9 @@ static void powerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
285848
285997
|
val = pow(r1,r2);
|
|
285849
285998
|
if (errno == 0) {
|
|
285850
285999
|
sqlite3_result_double(context, val);
|
|
285851
|
-
} else {
|
|
286000
|
+
} else {
|
|
285852
286001
|
sqlite3_result_error(context, strerror(errno), errno);
|
|
285853
|
-
}
|
|
286002
|
+
}
|
|
285854
286003
|
}
|
|
285855
286004
|
}
|
|
285856
286005
|
|
|
@@ -285864,9 +286013,9 @@ static void atn2Func(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
285864
286013
|
double r2 = 0.0;
|
|
285865
286014
|
|
|
285866
286015
|
assert( argc==2 );
|
|
285867
|
-
|
|
286016
|
+
|
|
285868
286017
|
if( sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL ){
|
|
285869
|
-
sqlite3_result_null(context);
|
|
286018
|
+
sqlite3_result_null(context);
|
|
285870
286019
|
}else{
|
|
285871
286020
|
r1 = sqlite3_value_double(argv[0]);
|
|
285872
286021
|
r2 = sqlite3_value_double(argv[1]);
|
|
@@ -285963,14 +286112,14 @@ static void floorFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
285963
286112
|
#endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
|
|
285964
286113
|
|
|
285965
286114
|
/*
|
|
285966
|
-
** Given a string (s) in the first argument and an integer (n) in the second returns the
|
|
286115
|
+
** Given a string (s) in the first argument and an integer (n) in the second returns the
|
|
285967
286116
|
** string that constains s contatenated n times
|
|
285968
286117
|
*/
|
|
285969
286118
|
static void replicateFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
285970
286119
|
unsigned char *z; /* input string */
|
|
285971
286120
|
unsigned char *zo; /* result string */
|
|
285972
286121
|
i64 iCount; /* times to repeat */
|
|
285973
|
-
i64 nLen; /* length of the input string (no multibyte considerations) */
|
|
286122
|
+
i64 nLen; /* length of the input string (no multibyte considerations) */
|
|
285974
286123
|
i64 nTLen; /* length of the result string (no multibyte considerations) */
|
|
285975
286124
|
i64 i=0;
|
|
285976
286125
|
|
|
@@ -286005,7 +286154,7 @@ static void replicateFunc(sqlite3_context *context, int argc, sqlite3_value **ar
|
|
|
286005
286154
|
}
|
|
286006
286155
|
}
|
|
286007
286156
|
|
|
286008
|
-
/*
|
|
286157
|
+
/*
|
|
286009
286158
|
** Some systems (win32 among others) don't have an isblank function, this will emulate it.
|
|
286010
286159
|
** This function is not UFT-8 safe since it only analyses a byte character.
|
|
286011
286160
|
*/
|
|
@@ -286070,9 +286219,9 @@ static void padlFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
286070
286219
|
char *zt;
|
|
286071
286220
|
|
|
286072
286221
|
assert( argc==2 );
|
|
286073
|
-
|
|
286222
|
+
|
|
286074
286223
|
if( sqlite3_value_type(argv[0]) == SQLITE_NULL ){
|
|
286075
|
-
sqlite3_result_null(context);
|
|
286224
|
+
sqlite3_result_null(context);
|
|
286076
286225
|
}else{
|
|
286077
286226
|
zi = (char *)sqlite3_value_text(argv[0]);
|
|
286078
286227
|
ilen = sqlite3_value_int64(argv[1]);
|
|
@@ -286124,9 +286273,9 @@ static void padrFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
286124
286273
|
char *zt;
|
|
286125
286274
|
|
|
286126
286275
|
assert( argc==2 );
|
|
286127
|
-
|
|
286276
|
+
|
|
286128
286277
|
if( sqlite3_value_type(argv[0]) == SQLITE_NULL ){
|
|
286129
|
-
sqlite3_result_null(context);
|
|
286278
|
+
sqlite3_result_null(context);
|
|
286130
286279
|
}else{
|
|
286131
286280
|
zi = (char *)sqlite3_value_text(argv[0]);
|
|
286132
286281
|
ilen = sqlite3_value_int64(argv[1]);
|
|
@@ -286179,9 +286328,9 @@ static void padcFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
286179
286328
|
char *zt;
|
|
286180
286329
|
|
|
286181
286330
|
assert( argc==2 );
|
|
286182
|
-
|
|
286331
|
+
|
|
286183
286332
|
if( sqlite3_value_type(argv[0]) == SQLITE_NULL ){
|
|
286184
|
-
sqlite3_result_null(context);
|
|
286333
|
+
sqlite3_result_null(context);
|
|
286185
286334
|
}else{
|
|
286186
286335
|
zi = (char *)sqlite3_value_text(argv[0]);
|
|
286187
286336
|
ilen = sqlite3_value_int64(argv[1]);
|
|
@@ -286238,17 +286387,17 @@ static void strfilterFunc(sqlite3_context *context, int argc, sqlite3_value **ar
|
|
|
286238
286387
|
int c2 = 0;
|
|
286239
286388
|
|
|
286240
286389
|
assert( argc==2 );
|
|
286241
|
-
|
|
286390
|
+
|
|
286242
286391
|
if( sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL ){
|
|
286243
|
-
sqlite3_result_null(context);
|
|
286392
|
+
sqlite3_result_null(context);
|
|
286244
286393
|
}else{
|
|
286245
286394
|
zi1 = (char *)sqlite3_value_text(argv[0]);
|
|
286246
286395
|
zi2 = (char *)sqlite3_value_text(argv[1]);
|
|
286247
|
-
/*
|
|
286248
|
-
** maybe I could allocate less, but that would imply 2 passes, rather waste
|
|
286396
|
+
/*
|
|
286397
|
+
** maybe I could allocate less, but that would imply 2 passes, rather waste
|
|
286249
286398
|
** (possibly) some memory
|
|
286250
286399
|
*/
|
|
286251
|
-
zo = sqlite3_malloc((int) (strlen(zi1)+1));
|
|
286400
|
+
zo = sqlite3_malloc((int) (strlen(zi1)+1));
|
|
286252
286401
|
if (!zo){
|
|
286253
286402
|
sqlite3_result_error_nomem(context);
|
|
286254
286403
|
return;
|
|
@@ -286292,11 +286441,11 @@ static int _substr(const char* z1, const char* z2, int s, const char** p){
|
|
|
286292
286441
|
if( '\0'==*z1 ){
|
|
286293
286442
|
return -1;
|
|
286294
286443
|
}
|
|
286295
|
-
|
|
286444
|
+
|
|
286296
286445
|
while( (sqliteCharVal((unsigned char *)z2) != 0) && (c++)<s){
|
|
286297
286446
|
sqliteNextChar(z2);
|
|
286298
286447
|
}
|
|
286299
|
-
|
|
286448
|
+
|
|
286300
286449
|
c = 0;
|
|
286301
286450
|
while( (sqliteCharVal((unsigned char *)z2)) != 0 ){
|
|
286302
286451
|
zt1 = z1;
|
|
@@ -286311,9 +286460,9 @@ static int _substr(const char* z1, const char* z2, int s, const char** p){
|
|
|
286311
286460
|
|
|
286312
286461
|
if( c1 == 0 ){
|
|
286313
286462
|
rVal = c;
|
|
286314
|
-
break;
|
|
286463
|
+
break;
|
|
286315
286464
|
}
|
|
286316
|
-
|
|
286465
|
+
|
|
286317
286466
|
sqliteNextChar(z2);
|
|
286318
286467
|
++c;
|
|
286319
286468
|
}
|
|
@@ -286394,7 +286543,7 @@ static void leftFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
286394
286543
|
}
|
|
286395
286544
|
strncpy((char*) rz, (char*) z, zt-z);
|
|
286396
286545
|
*(rz+cc) = '\0';
|
|
286397
|
-
sqlite3_result_text(context, (char*)rz, -1, SQLITE_TRANSIENT);
|
|
286546
|
+
sqlite3_result_text(context, (char*)rz, -1, SQLITE_TRANSIENT);
|
|
286398
286547
|
sqlite3_free(rz);
|
|
286399
286548
|
}
|
|
286400
286549
|
|
|
@@ -286433,7 +286582,7 @@ static void rightFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
286433
286582
|
cc=c-l;
|
|
286434
286583
|
if(cc<0)
|
|
286435
286584
|
cc=0;
|
|
286436
|
-
|
|
286585
|
+
|
|
286437
286586
|
while( cc-- > 0 ){
|
|
286438
286587
|
sqliteNextChar(zt);
|
|
286439
286588
|
}
|
|
@@ -286444,7 +286593,7 @@ static void rightFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
286444
286593
|
return;
|
|
286445
286594
|
}
|
|
286446
286595
|
strcpy((char*) rz, (char*) (zt));
|
|
286447
|
-
sqlite3_result_text(context, (char*)rz, -1, SQLITE_TRANSIENT);
|
|
286596
|
+
sqlite3_result_text(context, (char*)rz, -1, SQLITE_TRANSIENT);
|
|
286448
286597
|
sqlite3_free(rz);
|
|
286449
286598
|
}
|
|
286450
286599
|
|
|
@@ -286482,7 +286631,7 @@ static void ltrimFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
286482
286631
|
return;
|
|
286483
286632
|
}
|
|
286484
286633
|
z = sqlite3_value_text(argv[0]);
|
|
286485
|
-
sqlite3_result_text(context, ltrim(z), -1, SQLITE_TRANSIENT);
|
|
286634
|
+
sqlite3_result_text(context, ltrim(z), -1, SQLITE_TRANSIENT);
|
|
286486
286635
|
}
|
|
286487
286636
|
|
|
286488
286637
|
/*
|
|
@@ -286723,7 +286872,7 @@ static void modeStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
|
286723
286872
|
|
|
286724
286873
|
if( type == SQLITE_NULL)
|
|
286725
286874
|
return;
|
|
286726
|
-
|
|
286875
|
+
|
|
286727
286876
|
p = sqlite3_aggregate_context(context, sizeof(*p));
|
|
286728
286877
|
|
|
286729
286878
|
if( 0==(p->m) ){
|
|
@@ -286762,33 +286911,33 @@ static void modeIterate(void* e, i64 c, void* pp){
|
|
|
286762
286911
|
i64 ei;
|
|
286763
286912
|
double ed;
|
|
286764
286913
|
ModeCtx *p = (ModeCtx*)pp;
|
|
286765
|
-
|
|
286914
|
+
|
|
286766
286915
|
if( 0==p->is_double ){
|
|
286767
286916
|
ei = *(int*)(e);
|
|
286768
286917
|
|
|
286769
|
-
|
|
286918
|
+
if( p->mcnt==c ){
|
|
286770
286919
|
++p->mn;
|
|
286771
286920
|
}else if( p->mcnt<c ){
|
|
286772
286921
|
p->riM = ei;
|
|
286773
286922
|
p->mcnt = c;
|
|
286774
|
-
|
|
286923
|
+
p->mn=1;
|
|
286775
286924
|
}
|
|
286776
286925
|
}else{
|
|
286777
286926
|
ed = *(double*)(e);
|
|
286778
286927
|
|
|
286779
|
-
|
|
286928
|
+
if( p->mcnt==c ){
|
|
286780
286929
|
++p->mn;
|
|
286781
286930
|
}else if(p->mcnt<c){
|
|
286782
286931
|
p->rdM = ed;
|
|
286783
286932
|
p->mcnt = c;
|
|
286784
|
-
|
|
286933
|
+
p->mn=1;
|
|
286785
286934
|
}
|
|
286786
286935
|
}
|
|
286787
286936
|
}
|
|
286788
286937
|
|
|
286789
286938
|
/*
|
|
286790
286939
|
** Auxiliary function that iterates all elements in a map and finds the median
|
|
286791
|
-
** (the value such that the number of elements smaller is equal the the number of
|
|
286940
|
+
** (the value such that the number of elements smaller is equal the the number of
|
|
286792
286941
|
** elements larger)
|
|
286793
286942
|
*/
|
|
286794
286943
|
static void medianIterate(void* e, i64 c, void* pp){
|
|
@@ -286859,9 +287008,9 @@ static void _medianFinalize(sqlite3_context *context){
|
|
|
286859
287008
|
|
|
286860
287009
|
if( 0==p->is_double )
|
|
286861
287010
|
if( 1==p->mn )
|
|
286862
|
-
|
|
287011
|
+
sqlite3_result_int64(context, p->riM);
|
|
286863
287012
|
else
|
|
286864
|
-
|
|
287013
|
+
sqlite3_result_double(context, p->riM*1.0/p->mn);
|
|
286865
287014
|
else
|
|
286866
287015
|
sqlite3_result_double(context, p->rdM/p->mn);
|
|
286867
287016
|
}
|
|
@@ -286981,12 +287130,12 @@ static void differenceFunc(sqlite3_context *context, int argc, sqlite3_value **a
|
|
|
286981
287130
|
const u8 *zIn2;
|
|
286982
287131
|
|
|
286983
287132
|
assert( argc==2 );
|
|
286984
|
-
|
|
287133
|
+
|
|
286985
287134
|
if( sqlite3_value_type(argv[0])==SQLITE_NULL || sqlite3_value_type(argv[1])==SQLITE_NULL ){
|
|
286986
287135
|
sqlite3_result_null(context);
|
|
286987
287136
|
return;
|
|
286988
287137
|
}
|
|
286989
|
-
|
|
287138
|
+
|
|
286990
287139
|
zIn1 = (u8*)sqlite3_value_text(argv[0]);
|
|
286991
287140
|
zIn2 = (u8*)sqlite3_value_text(argv[1]);
|
|
286992
287141
|
|
|
@@ -287123,7 +287272,7 @@ int RegisterExtensionFunctions(sqlite3 *db){
|
|
|
287123
287272
|
aFuncs[i].eTextRep, pArg, aFuncs[i].xFunc, 0, 0);
|
|
287124
287273
|
#if 0
|
|
287125
287274
|
if( aFuncs[i].needCollSeq ){
|
|
287126
|
-
struct FuncDef *pFunc = sqlite3FindFunction(db, aFuncs[i].zName,
|
|
287275
|
+
struct FuncDef *pFunc = sqlite3FindFunction(db, aFuncs[i].zName,
|
|
287127
287276
|
strlen(aFuncs[i].zName), aFuncs[i].nArg, aFuncs[i].eTextRep, 0);
|
|
287128
287277
|
if( pFunc && aFuncs[i].needCollSeq ){
|
|
287129
287278
|
pFunc->needCollSeq = 1;
|
|
@@ -287140,7 +287289,7 @@ int RegisterExtensionFunctions(sqlite3 *db){
|
|
|
287140
287289
|
}
|
|
287141
287290
|
/* sqlite3CreateFunc */
|
|
287142
287291
|
/* LMH no error checking */
|
|
287143
|
-
sqlite3_create_function(db, aAggs[i].zName, aAggs[i].nArg, SQLITE_UTF8,
|
|
287292
|
+
sqlite3_create_function(db, aAggs[i].zName, aAggs[i].nArg, SQLITE_UTF8,
|
|
287144
287293
|
pArg, 0, aAggs[i].xStep, aAggs[i].xFinalize);
|
|
287145
287294
|
#if 0
|
|
287146
287295
|
if( aAggs[i].needCollSeq ){
|
|
@@ -287460,7 +287609,7 @@ static int csv_getc(CsvReader *p){
|
|
|
287460
287609
|
return ((unsigned char*)p->zIn)[p->iIn++];
|
|
287461
287610
|
}
|
|
287462
287611
|
|
|
287463
|
-
/* Increase the size of p->z and append character c to the end.
|
|
287612
|
+
/* Increase the size of p->z and append character c to the end.
|
|
287464
287613
|
** Return 0 on success and non-zero if there is an OOM error */
|
|
287465
287614
|
static CSV_NOINLINE int csv_resize_and_append(CsvReader *p, char c){
|
|
287466
287615
|
char *zNew;
|
|
@@ -287579,9 +287728,9 @@ static char *csv_read_one_field(CsvReader *p){
|
|
|
287579
287728
|
|
|
287580
287729
|
/* Forward references to the various virtual table methods implemented
|
|
287581
287730
|
** in this file. */
|
|
287582
|
-
static int csvtabCreate(sqlite3*, void*, int, const char*const*,
|
|
287731
|
+
static int csvtabCreate(sqlite3*, void*, int, const char*const*,
|
|
287583
287732
|
sqlite3_vtab**,char**);
|
|
287584
|
-
static int csvtabConnect(sqlite3*, void*, int, const char*const*,
|
|
287733
|
+
static int csvtabConnect(sqlite3*, void*, int, const char*const*,
|
|
287585
287734
|
sqlite3_vtab**,char**);
|
|
287586
287735
|
static int csvtabBestIndex(sqlite3_vtab*,sqlite3_index_info*);
|
|
287587
287736
|
static int csvtabDisconnect(sqlite3_vtab*);
|
|
@@ -287766,7 +287915,7 @@ static int csv_boolean_parameter(
|
|
|
287766
287915
|
** columns=N Assume the CSV file contains N columns.
|
|
287767
287916
|
**
|
|
287768
287917
|
** Only available if compiled with SQLITE_TEST:
|
|
287769
|
-
**
|
|
287918
|
+
**
|
|
287770
287919
|
** testflags=N Bitmask of test flags. Optional
|
|
287771
287920
|
**
|
|
287772
287921
|
** If schema= is omitted, then the columns are named "c0", "c1", "c2",
|
|
@@ -287793,7 +287942,7 @@ static int csvtabConnect(
|
|
|
287793
287942
|
CsvReader sRdr; /* A CSV file reader used to store an error
|
|
287794
287943
|
** message and/or to count the number of columns */
|
|
287795
287944
|
static const char *azParam[] = {
|
|
287796
|
-
"filename", "data", "schema",
|
|
287945
|
+
"filename", "data", "schema",
|
|
287797
287946
|
};
|
|
287798
287947
|
char *azPValue[3]; /* Parameter values */
|
|
287799
287948
|
# define CSV_FILENAME (azPValue[0])
|
|
@@ -288095,7 +288244,7 @@ static int csvtabEof(sqlite3_vtab_cursor *cur){
|
|
|
288095
288244
|
** the beginning.
|
|
288096
288245
|
*/
|
|
288097
288246
|
static int csvtabFilter(
|
|
288098
|
-
sqlite3_vtab_cursor *pVtabCursor,
|
|
288247
|
+
sqlite3_vtab_cursor *pVtabCursor,
|
|
288099
288248
|
int idxNum, const char *idxStr,
|
|
288100
288249
|
int argc, sqlite3_value **argv
|
|
288101
288250
|
){
|
|
@@ -288151,7 +288300,7 @@ static int csvtabBestIndex(
|
|
|
288151
288300
|
unsigned char op;
|
|
288152
288301
|
if( pIdxInfo->aConstraint[i].usable==0 ) continue;
|
|
288153
288302
|
op = pIdxInfo->aConstraint[i].op;
|
|
288154
|
-
if( op==SQLITE_INDEX_CONSTRAINT_EQ
|
|
288303
|
+
if( op==SQLITE_INDEX_CONSTRAINT_EQ
|
|
288155
288304
|
|| op==SQLITE_INDEX_CONSTRAINT_LIKE
|
|
288156
288305
|
|| op==SQLITE_INDEX_CONSTRAINT_GLOB
|
|
288157
288306
|
){
|
|
@@ -288238,14 +288387,14 @@ static sqlite3_module CsvModuleFauxWrite = {
|
|
|
288238
288387
|
#ifdef _WIN32
|
|
288239
288388
|
__declspec(dllexport)
|
|
288240
288389
|
#endif
|
|
288241
|
-
/*
|
|
288390
|
+
/*
|
|
288242
288391
|
** This routine is called when the extension is loaded. The new
|
|
288243
288392
|
** CSV virtual table module is registered with the calling database
|
|
288244
288393
|
** connection.
|
|
288245
288394
|
*/
|
|
288246
288395
|
int sqlite3_csv_init(
|
|
288247
|
-
sqlite3 *db,
|
|
288248
|
-
char **pzErrMsg,
|
|
288396
|
+
sqlite3 *db,
|
|
288397
|
+
char **pzErrMsg,
|
|
288249
288398
|
const sqlite3_api_routines *pApi
|
|
288250
288399
|
){
|
|
288251
288400
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
@@ -290826,7 +290975,7 @@ static unsigned char *SHA3Final(SHA3Context *p){
|
|
|
290826
290975
|
** Implementation of the sha3(X,SIZE) function.
|
|
290827
290976
|
**
|
|
290828
290977
|
** Return a BLOB which is the SIZE-bit SHA3 hash of X. The default
|
|
290829
|
-
** size is 256. If X is a BLOB, it is hashed as is.
|
|
290978
|
+
** size is 256. If X is a BLOB, it is hashed as is.
|
|
290830
290979
|
** For all other non-NULL types of input, X is converted into a UTF-8 string
|
|
290831
290980
|
** and the string is hashed without the trailing 0x00 terminator. The hash
|
|
290832
290981
|
** of a NULL value is NULL.
|
|
@@ -291117,7 +291266,7 @@ int sqlite3_carray_init(sqlite3* db, char** pzErrMsg, const sqlite3_api_routines
|
|
|
291117
291266
|
** ctype TEXT HIDDEN
|
|
291118
291267
|
** );
|
|
291119
291268
|
**
|
|
291120
|
-
** If the hidden columns "pointer" and "count" are unconstrained, then
|
|
291269
|
+
** If the hidden columns "pointer" and "count" are unconstrained, then
|
|
291121
291270
|
** the virtual table has no rows. Otherwise, the virtual table interprets
|
|
291122
291271
|
** the integer value of "pointer" as a pointer to the array and "count"
|
|
291123
291272
|
** as the number of elements in the array. The virtual table steps through
|
|
@@ -291136,7 +291285,7 @@ SQLITE_EXTENSION_INIT1
|
|
|
291136
291285
|
#else
|
|
291137
291286
|
# include <sys/uio.h>
|
|
291138
291287
|
#endif
|
|
291139
|
-
|
|
291288
|
+
|
|
291140
291289
|
/* Allowed values for the mFlags parameter to sqlite3_carray_bind().
|
|
291141
291290
|
** Must exactly match the definitions in carray.h.
|
|
291142
291291
|
*/
|
|
@@ -291343,7 +291492,7 @@ static int carrayEof(sqlite3_vtab_cursor *cur){
|
|
|
291343
291492
|
** to the first row of output.
|
|
291344
291493
|
*/
|
|
291345
291494
|
static int carrayFilter(
|
|
291346
|
-
sqlite3_vtab_cursor *pVtabCursor,
|
|
291495
|
+
sqlite3_vtab_cursor *pVtabCursor,
|
|
291347
291496
|
int idxNum, const char *idxStr,
|
|
291348
291497
|
int argc, sqlite3_value **argv
|
|
291349
291498
|
){
|
|
@@ -291457,7 +291606,7 @@ static int carrayBestIndex(
|
|
|
291457
291606
|
}
|
|
291458
291607
|
|
|
291459
291608
|
/*
|
|
291460
|
-
** This following structure defines all the methods for the
|
|
291609
|
+
** This following structure defines all the methods for the
|
|
291461
291610
|
** carray virtual table.
|
|
291462
291611
|
*/
|
|
291463
291612
|
static sqlite3_module carrayModule = {
|
|
@@ -291540,7 +291689,7 @@ SQLITE_API int sqlite3_carray_bind(
|
|
|
291540
291689
|
for(i=0; i<nData; i++){
|
|
291541
291690
|
sz += ((struct iovec*)aData)[i].iov_len;
|
|
291542
291691
|
}
|
|
291543
|
-
}
|
|
291692
|
+
}
|
|
291544
291693
|
pNew->aData = sqlite3_malloc64( sz );
|
|
291545
291694
|
if( pNew->aData==0 ){
|
|
291546
291695
|
sqlite3_free(pNew);
|
|
@@ -291614,8 +291763,8 @@ static void inttoptrFunc(
|
|
|
291614
291763
|
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
|
291615
291764
|
|
|
291616
291765
|
SQLITE_API int sqlite3_carray_init(
|
|
291617
|
-
sqlite3 *db,
|
|
291618
|
-
char **pzErrMsg,
|
|
291766
|
+
sqlite3 *db,
|
|
291767
|
+
char **pzErrMsg,
|
|
291619
291768
|
const sqlite3_api_routines *pApi
|
|
291620
291769
|
){
|
|
291621
291770
|
int rc = SQLITE_OK;
|
|
@@ -292088,8 +292237,8 @@ INT closedir(
|
|
|
292088
292237
|
** directory, NULL.
|
|
292089
292238
|
**
|
|
292090
292239
|
** If a non-NULL value is specified for the optional $dir parameter and
|
|
292091
|
-
** $path is a relative path, then $path is interpreted relative to $dir.
|
|
292092
|
-
** And the paths returned in the "name" column of the table are also
|
|
292240
|
+
** $path is a relative path, then $path is interpreted relative to $dir.
|
|
292241
|
+
** And the paths returned in the "name" column of the table are also
|
|
292093
292242
|
** relative to directory $dir.
|
|
292094
292243
|
**
|
|
292095
292244
|
** Notes on building this extension for Windows:
|
|
@@ -292146,7 +292295,7 @@ SQLITE_EXTENSION_INIT1
|
|
|
292146
292295
|
|
|
292147
292296
|
|
|
292148
292297
|
/*
|
|
292149
|
-
** Set the result stored by context ctx to a blob containing the
|
|
292298
|
+
** Set the result stored by context ctx to a blob containing the
|
|
292150
292299
|
** contents of file zName. Or, leave the result unchanged (NULL)
|
|
292151
292300
|
** if the file does not exist or is unreadable.
|
|
292152
292301
|
**
|
|
@@ -292379,7 +292528,7 @@ static int makeDirectory(
|
|
|
292379
292528
|
}
|
|
292380
292529
|
|
|
292381
292530
|
/*
|
|
292382
|
-
** This function does the work for the writefile() UDF. Refer to
|
|
292531
|
+
** This function does the work for the writefile() UDF. Refer to
|
|
292383
292532
|
** header comments at the top of this file for details.
|
|
292384
292533
|
*/
|
|
292385
292534
|
static int writeFile(
|
|
@@ -292481,10 +292630,10 @@ static int writeFile(
|
|
|
292481
292630
|
return 1;
|
|
292482
292631
|
}
|
|
292483
292632
|
#else
|
|
292484
|
-
/* Legacy unix.
|
|
292633
|
+
/* Legacy unix.
|
|
292485
292634
|
**
|
|
292486
292635
|
** Do not use utimes() on a symbolic link - it sees through the link and
|
|
292487
|
-
** modifies the timestamps on the target. Or fails if the target does
|
|
292636
|
+
** modifies the timestamps on the target. Or fails if the target does
|
|
292488
292637
|
** not exist. */
|
|
292489
292638
|
if( 0==S_ISLNK(mode) ){
|
|
292490
292639
|
struct timeval times[2];
|
|
@@ -292502,7 +292651,7 @@ static int writeFile(
|
|
|
292502
292651
|
}
|
|
292503
292652
|
|
|
292504
292653
|
/*
|
|
292505
|
-
** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
|
|
292654
|
+
** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
|
|
292506
292655
|
** Refer to header comments at the top of this file for details.
|
|
292507
292656
|
*/
|
|
292508
292657
|
static void writefileFunc(
|
|
@@ -292516,7 +292665,7 @@ static void writefileFunc(
|
|
|
292516
292665
|
sqlite3_int64 mtime = -1;
|
|
292517
292666
|
|
|
292518
292667
|
if( argc<2 || argc>4 ){
|
|
292519
|
-
sqlite3_result_error(context,
|
|
292668
|
+
sqlite3_result_error(context,
|
|
292520
292669
|
"wrong number of arguments to function writefile()", -1
|
|
292521
292670
|
);
|
|
292522
292671
|
return;
|
|
@@ -292586,7 +292735,7 @@ static void lsModeFunc(
|
|
|
292586
292735
|
|
|
292587
292736
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
292588
292737
|
|
|
292589
|
-
/*
|
|
292738
|
+
/*
|
|
292590
292739
|
** Cursor type for recursively iterating through a directory structure.
|
|
292591
292740
|
*/
|
|
292592
292741
|
typedef struct fsdir_cursor fsdir_cursor;
|
|
@@ -292734,7 +292883,7 @@ static int fsdirNext(sqlite3_vtab_cursor *cur){
|
|
|
292734
292883
|
}
|
|
292735
292884
|
pCur->iLvl = iNew;
|
|
292736
292885
|
pLvl = &pCur->aLvl[iNew];
|
|
292737
|
-
|
|
292886
|
+
|
|
292738
292887
|
pLvl->zDir = pCur->zPath;
|
|
292739
292888
|
pCur->zPath = 0;
|
|
292740
292889
|
pLvl->pDir = opendir(pLvl->zDir);
|
|
@@ -292865,7 +293014,7 @@ static int fsdirEof(sqlite3_vtab_cursor *cur){
|
|
|
292865
293014
|
** idxNum==2 Both PATH and DIR supplied
|
|
292866
293015
|
*/
|
|
292867
293016
|
static int fsdirFilter(
|
|
292868
|
-
sqlite3_vtab_cursor *cur,
|
|
293017
|
+
sqlite3_vtab_cursor *cur,
|
|
292869
293018
|
int idxNum, const char *idxStr,
|
|
292870
293019
|
int argc, sqlite3_value **argv
|
|
292871
293020
|
){
|
|
@@ -292954,7 +293103,7 @@ static int fsdirBestIndex(
|
|
|
292954
293103
|
}
|
|
292955
293104
|
break;
|
|
292956
293105
|
}
|
|
292957
|
-
}
|
|
293106
|
+
}
|
|
292958
293107
|
}
|
|
292959
293108
|
if( seenPath || seenDir ){
|
|
292960
293109
|
/* If input parameters are unusable, disallow this plan */
|
|
@@ -293026,14 +293175,14 @@ static int fsdirRegister(sqlite3 *db){
|
|
|
293026
293175
|
__declspec(dllexport)
|
|
293027
293176
|
#endif
|
|
293028
293177
|
int sqlite3_fileio_init(
|
|
293029
|
-
sqlite3 *db,
|
|
293030
|
-
char **pzErrMsg,
|
|
293178
|
+
sqlite3 *db,
|
|
293179
|
+
char **pzErrMsg,
|
|
293031
293180
|
const sqlite3_api_routines *pApi
|
|
293032
293181
|
){
|
|
293033
293182
|
int rc = SQLITE_OK;
|
|
293034
293183
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
293035
293184
|
(void)pzErrMsg; /* Unused parameter */
|
|
293036
|
-
rc = sqlite3_create_function(db, "readfile", 1,
|
|
293185
|
+
rc = sqlite3_create_function(db, "readfile", 1,
|
|
293037
293186
|
SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
|
|
293038
293187
|
readfileFunc, 0, 0);
|
|
293039
293188
|
if( rc==SQLITE_OK ){
|
|
@@ -293637,7 +293786,7 @@ static int seriesBestIndex(
|
|
|
293637
293786
|
return SQLITE_CONSTRAINT;
|
|
293638
293787
|
}
|
|
293639
293788
|
if( (idxNum & 0x03)==0x03 ){
|
|
293640
|
-
/* Both start= and stop= boundaries are available. This is the
|
|
293789
|
+
/* Both start= and stop= boundaries are available. This is the
|
|
293641
293790
|
** the preferred case */
|
|
293642
293791
|
pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0));
|
|
293643
293792
|
pIdxInfo->estimatedRows = 1000;
|
|
@@ -293663,7 +293812,7 @@ static int seriesBestIndex(
|
|
|
293663
293812
|
}
|
|
293664
293813
|
|
|
293665
293814
|
/*
|
|
293666
|
-
** This following structure defines all the methods for the
|
|
293815
|
+
** This following structure defines all the methods for the
|
|
293667
293816
|
** generate_series virtual table.
|
|
293668
293817
|
*/
|
|
293669
293818
|
static sqlite3_module seriesModule = {
|
|
@@ -293700,8 +293849,8 @@ static sqlite3_module seriesModule = {
|
|
|
293700
293849
|
__declspec(dllexport)
|
|
293701
293850
|
#endif
|
|
293702
293851
|
int sqlite3_series_init(
|
|
293703
|
-
sqlite3 *db,
|
|
293704
|
-
char **pzErrMsg,
|
|
293852
|
+
sqlite3 *db,
|
|
293853
|
+
char **pzErrMsg,
|
|
293705
293854
|
const sqlite3_api_routines *pApi
|
|
293706
293855
|
){
|
|
293707
293856
|
int rc = SQLITE_OK;
|
|
@@ -293954,7 +294103,7 @@ int sqlite3_uuid_init(
|
|
|
293954
294103
|
rc = sqlite3_create_function(db, "uuid", 0, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
|
|
293955
294104
|
sqlite3UuidFunc, 0, 0);
|
|
293956
294105
|
if( rc==SQLITE_OK ){
|
|
293957
|
-
rc = sqlite3_create_function(db, "uuid_str", 1,
|
|
294106
|
+
rc = sqlite3_create_function(db, "uuid_str", 1,
|
|
293958
294107
|
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
|
293959
294108
|
0, sqlite3UuidStrFunc, 0, 0);
|
|
293960
294109
|
}
|
|
@@ -294152,7 +294301,7 @@ static void re_add_state(ReStateSet *pSet, int newState){
|
|
|
294152
294301
|
|
|
294153
294302
|
/* Extract the next unicode character from *pzIn and return it. Advance
|
|
294154
294303
|
** *pzIn to the first byte past the end of the character returned. To
|
|
294155
|
-
** be clear: this routine converts utf8 to unicode. This routine is
|
|
294304
|
+
** be clear: this routine converts utf8 to unicode. This routine is
|
|
294156
294305
|
** optimized for the common case where the next character is a single byte.
|
|
294157
294306
|
*/
|
|
294158
294307
|
static unsigned re_next_char(ReInput *p){
|
|
@@ -294223,7 +294372,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
|
|
294223
294372
|
/* Look for the initial prefix match, if there is one. */
|
|
294224
294373
|
if( pRe->nInit ){
|
|
294225
294374
|
unsigned char x = pRe->zInit[0];
|
|
294226
|
-
while( in.i+pRe->nInit<=in.mx
|
|
294375
|
+
while( in.i+pRe->nInit<=in.mx
|
|
294227
294376
|
&& (zIn[in.i]!=x ||
|
|
294228
294377
|
strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
|
|
294229
294378
|
){
|
|
@@ -294693,7 +294842,7 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
|
|
|
294693
294842
|
/* The following is a performance optimization. If the regex begins with
|
|
294694
294843
|
** ".*" (if the input regex lacks an initial "^") and afterwards there are
|
|
294695
294844
|
** one or more matching characters, enter those matching characters into
|
|
294696
|
-
** zInit[]. The re_match() routine can then search ahead in the input
|
|
294845
|
+
** zInit[]. The re_match() routine can then search ahead in the input
|
|
294697
294846
|
** string looking for the initial match without having to run the whole
|
|
294698
294847
|
** regex engine over the string. Do not worry about trying to match
|
|
294699
294848
|
** unicode characters beyond plane 0 - those are very rare and this is
|
|
@@ -294836,14 +294985,14 @@ re_bytecode_func_err:
|
|
|
294836
294985
|
__declspec(dllexport)
|
|
294837
294986
|
#endif
|
|
294838
294987
|
int sqlite3_regexp_init(
|
|
294839
|
-
sqlite3 *db,
|
|
294840
|
-
char **pzErrMsg,
|
|
294988
|
+
sqlite3 *db,
|
|
294989
|
+
char **pzErrMsg,
|
|
294841
294990
|
const sqlite3_api_routines *pApi
|
|
294842
294991
|
){
|
|
294843
294992
|
int rc = SQLITE_OK;
|
|
294844
294993
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
294845
294994
|
(void)pzErrMsg; /* Unused */
|
|
294846
|
-
rc = sqlite3_create_function(db, "regexp", 2,
|
|
294995
|
+
rc = sqlite3_create_function(db, "regexp", 2,
|
|
294847
294996
|
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
|
294848
294997
|
0, re_sql_func, 0, 0);
|
|
294849
294998
|
if( rc==SQLITE_OK ){
|
|
@@ -294989,7 +295138,7 @@ int sqlite3_regexp_init(
|
|
|
294989
295138
|
|
|
294990
295139
|
|
|
294991
295140
|
|
|
294992
|
-
/* Defines to completely disable specific portions of miniz.c:
|
|
295141
|
+
/* Defines to completely disable specific portions of miniz.c:
|
|
294993
295142
|
If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. */
|
|
294994
295143
|
|
|
294995
295144
|
/* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */
|
|
@@ -295012,7 +295161,7 @@ int sqlite3_regexp_init(
|
|
|
295012
295161
|
/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. */
|
|
295013
295162
|
/*#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
|
|
295014
295163
|
|
|
295015
|
-
/* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
|
|
295164
|
+
/* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
|
|
295016
295165
|
Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
|
|
295017
295166
|
callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
|
|
295018
295167
|
functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */
|
|
@@ -295448,7 +295597,7 @@ extern MINIZ_EXPORT void *miniz_def_realloc_func(void *opaque, void *address, si
|
|
|
295448
295597
|
#ifdef __cplusplus
|
|
295449
295598
|
}
|
|
295450
295599
|
#endif
|
|
295451
|
-
|
|
295600
|
+
|
|
295452
295601
|
|
|
295453
295602
|
|
|
295454
295603
|
#ifdef __cplusplus
|
|
@@ -295638,7 +295787,7 @@ MINIZ_EXPORT void tdefl_compressor_free(tdefl_compressor *pComp);
|
|
|
295638
295787
|
#ifdef __cplusplus
|
|
295639
295788
|
}
|
|
295640
295789
|
#endif
|
|
295641
|
-
|
|
295790
|
+
|
|
295642
295791
|
|
|
295643
295792
|
/* ------------------- Low-level Decompression API Definitions */
|
|
295644
295793
|
|
|
@@ -295782,7 +295931,7 @@ struct tinfl_decompressor_tag
|
|
|
295782
295931
|
#ifdef __cplusplus
|
|
295783
295932
|
}
|
|
295784
295933
|
#endif
|
|
295785
|
-
|
|
295934
|
+
|
|
295786
295935
|
|
|
295787
295936
|
|
|
295788
295937
|
|
|
@@ -296100,13 +296249,13 @@ MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, c
|
|
|
296100
296249
|
|
|
296101
296250
|
#if 0
|
|
296102
296251
|
/* TODO */
|
|
296103
|
-
|
|
296104
|
-
|
|
296105
|
-
|
|
296106
|
-
|
|
296107
|
-
|
|
296108
|
-
|
|
296109
|
-
|
|
296252
|
+
typedef void *mz_zip_streaming_extract_state_ptr;
|
|
296253
|
+
mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
|
|
296254
|
+
uint64_t mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
|
|
296255
|
+
uint64_t mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
|
|
296256
|
+
mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, uint64_t new_ofs);
|
|
296257
|
+
size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size);
|
|
296258
|
+
mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
|
|
296110
296259
|
#endif
|
|
296111
296260
|
|
|
296112
296261
|
/* This function compares the archive's local headers, the optional local zip64 extended information block, and the optional descriptor following the compressed data vs. the data in the central directory. */
|
|
@@ -296168,8 +296317,8 @@ MINIZ_EXPORT mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const cha
|
|
|
296168
296317
|
/* Adds the contents of a file to an archive. This function also records the disk file's modified time into the archive. */
|
|
296169
296318
|
/* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/
|
|
296170
296319
|
MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 max_size,
|
|
296171
|
-
|
|
296172
|
-
|
|
296320
|
+
const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
|
296321
|
+
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
|
296173
296322
|
|
|
296174
296323
|
|
|
296175
296324
|
#ifndef MINIZ_NO_STDIO
|
|
@@ -297604,15 +297753,15 @@ static int tdefl_flush_block(tdefl_compressor *d, int flush)
|
|
|
297604
297753
|
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
|
297605
297754
|
static mz_uint16 TDEFL_READ_UNALIGNED_WORD(const mz_uint8* p)
|
|
297606
297755
|
{
|
|
297607
|
-
|
|
297608
|
-
|
|
297609
|
-
|
|
297756
|
+
mz_uint16 ret;
|
|
297757
|
+
memcpy(&ret, p, sizeof(mz_uint16));
|
|
297758
|
+
return ret;
|
|
297610
297759
|
}
|
|
297611
297760
|
static mz_uint16 TDEFL_READ_UNALIGNED_WORD2(const mz_uint16* p)
|
|
297612
297761
|
{
|
|
297613
|
-
|
|
297614
|
-
|
|
297615
|
-
|
|
297762
|
+
mz_uint16 ret;
|
|
297763
|
+
memcpy(&ret, p, sizeof(mz_uint16));
|
|
297764
|
+
return ret;
|
|
297616
297765
|
}
|
|
297617
297766
|
#else
|
|
297618
297767
|
#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16 *)(p)
|
|
@@ -297720,9 +297869,9 @@ static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahe
|
|
|
297720
297869
|
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
|
297721
297870
|
static mz_uint32 TDEFL_READ_UNALIGNED_WORD32(const mz_uint8* p)
|
|
297722
297871
|
{
|
|
297723
|
-
|
|
297724
|
-
|
|
297725
|
-
|
|
297872
|
+
mz_uint32 ret;
|
|
297873
|
+
memcpy(&ret, p, sizeof(mz_uint32));
|
|
297874
|
+
return ret;
|
|
297726
297875
|
}
|
|
297727
297876
|
#else
|
|
297728
297877
|
#define TDEFL_READ_UNALIGNED_WORD32(p) *(const mz_uint32 *)(p)
|
|
@@ -297797,7 +297946,7 @@ static mz_bool tdefl_compress_fast(tdefl_compressor *d)
|
|
|
297797
297946
|
|
|
297798
297947
|
pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN);
|
|
297799
297948
|
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
|
297800
|
-
|
|
297949
|
+
memcpy(&pLZ_code_buf[1], &cur_match_dist, sizeof(cur_match_dist));
|
|
297801
297950
|
#else
|
|
297802
297951
|
*(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist;
|
|
297803
297952
|
#endif
|
|
@@ -298966,7 +299115,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
|
|
|
298966
299115
|
do
|
|
298967
299116
|
{
|
|
298968
299117
|
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
|
298969
|
-
|
|
299118
|
+
memcpy(pOut_buf_cur, pSrc, sizeof(mz_uint32)*2);
|
|
298970
299119
|
#else
|
|
298971
299120
|
((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
|
|
298972
299121
|
((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
|
|
@@ -298993,7 +299142,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
|
|
|
298993
299142
|
pOut_buf_cur[2] = pSrc[2];
|
|
298994
299143
|
pOut_buf_cur += 3;
|
|
298995
299144
|
pSrc += 3;
|
|
298996
|
-
|
|
299145
|
+
counter -= 3;
|
|
298997
299146
|
}
|
|
298998
299147
|
if (counter > 0)
|
|
298999
299148
|
{
|
|
@@ -299931,47 +300080,47 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag
|
|
|
299931
300080
|
|
|
299932
300081
|
if (extra_size_remaining)
|
|
299933
300082
|
{
|
|
299934
|
-
|
|
299935
|
-
|
|
299936
|
-
|
|
299937
|
-
|
|
299938
|
-
|
|
299939
|
-
|
|
299940
|
-
|
|
299941
|
-
|
|
299942
|
-
|
|
299943
|
-
|
|
299944
|
-
|
|
299945
|
-
|
|
299946
|
-
|
|
299947
|
-
|
|
299948
|
-
|
|
299949
|
-
|
|
299950
|
-
|
|
299951
|
-
|
|
299952
|
-
|
|
299953
|
-
|
|
299954
|
-
|
|
300083
|
+
const mz_uint8 *pExtra_data;
|
|
300084
|
+
void* buf = NULL;
|
|
300085
|
+
|
|
300086
|
+
if (MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + ext_data_size > n)
|
|
300087
|
+
{
|
|
300088
|
+
buf = MZ_MALLOC(ext_data_size);
|
|
300089
|
+
if(buf==NULL)
|
|
300090
|
+
return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
|
|
300091
|
+
|
|
300092
|
+
if (pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size, buf, ext_data_size) != ext_data_size)
|
|
300093
|
+
{
|
|
300094
|
+
MZ_FREE(buf);
|
|
300095
|
+
return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
|
|
300096
|
+
}
|
|
300097
|
+
|
|
300098
|
+
pExtra_data = (mz_uint8*)buf;
|
|
300099
|
+
}
|
|
300100
|
+
else
|
|
300101
|
+
{
|
|
300102
|
+
pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size;
|
|
300103
|
+
}
|
|
299955
300104
|
|
|
299956
300105
|
do
|
|
299957
300106
|
{
|
|
299958
300107
|
mz_uint32 field_id;
|
|
299959
300108
|
mz_uint32 field_data_size;
|
|
299960
300109
|
|
|
299961
|
-
|
|
299962
|
-
|
|
299963
|
-
|
|
299964
|
-
|
|
299965
|
-
|
|
300110
|
+
if (extra_size_remaining < (sizeof(mz_uint16) * 2))
|
|
300111
|
+
{
|
|
300112
|
+
MZ_FREE(buf);
|
|
300113
|
+
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
|
300114
|
+
}
|
|
299966
300115
|
|
|
299967
300116
|
field_id = MZ_READ_LE16(pExtra_data);
|
|
299968
300117
|
field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
|
|
299969
300118
|
|
|
299970
|
-
|
|
299971
|
-
|
|
299972
|
-
|
|
299973
|
-
|
|
299974
|
-
|
|
300119
|
+
if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining)
|
|
300120
|
+
{
|
|
300121
|
+
MZ_FREE(buf);
|
|
300122
|
+
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
|
300123
|
+
}
|
|
299975
300124
|
|
|
299976
300125
|
if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
|
|
299977
300126
|
{
|
|
@@ -299985,7 +300134,7 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag
|
|
|
299985
300134
|
extra_size_remaining = extra_size_remaining - sizeof(mz_uint16) * 2 - field_data_size;
|
|
299986
300135
|
} while (extra_size_remaining);
|
|
299987
300136
|
|
|
299988
|
-
|
|
300137
|
+
MZ_FREE(buf);
|
|
299989
300138
|
}
|
|
299990
300139
|
}
|
|
299991
300140
|
|
|
@@ -300190,7 +300339,7 @@ mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename,
|
|
|
300190
300339
|
|
|
300191
300340
|
if (file_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
|
|
300192
300341
|
{
|
|
300193
|
-
|
|
300342
|
+
MZ_FCLOSE(pFile);
|
|
300194
300343
|
return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
|
|
300195
300344
|
}
|
|
300196
300345
|
|
|
@@ -302402,16 +302551,16 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
|
|
302402
302551
|
}
|
|
302403
302552
|
#endif /* #ifndef MINIZ_NO_TIME */
|
|
302404
302553
|
|
|
302405
|
-
|
|
302406
|
-
|
|
302407
|
-
|
|
302408
|
-
|
|
302409
|
-
|
|
302410
|
-
|
|
302411
|
-
|
|
302412
|
-
|
|
302413
|
-
|
|
302414
|
-
|
|
302554
|
+
if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
|
|
302555
|
+
{
|
|
302556
|
+
uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size);
|
|
302557
|
+
uncomp_size = buf_size;
|
|
302558
|
+
if (uncomp_size <= 3)
|
|
302559
|
+
{
|
|
302560
|
+
level = 0;
|
|
302561
|
+
store_data_uncompressed = MZ_TRUE;
|
|
302562
|
+
}
|
|
302563
|
+
}
|
|
302415
302564
|
|
|
302416
302565
|
archive_name_size = strlen(pArchive_name);
|
|
302417
302566
|
if (archive_name_size > MZ_UINT16_MAX)
|
|
@@ -302427,9 +302576,9 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
|
|
302427
302576
|
{
|
|
302428
302577
|
/* Bail early if the archive would obviously become too large */
|
|
302429
302578
|
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size
|
|
302430
|
-
|
|
302431
|
-
|
|
302432
|
-
|
|
302579
|
+
+ MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len +
|
|
302580
|
+
pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len
|
|
302581
|
+
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF)
|
|
302433
302582
|
{
|
|
302434
302583
|
pState->m_zip64 = MZ_TRUE;
|
|
302435
302584
|
/*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
|
|
@@ -302528,13 +302677,13 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
|
|
302528
302677
|
cur_archive_file_ofs += archive_name_size;
|
|
302529
302678
|
}
|
|
302530
302679
|
|
|
302531
|
-
|
|
302532
|
-
|
|
302533
|
-
|
|
302534
|
-
|
|
302680
|
+
if (user_extra_data_len > 0)
|
|
302681
|
+
{
|
|
302682
|
+
if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len)
|
|
302683
|
+
return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
|
|
302535
302684
|
|
|
302536
|
-
|
|
302537
|
-
|
|
302685
|
+
cur_archive_file_ofs += user_extra_data_len;
|
|
302686
|
+
}
|
|
302538
302687
|
|
|
302539
302688
|
if (store_data_uncompressed)
|
|
302540
302689
|
{
|
|
@@ -302686,8 +302835,8 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
|
|
|
302686
302835
|
{
|
|
302687
302836
|
/* Bail early if the archive would obviously become too large */
|
|
302688
302837
|
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE
|
|
302689
|
-
|
|
302690
|
-
|
|
302838
|
+
+ archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024
|
|
302839
|
+
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF)
|
|
302691
302840
|
{
|
|
302692
302841
|
pState->m_zip64 = MZ_TRUE;
|
|
302693
302842
|
/*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
|
|
@@ -302929,7 +303078,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
|
|
|
302929
303078
|
|
|
302930
303079
|
if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header,
|
|
302931
303080
|
(mz_uint16)archive_name_size, (mz_uint16)(extra_size + user_extra_data_len),
|
|
302932
|
-
(max_size >= MZ_UINT32_MAX) ? MZ_UINT32_MAX : uncomp_size,
|
|
303081
|
+
(max_size >= MZ_UINT32_MAX) ? MZ_UINT32_MAX : uncomp_size,
|
|
302933
303082
|
(max_size >= MZ_UINT32_MAX) ? MZ_UINT32_MAX : comp_size,
|
|
302934
303083
|
uncomp_crc32, method, gen_flags, dos_time, dos_date))
|
|
302935
303084
|
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
|
@@ -302978,20 +303127,20 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
|
|
|
302978
303127
|
|
|
302979
303128
|
static size_t mz_file_read_func_stdio(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
|
|
302980
303129
|
{
|
|
302981
|
-
|
|
302982
|
-
|
|
303130
|
+
MZ_FILE *pSrc_file = (MZ_FILE *)pOpaque;
|
|
303131
|
+
mz_int64 cur_ofs = MZ_FTELL64(pSrc_file);
|
|
302983
303132
|
|
|
302984
|
-
|
|
302985
|
-
|
|
303133
|
+
if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pSrc_file, (mz_int64)file_ofs, SEEK_SET))))
|
|
303134
|
+
return 0;
|
|
302986
303135
|
|
|
302987
|
-
|
|
303136
|
+
return MZ_FREAD(pBuf, 1, n, pSrc_file);
|
|
302988
303137
|
}
|
|
302989
303138
|
|
|
302990
303139
|
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
|
|
302991
|
-
|
|
303140
|
+
const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
|
|
302992
303141
|
{
|
|
302993
|
-
|
|
302994
|
-
|
|
303142
|
+
return mz_zip_writer_add_read_buf_callback(pZip, pArchive_name, mz_file_read_func_stdio, pSrc_file, max_size, pFile_time, pComment, comment_size, level_and_flags,
|
|
303143
|
+
user_extra_data, user_extra_data_len, user_extra_data_central, user_extra_data_central_len);
|
|
302995
303144
|
}
|
|
302996
303145
|
|
|
302997
303146
|
mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags)
|
|
@@ -303313,11 +303462,11 @@ mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *
|
|
|
303313
303462
|
{
|
|
303314
303463
|
/* src is zip64, dest must be zip64 */
|
|
303315
303464
|
|
|
303316
|
-
/* name
|
|
303317
|
-
/* id
|
|
303318
|
-
/* crc
|
|
303319
|
-
/* comp_size
|
|
303320
|
-
/* uncomp_size
|
|
303465
|
+
/* name uint32_t's */
|
|
303466
|
+
/* id 1 (optional in zip64?) */
|
|
303467
|
+
/* crc 1 */
|
|
303468
|
+
/* comp_size 2 */
|
|
303469
|
+
/* uncomp_size 2 */
|
|
303321
303470
|
if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, (sizeof(mz_uint32) * 6)) != (sizeof(mz_uint32) * 6))
|
|
303322
303471
|
{
|
|
303323
303472
|
pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
|
|
@@ -304112,14 +304261,14 @@ static void uncompressFunc(
|
|
|
304112
304261
|
__declspec(dllexport)
|
|
304113
304262
|
#endif
|
|
304114
304263
|
int sqlite3_compress_init(
|
|
304115
|
-
sqlite3 *db,
|
|
304116
|
-
char **pzErrMsg,
|
|
304264
|
+
sqlite3 *db,
|
|
304265
|
+
char **pzErrMsg,
|
|
304117
304266
|
const sqlite3_api_routines *pApi
|
|
304118
304267
|
){
|
|
304119
304268
|
int rc = SQLITE_OK;
|
|
304120
304269
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
304121
304270
|
(void)pzErrMsg; /* Unused parameter */
|
|
304122
|
-
rc = sqlite3_create_function(db, "compress", 1,
|
|
304271
|
+
rc = sqlite3_create_function(db, "compress", 1,
|
|
304123
304272
|
SQLITE_UTF8 | SQLITE_INNOCUOUS,
|
|
304124
304273
|
0, compressFunc, 0, 0);
|
|
304125
304274
|
if( rc==SQLITE_OK ){
|
|
@@ -304254,14 +304403,14 @@ static void sqlarUncompressFunc(
|
|
|
304254
304403
|
__declspec(dllexport)
|
|
304255
304404
|
#endif
|
|
304256
304405
|
int sqlite3_sqlar_init(
|
|
304257
|
-
sqlite3 *db,
|
|
304258
|
-
char **pzErrMsg,
|
|
304406
|
+
sqlite3 *db,
|
|
304407
|
+
char **pzErrMsg,
|
|
304259
304408
|
const sqlite3_api_routines *pApi
|
|
304260
304409
|
){
|
|
304261
304410
|
int rc = SQLITE_OK;
|
|
304262
304411
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
304263
304412
|
(void)pzErrMsg; /* Unused parameter */
|
|
304264
|
-
rc = sqlite3_create_function(db, "sqlar_compress", 1,
|
|
304413
|
+
rc = sqlite3_create_function(db, "sqlar_compress", 1,
|
|
304265
304414
|
SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
|
|
304266
304415
|
sqlarCompressFunc, 0, 0);
|
|
304267
304416
|
if( rc==SQLITE_OK ){
|
|
@@ -304365,10 +304514,10 @@ typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
|
|
|
304365
304514
|
/*
|
|
304366
304515
|
** Definitions for mode bitmasks S_IFDIR, S_IFREG and S_IFLNK.
|
|
304367
304516
|
**
|
|
304368
|
-
** In some ways it would be better to obtain these values from system
|
|
304517
|
+
** In some ways it would be better to obtain these values from system
|
|
304369
304518
|
** header files. But, the dependency is undesirable and (a) these
|
|
304370
304519
|
** have been stable for decades, (b) the values are part of POSIX and
|
|
304371
|
-
** are also made explicit in [man stat], and (c) are part of the
|
|
304520
|
+
** are also made explicit in [man stat], and (c) are part of the
|
|
304372
304521
|
** file format for zip archives.
|
|
304373
304522
|
*/
|
|
304374
304523
|
#ifndef S_IFDIR
|
|
@@ -304381,7 +304530,7 @@ typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
|
|
|
304381
304530
|
# define S_IFLNK 0120000
|
|
304382
304531
|
#endif
|
|
304383
304532
|
|
|
304384
|
-
static const char ZIPFILE_SCHEMA[] =
|
|
304533
|
+
static const char ZIPFILE_SCHEMA[] =
|
|
304385
304534
|
"CREATE TABLE y("
|
|
304386
304535
|
"name PRIMARY KEY," /* 0: Name of file in zip archive */
|
|
304387
304536
|
"mode," /* 1: POSIX mode for file */
|
|
@@ -304402,8 +304551,8 @@ static const char ZIPFILE_SCHEMA[] =
|
|
|
304402
304551
|
**
|
|
304403
304552
|
** ZIPFILE_NEWENTRY_MADEBY:
|
|
304404
304553
|
** Use this value for the "version-made-by" field in new zip file
|
|
304405
|
-
** entries. The upper byte indicates "unix", and the lower byte
|
|
304406
|
-
** indicates that the zip file matches pkzip specification 3.0.
|
|
304554
|
+
** entries. The upper byte indicates "unix", and the lower byte
|
|
304555
|
+
** indicates that the zip file matches pkzip specification 3.0.
|
|
304407
304556
|
** This is what info-zip seems to do.
|
|
304408
304557
|
**
|
|
304409
304558
|
** ZIPFILE_NEWENTRY_REQUIRED:
|
|
@@ -304432,7 +304581,7 @@ static const char ZIPFILE_SCHEMA[] =
|
|
|
304432
304581
|
#define ZIPFILE_SIGNATURE_EOCD 0x06054b50
|
|
304433
304582
|
|
|
304434
304583
|
/*
|
|
304435
|
-
** The sizes of the fixed-size part of each of the three main data
|
|
304584
|
+
** The sizes of the fixed-size part of each of the three main data
|
|
304436
304585
|
** structures in a zip archive.
|
|
304437
304586
|
*/
|
|
304438
304587
|
#define ZIPFILE_LFH_FIXED_SZ 30
|
|
@@ -304525,7 +304674,7 @@ struct ZipfileCDS {
|
|
|
304525
304674
|
*** uncompressed size 4 bytes
|
|
304526
304675
|
*** file name length 2 bytes
|
|
304527
304676
|
*** extra field length 2 bytes
|
|
304528
|
-
***
|
|
304677
|
+
***
|
|
304529
304678
|
*/
|
|
304530
304679
|
typedef struct ZipfileLFH ZipfileLFH;
|
|
304531
304680
|
struct ZipfileLFH {
|
|
@@ -304551,7 +304700,7 @@ struct ZipfileEntry {
|
|
|
304551
304700
|
ZipfileEntry *pNext; /* Next element in in-memory CDS */
|
|
304552
304701
|
};
|
|
304553
304702
|
|
|
304554
|
-
/*
|
|
304703
|
+
/*
|
|
304555
304704
|
** Cursor type for zipfile tables.
|
|
304556
304705
|
*/
|
|
304557
304706
|
typedef struct ZipfileCsr ZipfileCsr;
|
|
@@ -304624,7 +304773,7 @@ static void zipfileDequote(char *zIn){
|
|
|
304624
304773
|
|
|
304625
304774
|
/*
|
|
304626
304775
|
** Construct a new ZipfileTab virtual table object.
|
|
304627
|
-
**
|
|
304776
|
+
**
|
|
304628
304777
|
** argv[0] -> module name ("zipfile")
|
|
304629
304778
|
** argv[1] -> database name
|
|
304630
304779
|
** argv[2] -> table name
|
|
@@ -304693,7 +304842,7 @@ static void zipfileEntryFree(ZipfileEntry *p){
|
|
|
304693
304842
|
}
|
|
304694
304843
|
|
|
304695
304844
|
/*
|
|
304696
|
-
** Release resources that should be freed at the end of a write
|
|
304845
|
+
** Release resources that should be freed at the end of a write
|
|
304697
304846
|
** transaction.
|
|
304698
304847
|
*/
|
|
304699
304848
|
static void zipfileCleanupTransaction(ZipfileTab *pTab){
|
|
@@ -304802,7 +304951,7 @@ static void zipfileCursorErr(ZipfileCsr *pCsr, const char *zFmt, ...){
|
|
|
304802
304951
|
/*
|
|
304803
304952
|
** Read nRead bytes of data from offset iOff of file pFile into buffer
|
|
304804
304953
|
** aRead[]. Return SQLITE_OK if successful, or an SQLite error code
|
|
304805
|
-
** otherwise.
|
|
304954
|
+
** otherwise.
|
|
304806
304955
|
**
|
|
304807
304956
|
** If an error does occur, output variable (*pzErrmsg) may be set to point
|
|
304808
304957
|
** to an English language error message. It is the responsibility of the
|
|
@@ -305010,7 +305159,7 @@ static int zipfileScanExtra(u8 *aExtra, int nExtra, u32 *pmTime){
|
|
|
305010
305159
|
** File modification date:
|
|
305011
305160
|
** Bits 00-04: day
|
|
305012
305161
|
** Bits 05-08: month (1-12)
|
|
305013
|
-
** Bits 09-15: years from 1980
|
|
305162
|
+
** Bits 09-15: years from 1980
|
|
305014
305163
|
**
|
|
305015
305164
|
** https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
|
|
305016
305165
|
*/
|
|
@@ -305070,9 +305219,9 @@ static void zipfileMtimeToDos(ZipfileCDS *pCds, u32 mUnixTime){
|
|
|
305070
305219
|
pCds->mDate = pCds->mTime = 0;
|
|
305071
305220
|
}
|
|
305072
305221
|
|
|
305073
|
-
assert( mUnixTime<315507600
|
|
305074
|
-
|| mUnixTime==zipfileMtime(pCds)
|
|
305075
|
-
|| ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds))
|
|
305222
|
+
assert( mUnixTime<315507600
|
|
305223
|
+
|| mUnixTime==zipfileMtime(pCds)
|
|
305224
|
+
|| ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds))
|
|
305076
305225
|
/* || (mUnixTime % 2) */
|
|
305077
305226
|
);
|
|
305078
305227
|
}
|
|
@@ -305140,7 +305289,7 @@ static int zipfileGetEntry(
|
|
|
305140
305289
|
|
|
305141
305290
|
if( rc==SQLITE_OK ){
|
|
305142
305291
|
u32 *pt = &pNew->mUnixTime;
|
|
305143
|
-
pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead);
|
|
305292
|
+
pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead);
|
|
305144
305293
|
pNew->aExtra = (u8*)&pNew[1];
|
|
305145
305294
|
memcpy(pNew->aExtra, &aRead[nFile], nExtra);
|
|
305146
305295
|
if( pNew->cds.zFile==0 ){
|
|
@@ -305168,7 +305317,7 @@ static int zipfileGetEntry(
|
|
|
305168
305317
|
memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
|
|
305169
305318
|
}
|
|
305170
305319
|
}else{
|
|
305171
|
-
*pzErr = sqlite3_mprintf("failed to read LFH at offset %d",
|
|
305320
|
+
*pzErr = sqlite3_mprintf("failed to read LFH at offset %d",
|
|
305172
305321
|
(int)pNew->cds.iOffset
|
|
305173
305322
|
);
|
|
305174
305323
|
}
|
|
@@ -305220,8 +305369,8 @@ static int zipfileNext(sqlite3_vtab_cursor *cur){
|
|
|
305220
305369
|
return rc;
|
|
305221
305370
|
}
|
|
305222
305371
|
|
|
305223
|
-
static void zipfileFree(void *p) {
|
|
305224
|
-
sqlite3_free(p);
|
|
305372
|
+
static void zipfileFree(void *p) {
|
|
305373
|
+
sqlite3_free(p);
|
|
305225
305374
|
}
|
|
305226
305375
|
|
|
305227
305376
|
/*
|
|
@@ -305271,7 +305420,7 @@ static void zipfileInflate(
|
|
|
305271
305420
|
** Buffer aIn (size nIn bytes) contains uncompressed data. This function
|
|
305272
305421
|
** compresses it and sets (*ppOut) to point to a buffer containing the
|
|
305273
305422
|
** compressed data. The caller is responsible for eventually calling
|
|
305274
|
-
** sqlite3_free() to release buffer (*ppOut). Before returning, (*pnOut)
|
|
305423
|
+
** sqlite3_free() to release buffer (*ppOut). Before returning, (*pnOut)
|
|
305275
305424
|
** is set to the size of buffer (*ppOut) in bytes.
|
|
305276
305425
|
**
|
|
305277
305426
|
** If no error occurs, SQLITE_OK is returned. Otherwise, an SQLite error
|
|
@@ -305460,8 +305609,8 @@ static int zipfileReadEOCD(
|
|
|
305460
305609
|
|
|
305461
305610
|
/* Scan backwards looking for the signature bytes */
|
|
305462
305611
|
for(i=nRead-20; i>=0; i--){
|
|
305463
|
-
if( aRead[i]==0x50 && aRead[i+1]==0x4b
|
|
305464
|
-
&& aRead[i+2]==0x05 && aRead[i+3]==0x06
|
|
305612
|
+
if( aRead[i]==0x50 && aRead[i+1]==0x4b
|
|
305613
|
+
&& aRead[i+2]==0x05 && aRead[i+3]==0x06
|
|
305465
305614
|
){
|
|
305466
305615
|
break;
|
|
305467
305616
|
}
|
|
@@ -305486,14 +305635,14 @@ static int zipfileReadEOCD(
|
|
|
305486
305635
|
}
|
|
305487
305636
|
|
|
305488
305637
|
/*
|
|
305489
|
-
** Add object pNew to the linked list that begins at ZipfileTab.pFirstEntry
|
|
305638
|
+
** Add object pNew to the linked list that begins at ZipfileTab.pFirstEntry
|
|
305490
305639
|
** and ends with pLastEntry. If argument pBefore is NULL, then pNew is added
|
|
305491
305640
|
** to the end of the list. Otherwise, it is added to the list immediately
|
|
305492
305641
|
** before pBefore (which is guaranteed to be a part of said list).
|
|
305493
305642
|
*/
|
|
305494
305643
|
static void zipfileAddEntry(
|
|
305495
|
-
ZipfileTab *pTab,
|
|
305496
|
-
ZipfileEntry *pBefore,
|
|
305644
|
+
ZipfileTab *pTab,
|
|
305645
|
+
ZipfileEntry *pBefore,
|
|
305497
305646
|
ZipfileEntry *pNew
|
|
305498
305647
|
){
|
|
305499
305648
|
assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
|
|
@@ -305539,7 +305688,7 @@ static int zipfileLoadDirectory(ZipfileTab *pTab, const u8 *aBlob, int nBlob){
|
|
|
305539
305688
|
** xFilter callback.
|
|
305540
305689
|
*/
|
|
305541
305690
|
static int zipfileFilter(
|
|
305542
|
-
sqlite3_vtab_cursor *cur,
|
|
305691
|
+
sqlite3_vtab_cursor *cur,
|
|
305543
305692
|
int idxNum, const char *idxStr,
|
|
305544
305693
|
int argc, sqlite3_value **argv
|
|
305545
305694
|
){
|
|
@@ -305702,7 +305851,7 @@ static int zipfileAppendEntry(
|
|
|
305702
305851
|
}
|
|
305703
305852
|
|
|
305704
305853
|
static int zipfileGetMode(
|
|
305705
|
-
sqlite3_value *pVal,
|
|
305854
|
+
sqlite3_value *pVal,
|
|
305706
305855
|
int bIsDir, /* If true, default to directory */
|
|
305707
305856
|
u32 *pMode, /* OUT: Mode value */
|
|
305708
305857
|
char **pzErr /* OUT: Error message */
|
|
@@ -305765,7 +305914,7 @@ static int zipfileBegin(sqlite3_vtab *pVtab){
|
|
|
305765
305914
|
}
|
|
305766
305915
|
|
|
305767
305916
|
/* Open a write fd on the file. Also load the entire central directory
|
|
305768
|
-
** structure into memory. During the transaction any new file data is
|
|
305917
|
+
** structure into memory. During the transaction any new file data is
|
|
305769
305918
|
** appended to the archive file, but the central directory is accumulated
|
|
305770
305919
|
** in main-memory until the transaction is committed. */
|
|
305771
305920
|
pTab->pWriteFd = fopen(pTab->zFile, "ab+");
|
|
@@ -305848,9 +305997,9 @@ static void zipfileRemoveEntryFromList(ZipfileTab *pTab, ZipfileEntry *pOld){
|
|
|
305848
305997
|
** xUpdate method.
|
|
305849
305998
|
*/
|
|
305850
305999
|
static int zipfileUpdate(
|
|
305851
|
-
sqlite3_vtab *pVtab,
|
|
305852
|
-
int nVal,
|
|
305853
|
-
sqlite3_value **apVal,
|
|
306000
|
+
sqlite3_vtab *pVtab,
|
|
306001
|
+
int nVal,
|
|
306002
|
+
sqlite3_value **apVal,
|
|
305854
306003
|
sqlite_int64 *pRowid
|
|
305855
306004
|
){
|
|
305856
306005
|
ZipfileTab *pTab = (ZipfileTab*)pVtab;
|
|
@@ -305905,7 +306054,7 @@ static int zipfileUpdate(
|
|
|
305905
306054
|
rc = SQLITE_CONSTRAINT;
|
|
305906
306055
|
}
|
|
305907
306056
|
if( sqlite3_value_type(apVal[6])!=SQLITE_NULL ){
|
|
305908
|
-
zipfileTableErr(pTab, "rawdata must be NULL");
|
|
306057
|
+
zipfileTableErr(pTab, "rawdata must be NULL");
|
|
305909
306058
|
rc = SQLITE_CONSTRAINT;
|
|
305910
306059
|
}
|
|
305911
306060
|
|
|
@@ -306497,7 +306646,7 @@ static int zipfileRegister(sqlite3 *db){
|
|
|
306497
306646
|
int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0);
|
|
306498
306647
|
if( rc==SQLITE_OK ) rc = sqlite3_overload_function(db, "zipfile_cds", -1);
|
|
306499
306648
|
if( rc==SQLITE_OK ){
|
|
306500
|
-
rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0,
|
|
306649
|
+
rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0,
|
|
306501
306650
|
zipfileStep, zipfileFinal
|
|
306502
306651
|
);
|
|
306503
306652
|
}
|
|
@@ -306515,8 +306664,8 @@ static int zipfileRegister(sqlite3 *db){
|
|
|
306515
306664
|
__declspec(dllexport)
|
|
306516
306665
|
#endif
|
|
306517
306666
|
int sqlite3_zipfile_init(
|
|
306518
|
-
sqlite3 *db,
|
|
306519
|
-
char **pzErrMsg,
|
|
306667
|
+
sqlite3 *db,
|
|
306668
|
+
char **pzErrMsg,
|
|
306520
306669
|
const sqlite3_api_routines *pApi
|
|
306521
306670
|
){
|
|
306522
306671
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
@@ -306635,6 +306784,8 @@ static int mcIoUnfetch(sqlite3_file* pFile, sqlite3_int64 iOfst, void* p);
|
|
|
306635
306784
|
|
|
306636
306785
|
#define SQLITE3MC_VFS_NAME ("multipleciphers")
|
|
306637
306786
|
|
|
306787
|
+
#define SQLITE3MC_FCNTL_PVFS 0x3f98c078
|
|
306788
|
+
|
|
306638
306789
|
/*
|
|
306639
306790
|
** Header sizes of WAL journal files
|
|
306640
306791
|
*/
|
|
@@ -306750,7 +306901,7 @@ static void mcMainListRemove(sqlite3mc_file* pFile)
|
|
|
306750
306901
|
}
|
|
306751
306902
|
|
|
306752
306903
|
/*
|
|
306753
|
-
** Given that zFileName points to a buffer containing a database file name passed to
|
|
306904
|
+
** Given that zFileName points to a buffer containing a database file name passed to
|
|
306754
306905
|
** either the xOpen() or xAccess() VFS method, search the list of main database files
|
|
306755
306906
|
** for a file handle opened by the same database connection on the corresponding
|
|
306756
306907
|
** database file.
|
|
@@ -306779,36 +306930,29 @@ static sqlite3mc_vfs* mcFindVfs(sqlite3* db, const char* zDbName)
|
|
|
306779
306930
|
{
|
|
306780
306931
|
/*
|
|
306781
306932
|
** The top level VFS is not a Multiple Ciphers VFS.
|
|
306782
|
-
** Retrieve the VFS
|
|
306933
|
+
** Retrieve the Multiple Ciphers VFS via file control function,
|
|
306934
|
+
** if it is included in the VFS stack.
|
|
306783
306935
|
*/
|
|
306784
|
-
|
|
306785
|
-
if ((sqlite3_file_control(db, zDbName,
|
|
306936
|
+
sqlite3mc_vfs* pVfs = NULL;
|
|
306937
|
+
if ((sqlite3_file_control(db, zDbName, SQLITE3MC_FCNTL_PVFS, &pVfs) == SQLITE_OK) &&
|
|
306938
|
+
(pVfs && pVfs->base.xOpen == mcVfsOpen))
|
|
306786
306939
|
{
|
|
306787
|
-
|
|
306788
|
-
char* zVfsName = strstr(zVfsNameStack, SQLITE3MC_VFS_NAME);
|
|
306789
|
-
if (zVfsName != NULL)
|
|
306790
|
-
{
|
|
306791
|
-
/* The prefix was found, now determine the full VFS name. */
|
|
306792
|
-
char* zVfsNameEnd = zVfsName + strlen(SQLITE3MC_VFS_NAME);
|
|
306793
|
-
if (*zVfsNameEnd == '-')
|
|
306794
|
-
{
|
|
306795
|
-
for (++zVfsNameEnd; *zVfsNameEnd != '/' && *zVfsNameEnd != 0; ++zVfsNameEnd);
|
|
306796
|
-
if (*zVfsNameEnd == '/') *zVfsNameEnd = 0;
|
|
306797
|
-
|
|
306798
|
-
/* Find a pointer to the VFS with the determined name. */
|
|
306799
|
-
sqlite3_vfs* pVfs = sqlite3_vfs_find(zVfsName);
|
|
306800
|
-
if (pVfs && pVfs->xOpen == mcVfsOpen)
|
|
306801
|
-
{
|
|
306802
|
-
pVfsMC = (sqlite3mc_vfs*) pVfs;
|
|
306803
|
-
}
|
|
306804
|
-
}
|
|
306805
|
-
}
|
|
306806
|
-
sqlite3_free(zVfsNameStack);
|
|
306940
|
+
pVfsMC = pVfs;
|
|
306807
306941
|
}
|
|
306808
306942
|
}
|
|
306809
306943
|
return pVfsMC;
|
|
306810
306944
|
}
|
|
306811
306945
|
|
|
306946
|
+
/*
|
|
306947
|
+
** Check whether the VFS of the database file corresponding
|
|
306948
|
+
** to the database schema name supports encryption.
|
|
306949
|
+
*/
|
|
306950
|
+
SQLITE_PRIVATE int sqlite3mcIsEncryptionSupported(sqlite3* db, const char* zDbName)
|
|
306951
|
+
{
|
|
306952
|
+
sqlite3mc_vfs* pVfsMC = mcFindVfs(db, zDbName);
|
|
306953
|
+
return (pVfsMC != NULL);
|
|
306954
|
+
}
|
|
306955
|
+
|
|
306812
306956
|
/*
|
|
306813
306957
|
** Find the codec of the database file
|
|
306814
306958
|
** corresponding to the database schema name.
|
|
@@ -306838,6 +306982,30 @@ SQLITE_PRIVATE Codec* sqlite3mcGetMainCodec(sqlite3* db)
|
|
|
306838
306982
|
return sqlite3mcGetCodec(db, "main");
|
|
306839
306983
|
}
|
|
306840
306984
|
|
|
306985
|
+
SQLITE_PRIVATE int sqlite3mcIsBackupSupported(sqlite3* pSrc, const char* zSrc, sqlite3* pDest, const char* zDest)
|
|
306986
|
+
{
|
|
306987
|
+
int ok = 1;
|
|
306988
|
+
if (pSrc != pDest)
|
|
306989
|
+
{
|
|
306990
|
+
Codec* codecSrc = sqlite3mcGetCodec(pSrc, zSrc);
|
|
306991
|
+
Codec* codecDest = sqlite3mcGetCodec(pDest, zDest);
|
|
306992
|
+
if (codecSrc && codecDest)
|
|
306993
|
+
{
|
|
306994
|
+
/* Both databases have a codec, are encrypted, and have the same page size */
|
|
306995
|
+
ok = sqlite3mcIsEncrypted(codecSrc) && sqlite3mcIsEncrypted(codecDest) &&
|
|
306996
|
+
(sqlite3mcGetPageSizeReadCipher(codecSrc) == sqlite3mcGetPageSizeWriteCipher(codecDest)) &&
|
|
306997
|
+
(sqlite3mcGetReadReserved(codecSrc) == sqlite3mcGetWriteReserved(codecDest));
|
|
306998
|
+
}
|
|
306999
|
+
else
|
|
307000
|
+
{
|
|
307001
|
+
/* At least one database has no codec */
|
|
307002
|
+
/* Backup supported if both databases are plain databases */
|
|
307003
|
+
ok = !codecSrc && !codecDest;
|
|
307004
|
+
}
|
|
307005
|
+
}
|
|
307006
|
+
return ok;
|
|
307007
|
+
}
|
|
307008
|
+
|
|
306841
307009
|
/*
|
|
306842
307010
|
** Set the codec of the database file with the given database file name.
|
|
306843
307011
|
**
|
|
@@ -306854,12 +307022,13 @@ SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const ch
|
|
|
306854
307022
|
sqlite3mc_vfs* pVfsMC = mcFindVfs(db, zDbName);
|
|
306855
307023
|
if (pVfsMC)
|
|
306856
307024
|
{
|
|
306857
|
-
pDbMain = mcFindDbMainFileName(
|
|
307025
|
+
pDbMain = mcFindDbMainFileName(pVfsMC, zFileName);
|
|
306858
307026
|
}
|
|
306859
307027
|
if (pDbMain)
|
|
306860
307028
|
{
|
|
306861
307029
|
Codec* prevCodec = pDbMain->codec;
|
|
306862
307030
|
Codec* msgCodec = (codec) ? codec : prevCodec;
|
|
307031
|
+
pDbMain->codec = codec;
|
|
306863
307032
|
if (msgCodec)
|
|
306864
307033
|
{
|
|
306865
307034
|
/* Reset error state of pager */
|
|
@@ -306872,7 +307041,6 @@ SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const ch
|
|
|
306872
307041
|
*/
|
|
306873
307042
|
sqlite3mcCodecFree(prevCodec);
|
|
306874
307043
|
}
|
|
306875
|
-
pDbMain->codec = codec;
|
|
306876
307044
|
}
|
|
306877
307045
|
else
|
|
306878
307046
|
{
|
|
@@ -306894,8 +307062,8 @@ SQLITE_PRIVATE void* sqlite3mcPagerCodec(PgHdrMC* pPg)
|
|
|
306894
307062
|
{
|
|
306895
307063
|
sqlite3_file* pFile = sqlite3PagerFile(pPg->pPager);
|
|
306896
307064
|
void* aData = 0;
|
|
306897
|
-
if (pFile->pMethods == &mcIoMethodsGlobal1 ||
|
|
306898
|
-
pFile->pMethods == &mcIoMethodsGlobal2 ||
|
|
307065
|
+
if (pFile->pMethods == &mcIoMethodsGlobal1 ||
|
|
307066
|
+
pFile->pMethods == &mcIoMethodsGlobal2 ||
|
|
306899
307067
|
pFile->pMethods == &mcIoMethodsGlobal3)
|
|
306900
307068
|
{
|
|
306901
307069
|
sqlite3mc_file* mcFile = (sqlite3mc_file*) pFile;
|
|
@@ -307169,6 +307337,7 @@ static int mcReadMainDb(sqlite3_file* pFile, void* buffer, int count, sqlite3_in
|
|
|
307169
307337
|
*/
|
|
307170
307338
|
pageNo = prevOffset / pageSize + 1;
|
|
307171
307339
|
bufferDecrypted = sqlite3mcCodec(mcFile->codec, pageBuffer, pageNo, 3);
|
|
307340
|
+
rc = sqlite3mcGetCodecLastError(mcFile->codec);
|
|
307172
307341
|
|
|
307173
307342
|
/*
|
|
307174
307343
|
** Return the requested content
|
|
@@ -307197,6 +307366,7 @@ static int mcReadMainDb(sqlite3_file* pFile, void* buffer, int count, sqlite3_in
|
|
|
307197
307366
|
for (iPage = 0; iPage < nPages; ++iPage)
|
|
307198
307367
|
{
|
|
307199
307368
|
void* bufferDecrypted = sqlite3mcCodec(mcFile->codec, data, pageNo, 3);
|
|
307369
|
+
rc = sqlite3mcGetCodecLastError(mcFile->codec);
|
|
307200
307370
|
data += pageSize;
|
|
307201
307371
|
offset += pageSize;
|
|
307202
307372
|
++pageNo;
|
|
@@ -307225,6 +307395,7 @@ static int mcReadMainJournal(sqlite3_file* pFile, const void* buffer, int count,
|
|
|
307225
307395
|
** Decrypt the page buffer, but only if the page number is valid
|
|
307226
307396
|
*/
|
|
307227
307397
|
void* bufferDecrypted = sqlite3mcCodec(codec, (char*) buffer, mcFile->pageNo, 3);
|
|
307398
|
+
rc = sqlite3mcGetCodecLastError(codec);
|
|
307228
307399
|
mcFile->pageNo = 0;
|
|
307229
307400
|
}
|
|
307230
307401
|
else if (count == 4)
|
|
@@ -307258,6 +307429,7 @@ static int mcReadSubJournal(sqlite3_file* pFile, const void* buffer, int count,
|
|
|
307258
307429
|
** Decrypt the page buffer, but only if the page number is valid
|
|
307259
307430
|
*/
|
|
307260
307431
|
void* bufferDecrypted = sqlite3mcCodec(codec, (char*) buffer, mcFile->pageNo, 3);
|
|
307432
|
+
rc = sqlite3mcGetCodecLastError(codec);
|
|
307261
307433
|
}
|
|
307262
307434
|
else if (count == 4)
|
|
307263
307435
|
{
|
|
@@ -307306,6 +307478,7 @@ static int mcReadWal(sqlite3_file* pFile, const void* buffer, int count, sqlite3
|
|
|
307306
307478
|
if (pageNo != 0)
|
|
307307
307479
|
{
|
|
307308
307480
|
void* bufferDecrypted = sqlite3mcCodec(codec, (char*)buffer, pageNo, 3);
|
|
307481
|
+
rc = sqlite3mcGetCodecLastError(codec);
|
|
307309
307482
|
}
|
|
307310
307483
|
}
|
|
307311
307484
|
else if (codec->m_walLegacy != 0 && count == pageSize + walFrameHeaderSize)
|
|
@@ -307318,6 +307491,7 @@ static int mcReadWal(sqlite3_file* pFile, const void* buffer, int count, sqlite3
|
|
|
307318
307491
|
if (pageNo != 0)
|
|
307319
307492
|
{
|
|
307320
307493
|
void* bufferDecrypted = sqlite3mcCodec(codec, (char*)buffer+walFrameHeaderSize, pageNo, 3);
|
|
307494
|
+
rc = sqlite3mcGetCodecLastError(codec);
|
|
307321
307495
|
}
|
|
307322
307496
|
}
|
|
307323
307497
|
}
|
|
@@ -307729,6 +307903,12 @@ static int mcIoFileControl(sqlite3_file* pFile, int op, void* pArg)
|
|
|
307729
307903
|
|
|
307730
307904
|
switch (op)
|
|
307731
307905
|
{
|
|
307906
|
+
case SQLITE3MC_FCNTL_PVFS:
|
|
307907
|
+
{
|
|
307908
|
+
*(sqlite3mc_vfs**) pArg = p->pVfsMC;
|
|
307909
|
+
doReal = 0;
|
|
307910
|
+
}
|
|
307911
|
+
break;
|
|
307732
307912
|
case SQLITE_FCNTL_PDB:
|
|
307733
307913
|
{
|
|
307734
307914
|
#if 0
|
|
@@ -307745,7 +307925,7 @@ static int mcIoFileControl(sqlite3_file* pFile, int op, void* pArg)
|
|
|
307745
307925
|
*/
|
|
307746
307926
|
sqlite3* db = *((sqlite3**) pArg);
|
|
307747
307927
|
#endif
|
|
307748
|
-
|
|
307928
|
+
}
|
|
307749
307929
|
break;
|
|
307750
307930
|
case SQLITE_FCNTL_PRAGMA:
|
|
307751
307931
|
{
|
|
@@ -308321,7 +308501,7 @@ sqlite3mcTermCipherTables()
|
|
|
308321
308501
|
globalCipherCount = 0;
|
|
308322
308502
|
}
|
|
308323
308503
|
|
|
308324
|
-
int
|
|
308504
|
+
SQLITE_PRIVATE int
|
|
308325
308505
|
sqlite3mc_initialize(const char* arg)
|
|
308326
308506
|
{
|
|
308327
308507
|
int rc = sqlite3mcInitCipherTables();
|
|
@@ -308453,7 +308633,7 @@ sqlite3mc_initialize(const char* arg)
|
|
|
308453
308633
|
return rc;
|
|
308454
308634
|
}
|
|
308455
308635
|
|
|
308456
|
-
void
|
|
308636
|
+
SQLITE_PRIVATE void
|
|
308457
308637
|
sqlite3mc_shutdown(void)
|
|
308458
308638
|
{
|
|
308459
308639
|
sqlite3mc_vfs_shutdown();
|
|
@@ -309526,7 +309706,7 @@ static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value**argv){
|
|
|
309526
309706
|
eType = SQLITE_BLOB;
|
|
309527
309707
|
}else if( (c=='b' && strcmp(zType,"boolean")==0)
|
|
309528
309708
|
|| (c=='w' && strcmp(zType,"wideInt")==0)
|
|
309529
|
-
|| (c=='i' && strcmp(zType,"int")==0)
|
|
309709
|
+
|| (c=='i' && strcmp(zType,"int")==0)
|
|
309530
309710
|
){
|
|
309531
309711
|
eType = SQLITE_INTEGER;
|
|
309532
309712
|
}else if( c=='d' && strcmp(zType,"double")==0 ){
|
|
@@ -310326,9 +310506,9 @@ static int SQLITE_TCLAPI DbEvalNextCmd(
|
|
|
310326
310506
|
if( pArray==0 ){
|
|
310327
310507
|
Tcl_ObjSetVar2(interp, apColName[i], 0, dbEvalColumnValue(p,i), 0);
|
|
310328
310508
|
}else if( (p->evalFlags & SQLITE_EVAL_WITHOUTNULLS)!=0
|
|
310329
|
-
&& sqlite3_column_type(p->pPreStmt->pStmt, i)==SQLITE_NULL
|
|
310509
|
+
&& sqlite3_column_type(p->pPreStmt->pStmt, i)==SQLITE_NULL
|
|
310330
310510
|
){
|
|
310331
|
-
Tcl_UnsetVar2(interp, Tcl_GetString(pArray),
|
|
310511
|
+
Tcl_UnsetVar2(interp, Tcl_GetString(pArray),
|
|
310332
310512
|
Tcl_GetString(apColName[i]), 0);
|
|
310333
310513
|
}else{
|
|
310334
310514
|
Tcl_ObjSetVar2(interp, pArray, apColName[i], dbEvalColumnValue(p,i), 0);
|
|
@@ -310440,7 +310620,7 @@ static int SQLITE_TCLAPI DbObjCmd(
|
|
|
310440
310620
|
"timeout", "total_changes", "trace",
|
|
310441
310621
|
"trace_v2", "transaction", "unlock_notify",
|
|
310442
310622
|
"update_hook", "version", "wal_hook",
|
|
310443
|
-
0
|
|
310623
|
+
0
|
|
310444
310624
|
};
|
|
310445
310625
|
enum DB_enum {
|
|
310446
310626
|
DB_AUTHORIZER, DB_BACKUP, DB_BIND_FALLBACK,
|
|
@@ -310586,7 +310766,7 @@ static int SQLITE_TCLAPI DbObjCmd(
|
|
|
310586
310766
|
** value of the CALLBACK as the binding. If CALLBACK returns something
|
|
310587
310767
|
** other than TCL_OK or TCL_ERROR then bind a NULL.
|
|
310588
310768
|
**
|
|
310589
|
-
** If CALLBACK is an empty string, then revert to the default behavior
|
|
310769
|
+
** If CALLBACK is an empty string, then revert to the default behavior
|
|
310590
310770
|
** which is to set the binding to NULL.
|
|
310591
310771
|
**
|
|
310592
310772
|
** If CALLBACK returns an error, that causes the statement execution to
|
|
@@ -311180,7 +311360,7 @@ static int SQLITE_TCLAPI DbObjCmd(
|
|
|
311180
311360
|
}
|
|
311181
311361
|
deserialize_error:
|
|
311182
311362
|
#endif
|
|
311183
|
-
break;
|
|
311363
|
+
break;
|
|
311184
311364
|
}
|
|
311185
311365
|
|
|
311186
311366
|
/*
|
|
@@ -311290,7 +311470,7 @@ deserialize_error:
|
|
|
311290
311470
|
objv++;
|
|
311291
311471
|
}
|
|
311292
311472
|
if( objc<3 || objc>5 ){
|
|
311293
|
-
Tcl_WrongNumArgs(interp, 2, objv,
|
|
311473
|
+
Tcl_WrongNumArgs(interp, 2, objv,
|
|
311294
311474
|
"?OPTIONS? SQL ?ARRAY-NAME? ?SCRIPT?");
|
|
311295
311475
|
return TCL_ERROR;
|
|
311296
311476
|
}
|
|
@@ -311693,7 +311873,7 @@ deserialize_error:
|
|
|
311693
311873
|
/*
|
|
311694
311874
|
** $db serialize ?DATABASE?
|
|
311695
311875
|
**
|
|
311696
|
-
** Return a serialization of a database.
|
|
311876
|
+
** Return a serialization of a database.
|
|
311697
311877
|
*/
|
|
311698
311878
|
case DB_SERIALIZE: {
|
|
311699
311879
|
#ifdef SQLITE_OMIT_DESERIALIZE
|
|
@@ -312019,7 +312199,7 @@ deserialize_error:
|
|
|
312019
312199
|
*/
|
|
312020
312200
|
case DB_PREUPDATE: {
|
|
312021
312201
|
#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
|
|
312022
|
-
Tcl_AppendResult(interp, "preupdate_hook was omitted at compile-time",
|
|
312202
|
+
Tcl_AppendResult(interp, "preupdate_hook was omitted at compile-time",
|
|
312023
312203
|
(char*)0);
|
|
312024
312204
|
rc = TCL_ERROR;
|
|
312025
312205
|
#else
|
|
@@ -312158,7 +312338,7 @@ deserialize_error:
|
|
|
312158
312338
|
return TCL_ERROR;
|
|
312159
312339
|
}
|
|
312160
312340
|
}
|
|
312161
|
-
if( i==2 ){
|
|
312341
|
+
if( i==2 ){
|
|
312162
312342
|
Tcl_SetResult(interp, (char *)sqlite3_libversion(), TCL_STATIC);
|
|
312163
312343
|
}
|
|
312164
312344
|
break;
|