Discussion:
Crypto++ module is too big.
SeungYoup Lee
2014-09-19 03:20:59 UTC
Permalink
I have a problem.

I want to only RSA module in Android ndk enviroment.
When I build Crypto++ ..(so) .. but module size too big
(cryptopp module, stl module, user module = 3.. too many..)

I visits many site.. but i can't small build..
(also i sam it. .. http://morgwai.pl/ndkTutorial/ )

I want to build crypto++ static library (because reduce module size..)
How can I start... ?

Please help me..


Reference..

https://stackoverflow.com/questions/8914264/subset-of-cryptopp-library-for-mobile-usage-ios-android-ndk

*If you want to use crypto++ (and there are many good reasons you'd want
to) this is probably a scenario where you're just best off letting the
linkers do their job. I was concerned about this some time ago, and I could
not do any better by hand than the optimizing linkers could.*

*I confirmed this by dusting off my old test app that uses crypto++ to
generate a new random RSA key, sign a string and verify that string. Here
are the numbers I see:*

-

*libcryptopp.a - crypto++ built for release as a static library using
clang++ against the iOS SDK 5.0. There was no special attmept to minimize
size, just built with -fvisibility=hidden -fvisibility-inlines-hidden and
-Os:22.5MB*
-

*Empty app from the default iOS single view template, built with
-Os: 34KB*
-

*The same empty app with "self test" code added that generates a
keypair, signs (and therefore hashes) a string using RSA/SHA256, hex
encodes it, prints the signature, decodes the signature and verifies the
signature over the original string, built with -Os against the
libcryptopp.a from my first bullet above: 389KB*

*The linker seems to be doing a good job here. If you're seeing something
drastically different, make sure you're really looking at release binaries.*
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Walton
2014-09-20 17:52:40 UTC
Permalink
Post by SeungYoup Lee
I want to only RSA module in Android ndk enviroment.
When I build Crypto++ ..(so) .. but module size too big
(cryptopp module, stl module, user module = 3.. too many..)
I visits many site.. but i can't small build..
(also i sam it. .. http://morgwai.pl/ndkTutorial/ )
I want to build crypto++ static library (because reduce module size..)
How can I start... ?
Please help me..
I think you are doing many things you should be. The issue is the Crypto++
shared object has a lot of functionality, and you don't want or need it.

Here's how I would approach it:

1. Compile Crypto++ with -ffunction-sections -fdata-sections
2. Create a wrapped shared object, compile with -Os
3. Wrapper uses -fvisibility=hidden and -Wl,--exclude-libs,ALL
4 Wrapper links against libcryptopp.a
5. Run 'strip' after building you library

I believe strip uses --strip-unneeded. I think you can get more aggressive
(like --strip-debug and --strip-all) . But the downside is your crash
reports will become useless.

You should add -ffunction-sections, -fdata-sections, -fvisibility=hidden
and -Wl,--exclude-libs,ALL to CFLAGS and CXXFLAGS.

There's also a page on the Crypto++ wiki covering Android at
http://www.cryptopp.com/wiki/Android_%28Command_Line%29 . The wiki is still
having some problems (like thumbnail images not available), but you can
read it.
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
SeungYoup Lee
2014-09-28 14:50:30 UTC
Permalink
Hi ! First of all .. I very appreciate with your answer !
I don't expect answer .. but I saw your answer and I moved it.

I saw your other article about crypto++ and I learned a lot of things !
for example..
http://www.codeproject.com/script/Membership/View.aspx?mid=349853





CASE1 : Vmware + Ubuntu 14.0 + NDK 10r

I saw this site. but it is very difficult for me.
http://www.cryptopp.com/wiki/Android_%28Command_Line%29


So, I download source file and I unzip cryptopp-android-14.zip
https://github.com/noloader/cryptopp-5.6.2-android-14

After unzip file (cryptopp-android-14.zip) i get libcryptopp.a file.

1) I create Android Application Project in Eclipse ( also I install CDT
Plugin )
2) I create jni folder and copy cryptopp header file (in
cryptopp-android-14.zip include files)
3) I put libcryptopp.a file in libs/libcryptopp.a
4) I reference this site http://morgwai.pl/ndkTutorial/
and visit http://morgwai.pl/ndkTutorial/

5) download NdkTutorial project and copy src folder, AndroidmManifest.xml,
res folder
(if you error file in res folder just remove!, and R file error appropreate
change)

6) I create my module in jni folder named crypt_user.cpp


extern "C" {

JNIEXPORT jstring JNICALL Java_pl_morgwai_ndktutorial_Native_fun(JNIEnv
*env,
jobject) {

string readSignater;
string publicFileName = "publicKey";
string message = "RSA System Test";

try {
AutoSeededRandomPool rng;
InvertibleRSAFunction parameters;
parameters.GenerateRandomWithKeySize(rng, 1024);
RSA::PublicKey publicKey(parameters);
....
} // try

catch (CryptoPP::Exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}

return (env)->NewStringUTF("Hello JNI!!!!!");

}
}


7) Edit Android.mk file

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := static_crypt # anything..
LOCAL_SRC_FILES := ../libs/libcryptopp.a # libs/libcryptopp.a (in
cryptopp-android-14.zip include files)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)

LOCAL_MODULE := mymodule
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/cryptopp \

FILE_LIST := \
$(wildcard $(LOCAL_PATH)/*.c*) \
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

# Add ..
LOCAL_CFLAGS := -Os
LOCAL_CFLAGS += -ffunction-sections
LOCAL_CFLAGS += -fdata-sections
LOCAL_CFLAGS += -fvisibility=hidden
LOCAL_CFLAGS += -Wl
LOCAL_CFLAGS += --exclude-libs
LOCAL_STATIC_LIBRARIES := static_crypt

include $(BUILD_SHARED_LIBRARY)


8) Edit Application.mk
APP_ABI := armeabi
APP_STL := stlport_static
APP_PLATFORM := android-8
APP_CFLAGS += -Wno-error=format-security
APP_CFLAGS += -fexceptions \
-fpermissive \
-frtti



9) build command ndk-build
move project position
ex) /workspace/Staticbuild/jni
and ndk-build


$ ndk-build
[armeabi] SharedLibrary : libmymodule.so
[armeabi] Install : libmymodule.so


10) After build the module size 5KB !!
11) For test, I Edit

package pl.morgwai.ndktutorial;


public class Native {

public static final String LOG_TAG = Native.class.getSimpleName();

static {
System.loadLibrary("mymodule");
}

public native String fun();
}







CASE2 : window + NDK 10r

I download Crypto++ 5.6.2 and build in eclipse with window enviroment
( setting : install cygwin for window & install eclipse CDT plugin )

Environment
- Eclipse with CDT
- window
- cygwin
- NDK, SDK (android)


First, I build raw crypto++ source code static library.
1) Create Android Application Project in Eclipse
2) Create JNI Folder and copy Crypto++ source code all (Specific position)
3) In Eclipse project, click right click . new -> convert c++ project (
select static library option)
4) create Android.mk file and Application.mk file


< Application.mk >
APP_ABI := armeabi
APP_STL := stlport_static
APP_CFLAGS += -Wno-error=format-security
APP_CFLAGS += -fexceptions \
-fpermissive

< Android.mk >
# sattic library build file
include $(CLEAR_VARS)
# module name ramdom .. (you want)
LOCAL_MODULE := random name
# put crptopp all file (jni/cryptopp)
FILE_LIST := $(wildcard $(LOCAL_PATH)/cryptopp/*.c*)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

include $(BUILD_STATIC_LIBRARY)

# dummy so file
include $(CLEAR_VARS)
LOCAL_MODULE := garbage
LOCAL_STATIC_LIBRARIES := random name
include $(BUILD_SHARED_LIBRARY)

5) Chaing eclipse project setting properties
-C/C++ build : builder Settings - build command : ndk-build.cmd
-C/C++ General : Path and symbols - Include Setting position toolchain..
(similar : http://202psj.tistory.com/465)

6) build and get libcrypto.a ( project - obj - local - armeabi - XXX.a)




Second, I create another project
1) Create Android Application Project in Eclipse
2) Create Jni Folder and copyt crypto++ header file
3) And write my code under jni folder ( reference crypto++ api ) + put
libcrypto.a file
4) Edit Android.mk, Application.mk and build so library


LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cryptopplibrary
# static build library position
LOCAL_SRC_FILES := ../libs/libcrpytopp.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog -lz
LOCAL_MODULE := temp
LOCAL_CFLAGS := -Os
LOCAL_CFLAGS += -ffunction-sections
LOCAL_CFLAGS += -fdata-sections
LOCAL_CFLAGS += -fvisibility=hidden
LOCAL_CFLAGS += -Wl
LOCAL_CFLAGS += --exclude-libs

LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/cryptopp \

FILE_LIST := \
$(wildcard $(LOCAL_PATH)/*.c*) \
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_STATIC_LIBRARIES := cryptopplibrary
include $(BUILD_SHARED_LIBRARY)

4) After build , I create my crypto library (only i want function )
The size is down!!
--
--
You received this message because you are subscribed to the "Crypto++ Users" Google Group.
To unsubscribe, send an email to cryptopp-users-***@googlegroups.com.
More information about Crypto++ and this group is available at http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jeffrey Walton
2018-08-27 13:41:09 UTC
Permalink
Post by SeungYoup Lee
I have a problem.
I want to only RSA module in Android ndk enviroment.
When I build Crypto++ ..(so) .. but module size too big
(cryptopp module, stl module, user module = 3.. too many..)
I visits many site.. but i can't small build..
(also i sam it. .. http://morgwai.pl/ndkTutorial/ )
I want to build crypto++ static library (because reduce module size..)
How can I start... ?
This is a bit late but... We added a wiki page on creating wrapper DLLs.
Also see https://www.cryptopp.com/wiki/Wrapper_DLL .

Jeff
--
You received this message because you are subscribed to "Crypto++ Users". More information about Crypto++ and this group is available at http://www.cryptopp.com and http://groups.google.com/forum/#!forum/cryptopp-users.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...