diff --git a/src/crypto.c b/src/crypto.c index 262318b..5c832f1 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -108,18 +108,26 @@ int codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLeft, const c if(ctx) sqlcipher_codec_ctx_set_cipher(ctx, zRight, 1); // change write cipher only }else if( sqlite3StrICmp(zLeft, "kdf_iter")==0 ){ - if( zRight ) { - if(ctx) sqlcipher_codec_ctx_set_kdf_iter(ctx, atoi(zRight), 2); // change of RW PBKDF2 iteration - } else { - if(ctx) { + if(ctx) { + if( zRight ) { + sqlcipher_codec_ctx_set_kdf_iter(ctx, atoi(zRight), 2); // change of RW PBKDF2 iteration + } else { char *kdf_iter = sqlite3_mprintf("%d", sqlcipher_codec_ctx_get_kdf_iter(ctx, 2)); codec_vdbe_return_static_string(pParse, "kdf_iter", kdf_iter); sqlite3_free(kdf_iter); - } + } } }else - if( sqlite3StrICmp(zLeft, "fast_kdf_iter")==0 && zRight ){ - if(ctx) sqlcipher_codec_ctx_set_fast_kdf_iter(ctx, atoi(zRight), 2); // change of RW PBKDF2 iteration + if( sqlite3StrICmp(zLeft, "fast_kdf_iter")==0){ + if(ctx) { + if( zRight ) { + sqlcipher_codec_ctx_set_fast_kdf_iter(ctx, atoi(zRight), 2); // change of RW PBKDF2 iteration + } else { + char *fast_kdf_iter = sqlite3_mprintf("%d", sqlcipher_codec_ctx_get_fast_kdf_iter(ctx, 2)); + codec_vdbe_return_static_string(pParse, "fast_kdf_iter", fast_kdf_iter); + sqlite3_free(fast_kdf_iter); + } + } }else if( sqlite3StrICmp(zLeft, "rekey_kdf_iter")==0 && zRight ){ if(ctx) sqlcipher_codec_ctx_set_kdf_iter(ctx, atoi(zRight), 1); // write iterations only diff --git a/src/crypto.h b/src/crypto.h index 5e2e308..ac98281 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -171,6 +171,7 @@ int sqlcipher_codec_ctx_get_kdf_iter(codec_ctx *ctx, int); void* sqlcipher_codec_ctx_get_kdf_salt(codec_ctx *ctx); int sqlcipher_codec_ctx_set_fast_kdf_iter(codec_ctx *, int, int); +int sqlcipher_codec_ctx_get_fast_kdf_iter(codec_ctx *, int); int sqlcipher_codec_ctx_set_cipher(codec_ctx *, const char *, int); const char* sqlcipher_codec_ctx_get_cipher(codec_ctx *ctx, int for_ctx); diff --git a/src/crypto_impl.c b/src/crypto_impl.c index 1ff86fe..f018189 100644 --- a/src/crypto_impl.c +++ b/src/crypto_impl.c @@ -385,6 +385,11 @@ int sqlcipher_codec_ctx_set_fast_kdf_iter(codec_ctx *ctx, int fast_kdf_iter, int return SQLITE_OK; } +int sqlcipher_codec_ctx_get_fast_kdf_iter(codec_ctx *ctx, int for_ctx) { + cipher_ctx *c_ctx = for_ctx ? ctx->write_ctx : ctx->read_ctx; + return c_ctx->fast_kdf_iter; +} + /* set the global default flag for HMAC */ void sqlcipher_set_default_use_hmac(int use) { if(use) default_flags |= CIPHER_FLAG_HMAC; diff --git a/test/crypto.test b/test/crypto.test index e077e1c..96aaec0 100644 --- a/test/crypto.test +++ b/test/crypto.test @@ -1683,6 +1683,31 @@ do_test verify-pragma-kdf-iter-reports-value-changed { db close file delete -force test.db +# verify the pragma fast_kdf_iter +# reports the default value +do_test verify-pragma-fast-kdf-iter-reports-default { + sqlite_orig db test.db + execsql { + PRAGMA key = 'test'; + PRAGMA fast_kdf_iter; + } +} {2} +db close +file delete -force test.db + +# verify the pragma fast_kdf_iter +# reports value changed +do_test verify-pragma-kdf-iter-reports-value-changed { + sqlite_orig db test.db + execsql { + PRAGMA key = 'test'; + PRAGMA fast_kdf_iter = 4000; + PRAGMA fast_kdf_iter; + } +} {4000} +db close +file delete -force test.db + # verify the pragma cipher_page_size # reports default value do_test verify-pragma-cipher-page-size-default {