8000 Checking for SQLITE_OK as return code for random · PHPDOTSQL/sqlcipher@51f2855 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51f2855

Browse files
Checking for SQLITE_OK as return code for random
1 parent 689b22e commit 51f2855

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/crypto_impl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ int sqlcipher_codec_ctx_init(codec_ctx **iCtx, Db *pDb, Pager *pPager, sqlite3_f
557557

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

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

663663
if(mode == CIPHER_ENCRYPT) {
664664
/* start at front of the reserve block, write random data to the end */
665-
if(c_ctx->provider->random(c_ctx->provider_ctx, iv_out, c_ctx->reserve_sz) != 1) return SQLITE_ERROR;
665+
if(c_ctx->provider->random(c_ctx->provider_ctx, iv_out, c_ctx->reserve_sz) != SQLITE_OK) return SQLITE_ERROR;
666666
} else { /* CIPHER_DECRYPT */
667667
memcpy(iv_out, iv_in, c_ctx->iv_sz); /* copy the iv from the input to output buffer */
668668
}

src/crypto_libtomcrypt.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int sqlcipher_ltc_activate(void *ctx) {
1919
ltc_ctx *ltc = (ltc_ctx*)ctx;
2020
int random_buffer_sz = 32;
2121
unsigned char random_buffer[random_buffer_sz];
22-
22+
2323
if(ltc_init == 0) {
2424
if(register_prng(&fortuna_desc) != CRYPT_OK) return SQLITE_ERROR;
2525
if(register_cipher(&rijndael_desc) != CRYPT_OK) return SQLITE_ERROR;
@@ -53,8 +53,11 @@ static const char* sqlcipher_ltc_get_provider_name(void *ctx) {
5353

5454
static int sqlcipher_ltc_random(void *ctx, void *buffer, int length) {
5555
ltc_ctx *ltc = (ltc_ctx*)ctx;
56-
57-
fortuna_ready(&(ltc->prng));
56+
int rc;
57+
58+
if((rc = fortuna_ready(&(ltc->prng))) != CRYPT_OK) {
59+
return SQLITE_ERROR;
60+
}
5861
fortuna_read(buffer, length, &(ltc->prng));
5962
return SQLITE_OK;
6063
}

src/crypto_openssl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ static const char* sqlcipher_openssl_get_provider_name(void *ctx) {
7171

7272
/* generate a defined number of pseudorandom bytes */
7373
static int sqlcipher_openssl_random (void *ctx, void *buffer, int length) {
74-
return RAND_bytes((unsigned char *)buffer, length);
74+
RAND_bytes((unsigned char *)buffer, length);
75+
return SQLITE_OK;
7576
}
7677

7778
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) {

0 commit comments

Comments
 (0)
0