diff --git a/src/sqlite3.c b/src/sqlite3.c index 64111dd365b57b8fa3dbffaf0ed2030968326e2e..68243deaea1b06ccba27d5f794a7a20b9ca8604b 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -245357,6 +245357,7 @@ CODEC_STATIC int sqlite3CodecInitKeyContext(CodecContext *ctx, Btree *p, const v rc = sqlite3CodecSetCodecConstant(keyCtx, DEFAULT_CIPHER); rc += sqlite3CodecSetIter(keyCtx, DEFAULT_ITER); rc += sqlite3CodecSetHmacAlgorithm(keyCtx, DEFAULT_HMAC_ALGORITHM); + rc += sqlite3CodecSetKdfAlgorithm(keyCtx, DEFAULT_KDF_ALGORITHM); #endif keyCtx->codecConst.rekeyHmacAlgo = DEFAULT_HMAC_ALGORITHM; rc += sqlite3CodecSetPassword(keyCtx, zKey, nKey); @@ -245597,7 +245598,8 @@ CODEC_STATIC int sqlite3CodecDecryptData(CodecContext *ctx, OperateContext which inputBuffer.buffer = input; inputBuffer.bufferSize = bufferSize - keyCtx->codecConst.reserveSize; if(sqlite3CodecCheckHmac(keyCtx, pgno, inputBuffer.bufferSize + keyCtx->codecConst.initVectorSize, input, input + inputBuffer.bufferSize + keyCtx->codecConst.initVectorSize)){ - sqlite3_log(SQLITE_WARNING, "codec: check hmac error at page %d when decrypt data.", pgno); + sqlite3_log(SQLITE_ERROR, "codec: check hmac error at page %d, hmac %d, kdf %d, pageSize %d.", + pgno, keyCtx->codecConst.hmacAlgo, keyCtx->codecConst.kdfAlgo, keyCtx->codecConst.cipherPageSize); return SQLITE_ERROR; } unsigned char *initVector = input + inputBuffer.bufferSize; @@ -245801,6 +245803,7 @@ int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ int oldHmacAlgo = ctx->writeCtx->codecConst.hmacAlgo; if( ctx->writeCtx->codecConst.rekeyHmacAlgo!=ctx->writeCtx->codecConst.hmacAlgo ){ sqlite3CodecSetHmacAlgorithm(ctx->writeCtx, ctx->writeCtx->codecConst.rekeyHmacAlgo); + sqlite3CodecSetKdfAlgorithm(ctx->writeCtx, ctx->writeCtx->codecConst.rekeyHmacAlgo); } for(pgno = 1; pgno <= (unsigned int)pageCount; pgno++){ @@ -245825,6 +245828,7 @@ int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ }else{ if( ctx->writeCtx->codecConst.rekeyHmacAlgo!=oldHmacAlgo ){ sqlite3CodecSetHmacAlgorithm(ctx->writeCtx, oldHmacAlgo); + sqlite3CodecSetKdfAlgorithm(ctx->writeCtx, oldHmacAlgo); } (void)sqlite3BtreeRollback(p, SQLITE_ABORT_ROLLBACK, 0); } @@ -245902,6 +245906,7 @@ int sqlite3CodecPragma(sqlite3 *db, int iDb, Parse *parse, const char *zLeft, co sqlite3_mutex_enter(db->mutex); (void)sqlite3CodecSetCodecConstant(ctx->readCtx, zRight); (void)sqlite3CodecSetHmacAlgorithm(ctx->readCtx, ctx->readCtx->codecConst.hmacAlgo); + (void)sqlite3CodecSetKdfAlgorithm(ctx->readCtx, ctx->readCtx->codecConst.hmacAlgo); sqlite3CodecFreeKeyContext(ctx->writeCtx); (void)sqlite3CodecCopyKeyContext(ctx->readCtx, ctx->writeCtx); sqlite3BtreeSetPageSize(p, ctx->readCtx->codecConst.cipherPageSize, ctx->readCtx->codecConst.reserveSize, 0);