8000 Change pass field to unsigned char * in cipher_ctx · magic-coder/sqlcipher@bdd8d0a · GitHub
[go: up one dir, main page]

Skip to content

Commit bdd8d0a

Browse files
Change pass field to unsigned char * in cipher_ctx
1 parent 035ae3e commit bdd8d0a

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

src/crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
220220
if(zRight) {
221221
if (sqlite3StrNICmp(zRight ,"x'", 2) == 0 && sqlite3Strlen30(zRight) == 5) {
222222
unsigned char mask = 0;
223-
const char *hex = zRight+2;
223+
const unsigned char *hex = (const unsigned char *)zRight+2;
224224
cipher_hex2bin(hex,2,&mask);
225225
sqlcipher_set_hmac_salt_mask(mask);
226226
}

src/crypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static int cipher_hex2int(char c) {
142142
(c>='a' && c<='f') ? (c)-'a'+10 : 0;
143143
}
144144

145-
static void cipher_hex2bin(const char *hex, int sz, unsigned char *out){
145+
static void cipher_hex2bin(const unsigned char *hex, int sz, unsigned char *out){
146146
int i;
147147
for(i = 0; i < sz; i += 2){
148148
out[i/2] = (cipher_hex2int(hex[i])<<4) | cipher_hex2int(hex[i+1]);

src/crypto_cc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ static int sqlcipher_cc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, uns
5454
return SQLITE_OK;
5555
}
5656

57-
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) {
58-
CCKeyDerivationPBKDF(kCCPBKDF2, pass, pass_sz, salt, salt_sz, kCCPRFHmacAlgSHA1, workfactor, key, key_sz);
57+
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) {
58+
CCKeyDerivationPBKDF(kCCPBKDF2, (const char *)pass, pass_sz, salt, salt_sz, kCCPRFHmacAlgSHA1, workfactor, key, key_sz);
5959
return SQLITE_OK;
6060
}
6161

src/crypto_impl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef struct {
6060
unsigned int flags;
6161
unsigned char *key;
6262
unsigned char *hmac_key;
63-
char *pass;
63+
unsigned char *pass;
6464
char *keyspec;
6565
sqlcipher_provider *provider;
6666
void *provider_ctx;
@@ -821,19 +821,19 @@ static int sqlcipher_cipher_ctx_key_derive(codec_ctx *ctx, cipher_ctx *c_ctx) {
821821

822822

823823
if(c_ctx->pass && c_ctx->pass_sz) { // if pass is not null
824-
if (c_ctx->pass_sz == ((c_ctx->key_sz * 2) + 3) && sqlite3StrNICmp(c_ctx->pass ,"x'", 2) == 0) {
824+
if (c_ctx->pass_sz == ((c_ctx->key_sz * 2) + 3) && sqlite3StrNICmp((const char *)c_ctx->pass ,"x'", 2) == 0) {
825825
int n = c_ctx->pass_sz - 3; /* adjust for leading x' and tailing ' */
826-
const char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
826+
const unsigned char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
827827
CODEC_TRACE(("cipher_ctx_key_derive: using raw key from hex\n"));
828828
cipher_hex2bin(z, n, c_ctx->key);
829-
} else if (c_ctx->pass_sz == (((c_ctx->key_sz + ctx->kdf_salt_sz) * 2) + 3) && sqlite3StrNICmp(c_ctx->pass ,"x'", 2) == 0) {
830-
const char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
829+
} 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) {
830+
const unsigned char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
831831
CODEC_TRACE(("cipher_ctx_key_derive: using raw key from hex\n"));
832832
cipher_hex2bin(z, (c_ctx->key_sz * 2), c_ctx->key);
833833
cipher_hex2bin(z + (c_ctx->key_sz * 2), (ctx->kdf_salt_sz * 2), ctx->kdf_salt);
834834
} else {
835835
CODEC_TRACE(("cipher_ctx_key_derive: deriving key using full PBKDF2 with %d iterations\n", c_ctx->kdf_iter));
836-
c_ctx->provider->kdf(c_ctx->provider_ctx, (const char*) c_ctx->pass, c_ctx->pass_sz,
836+
c_ctx->provider->kdf(c_ctx->provider_ctx, c_ctx->pass, c_ctx->pass_sz,
837837
ctx->kdf_salt, ctx->kdf_salt_sz, c_ctx->kdf_iter,
838838
c_ctx->key_sz, c_ctx->key);
839839
}
@@ -861,7 +861,7 @@ static int sqlcipher_cipher_ctx_key_derive(codec_ctx *ctx, cipher_ctx *c_ctx) {
861861
c_ctx->fast_kdf_iter));
862862

863863

864-
c_ctx->provider->kdf(c_ctx->provider_ctx, (const char*)c_ctx->key, c_ctx->key_sz,
864+
c_ctx->provider->kdf(c_ctx->provider_ctx, c_ctx->key, c_ctx->key_sz,
865865
ctx->hmac_kdf_salt, ctx->kdf_salt_sz, c_ctx->fast_kdf_iter,
866866
c_ctx->key_sz, c_ctx->hmac_key);
867867
}

src/crypto_libtomcrypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int sqlcipher_ltc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, un
110110
return SQLITE_OK;
111111
}
112112

113-
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) {
113+
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) {
114114
int rc, hash_idx;
115115
ltc_ctx *ltc = (ltc_ctx*)ctx;
116116
unsigned long outlen = key_sz;

src/crypto_openssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ static int sqlcipher_openssl_hmac(void *ctx, unsigned char *hmac_key, int key_sz
154154
return SQLITE_OK;
155155
}
156156

157-
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) {
158-
PKCS5_PBKDF2_HMAC_SHA1(pass, pass_sz, salt, salt_sz, workfactor, key_sz, key);
157+
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) {
158+
PKCS5_PBKDF2_HMAC_SHA1((const char *)pass, pass_sz, salt, salt_sz, workfactor, key_sz, key);
159159
return SQLITE_OK;
160160
}
161161

src/sqlcipher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct {
4343
int (*add_random)(void *ctx, void *buffer, int length);
4444
int (*random)(void *ctx, void *buffer, int length);
4545
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);
46-
int (*kdf)(void *ctx, const char *pass, int pass_sz, unsigned char* salt, int salt_sz, int workfactor, int key_sz, unsigned char *key);
46+
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);
4747
int (*cipher)(void *ctx, int mode, unsigned char *key, int key_sz, unsigned char *iv, unsigned char *in, int in_sz, unsigned char *out);
4848
int (*set_cipher)(void *ctx, const char *cipher_name);
4949
const char* (*get_cipher)(void *ctx);

0 commit comments

Comments
 (0)
0