3535
3636#include "sqliteInt.h"
3737#include "btreeInt.h"
38+ #include "sqlcipher.h"
3839#include "crypto.h"
3940#ifndef OMIT_MEMLOCK
4041#if defined(__unix__ ) || defined(__APPLE__ )
@@ -65,16 +66,6 @@ typedef struct {
6566 void * provider_ctx ;
6667} cipher_ctx ;
6768
68- void sqlcipher_cipher_ctx_free (cipher_ctx * * );
69- int sqlcipher_cipher_ctx_cmp (cipher_ctx * , cipher_ctx * );
70- int sqlcipher_cipher_ctx_copy (cipher_ctx * , cipher_ctx * );
71- int sqlcipher_cipher_ctx_init (cipher_ctx * * );
72- int sqlcipher_cipher_ctx_set_pass (cipher_ctx * , const void * , int );
73- int sqlcipher_cipher_ctx_key_derive (codec_ctx * , cipher_ctx * );
74-
75- /* prototype for pager HMAC function */
76- int sqlcipher_page_hmac (cipher_ctx * , Pgno , unsigned char * , int , unsigned char * );
77-
7869static unsigned int default_flags = DEFAULT_CIPHER_FLAGS ;
7970static unsigned char hmac_salt_mask = HMAC_SALT_MASK ;
8071
@@ -91,7 +82,7 @@ struct codec_ctx {
9182 cipher_ctx * write_ctx ;
9283};
9384
94- static int sqlcipher_register_provider (sqlcipher_provider * p ) {
85+ int sqlcipher_register_provider (sqlcipher_provider * p ) {
9586 if (default_provider != NULL ) {
9687 sqlcipher_free (default_provider , sizeof (sqlcipher_provider ));
9788 }
@@ -221,7 +212,7 @@ void* sqlcipher_malloc(int sz) {
221212 * returns SQLITE_OK if initialization was successful
222213 * returns SQLITE_NOMEM if an error occured allocating memory
223214 */
224- int sqlcipher_cipher_ctx_init (cipher_ctx * * iCtx ) {
215+ static int sqlcipher_cipher_ctx_init (cipher_ctx * * iCtx ) {
225216 int rc ;
226217 cipher_ctx * ctx ;
227218 * iCtx = (cipher_ctx * ) sqlcipher_malloc (sizeof (cipher_ctx ));
@@ -247,7 +238,7 @@ int sqlcipher_cipher_ctx_init(cipher_ctx **iCtx) {
247238/**
248239 * Free and wipe memory associated with a cipher_ctx
249240 */
250- void sqlcipher_cipher_ctx_free (cipher_ctx * * iCtx ) {
241+ static void sqlcipher_cipher_ctx_free (cipher_ctx * * iCtx ) {
251242 cipher_ctx * ctx = * iCtx ;
252243 CODEC_TRACE (("cipher_ctx_free: entered iCtx=%p\n" , iCtx ));
253244 ctx -> provider -> ctx_free (& ctx -> provider_ctx );
@@ -264,7 +255,7 @@ void sqlcipher_cipher_ctx_free(cipher_ctx **iCtx) {
264255 * returns 0 if all the parameters (except the derived key data) are the same
265256 * returns 1 otherwise
266257 */
267- int sqlcipher_cipher_ctx_cmp (cipher_ctx * c1 , cipher_ctx * c2 ) {
258+ static int sqlcipher_cipher_ctx_cmp (cipher_ctx * c1 , cipher_ctx * c2 ) {
268259 CODEC_TRACE (("sqlcipher_cipher_ctx_cmp: entered c1=%p c2=%p\n" , c1 , c2 ));
269260
270261 if (
@@ -294,7 +285,7 @@ int sqlcipher_cipher_ctx_cmp(cipher_ctx *c1, cipher_ctx *c2) {
294285 * returns SQLITE_OK if initialization was successful
295286 * returns SQLITE_NOMEM if an error occured allocating memory
296287 */
297- int sqlcipher_cipher_ctx_copy (cipher_ctx * target , cipher_ctx * source ) {
288+ static int sqlcipher_cipher_ctx_copy (cipher_ctx * target , cipher_ctx * source ) {
298289 void * key = target -> key ;
299290 void * hmac_key = target -> hmac_key ;
300291 void * provider = target -> provider ;
@@ -331,7 +322,7 @@ int sqlcipher_cipher_ctx_copy(cipher_ctx *target, cipher_ctx *source) {
331322 * returns SQLITE_NOMEM if an error occured allocating memory
332323 * returns SQLITE_ERROR if the key couldn't be set because the pass was null or size was zero
333324 */
334- int sqlcipher_cipher_ctx_set_pass (cipher_ctx * ctx , const void * zKey , int nKey ) {
325+ static int sqlcipher_cipher_ctx_set_pass (cipher_ctx * ctx , const void * zKey , int nKey ) {
335326 sqlcipher_free (ctx -> pass , ctx -> pass_sz );
336327 ctx -> pass_sz = nKey ;
337328 if (zKey && nKey ) {
@@ -603,7 +594,7 @@ static void sqlcipher_put4byte_le(unsigned char *p, u32 v) {
603594 p [3 ] = (u8 )(v >>24 );
604595}
605596
606- int sqlcipher_page_hmac (cipher_ctx * ctx , Pgno pgno , unsigned char * in , int in_sz , unsigned char * out ) {
597+ static int sqlcipher_page_hmac (cipher_ctx * ctx , Pgno pgno , unsigned char * in , int in_sz , unsigned char * out ) {
607598 unsigned char pgno_raw [sizeof (pgno )];
608599 /* we may convert page number to consistent representation before calculating MAC for
609600 compatibility across big-endian and little-endian platforms.
@@ -723,7 +714,7 @@ int sqlcipher_page_cipher(codec_ctx *ctx, int for_ctx, Pgno pgno, int mode, int
723714 * returns SQLITE_OK if initialization was successful
724715 * returns SQLITE_ERROR if the key could't be derived (for instance if pass is NULL or pass_sz is 0)
725716 */
726- int sqlcipher_cipher_ctx_key_derive (codec_ctx * ctx , cipher_ctx * c_ctx ) {
717+ static int sqlcipher_cipher_ctx_key_derive (codec_ctx * ctx , cipher_ctx * c_ctx ) {
727718 CODEC_TRACE (("codec_key_derive: entered c_ctx->pass=%s, c_ctx->pass_sz=%d \
728719 ctx->kdf_salt=%p ctx->kdf_salt_sz=%d c_ctx->kdf_iter=%d \
729720 ctx->hmac_kdf_salt=%p, c_ctx->fast_kdf_iter=%d c_ctx->key_sz=%d\n" ,
0 commit comments