Skip to content

Commit 20d7831

Browse files
committed
tighten up public functions
1 parent c7f1d14 commit 20d7831

5 files changed

Lines changed: 21 additions & 51 deletions

File tree

Makefile.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ LTLINK_EXTRAS += $(GCOV_LDFLAGS$(USE_GCOV))
135135
# BEGIN CRYPTO
136136
CRYPTOLIBOBJ = \
137137
crypto.lo \
138-
crypto_impl.lo
138+
crypto_impl.lo \
139+
crypto_openssl.lo \
140+
crypto_libtomcrypt.lo
139141

140142
CRYPTOSRC = \
141143
$(TOP)/src/crypto.h \
@@ -590,6 +592,10 @@ crypto.lo: $(TOP)/src/crypto.c $(HDR)
590592
$(LTCOMPILE) -c $(TOP)/src/crypto.c
591593
crypto_impl.lo: $(TOP)/src/crypto_impl.c $(HDR)
592594
$(LTCOMPILE) -c $(TOP)/src/crypto_impl.c
595+
crypto_openssl.lo: $(TOP)/src/crypto_openssl.c $(HDR)
596+
$(LTCOMPILE) -c $(TOP)/src/crypto_openssl.c
597+
crypto_libtomcrypt.lo: $(TOP)/src/crypto_libtomcrypt.c $(HDR)
598+
$(LTCOMPILE) -c $(TOP)/src/crypto_libtomcrypt.c
593599
# END CRYPTO
594600

595601
# Rules to build individual *.o files from files in the src directory.

src/crypto.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,8 @@ static void cipher_hex2bin(const char *hex, int sz, unsigned char *out){
144144
}
145145

146146
/* extensions defined in crypto_impl.c */
147-
148147
typedef struct codec_ctx codec_ctx;
149148

150-
void sqlcipher_free(void *ptr, int sz);
151-
void* sqlcipher_malloc(int sz);
152-
153-
/* utility functions */
154-
void* sqlcipher_memset(void *v, unsigned char value, int len);
155-
int sqlcipher_ismemset(const void *v, unsigned char value, int len);
156-
int sqlcipher_memcmp(const void *v0, const void *v1, int len);
157-
int sqlcipher_pseudorandom(void *, int);
158-
void sqlcipher_free(void *, int);
159-
160149
/* activation and initialization */
161150
void sqlcipher_activate();
162151
void sqlcipher_deactivate();
@@ -206,27 +195,6 @@ int sqlcipher_codec_ctx_set_flag(codec_ctx *ctx, unsigned int flag);
206195
int sqlcipher_codec_ctx_unset_flag(codec_ctx *ctx, unsigned int flag);
207196
int sqlcipher_codec_ctx_get_flag(codec_ctx *ctx, unsigned int flag, int for_ctx);
208197

209-
/* end extensions defined in crypto_impl.c */
210-
211-
typedef struct {
212-
int (*activate)(void *ctx);
213-
int (*deactivate)(void *ctx);
214-
int (*random)(void *ctx, void *buffer, int length);
215-
int (*hmac)(void *ctx, unsigned char *hmac_key, int key_sz, unsigned char *in, int in_sz, unsigned char *in2, int in2_sz, unsigned char *out);
216-
int (*kdf)(void *ctx, const unsigned char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key);
217-
int (*cipher)(void *ctx, int mode, unsigned char *key, int key_sz, unsigned char *iv, unsigned char *in, int in_sz, unsigned char *out);
218-
int (*set_cipher)(void *ctx, const char *cipher_name);
219-
const char* (*get_cipher)(void *ctx);
220-
int (*get_key_sz)(void *ctx);
221-
int (*get_iv_sz)(void *ctx);
222-
int (*get_block_sz)(void *ctx);
223-
int (*get_hmac_sz)(void *ctx);
224-
int (*ctx_copy)(void *target_ctx, void *source_ctx);
225-
int (*ctx_cmp)(void *c1, void *c2);
226-
int (*ctx_init)(void **ctx);
227-
int (*ctx_free)(void **ctx);
228-
} sqlcipher_provider;
229-
230198
#endif
231199
#endif
232200
/* END CRYPTO */

src/crypto_impl.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
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-
7869
static unsigned int default_flags = DEFAULT_CIPHER_FLAGS;
7970
static 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",

src/crypto_libtomcrypt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#ifdef SQLCIPHER_CRYPTO_LIBTOMCRYPT
2+
#include "sqliteInt.h"
3+
#include "sqlcipher.h"
24
#include <tomcrypt.h>
35

46
static unsigned int ltc_init = 0;

src/crypto_openssl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#ifdef SQLCIPHER_CRYPTO_OPENSSL
2+
#include "sqliteInt.h"
3+
#include "crypto.h"
4+
#include "sqlcipher.h"
25
#include <openssl/rand.h>
36
#include <openssl/evp.h>
47
#include <openssl/hmac.h>

0 commit comments

Comments
 (0)