Skip to content

Commit

Permalink
Fix compilation for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
developernotes committed Nov 25, 2013
1 parent bc05812 commit 8348d8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/crypto_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,14 +1127,15 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
int sqlcipher_codec_add_random(codec_ctx *ctx, const char *zRight){
int random_sz = strlen(zRight);
if (random_sz == ((ctx->read_ctx->key_sz * 2) + 3) && sqlite3StrNICmp((const char *)zRight ,"x'", 2) == 0) {
int rc = 0;
unsigned char *random;
int n = random_sz - 3; /* adjust for leading x' and tailing ' */
const unsigned char *z = (const unsigned char *)zRight + 2; /* adjust lead offset of x' */
CODEC_TRACE(("sqlcipher_codec_add_random: using raw random blob from hex\n"));
random = sqlcipher_malloc(n);
memset(random, 0, n);
cipher_hex2bin(z, n, random);
int rc = ctx->read_ctx->provider->add_random(ctx->read_ctx->provider_ctx, random, n);
rc = ctx->read_ctx->provider->add_random(ctx->read_ctx->provider_ctx, random, n);
sqlcipher_free(random, n);
return rc;
}
Expand Down
9 changes: 5 additions & 4 deletions src/crypto_libtomcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ static sqlite3_mutex* ltc_rand_mutex = NULL;

static int sqlcipher_ltc_add_random(void *ctx, void *buffer, int length) {
ltc_ctx *ltc = (ltc_ctx*)ctx;
int rc = 0;
int rc, block_idx = 0;
int block_count = length / random_block_sz;
const unsigned char * data = (const unsigned char *)buffer;
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
sqlite3_mutex_enter(ltc_rand_mutex);
#endif
for(int block_idx = 0; block_idx < block_count; block_idx++){
rc = fortuna_add_entropy(buffer, random_block_sz, &(ltc->prng));
buffer += random_block_sz;
for(; block_idx < block_count; block_idx++){
rc = fortuna_add_entropy(data, random_block_sz, &(ltc->prng));
data += random_block_sz;
rc = rc != CRYPT_OK ? SQLITE_ERROR : SQLITE_OK;
if(rc != SQLITE_OK) {
break;
Expand Down

0 comments on commit 8348d8e

Please sign in to comment.