mirror of
https://github.com/status-im/sqlcipher.git
synced 2026-08-30 22:11:14 +00:00
Merge branch 'prerelease' into ditto
This commit is contained in:
@@ -25,6 +25,16 @@
|
||||
9069D0A30FCE1A4D0042E34C /* sqlite3.c in Sources */ = {isa = PBXBuildFile; fileRef = 9069D0A20FCE1A4D0042E34C /* sqlite3.c */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
289BE0E7180C4930003E52DA /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 9069D08B0FCE185A0042E34C;
|
||||
remoteInfo = amalgamation;
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
28B46E6217CD07A600672510 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
|
||||
9069D0A20FCE1A4D0042E34C /* sqlite3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sqlite3.c; sourceTree = "<group>"; };
|
||||
@@ -101,6 +111,7 @@
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
289BE0E8180C4930003E52DA /* PBXTargetDependency */,
|
||||
);
|
||||
name = sqlcipher;
|
||||
productName = sqlcipher;
|
||||
@@ -149,7 +160,7 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "./configure --enable-tempstore=yes --with-crypto-lib=commoncrypto CFLAGS=\"-DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLCIPHER_CRYPTO_CC\"\nmake sqlite3.c\nexit 0";
|
||||
shellScript = "./configure --enable-tempstore=yes --with-crypto-lib=commoncrypto CFLAGS=\"-DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2\"\nmake sqlite3.c\nexit 0";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
@@ -164,6 +175,14 @@
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
289BE0E8180C4930003E52DA /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 9069D08B0FCE185A0042E34C /* amalgamation */;
|
||||
targetProxy = 289BE0E7180C4930003E52DA /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
1DEB91EC08733DB70010E9CD /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
@@ -247,7 +266,7 @@
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
|
||||
"IPHONEOS_DEPLOYMENT_TARGET[arch=arm64]" = 6.0;
|
||||
"IPHONEOS_DEPLOYMENT_TARGET[arch=arm64]" = 7.0;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
@@ -269,7 +288,7 @@
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
|
||||
"IPHONEOS_DEPLOYMENT_TARGET[arch=arm64]" = 6.0;
|
||||
"IPHONEOS_DEPLOYMENT_TARGET[arch=arm64]" = 7.0;
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
SUPPORTED_PLATFORMS = "iphonesimulator macosx iphoneos";
|
||||
|
||||
+1
-1
@@ -220,7 +220,7 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
|
||||
if(zRight) {
|
||||
if (sqlite3StrNICmp(zRight ,"x'", 2) == 0 && sqlite3Strlen30(zRight) == 5) {
|
||||
unsigned char mask = 0;
|
||||
const char *hex = zRight+2;
|
||||
const unsigned char *hex = (const unsigned char *)zRight+2;
|
||||
cipher_hex2bin(hex,2,&mask);
|
||||
sqlcipher_set_hmac_salt_mask(mask);
|
||||
}
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ static int cipher_hex2int(char c) {
|
||||
(c>='a' && c<='f') ? (c)-'a'+10 : 0;
|
||||
}
|
||||
|
||||
static void cipher_hex2bin(const char *hex, int sz, unsigned char *out){
|
||||
static void cipher_hex2bin(const unsigned char *hex, int sz, unsigned char *out){
|
||||
int i;
|
||||
for(i = 0; i < sz; i += 2){
|
||||
out[i/2] = (cipher_hex2int(hex[i])<<4) | cipher_hex2int(hex[i+1]);
|
||||
|
||||
+2
-2
@@ -54,8 +54,8 @@ static int sqlcipher_cc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, uns
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int sqlcipher_cc_kdf(void *ctx, const char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key) {
|
||||
CCKeyDerivationPBKDF(kCCPBKDF2, pass, pass_sz, salt, salt_sz, kCCPRFHmacAlgSHA1, workfactor, key, key_sz);
|
||||
static int sqlcipher_cc_kdf(void *ctx, const unsigned char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key) {
|
||||
CCKeyDerivationPBKDF(kCCPBKDF2, (const char *)pass, pass_sz, salt, salt_sz, kCCPRFHmacAlgSHA1, workfactor, key, key_sz);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -60,7 +60,7 @@ typedef struct {
|
||||
unsigned int flags;
|
||||
unsigned char *key;
|
||||
unsigned char *hmac_key;
|
||||
char *pass;
|
||||
unsigned char *pass;
|
||||
char *keyspec;
|
||||
sqlcipher_provider *provider;
|
||||
void *provider_ctx;
|
||||
@@ -821,19 +821,19 @@ static int sqlcipher_cipher_ctx_key_derive(codec_ctx *ctx, cipher_ctx *c_ctx) {
|
||||
|
||||
|
||||
if(c_ctx->pass && c_ctx->pass_sz) { // if pass is not null
|
||||
if (c_ctx->pass_sz == ((c_ctx->key_sz * 2) + 3) && sqlite3StrNICmp(c_ctx->pass ,"x'", 2) == 0) {
|
||||
if (c_ctx->pass_sz == ((c_ctx->key_sz * 2) + 3) && sqlite3StrNICmp((const char *)c_ctx->pass ,"x'", 2) == 0) {
|
||||
int n = c_ctx->pass_sz - 3; /* adjust for leading x' and tailing ' */
|
||||
const char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
|
||||
const unsigned char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
|
||||
CODEC_TRACE(("cipher_ctx_key_derive: using raw key from hex\n"));
|
||||
cipher_hex2bin(z, n, c_ctx->key);
|
||||
} else if (c_ctx->pass_sz == (((c_ctx->key_sz + ctx->kdf_salt_sz) * 2) + 3) && sqlite3StrNICmp(c_ctx->pass ,"x'", 2) == 0) {
|
||||
const char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
|
||||
} else if (c_ctx->pass_sz == (((c_ctx->key_sz + ctx->kdf_salt_sz) * 2) + 3) && sqlite3StrNICmp((const char *)c_ctx->pass ,"x'", 2) == 0) {
|
||||
const unsigned char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
|
||||
CODEC_TRACE(("cipher_ctx_key_derive: using raw key from hex\n"));
|
||||
cipher_hex2bin(z, (c_ctx->key_sz * 2), c_ctx->key);
|
||||
cipher_hex2bin(z + (c_ctx->key_sz * 2), (ctx->kdf_salt_sz * 2), ctx->kdf_salt);
|
||||
} else {
|
||||
CODEC_TRACE(("cipher_ctx_key_derive: deriving key using full PBKDF2 with %d iterations\n", c_ctx->kdf_iter));
|
||||
c_ctx->provider->kdf(c_ctx->provider_ctx, (const char*) c_ctx->pass, c_ctx->pass_sz,
|
||||
c_ctx->provider->kdf(c_ctx->provider_ctx, c_ctx->pass, c_ctx->pass_sz,
|
||||
ctx->kdf_salt, ctx->kdf_salt_sz, c_ctx->kdf_iter,
|
||||
c_ctx->key_sz, c_ctx->key);
|
||||
}
|
||||
@@ -861,7 +861,7 @@ static int sqlcipher_cipher_ctx_key_derive(codec_ctx *ctx, cipher_ctx *c_ctx) {
|
||||
c_ctx->fast_kdf_iter));
|
||||
|
||||
|
||||
c_ctx->provider->kdf(c_ctx->provider_ctx, (const char*)c_ctx->key, c_ctx->key_sz,
|
||||
c_ctx->provider->kdf(c_ctx->provider_ctx, c_ctx->key, c_ctx->key_sz,
|
||||
ctx->hmac_kdf_salt, ctx->kdf_salt_sz, c_ctx->fast_kdf_iter,
|
||||
c_ctx->key_sz, c_ctx->hmac_key);
|
||||
}
|
||||
|
||||
@@ -49,8 +49,9 @@ static int sqlcipher_ltc_add_random(void *ctx, void *buffer, int length) {
|
||||
|
||||
static int sqlcipher_ltc_activate(void *ctx) {
|
||||
ltc_ctx *ltc = (ltc_ctx*)ctx;
|
||||
int random_buffer_sz = 32;
|
||||
unsigned char random_buffer[random_buffer_sz];
|
||||
int random_buffer_sz = sizeof(char) * 32;
|
||||
unsigned char *random_buffer = sqlcipher_malloc(random_buffer_sz);
|
||||
sqlcipher_memset(random_buffer, 0, random_buffer_sz);
|
||||
|
||||
if(ltc_init == 0) {
|
||||
if(register_prng(&fortuna_desc) != CRYPT_OK) return SQLITE_ERROR;
|
||||
@@ -61,7 +62,7 @@ static int sqlcipher_ltc_activate(void *ctx) {
|
||||
if(fortuna_start(&(ltc->prng)) != CRYPT_OK) {
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
sqlite3_randomness(random_buffer_sz, &random_buffer);
|
||||
sqlite3_randomness(random_buffer_sz, random_buffer);
|
||||
if(sqlcipher_ltc_add_random(ctx, random_buffer, random_buffer_sz) != SQLITE_OK) {
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
@@ -71,12 +72,14 @@ static int sqlcipher_ltc_activate(void *ctx) {
|
||||
if(fortuna_ready(&(ltc->prng)) != CRYPT_OK) {
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
sqlcipher_free(random_buffer, random_buffer_sz);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int sqlcipher_ltc_deactivate(void *ctx) {
|
||||
ltc_ctx *ltc = (ltc_ctx*)ctx;
|
||||
fortuna_done(&(ltc->prng));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static const char* sqlcipher_ltc_get_provider_name(void *ctx) {
|
||||
@@ -107,12 +110,13 @@ static int sqlcipher_ltc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, un
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int sqlcipher_ltc_kdf(void *ctx, const char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key) {
|
||||
static int sqlcipher_ltc_kdf(void *ctx, const unsigned char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key) {
|
||||
int rc, hash_idx;
|
||||
unsigned long outlen = key_sz;
|
||||
unsigned long random_buffer_sz = 256;
|
||||
char random_buffer[random_buffer_sz];
|
||||
ltc_ctx *ltc = (ltc_ctx*)ctx;
|
||||
unsigned long outlen = key_sz;
|
||||
unsigned long random_buffer_sz = sizeof(char) * 256;
|
||||
unsigned char *random_buffer = sqlcipher_malloc(random_buffer_sz);
|
||||
sqlcipher_memset(random_buffer, 0, random_buffer_sz);
|
||||
|
||||
hash_idx = find_hash("sha1");
|
||||
if((rc = pkcs_5_alg2(pass, pass_sz, salt, salt_sz,
|
||||
@@ -124,6 +128,7 @@ static int sqlcipher_ltc_kdf(void *ctx, const char *pass, int pass_sz, unsigned
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
sqlcipher_ltc_add_random(ctx, random_buffer, random_buffer_sz);
|
||||
sqlcipher_free(random_buffer, random_buffer_sz);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -132,7 +137,7 @@ static const char* sqlcipher_ltc_get_cipher(void *ctx) {
|
||||
}
|
||||
|
||||
static int sqlcipher_ltc_cipher(void *ctx, int mode, unsigned char *key, int key_sz, unsigned char *iv, unsigned char *in, int in_sz, unsigned char *out) {
|
||||
int rc, cipher_idx, hash_idx;
|
||||
int rc, cipher_idx;
|
||||
symmetric_CBC cbc;
|
||||
|
||||
if((cipher_idx = find_cipher(sqlcipher_ltc_get_cipher(ctx))) == -1) return SQLITE_ERROR;
|
||||
@@ -208,6 +213,7 @@ int sqlcipher_ltc_setup(sqlcipher_provider *p) {
|
||||
p->ctx_init = sqlcipher_ltc_ctx_init;
|
||||
p->ctx_free = sqlcipher_ltc_ctx_free;
|
||||
p->add_random = sqlcipher_ltc_add_random;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -154,8 +154,8 @@ static int sqlcipher_openssl_hmac(void *ctx, unsigned char *hmac_key, int key_sz
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int sqlcipher_openssl_kdf(void *ctx, const char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key) {
|
||||
PKCS5_PBKDF2_HMAC_SHA1(pass, pass_sz, salt, salt_sz, workfactor, key_sz, key);
|
||||
static int sqlcipher_openssl_kdf(void *ctx, const unsigned char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key) {
|
||||
PKCS5_PBKDF2_HMAC_SHA1((const char *)pass, pass_sz, salt, salt_sz, workfactor, key_sz, key);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ typedef struct {
|
||||
int (*add_random)(void *ctx, void *buffer, int length);
|
||||
int (*random)(void *ctx, void *buffer, int length);
|
||||
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);
|
||||
int (*kdf)(void *ctx, const char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key);
|
||||
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);
|
||||
int (*cipher)(void *ctx, int mode, unsigned char *key, int key_sz, unsigned char *iv, unsigned char *in, int in_sz, unsigned char *out);
|
||||
int (*set_cipher)(void *ctx, const char *cipher_name);
|
||||
const char* (*get_cipher)(void *ctx);
|
||||
|
||||
Reference in New Issue
Block a user