10000 Fix compiler warnings · magic-coder/sqlcipher@035ae3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 035ae3e

Browse files
Fix compiler warnings
1 parent d2a266e commit 035ae3e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/crypto_libtomcrypt.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ static int sqlcipher_ltc_add_random(void *ctx, void *buffer, int length) {
4949

5050
static int sqlcipher_ltc_activate(void *ctx) {
5151
ltc_ctx *ltc = (ltc_ctx*)ctx;
52-
int random_buffer_sz = 32;
53-
unsigned char random_buffer[random_buffer_sz];
52+
int random_buffer_sz = sizeof(char) * 32;
53+
unsigned char *random_buffer = sqlcipher_malloc(random_buffer_sz);
54+
sqlcipher_memset(random_buffer, 0, random_buffer_sz);
5455

5556
if(ltc_init == 0) {
5657
if(register_prng(&fortuna_desc) != CRYPT_OK) return SQLITE_ERROR;
@@ -61,7 +62,7 @@ static int sqlcipher_ltc_activate(void *ctx) {
6162
if(fortuna_start(&(ltc->prng)) != CRYPT_OK) {
6263
return SQLITE_ERROR;
6364
}
64-
sqlite3_randomness(random_buffer_sz, &random_buffer);
65+
sqlite3_randomness(random_buffer_sz, random_buffer);
6566
if(sqlcipher_ltc_add_random(ctx, random_buffer, random_buffer_sz) != SQLITE_OK) {
6667
return SQLITE_ERROR;
6768
}
@@ -71,12 +72,14 @@ static int sqlcipher_ltc_activate(void *ctx) {
7172
if(fortuna_ready(&(ltc->prng)) != CRYPT_OK) {
7273
return SQLITE_ERROR;
7374
}
75+
sqlcipher_free(random_buffer, random_buffer_sz);
7476
return SQLITE_OK;
7577
}
7678

7779
static int sqlcipher_ltc_deactivate(void *ctx) {
7880
ltc_ctx *ltc = (ltc_ctx*)ctx;
7981
fortuna_done(&(ltc->prng));
82+
return SQLITE_OK;
8083
}
8184

8285
static const char* sqlcipher_ltc_get_provider_name(void *ctx) {
@@ -109,10 +112,11 @@ static int sqlcipher_ltc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, un
109112

110113
static int sqlcipher_ltc_kdf(void *ctx, const char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key) {
111114
int rc, hash_idx;
112-
unsigned long outlen = key_sz;
113-
unsigned long random_buffer_sz = 256;
114-
char random_buffer[random_buffer_sz];
115115
ltc_ctx *ltc = (ltc_ctx*)ctx;
116+
unsigned long outlen = key_sz;
117+
unsigned long random_buffer_sz = sizeof(char) * 256;
118+
unsigned char *random_buffer = sqlcipher_malloc(random_buffer_sz);
119+
sqlcipher_memset(random_buffer, 0, random_buffer_sz);
116120

117121
hash_idx = find_hash("sha1");
118122
if((rc = pkcs_5_alg2(pass, pass_sz, salt, salt_sz,
@@ -124,6 +128,7 @@ static int sqlcipher_ltc_kdf(void *ctx, const char *pass, int pass_sz, unsigned
124128
return SQLITE_ERROR;
125129
}
126130
sqlcipher_ltc_add_random(ctx, random_buffer, random_buffer_sz);
131+
sqlcipher_free(random_buffer, random_buffer_sz);
127132
return SQLITE_OK;
128133
}
129134

@@ -132,7 +137,7 @@ static const char* sqlcipher_ltc_get_cipher(void *ctx) {
132137
}
133138

134139
static int sqlcipher_ltc_cipher(void *ctx, int mode, unsigned char *key, int key_sz, unsigned char *iv, unsigned char *in, int in_sz, unsigned char *out) {
135-
int rc, cipher_idx, hash_idx;
140+
int rc, cipher_idx;
136141
symmetric_CBC cbc;
137142

138143
if((cipher_idx = find_cipher(sqlcipher_ltc_get_cipher(ctx))) == -1) return SQLITE_ERROR;
@@ -208,6 +213,7 @@ int sqlcipher_ltc_setup(sqlcipher_provider *p) {
208213
p->ctx_init = sqlcipher_ltc_ctx_init;
209214
p->ctx_free = sqlcipher_ltc_ctx_free;
210215
p->add_random = sqlcipher_ltc_add_random;
216+
return SQLITE_OK;
211217
}
212218

213219
#endif

0 commit comments

Comments
 (0)
0