Skip to content

Commit 9c4d19e

Browse files
Add read-only PRAGMA cipher_provider
Provides a readonly name of the cipher provider. Available once the codec_ctx has been properly initialized as the provider name is sourced from the sqlcipher_provider implementation.
1 parent eb3c1dc commit 9c4d19e

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

src/crypto.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ int codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLeft, const c
9191

9292
CODEC_TRACE(("codec_pragma: entered db=%p iDb=%d pParse=%p zLeft=%s zRight=%s ctx=%p\n", db, iDb, pParse, zLeft, zRight, ctx));
9393

94+
if( sqlite3StrICmp(zLeft, "cipher_provider")==0 && !zRight ){
95+
if(ctx) { codec_vdbe_return_static_string(pParse, "cipher_provider",
96+
sqlcipher_codec_get_cipher_provider(ctx));
97+
}
98+
} else
9499
if( sqlite3StrICmp(zLeft, "cipher_version")==0 && !zRight ){
95100
codec_vdbe_return_static_string(pParse, "cipher_version", codec_get_cipher_version());
96101
}else

src/crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ int sqlcipher_codec_ctx_set_flag(codec_ctx *ctx, unsigned int flag);
195195
int sqlcipher_codec_ctx_unset_flag(codec_ctx *ctx, unsigned int flag);
196196
int sqlcipher_codec_ctx_get_flag(codec_ctx *ctx, unsigned int flag, int for_ctx);
197197

198+
const char* sqlcipher_codec_get_cipher_provider(codec_ctx *ctx);
198199
#endif
199200
#endif
200201
/* END CRYPTO */

src/crypto_impl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,5 +792,8 @@ int sqlcipher_codec_key_copy(codec_ctx *ctx, int source) {
792792
}
793793
}
794794

795+
const char* sqlcipher_codec_get_cipher_provider(codec_ctx *ctx) {
796+
return ctx->read_ctx->provider->get_provider_name(ctx->read_ctx);
797+
}
795798

796799
#endif

src/crypto_libtomcrypt.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ static int sqlcipher_ltc_deactivate(void *ctx) {
2828
fortuna_done(&(ltc->prng));
2929
}
3030

31+
static const char* sqlcipher_ltc_get_provider_name(void *ctx) {
32+
return "libtomcrypt";
33+
}
34+
3135
static int sqlcipher_ltc_random(void *ctx, void *buffer, int length) {
3236
int random_value;
3337
int random_buffer_sz = 256;
3438
char random_buffer[random_buffer_sz];
35-
ltc_ctx *ltc = (ltc_ctx*)ctx;
3639

40+
ltc_ctx *ltc = (ltc_ctx*)ctx;
3741
sqlite3_randomness(sizeof(random_value), &random_value);
3842
sqlite3_snprintf(random_buffer_sz, random_buffer, "%d", random_value);
3943
if(fortuna_add_entropy(random_buffer, random_buffer_sz, &(ltc->prng)) != CRYPT_OK) return SQLITE_ERROR;
@@ -128,7 +132,8 @@ static int sqlcipher_ltc_ctx_free(void **ctx) {
128132

129133
int sqlcipher_ltc_setup(sqlcipher_provider *p) {
130134
p->activate = sqlcipher_ltc_activate;
131-
p->deactivate = sqlcipher_ltc_deactivate;
135+
p->deactivate = sqlcipher_ltc_deactivate;
136+
p->get_provider_name = sqlcipher_ltc_get_provider_name;
132137
p->random = sqlcipher_ltc_random;
133138
p->hmac = sqlcipher_ltc_hmac;
134139
p->kdf = sqlcipher_ltc_kdf;

src/crypto_openssl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ static int sqlcipher_openssl_deactivate(void *ctx) {
6060
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
6161
}
6262

63+
static const char* sqlcipher_openssl_get_provider_name(void *ctx) {
64+
return "openssl";
65+
}
66+
6367
/* generate a defined number of pseudorandom bytes */
6468
static int sqlcipher_openssl_random (void *ctx, void *buffer, int length) {
6569
return RAND_bytes((unsigned char *)buffer, length);
@@ -148,7 +152,8 @@ static int sqlcipher_openssl_ctx_free(void **ctx) {
148152

149153
int sqlcipher_openssl_setup(sqlcipher_provider *p) {
150154
p->activate = sqlcipher_openssl_activate;
151-
p->deactivate = sqlcipher_openssl_deactivate;
155+
p->deactivate = sqlcipher_openssl_deactivate;
156+
p->get_provider_name = sqlcipher_openssl_get_provider_name;
152157
p->random = sqlcipher_openssl_random;
153158
p->hmac = sqlcipher_openssl_hmac;
154159
p->kdf = sqlcipher_openssl_kdf;

src/sqlcipher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
typedef struct {
4040
int (*activate)(void *ctx);
4141
int (*deactivate)(void *ctx);
42+
const char* (*get_provider_name)(void *ctx);
4243
int (*random)(void *ctx, void *buffer, int length);
4344
int (*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);
4445
int (*kdf)(void *ctx, const unsigned char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key);

0 commit comments

Comments
 (0)