Skip to content

Commit 8348d8e

Browse files
Fix compilation for Windows
1 parent bc05812 commit 8348d8e

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/crypto_impl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,14 +1127,15 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
11271127
int sqlcipher_codec_add_random(codec_ctx *ctx, const char *zRight){
11281128
int random_sz = strlen(zRight);
11291129
if (random_sz == ((ctx->read_ctx->key_sz * 2) + 3) && sqlite3StrNICmp((const char *)zRight ,"x'", 2) == 0) {
1130+
int rc = 0;
11301131
unsigned char *random;
11311132
int n = random_sz - 3; /* adjust for leading x' and tailing ' */
11321133
const unsigned char *z = (const unsigned char *)zRight + 2; /* adjust lead offset of x' */
11331134
CODEC_TRACE(("sqlcipher_codec_add_random: using raw random blob from hex\n"));
11341135
random = sqlcipher_malloc(n);
11351136
memset(random, 0, n);
11361137
cipher_hex2bin(z, n, random);
1137-
int rc = ctx->read_ctx->provider->add_random(ctx->read_ctx->provider_ctx, random, n);
1138+
rc = ctx->read_ctx->provider->add_random(ctx->read_ctx->provider_ctx, random, n);
11381139
sqlcipher_free(random, n);
11391140
return rc;
11401141
}

src/crypto_libtomcrypt.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ static sqlite3_mutex* ltc_rand_mutex = NULL;
4747

4848
static int sqlcipher_ltc_add_random(void *ctx, void *buffer, int length) {
4949
ltc_ctx *ltc = (ltc_ctx*)ctx;
50-
int rc = 0;
50+
int rc, block_idx = 0;
5151
int block_count = length / random_block_sz;
52+
const unsigned char * data = (const unsigned char *)buffer;
5253
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
5354
sqlite3_mutex_enter(ltc_rand_mutex);
5455
#endif
55-
for(int block_idx = 0; block_idx < block_count; block_idx++){
56-
rc = fortuna_add_entropy(buffer, random_block_sz, &(ltc->prng));
57-
buffer += random_block_sz;
56+
for(; block_idx < block_count; block_idx++){
57+
rc = fortuna_add_entropy(data, random_block_sz, &(ltc->prng));
58+
data += random_block_sz;
5859
rc = rc != CRYPT_OK ? SQLITE_ERROR : SQLITE_OK;
5960
if(rc != SQLITE_OK) {
6061
break;

0 commit comments

Comments
 (0)