Hi, What I am trying to do is building SQLCipher from sources for Android, but need to link against LibTomCrypt library(libtomcrypt.so or libtomcrypt.a) instead of Openssl.
I need to use the generated library (libsqlite3.so or as it is called libsqlcihper.so now) from command-line to test different encryption algorithms programmatically on my Galaxy tab device.
No application integration is required for now, just I need the libsqlite3.so with Sqlcipher encryption support using LibTomCrypt.
My requirements: SQLCipher community edition source code for Android, Android ICS 4.0.4, SQLite 3.7.4 Amalgamation,
and LibTomCrypt 1.17 with full featured algorithms and modes.
How can I achieve that and where to find the proper source code for that? Does the Sqlcipher community edition provide these sources?
What about if I compile a stock SQLite 3.7.4 amalgamation file (sqlite3.c) to use SQLCipher and link to libtomcrypt.so?
Can that work and provide an libsqlite3.so with Libtomcrypt encryption support? All hints are appreciated, Thanks, Mosed
Hello Nick, Thanks for the info and sorry for late reply since I was out for a few days. I will give it a try to compile SQLCipher with the help of your hints then I will keep you informed. The reason of using Libtomcrypt over OpenSSL is that I am experimenting on some algorithms that are not available in OpenSSL (such as Twofish, RC6, and others) to study their performance aspects in mobile devices. “Specifically you would need to build static libtomcrypt libraries” What about building and linking against dynamic Libtomcrypt (libtomcrypt.so)? Will that work, since I already compiled dynamic Libtomcrypt for Android but still have problems with static one. When running make init command I get this error:
android-database-sqlcipher$ make init fatal: Not a git repository (or any of the parent directories): .git fatal: Not a git repository (or any of the parent directories): .git git submodule update --init fatal: Not a git repository (or any of the parent directories): .git make: *** [init] Error 128 Any hint about this error? Thanks, Mosed
Hi Nick, I followed the points you provided to build Sqlcipher with Libtomcrypt as follow:
I compiled Libtomcrypt statically for Android (armeabi)
I modified the ndk build to link with Libtomcrypt instead of Openssl by modifying the Android.mk file
I have SQLCipher configured with -DSQLCIPHER_CRYPTO_LIBTOMCRYPT and also with the help of --with-crypto-lib=libtomcrypt
All seems to be ok and linking to Libtomcrypt is progressing instead of Openssl but some errors occurred:
/android-database-sqlcipher/obj/local/armeabi/objs/sqlcipher/sqlcipher/sqlite3.o: In function `sqlcipher_ltc_add_random':
/android-database-sqlcipher/external/sqlcipher/sqlite3.c:15420: undefined reference to `fortuna_add_entropy'
/android-database-sqlcipher/external/sqlcipher/sqlite3.c:15420: undefined reference to `fortuna_add_entropy'
/android-database-sqlcipher/external/sqlcipher/sqlite3.c:15429: undefined reference to `fortuna_ready'
/android-database-sqlcipher/obj/local/armeabi/objs/sqlcipher/sqlcipher/sqlite3.o: In function `sqlcipher_ltc_random':
/android-database-sqlcipher/external/sqlcipher/sqlite3.c:15498: undefined reference to `fortuna_read'
/android-database-sqlcipher/obj/local/armeabi/objs/sqlcipher/sqlcipher/sqlite3.o: In function `sqlcipher_ltc_deactivate':
/android-database-sqlcipher/external/sqlcipher/sqlite3.c:15474: undefined reference to `fortuna_done'
/android-database-sqlcipher/obj/local/armeabi/objs/sqlcipher/sqlcipher/sqlite3.o: In function `sqlcipher_ltc_activate':
/android-database-sqlcipher/external/sqlcipher/sqlite3.c:15449: undefined reference to `fortuna_start'
/android-database-sqlcipher/external/sqlcipher/sqlite3.c:15466: undefined reference to `fortuna_desc'
collect2: ld returned 1 exit status
make[1]: *** [/android-database-sqlcipher/obj/local/armeabi/libsqlcipher.so] Error 1
make[1]: Leaving directory `/android-database-sqlcipher/external'
make: *** [build-external] Error 2
What do you think the reasons behind these errors? They looks related to Libtomcrypt but how to remove them and continue to build libsqlcipher (.so or .a) which is the library I need. Thank you. Mosed
Hi Nick,
SQLCipher with different ciphers and modes is working fine now.
To confirm the type of cipher used, I added a simple printf in the crypto_libtomcrypt.c:
printf("%s\n",cipher_descriptor[cipher_idx].name);
It shows the cipher name properly but that is printed on screen multiple times instead of one time.
I thought that is due to some threading/mutexing. My work now need single-threading mode.
To stop any threading and go in single-thread mode, I tried to use many options:
Rebuild libsqlcipher with compile option -DSQLITE_THREADSAFE=0
Use the runtime option sqlite3_config(SQLITE_CONFIG_SINGLETHREAD); inside application code
Compile with the following option: -DSQLITE_MUTEX_APPDEF=1
Also this compile option SQLCIPHER_LTC_NO_MUTEX_RAND
All that has no benefit, still the printf message prints repeatedly (around 4 times with each db insert)
which shows that some threading is still lurking somewhere.
My question is that does Sqlcipher has any built-in threading? If yes, how to stop it to go in single-thread mode?
If no, what do think is the reason behind this multi message printing. I would like just to confirm
that no thread are active in my current serial tests.
Thank you,
Mosed
--
---
You received this message because you are subscribed to the Google Groups "SQLCipher Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlcipher+...@googlegroups.com.
Hello Nick,
Firstly, I would like to thank you for your continuous help in the last few months to work
and build SQLCipher which greatly assisted me to proceed with my academic work.
Sorry for late response since I was working with other projects for a while.
In your last post you asked me for more details about the scenario I am testing. Here they are.
My main idea is to test the performance of SQLCipher encryption when using one core (one thread) and two
cores or more (two threads or more). I use OpenMP to manage parallel threads. I do the tests on a real device.
What I did is that I compiled SQLCipher for Android with LibTomCrypt and I came up with libsqlcipher.so library
which I will call from my native code through command line (I sent to your email a small C code with details).
I added OpenMP to the environment (with the help of NDK) to provide parallel processing functionality.
Using OpenMP, I placed a parallel pragma inside the main encryption code that is available in the mode of
operation (inside LibTomCrypt). This pragma will create two threads and divide the encryption work between them.
I did that to measure the performance of an SQLCipher database when using one thread (one core) and two threads (two cores).
But unfortunately I was getting no improvement when using two threads. That looks strange to me since two threads
should be much faster than one!
When I worked with the same scenario inside an Android device without SQLCipher databases, I got almost double of
the speedup (less encryption time when I used two threads/cores). But when I tried to implement it with SQLCipher, I can not see
any improvement in performance. I don’t know why? Any advice?
My questions:
Is it possible, theoretically, to get significant improvement in the db encryption time when using two threads (two cores) as compared to one thread (one core)?
What about practically? How to achieve that and get good speedup since my scenario is not able to do that? What is wrong with it?
What might prevent the two threads to achieve better than one thread?
Am I facing any kind of database file locks? Or other reasons?
Any hints from you will be highly helping and appreciated.
If you need any further details, please inform me.
Thank you,
Mosed
To unsubscribe from this group and stop receiving emails from it, send an email to sqlcipher+...@googlegroups.com.
Hello Stephen,
Hello Nick,
Mosed is back :). Busy for long time with different projects.
Not feeling good to leave the work in this thread until finished and get fruitful results.
About “I'm not clear exactly how you are redefining the encryption inside the libtomcrypt code”
As you know that Sqlcipher does add ltc support to Sqlite using CBC mode. By changing that part of
code you can redefine other encryption modes, which are supported by Libtomcrypt, instead of CBC.
“Thus, at most you would be parallelizing the encryption of a single page of data at a time”
Yes you are right. What I try to do is divide the page data between threads to improve performance.
But how much do you think that can improve performance?
Although this work is an academic one, I am willing to contact your customer support service and
get a paid support to help complete this work.
Thank you,
Mosed