Skip to content

Commit

Permalink
Checking for SQLITE_OK as return code for random
Browse files Browse the repository at this point in the history
  • Loading branch information
developernotes committed Jun 11, 2013
1 parent 689b22e commit 51f2855
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/crypto_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ int sqlcipher_codec_ctx_init(codec_ctx **iCtx, Db *pDb, Pager *pPager, sqlite3_f

if(fd == NULL || sqlite3OsRead(fd, ctx->kdf_salt, FILE_HEADER_SZ, 0) != SQLITE_OK) {
/* if unable to read the bytes, generate random salt */
if(ctx->read_ctx->provider->random(ctx->read_ctx->provider_ctx, ctx->kdf_salt, FILE_HEADER_SZ) != 1) return SQLITE_ERROR;
if(ctx->read_ctx->provider->random(ctx->read_ctx->provider_ctx, ctx->kdf_salt, FILE_HEADER_SZ) != SQLITE_OK) return SQLITE_ERROR;
}

if((rc = sqlcipher_codec_ctx_set_cipher(ctx, CIPHER, 0)) != SQLITE_OK) return rc;
Expand Down Expand Up @@ -662,7 +662,7 @@ int sqlcipher_page_cipher(codec_ctx *ctx, int for_ctx, Pgno pgno, int mode, int

if(mode == CIPHER_ENCRYPT) {
/* start at front of the reserve block, write random data to the end */
if(c_ctx->provider->random(c_ctx->provider_ctx, iv_out, c_ctx->reserve_sz) != 1) return SQLITE_ERROR;
if(c_ctx->provider->random(c_ctx->provider_ctx, iv_out, c_ctx->reserve_sz) != SQLITE_OK) return SQLITE_ERROR;
} else { /* CIPHER_DECRYPT */
memcpy(iv_out, iv_in, c_ctx->iv_sz); /* copy the iv from the input to output buffer */
}
Expand Down
9 changes: 6 additions & 3 deletions src/crypto_libtomcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static int sqlcipher_ltc_activate(void *ctx) {
ltc_ctx *ltc = (ltc_ctx*)ctx;
int random_buffer_sz = 32;
unsigned char random_buffer[random_buffer_sz];

if(ltc_init == 0) {
if(register_prng(&fortuna_desc) != CRYPT_OK) return SQLITE_ERROR;
if(register_cipher(&rijndael_desc) != CRYPT_OK) return SQLITE_ERROR;
Expand Down Expand Up @@ -53,8 +53,11 @@ static const char* sqlcipher_ltc_get_provider_name(void *ctx) {

static int sqlcipher_ltc_random(void *ctx, void *buffer, int length) {
ltc_ctx *ltc = (ltc_ctx*)ctx;

fortuna_ready(&(ltc->prng));
int rc;

if((rc = fortuna_ready(&(ltc->prng))) != CRYPT_OK) {
return SQLITE_ERROR;
}
fortuna_read(buffer, length, &(ltc->prng));
return SQLITE_OK;
}
Expand Down
3 changes: 2 additions & 1 deletion src/crypto_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ static const char* sqlcipher_openssl_get_provider_name(void *ctx) {

/* generate a defined number of pseudorandom bytes */
static int sqlcipher_openssl_random (void *ctx, void *buffer, int length) {
return RAND_bytes((unsigned char *)buffer, length);
RAND_bytes((unsigned char *)buffer, length);
return SQLITE_OK;
}

static int sqlcipher_openssl_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) {
Expand Down

0 comments on commit 51f2855

Please sign in to comment.