Skip to content

Commit 167aab2

Browse files
committed
Merge branch 'prerelease' into Xcode5
2 parents 4534af9 + f4eb3b3 commit 167aab2

File tree

5 files changed

+483
-47
lines changed

5 files changed

+483
-47
lines changed

sqlcipher-2.3-testkey.db

2 KB
Binary file not shown.

src/crypto.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ int codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLeft, const c
8989

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

92+
if( sqlite3StrICmp(zLeft, "cipher_migrate")==0 && !zRight ){
93+
if(ctx){
94+
char *migrate_status = sqlite3_mprintf("%d", sqlcipher_codec_ctx_migrate(ctx));
95+
codec_vdbe_return_static_string(pParse, "sqlcipher_migrate", migrate_status);
96+
sqlite3_free(migrate_status);
97+
}
98+
} else
9299
if( sqlite3StrICmp(zLeft, "cipher_provider")==0 && !zRight ){
93100
if(ctx) { codec_vdbe_return_static_string(pParse, "cipher_provider",
94101
sqlcipher_codec_get_cipher_provider(ctx));
@@ -110,6 +117,15 @@ int codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLeft, const c
110117
if( sqlite3StrICmp(zLeft, "rekey_cipher")==0 && zRight ){
111118
if(ctx) sqlcipher_codec_ctx_set_cipher(ctx, zRight, 1); // change write cipher only
112119
}else
120+
if( sqlite3StrICmp(zLeft,"cipher_default_kdf_iter")==0 ){
121+
if( zRight ) {
122+
sqlcipher_set_default_kdf_iter(atoi(zRight)); // change default KDF iterations
123+
} else {
124+
char *kdf_iter = sqlite3_mprintf("%d", sqlcipher_get_default_kdf_iter());
125+
codec_vdbe_return_static_string(pParse, "cipher_default_kdf_iter", kdf_iter);
126+
sqlite3_free(kdf_iter);
127+
}
128+
}else
113129
if( sqlite3StrICmp(zLeft, "kdf_iter")==0 ){
114130
if(ctx) {
115131
if( zRight ) {
@@ -412,13 +428,11 @@ int sqlite3_rekey(sqlite3 *db, const void *pKey, int nKey) {
412428
void sqlite3CodecGetKey(sqlite3* db, int nDb, void **zKey, int *nKey) {
413429
struct Db *pDb = &db->aDb[nDb];
414430
CODEC_TRACE(("sqlite3CodecGetKey: entered db=%p, nDb=%d\n", db, nDb));
415-
416431
if( pDb->pBt ) {
417432
codec_ctx *ctx;
418433
sqlite3pager_get_codec(pDb->pBt->pBt->pPager, (void **) &ctx);
419-
420434
if(ctx) { /* if the codec has an attached codec_context user the raw key data */
421-
sqlcipher_codec_get_pass(ctx, zKey, nKey);
435+
sqlcipher_codec_get_keyspec(ctx, zKey, nKey);
422436
} else {
423437
*zKey = NULL;
424438
*nKey = 0;

src/crypto.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define FILE_HEADER_SZ 16
4545

4646
#ifndef CIPHER_VERSION
47-
#define CIPHER_VERSION "2.2.1"
47+
#define CIPHER_VERSION "3.0.0"
4848
#endif
4949

5050
#ifndef CIPHER
@@ -59,7 +59,7 @@
5959
#define CIPHER_READWRITE_CTX 2
6060

6161
#ifndef PBKDF2_ITER
62-
#define PBKDF2_ITER 4000
62+
#define PBKDF2_ITER 64000
6363
#endif
6464

6565
/* possible flags for cipher_ctx->flags */
@@ -149,6 +149,13 @@ static void cipher_hex2bin(const char *hex, int sz, unsigned char *out){
149149
}
150150
}
151151

152+
static void cipher_bin2hex(const unsigned char* in, int sz, char *out) {
153+
int i;
154+
for(i=0; i < sz; i++) {
155+
sprintf(out + (i*2), "%02x ", in[i]);
156+
}
157+
}
158+
152159
/* extensions defined in crypto_impl.c */
153160
typedef struct codec_ctx codec_ctx;
154161

@@ -167,12 +174,15 @@ int sqlcipher_page_cipher(codec_ctx *, int, Pgno, int, int, unsigned char *, uns
167174
void sqlcipher_codec_ctx_set_error(codec_ctx *, int);
168175

169176
int sqlcipher_codec_ctx_set_pass(codec_ctx *, const void *, int, int);
170-
void sqlcipher_codec_get_pass(codec_ctx *, void **zKey, int *nKey);
177+
void sqlcipher_codec_get_keyspec(codec_ctx *, void **zKey, int *nKey);
171178

172179
int sqlcipher_codec_ctx_set_pagesize(codec_ctx *, int);
173180
int sqlcipher_codec_ctx_get_pagesize(codec_ctx *);
174181
int sqlcipher_codec_ctx_get_reservesize(codec_ctx *);
175182

183+
void sqlcipher_set_default_kdf_iter(int iter);
184+
int sqlcipher_get_default_kdf_iter();
185+
176186
int sqlcipher_codec_ctx_set_kdf_iter(codec_ctx *, int, int);
177187
int sqlcipher_codec_ctx_get_kdf_iter(codec_ctx *ctx, int);
178188

@@ -202,6 +212,7 @@ int sqlcipher_codec_ctx_unset_flag(codec_ctx *ctx, unsigned int flag);
202212
int sqlcipher_codec_ctx_get_flag(codec_ctx *ctx, unsigned int flag, int for_ctx);
203213

204214
const char* sqlcipher_codec_get_cipher_provider(codec_ctx *ctx);
215+
int sqlcipher_codec_ctx_migrate(codec_ctx *ctx);
205216
#endif
206217
#endif
207218
/* END SQLCIPHER */

0 commit comments

Comments
 (0)