8000 fix redundant key derivation with common crypto provider · githubzhaoliang/sqlcipher@c607283 · GitHub
[go: up one dir, main page]

Skip to content

Commit c607283

Browse files
committed
fix redundant key derivation with common crypto provider
1 parent 90606b3 commit c607283

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

src/crypto_cc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int sqlcipher_cc_ctx_copy(void *target_ctx, void *source_ctx) {
109109
}
110110

111111
static int sqlcipher_cc_ctx_cmp(void *c1, void *c2) {
112-
return SQLITE_OK;
112+
return 1; /* always indicate contexts are the same */
113113
}
114114

115115
static int sqlcipher_cc_ctx_init(void **ctx) {

src/crypto_impl.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ static void sqlcipher_cipher_ctx_free(cipher_ctx **iCtx) {
310310
* returns 1 otherwise
311311
*/
312312
static int sqlcipher_cipher_ctx_cmp(cipher_ctx *c1, cipher_ctx *c2) {
313-
CODEC_TRACE(("sqlcipher_cipher_ctx_cmp: entered c1=%p c2=%p\n", c1, c2));
314-
315-
if(
313+
int are_equal = (
316314
c1->iv_sz == c2->iv_sz
317315
&& c1->kdf_iter == c2->kdf_iter
318316
&& c1->fast_kdf_iter == c2->fast_kdf_iter
@@ -326,9 +324,43 @@ static int sqlcipher_cipher_ctx_cmp(cipher_ctx *c1, cipher_ctx *c2) {
326324
|| !sqlcipher_memcmp((const unsigned char*)c1->pass,
327325
(const unsigned char*)c2->pass,
328326
c1->pass_sz)
329-
)
330-
) return 0;
331-
return 1;
327+
));
328+
329+
CODEC_TRACE(("sqlcipher_cipher_ctx_cmp: entered \
330+
c1=%p c2=%p \
331+
c1->iv_sz=%d c2->iv_sz=%d \
332+
c1->kdf_iter=%d c2->kdf_iter=%d \
333+
c1->fast_kdf_iter=%d c2->fast_kdf_iter=%d \
334+
c1->key_sz=%d c2->key_sz=%d \
335+
c1->pass_sz=%d c2->pass_sz=%d \
336+
c1->flags=%d c2->flags=%d \
337+
c1->hmac_sz=%d c2->hmac_sz=%d \
338+
c1->provider_ctx=%p c2->provider_ctx=%p \
339+
c1->pass=%p c2->pass=%p \
340+
c1->pass=%s c2->pass=%s \
341+
provider->ctx_cmp=%d \
342+
sqlcipher_memcmp=%d \
343+
are_equal=%d \
344+
\n",
345+
c1, c2,
346+
c1->iv_sz, c2->iv_sz,
347+
c1->kdf_iter, c2->kdf_iter,
348+
c1->fast_kdf_iter, c2->fast_kdf_iter,
349+
c1->key_sz, c2->key_sz,
350+
c1->pass_sz, c2->pass_sz,
351+
c1->flags, c2->flags,
352+
c1->hmac_sz, c2->hmac_sz,
353+
c1->provider_ctx, c2->provider_ctx,
354+
c1->pass, c2->pass,
355+
c1->pass, c2->pass,
356+
c1->provider->ctx_cmp(c1->provider_ctx, c2->provider_ctx),
357+
sqlcipher_memcmp((const unsigned char*)c1->pass,
358+
(const unsigned char*)c2->pass,
359+
c1->pass_sz),
360+
are_equal
361+
));
362+
363+
return !are_equal; /* return 0 if they are the same, 1 otherwise */
332364
}
333365

334366
/**

0 commit comments

Comments
 (0)
0