mirror of
https://github.com/status-im/sqlcipher.git
synced 2025-02-23 17:28:17 +00:00
takes advantage of sqlites new hexkey and hexrekey pragmas
- detect number of key bytes passed in to make decision about whether to hash key
This commit is contained in:
parent
cbbb7b2a89
commit
4314238203
@ -141,6 +141,7 @@ CRYPTOLIBOBJ = \
|
||||
crypto.lo
|
||||
|
||||
CRYPTOSRC = \
|
||||
$(TOP)/src/crypto.h \
|
||||
$(TOP)/src/crypto.c
|
||||
# END CRYPTO
|
||||
|
||||
|
18
src/crypto.c
18
src/crypto.c
@ -65,18 +65,11 @@ static int codec_passphrase_hash(const void *in, int inLen, void *out, int *outL
|
||||
*outLen = md_sz;
|
||||
}
|
||||
|
||||
static int codec_prepare_key(sqlite3 *db, const void *zKey, int nKey, void *out, int *nOut) {
|
||||
/* if key string starts with x' then assume this is a blob literal key*/
|
||||
if (sqlite3StrNICmp(zKey ,"x'", 2) == 0) {
|
||||
int n = nKey - 3; /* adjust for leading x' and tailing ' */
|
||||
int half_n = n/2;
|
||||
const char *z = zKey + 2; /* adjust lead offset of x' */
|
||||
void *key = sqlite3HexToBlob(db, z, n);
|
||||
memcpy(out, key, half_n);
|
||||
*nOut = half_n;
|
||||
|
||||
memset(key, 0, half_n); /* cleanup temporary key data */
|
||||
sqlite3DbFree(db, key);
|
||||
static void codec_prepare_key(sqlite3 *db, const void *zKey, int nKey, void *out, int *nOut) {
|
||||
/* if key data lenght is exactly 256 bits / 32 bytes use the data directly */
|
||||
if (nKey == 32) {
|
||||
memcpy(out, zKey, nKey);
|
||||
*nOut = nKey;
|
||||
/* otherwise the key is provided as a string so hash it to get key data */
|
||||
} else {
|
||||
codec_passphrase_hash(zKey, nKey, out, nOut);
|
||||
@ -128,6 +121,7 @@ static int codec_cipher(codec_ctx *ctx, Pgno pgno, int mode, int size, void *in,
|
||||
EVP_CIPHER_CTX_cleanup(&ectx);
|
||||
assert(size == csz);
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -110,7 +110,7 @@ do_test codec-1.6 {
|
||||
db close
|
||||
sqlite_orig db test.db
|
||||
execsql {
|
||||
PRAGMA key = "x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836489'";
|
||||
PRAGMA hexkey = '98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836489';
|
||||
SELECT * from t1;
|
||||
}
|
||||
} {test1 test2}
|
||||
@ -120,7 +120,7 @@ do_test codec-1.7 {
|
||||
db close
|
||||
sqlite_orig db test.db
|
||||
catchsql {
|
||||
PRAGMA key = "x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836480'";
|
||||
PRAGMA hexkey = '98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836480';
|
||||
SELECT name FROM sqlite_master WHERE type='table';
|
||||
}
|
||||
} {1 {file is encrypted or is not a database}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user