Skip to content

Commit

Permalink
change sqlcipher memory functions to use u64 params
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlombardo committed Apr 29, 2020
1 parent 621d704 commit 005ea9d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
24 changes: 12 additions & 12 deletions src/crypto_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ void sqlcipher_deactivate() {
optimized out by the compiler.
Note: As suggested by Joachim Schipper ([email protected])
*/
void* sqlcipher_memset(void *v, unsigned char value, int len) {
int i = 0;
void* sqlcipher_memset(void *v, unsigned char value, u64 len) {
u64 i = 0;
volatile unsigned char *a = v;

if (v == NULL) return v;

CODEC_TRACE_MEMORY("sqlcipher_memset: setting %p[0-%d]=%d)\n", a, len, value);
CODEC_TRACE_MEMORY("sqlcipher_memset: setting %p[0-%llu]=%d)\n", a, len, value);
for(i = 0; i < len; i++) {
a[i] = value;
}
Expand All @@ -257,9 +257,9 @@ void* sqlcipher_memset(void *v, unsigned char value, int len) {
/* constant time memory check tests every position of a memory segement
matches a single value (i.e. the memory is all zeros)
returns 0 if match, 1 of no match */
int sqlcipher_ismemset(const void *v, unsigned char value, int len) {
int sqlcipher_ismemset(const void *v, unsigned char value, u64 len) {
const unsigned char *a = v;
int i = 0, result = 0;
u64 i = 0, result = 0;

for(i = 0; i < len; i++) {
result |= a[i] ^ value;
Expand All @@ -281,7 +281,7 @@ int sqlcipher_memcmp(const void *v0, const void *v1, int len) {
return (result != 0);
}

void sqlcipher_mlock(void *ptr, int sz) {
void sqlcipher_mlock(void *ptr, u64 sz) {
#ifndef OMIT_MEMLOCK
#if defined(__unix__) || defined(__APPLE__)
int rc;
Expand All @@ -308,7 +308,7 @@ void sqlcipher_mlock(void *ptr, int sz) {
#endif
}

void sqlcipher_munlock(void *ptr, int sz) {
void sqlcipher_munlock(void *ptr, u64 sz) {
#ifndef OMIT_MEMLOCK
#if defined(__unix__) || defined(__APPLE__)
int rc;
Expand Down Expand Up @@ -343,8 +343,8 @@ void sqlcipher_munlock(void *ptr, int sz) {
* If sz is > 0, and not compiled with OMIT_MEMLOCK, system will attempt to unlock the
* memory segment so it can be paged
*/
void sqlcipher_free(void *ptr, int sz) {
CODEC_TRACE_MEMORY("sqlcipher_free: calling sqlcipher_memset(%p,0,%d)\n", ptr, sz);
void sqlcipher_free(void *ptr, u64 sz) {
CODEC_TRACE_MEMORY("sqlcipher_free: calling sqlcipher_memset(%p,0,%llu)\n", ptr, sz);
sqlcipher_memset(ptr, 0, sz);
sqlcipher_munlock(ptr, sz);
sqlite3_free(ptr);
Expand All @@ -355,11 +355,11 @@ void sqlcipher_free(void *ptr, int sz) {
* reference counted and leak detection works. Unless compiled with OMIT_MEMLOCK
* attempts to lock the memory pages so sensitive information won't be swapped
*/
void* sqlcipher_malloc(int sz) {
void* sqlcipher_malloc(u64 sz) {
void *ptr;
CODEC_TRACE_MEMORY("sqlcipher_malloc: calling sqlite3Malloc(%d)\n", sz);
CODEC_TRACE_MEMORY("sqlcipher_malloc: calling sqlite3Malloc(%llu)\n", sz);
ptr = sqlite3Malloc(sz);
CODEC_TRACE_MEMORY("sqlcipher_malloc: calling sqlcipher_memset(%p,0,%d)\n", ptr, sz);
CODEC_TRACE_MEMORY("sqlcipher_malloc: calling sqlcipher_memset(%p,0,%llu)\n", ptr, sz);
sqlcipher_memset(ptr, 0, sz);
sqlcipher_mlock(ptr, sz);
return ptr;
Expand Down
13 changes: 6 additions & 7 deletions src/sqlcipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ typedef struct {
} sqlcipher_provider;

/* utility functions */
void sqlcipher_free(void *, int);
void* sqlcipher_malloc(int);
void sqlcipher_mlock(void *, int);
void sqlcipher_munlock(void *, int);
void* sqlcipher_memset(void *, unsigned char, int);
int sqlcipher_ismemset(const void *, unsigned char, int);
void* sqlcipher_malloc(u64);
void sqlcipher_mlock(void *, u64);
void sqlcipher_munlock(void *, u64);
void* sqlcipher_memset(void *, unsigned char, u64);
int sqlcipher_ismemset(const void *, unsigned char, u64);
int sqlcipher_memcmp(const void *, const void *, int);
void sqlcipher_free(void *, int);
void sqlcipher_free(void *, u64);
char* sqlcipher_version();

/* provider interfaces */
Expand Down

0 comments on commit 005ea9d

Please sign in to comment.