|
35 | 35 | #include "sqliteInt.h" |
36 | 36 | #include "btreeInt.h" |
37 | 37 | #include "crypto.h" |
| 38 | +#include "sqlcipher.h" |
38 | 39 |
|
39 | 40 | static const char* codec_get_cipher_version() { |
40 | 41 | return CIPHER_VERSION; |
@@ -328,6 +329,100 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef |
328 | 329 | sqlite3_free(salt); |
329 | 330 | } |
330 | 331 | } |
| 332 | + }else |
| 333 | + if( sqlite3StrICmp(zLeft,"cipher_hmac_algorithm")==0 ){ |
| 334 | + if(ctx) { |
| 335 | + if(zRight) { |
| 336 | + int rc = SQLITE_ERROR; |
| 337 | + if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA1_LABEL) == 0) { |
| 338 | + rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA1); |
| 339 | + } else if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA256_LABEL) == 0) { |
| 340 | + rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA256); |
| 341 | + } else if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA512_LABEL) == 0) { |
| 342 | + rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA512); |
| 343 | + } |
| 344 | + if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR); |
| 345 | + rc = codec_set_btree_to_codec_pagesize(db, pDb, ctx); |
| 346 | + if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR); |
| 347 | + } else { |
| 348 | + int algorithm = sqlcipher_codec_ctx_get_hmac_algorithm(ctx); |
| 349 | + if(algorithm == SQLCIPHER_HMAC_SHA1) { |
| 350 | + codec_vdbe_return_static_string(pParse, "cipher_hmac_algorithm", SQLCIPHER_HMAC_SHA1_LABEL); |
| 351 | + } else if(algorithm == SQLCIPHER_HMAC_SHA256) { |
| 352 | + codec_vdbe_return_static_string(pParse, "cipher_hmac_algorithm", SQLCIPHER_HMAC_SHA256_LABEL); |
| 353 | + } else if(algorithm == SQLCIPHER_HMAC_SHA512) { |
| 354 | + codec_vdbe_return_static_string(pParse, "cipher_hmac_algorithm", SQLCIPHER_HMAC_SHA512_LABEL); |
| 355 | + } |
| 356 | + } |
| 357 | + } |
| 358 | + }else |
| 359 | + if( sqlite3StrICmp(zLeft,"cipher_default_hmac_algorithm")==0 ){ |
| 360 | + if(zRight) { |
| 361 | + int rc = SQLITE_ERROR; |
| 362 | + if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA1_LABEL) == 0) { |
| 363 | + rc = sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA1); |
| 364 | + } else if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA256_LABEL) == 0) { |
| 365 | + rc = sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA256); |
| 366 | + } else if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA512_LABEL) == 0) { |
| 367 | + rc = sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA512); |
| 368 | + } |
| 369 | + if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR); |
| 370 | + } else { |
| 371 | + int algorithm = sqlcipher_get_default_hmac_algorithm(); |
| 372 | + if(algorithm == SQLCIPHER_HMAC_SHA1) { |
| 373 | + codec_vdbe_return_static_string(pParse, "cipher_default_hmac_algorithm", SQLCIPHER_HMAC_SHA1_LABEL); |
| 374 | + } else if(algorithm == SQLCIPHER_HMAC_SHA256) { |
| 375 | + codec_vdbe_return_static_string(pParse, "cipher_default_hmac_algorithm", SQLCIPHER_HMAC_SHA256_LABEL); |
| 376 | + } else if(algorithm == SQLCIPHER_HMAC_SHA512) { |
| 377 | + codec_vdbe_return_static_string(pParse, "cipher_default_hmac_algorithm", SQLCIPHER_HMAC_SHA512_LABEL); |
| 378 | + } |
| 379 | + } |
| 380 | + }else |
| 381 | + if( sqlite3StrICmp(zLeft,"cipher_kdf_algorithm")==0 ){ |
| 382 | + if(ctx) { |
| 383 | + if(zRight) { |
| 384 | + int rc = SQLITE_ERROR; |
| 385 | + if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL) == 0) { |
| 386 | + rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA1); |
| 387 | + } else if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL) == 0) { |
| 388 | + rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA256); |
| 389 | + } else if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL) == 0) { |
| 390 | + rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA512); |
| 391 | + } |
| 392 | + if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR); |
| 393 | + } else { |
| 394 | + int algorithm = sqlcipher_codec_ctx_get_kdf_algorithm(ctx); |
| 395 | + if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA1) { |
| 396 | + codec_vdbe_return_static_string(pParse, "cipher_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL); |
| 397 | + } else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA256) { |
| 398 | + codec_vdbe_return_static_string(pParse, "cipher_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL); |
| 399 | + } else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA512) { |
| 400 | + codec_vdbe_return_static_string(pParse, "cipher_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL); |
| 401 | + } |
| 402 | + } |
| 403 | + } |
| 404 | + }else |
| 405 | + if( sqlite3StrICmp(zLeft,"cipher_default_kdf_algorithm")==0 ){ |
| 406 | + if(zRight) { |
| 407 | + int rc = SQLITE_ERROR; |
| 408 | + if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL) == 0) { |
| 409 | + rc = sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA1); |
| 410 | + } else if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL) == 0) { |
| 411 | + rc = sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA256); |
| 412 | + } else if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL) == 0) { |
| 413 | + rc = sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA512); |
| 414 | + } |
| 415 | + if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR); |
| 416 | + } else { |
| 417 | + int algorithm = sqlcipher_get_default_kdf_algorithm(); |
| 418 | + if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA1) { |
| 419 | + codec_vdbe_return_static_string(pParse, "cipher_default_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL); |
| 420 | + } else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA256) { |
| 421 | + codec_vdbe_return_static_string(pParse, "cipher_default_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL); |
| 422 | + } else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA512) { |
| 423 | + codec_vdbe_return_static_string(pParse, "cipher_default_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL); |
| 424 | + } |
| 425 | + } |
331 | 426 | }else { |
332 | 427 | return 0; |
333 | 428 | } |
|
0 commit comments