From: drh Date: Wed, 1 Jan 2014 14:00:13 +0000 (+0000) Subject: Enhance sqlite3_randomness(N,P) such that it resets the internal PRNG X-Git-Tag: version-3.8.3~70 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe98081e18e03e4f3a3389f94b44eeb201276721;p=thirdparty%2Fsqlite.git Enhance sqlite3_randomness(N,P) such that it resets the internal PRNG if N is less than 1. Subsequent calls to sqlite3_randomness() will reinitialize the internal PRNG by calling the xRandomness() method of the default VFS. FossilOrigin-Name: a221aa82bb5496885fd0bf76e4601443799511de --- diff --git a/manifest b/manifest index 56fb6db832..df2e8029ab 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\s-I.\sto\sthe\smain.mk\smakefile\sfor\sbuilding\ssqlite3.o\sand\sspeedtest1. -D 2013-12-24T12:04:24.811 +C Enhance\ssqlite3_randomness(N,P)\ssuch\sthat\sit\sresets\sthe\sinternal\sPRNG\nif\sN\sis\sless\sthan\s1.\s\sSubsequent\scalls\sto\ssqlite3_randomness()\swill\sreinitialize\nthe\sinternal\sPRNG\sby\scalling\sthe\sxRandomness()\smethod\sof\sthe\sdefault\sVFS. +D 2014-01-01T14:00:13.905 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -188,7 +188,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c 5307601c58b6e08153a15846098399a59c166d8d +F src/main.c 37f55de2000f6c882414ad3e1bcdb751c531fddd F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b @@ -216,15 +216,15 @@ F src/pcache1.c 57fee9a9a617218f5037afbbe49b09da65bde56b F src/pragma.c 5ab7279d132143feb77f773688a24ab05da75fd7 F src/prepare.c 677521ab7132615a8a26107a1d1c3132f44ae337 F src/printf.c 85d07756e45d7496d19439dcae3e6e9e0090f269 -F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68 +F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 819bb090c9a348d17f69f136cad2bfa9ee9cbb41 F src/shell.c a3541193d5fce37e91dad8ef46a9505aa7c9b344 -F src/sqlite.h.in 4ef56464aeaa3785a2c5ca37fb3a0fb229d68b2e +F src/sqlite.h.in d94a8b89522f526ba711182ee161e06f8669bcc9 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h fdb8c1e4bc5424ad82a9394a845781abf0d7d849 +F src/sqliteInt.h 62664868458b53a815380733f059ff9d92cb08be F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -1147,7 +1147,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P c289a253c0c053ac8fc344efe138262c327d8096 -R 2bb3d3295c5bbe58e528a8069b6e67b9 +P cc72c5aec7fe93d4a1368517aab949dc98d33003 +R 4dbb82094f79fe324b8594c5661b9532 U drh -Z 2be15cf525011fea6a70c12bcaf2ac37 +Z 7f33812905741a2d8942dba59b43dd66 diff --git a/manifest.uuid b/manifest.uuid index 5e0ef5b21c..691c3bd9a8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cc72c5aec7fe93d4a1368517aab949dc98d33003 \ No newline at end of file +a221aa82bb5496885fd0bf76e4601443799511de \ No newline at end of file diff --git a/src/main.c b/src/main.c index fff1bc42e6..13ad2b9081 100644 --- a/src/main.c +++ b/src/main.c @@ -3101,7 +3101,7 @@ int sqlite3_test_control(int op, ...){ ** to the xRandomness method of the default VFS. */ case SQLITE_TESTCTRL_PRNG_RESET: { - sqlite3PrngResetState(); + sqlite3_randomness(0,0); break; } diff --git a/src/random.c b/src/random.c index 7afff50885..b82566524c 100644 --- a/src/random.c +++ b/src/random.c @@ -52,6 +52,12 @@ void sqlite3_randomness(int N, void *pBuf){ sqlite3_mutex_enter(mutex); #endif + if( N<=0 ){ + wsdPrng.isInit = 0; + sqlite3_mutex_leave(mutex); + return; + } + /* Initialize the state of the random number generator once, ** the first time this routine is called. The seed value does ** not need to contain a lot of randomness since we are not @@ -79,7 +85,8 @@ void sqlite3_randomness(int N, void *pBuf){ wsdPrng.isInit = 1; } - while( N-- ){ + assert( N>0 ); + do{ wsdPrng.i++; t = wsdPrng.s[wsdPrng.i]; wsdPrng.j += t; @@ -87,7 +94,7 @@ void sqlite3_randomness(int N, void *pBuf){ wsdPrng.s[wsdPrng.j] = t; t += wsdPrng.s[wsdPrng.i]; *(zBuf++) = wsdPrng.s[t]; - } + }while( --N ); sqlite3_mutex_leave(mutex); } @@ -116,7 +123,4 @@ void sqlite3PrngRestoreState(void){ sizeof(sqlite3Prng) ); } -void sqlite3PrngResetState(void){ - GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0; -} #endif /* SQLITE_OMIT_BUILTIN_TEST */ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 7b0e648bfc..5012f864a5 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2395,11 +2395,13 @@ sqlite3_int64 sqlite3_memory_highwater(int resetFlag); ** applications to access the same PRNG for other purposes. ** ** ^A call to this routine stores N bytes of randomness into buffer P. +** ^If N is less than one, then P can be a NULL pointer. ** -** ^The first time this routine is invoked (either internally or by -** the application) the PRNG is seeded using randomness obtained -** from the xRandomness method of the default [sqlite3_vfs] object. -** ^On all subsequent invocations, the pseudo-randomness is generated +** ^If this routine has not been previously called or if the previous +** call had N less than one, then the PRNG is seeded using randomness +** obtained from the xRandomness method of the default [sqlite3_vfs] object. +** ^If the previous call to this routine had an N of 1 or more then +** the pseudo-randomness is generated ** internally and without recourse to the [sqlite3_vfs] xRandomness ** method. */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e7dc69cc73..77ed38374f 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2972,7 +2972,6 @@ int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); Vdbe *sqlite3GetVdbe(Parse*); void sqlite3PrngSaveState(void); void sqlite3PrngRestoreState(void); -void sqlite3PrngResetState(void); void sqlite3RollbackAll(sqlite3*,int); void sqlite3CodeVerifySchema(Parse*, int); void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);