Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Android.mk to build using android NDK #3

Closed
wants to merge 1 commit into from

Conversation

cawka
Copy link
Contributor

@cawka cawka commented Jun 29, 2015

No description provided.

@cawka cawka force-pushed the android branch 2 times, most recently from 069b3c4 to a462cf8 Compare June 29, 2015 19:34
@noloader
Copy link
Collaborator

I have not forgot about this request. I need to get with folks and see where we should put it.

@noloader
Copy link
Collaborator

@alex - I want to grab this one eventually, too.

I need to talk to Wei about adding a Extra/ folder, and putting goodies like this in there. I have some stuff that would be appropriate, also.

By the way, do you do Cmake? If so, that's another one I would like for users who want it.

@noloader
Copy link
Collaborator

noloader commented Dec 4, 2015

@alex - This is now up for debate at Android setenv script. If all goes well, we will grab it in a week or two.

@noloader noloader added this to the 5.7 milestone Dec 4, 2015
@cawka cawka force-pushed the android branch 2 times, most recently from 045b07f to 89b0fa7 Compare December 6, 2015 20:30
@noloader
Copy link
Collaborator

noloader commented Dec 26, 2015

I really want the Android.mk, but I don't want the additional directory structure. Can you think of anything we can do to get _Android.mk_ without the directory structure?

@KayEss
Copy link
Contributor

KayEss commented Nov 2, 2016

Just wanted to pop up and suggest that the source file list be split into a separate file that each .mk can then include. That way it only needs to be managed in one place.

@anonimal
Copy link
Contributor

2015
2016

Status?

@Deadpikle
Copy link
Contributor

Deadpikle commented Sep 8, 2017

I was able to build for all platforms using ndk-build, NDK r15c, and the fix from #489 using the following files just plopped into the main cryptopp directory (no extra folders in the main source tree, in other words):

Android.mk

LOCAL_PATH := $(call my-dir)
 
CRYPTOPP_SRC_FILES := cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp algebra.cpp algparam.cpp arc4.cpp aria.cpp aria-simd.cpp ariatab.cpp asn.cpp authenc.cpp base32.cpp base64.cpp basecode.cpp bfinit.cpp blake2.cpp blake2-simd.cpp blowfish.cpp blumshub.cpp camellia.cpp cast.cpp casts.cpp cbcmac.cpp ccm.cpp chacha.cpp channels.cpp cmac.cpp crc.cpp crc-simd.cpp default.cpp des.cpp dessp.cpp dh.cpp dh2.cpp dll.cpp dsa.cpp eax.cpp ec2n.cpp eccrypto.cpp ecp.cpp elgamal.cpp emsa2.cpp eprecomp.cpp esign.cpp files.cpp filters.cpp fips140.cpp fipsalgt.cpp gcm.cpp gcm-simd.cpp gf256.cpp gf2_32.cpp gf2n.cpp gfpcrypt.cpp gost.cpp gzip.cpp hex.cpp hmac.cpp hrtimer.cpp ida.cpp idea.cpp iterhash.cpp kalyna.cpp kalynatab.cpp keccak.cpp luc.cpp mars.cpp marss.cpp md2.cpp md4.cpp md5.cpp misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp neon-simd.cpp network.cpp oaep.cpp osrng.cpp padlkrng.cpp panama.cpp pch.cpp pkcspad.cpp poly1305.cpp polynomi.cpp pssr.cpp pubkey.cpp queue.cpp rabin.cpp randpool.cpp rc2.cpp rc5.cpp rc6.cpp rdrand.cpp rdtables.cpp rijndael.cpp rijndael-simd.cpp ripemd.cpp rng.cpp rsa.cpp rw.cpp safer.cpp salsa.cpp seal.cpp seed.cpp serpent.cpp sha.cpp sha3.cpp shacal2.cpp shacal2-simd.cpp shark.cpp sharkbox.cpp sha-simd.cpp simple.cpp skipjack.cpp socketft.cpp sosemanuk.cpp square.cpp squaretb.cpp strciphr.cpp tea.cpp tftables.cpp threefish.cpp tiger.cpp tigertab.cpp trdlocal.cpp ttmac.cpp twofish.cpp vmac.cpp wait.cpp wake.cpp whrlpool.cpp winpipes.cpp xtr.cpp xtrcrypt.cpp zdeflate.cpp zinflate.cpp zlib.cpp
 
include $(CLEAR_VARS)
LOCAL_MODULE := cryptopp
LOCAL_SRC_FILES := $(CRYPTOPP_SRC_FILES)
LOCAL_CFLAGS := -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_SSSE3 -DCRYPTOPP_DISABLE_AESNI
LOCAL_LDLIBS := -latomic
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := cpufeatures
include $(BUILD_SHARED_LIBRARY)
 
$(call import-module,android/cpufeatures)

Application.mk

APP_ABI := all
APP_STL := c++_static
APP_CPPFLAGS += -fexceptions -frtti
APP_PLATFORM := android-21
APP_OPTIM := release

Command line

$ [path to android-ndk/ndk-build] NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk

@noloader
Copy link
Collaborator

noloader commented Sep 8, 2017

Thanks @Deadpikle.

So it looks like thrust of your change was to add CRYPTOPP_SRC_FILES.

I'll need a few days to test things and write-up a wiki page.

With the fix and documentation we should be able to merge it.

Thanks to @cawka for the initial PR and @Deadpikle for the update.

@Deadpikle
Copy link
Contributor

@noloader There are a few other things that I might as well document here for the future:

LOCAL_LDLIBS := -latomic to fix an issue compiling on armeabi (see android/ndk#104)

This block fixes issues with using android_getCpuFeatures() (same sort of deal as #489)

LOCAL_STATIC_LIBRARIES := cpufeatures
...
$(call import-module,android/cpufeatures)

As far as not duplicating the source list goes, you can apparently use a wildcard selection of .cpp files as seen here: https://stackoverflow.com/a/8980441/3938401

FILE_LIST := $(wildcard $(LOCAL_PATH)/[DIRECTORY]/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

But with the test files and the source files in the same directory, I haven't yet found a way to do a wildcard and then take out the test files (Searching on Google has failed me; it's possible there is a way 😜).

Just to save you some Google time when making that wiki page if you need these links:

@noloader
Copy link
Collaborator

noloader commented Sep 9, 2017

As far as not duplicating the source list goes, you can apparently use a wildcard selection of .cpp files as seen here: https://stackoverflow.com/a/8980441/3938401

Well, there's a few issues. We do just filter them out in the makefile: GNUmakefile and GNUmakefile-cross. However...

You need to order the object files like the makefile does. Also see Static Initialization Order Fiasco. You also need to sort the files by name for PR #426, Have constant link order.


This block fixes issues with using android_getCpuFeatures()

Thanks. I did not know another library was needed for it.

@Deadpikle
Copy link
Contributor

Deadpikle commented Sep 17, 2017

@noloader It appears as though Android.mk is a standard make file, so we can actually just do the same thing as GNUmakefile-cross to grab filenames (I filtered out test files in this sample):

Android.mk

LOCAL_PATH := $(call my-dir)
 
SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp winpipes.cpp cryptlib_bds.cpp,$(sort $(wildcard *.cpp)))
TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp datatest.cpp regtest1.cpp regtest2.cpp regtest3.cpp fipsalgt.cpp dlltest.cpp
SRCS := $(filter-out $(TESTSRCS), $(SRCS))

include $(CLEAR_VARS)
LOCAL_MODULE := cryptopp
LOCAL_SRC_FILES := $(SRCS)
LOCAL_CFLAGS := -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_SSSE3 -DCRYPTOPP_DISABLE_AESNI 
LOCAL_LDLIBS := -latomic
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := cpufeatures
include $(BUILD_SHARED_LIBRARY)
 
$(call import-module,android/cpufeatures)

This compiles everything in the order given in SRCS. I ran ndk-build with V=1 to get compiler output to verify that the linker orders things in alpha order:

[arm64-v8a] SharedLibrary  : libcryptopp.so
/home/[username]/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -Wl,-soname,libcryptopp.so -shared --sysroot=/home/[username]/android-ndk-r15c/platforms/android-21/arch-arm64 ./obj/local/arm64-v8a/objs/cryptopp/cryptlib.o ./obj/local/arm64-v8a/objs/cryptopp/cpu.o ./obj/local/arm64-v8a/objs/cryptopp/integer.o ./obj/local/arm64-v8a/objs/cryptopp/3way.o ./obj/local/arm64-v8a/objs/cryptopp/adler32.o ./obj/local/arm64-v8a/objs/cryptopp/algebra.o ./obj/local/arm64-v8a/objs/cryptopp/algparam.o ./obj/local/arm64-v8a/objs/cryptopp/arc4.o ./obj/local/arm64-v8a/objs/cryptopp/aria-simd.o ./obj/local/arm64-v8a/objs/cryptopp/aria.o ./obj/local/arm64-v8a/objs/cryptopp/ariatab.o ./obj/local/arm64-v8a/objs/cryptopp/asn.o ./obj/local/arm64-v8a/objs/cryptopp/authenc.o ./obj/local/arm64-v8a/objs/cryptopp/base32.o ./obj/local/arm64-v8a/objs/cryptopp/base64.o ./obj/local/arm64-v8a/objs/cryptopp/basecode.o ./obj/local/arm64-v8a/objs/cryptopp/bfinit.o ./obj/local/arm64-v8a/objs/cryptopp/blake2-simd.o ./obj/local/arm64-v8a/objs/cryptopp/blake2.o ./obj/local/arm64-v8a/objs/cryptopp/blowfish.o ./obj/local/arm64-v8a/objs/cryptopp/blumshub.o ./obj/local/arm64-v8a/objs/cryptopp/camellia.o ./obj/local/arm64-v8a/objs/cryptopp/cast.o ./obj/local/arm64-v8a/objs/cryptopp/casts.o ./obj/local/arm64-v8a/objs/cryptopp/cbcmac.o ./obj/local/arm64-v8a/objs/cryptopp/ccm.o ./obj/local/arm64-v8a/objs/cryptopp/chacha.o ./obj/local/arm64-v8a/objs/cryptopp/channels.o ./obj/local/arm64-v8a/objs/cryptopp/cmac.o ./obj/local/arm64-v8a/objs/cryptopp/crc-simd.o ./obj/local/arm64-v8a/objs/cryptopp/crc.o ./obj/local/arm64-v8a/objs/cryptopp/default.o ./obj/local/arm64-v8a/objs/cryptopp/des.o ./obj/local/arm64-v8a/objs/cryptopp/dessp.o ./obj/local/arm64-v8a/objs/cryptopp/dh.o ./obj/local/arm64-v8a/objs/cryptopp/dh2.o ./obj/local/arm64-v8a/objs/cryptopp/dll.o ./obj/local/arm64-v8a/objs/cryptopp/dsa.o ./obj/local/arm64-v8a/objs/cryptopp/eax.o ./obj/local/arm64-v8a/objs/cryptopp/ec2n.o ./obj/local/arm64-v8a/objs/cryptopp/eccrypto.o ./obj/local/arm64-v8a/objs/cryptopp/ecp.o ./obj/local/arm64-v8a/objs/cryptopp/elgamal.o ./obj/local/arm64-v8a/objs/cryptopp/emsa2.o ./obj/local/arm64-v8a/objs/cryptopp/eprecomp.o ./obj/local/arm64-v8a/objs/cryptopp/esign.o ./obj/local/arm64-v8a/objs/cryptopp/files.o ./obj/local/arm64-v8a/objs/cryptopp/filters.o ./obj/local/arm64-v8a/objs/cryptopp/fips140.o ./obj/local/arm64-v8a/objs/cryptopp/fipstest.o ./obj/local/arm64-v8a/objs/cryptopp/gcm-simd.o ./obj/local/arm64-v8a/objs/cryptopp/gcm.o ./obj/local/arm64-v8a/objs/cryptopp/gf256.o ./obj/local/arm64-v8a/objs/cryptopp/gf2_32.o ./obj/local/arm64-v8a/objs/cryptopp/gf2n.o ./obj/local/arm64-v8a/objs/cryptopp/gfpcrypt.o ./obj/local/arm64-v8a/objs/cryptopp/gost.o ./obj/local/arm64-v8a/objs/cryptopp/gzip.o ./obj/local/arm64-v8a/objs/cryptopp/hex.o ./obj/local/arm64-v8a/objs/cryptopp/hmac.o ./obj/local/arm64-v8a/objs/cryptopp/hrtimer.o ./obj/local/arm64-v8a/objs/cryptopp/ida.o ./obj/local/arm64-v8a/objs/cryptopp/idea.o ./obj/local/arm64-v8a/objs/cryptopp/iterhash.o ./obj/local/arm64-v8a/objs/cryptopp/kalyna.o ./obj/local/arm64-v8a/objs/cryptopp/kalynatab.o ./obj/local/arm64-v8a/objs/cryptopp/keccak.o ./obj/local/arm64-v8a/objs/cryptopp/luc.o ./obj/local/arm64-v8a/objs/cryptopp/mars.o ./obj/local/arm64-v8a/objs/cryptopp/marss.o ./obj/local/arm64-v8a/objs/cryptopp/md2.o ./obj/local/arm64-v8a/objs/cryptopp/md4.o ./obj/local/arm64-v8a/objs/cryptopp/md5.o ./obj/local/arm64-v8a/objs/cryptopp/misc.o ./obj/local/arm64-v8a/objs/cryptopp/modes.o ./obj/local/arm64-v8a/objs/cryptopp/mqueue.o ./obj/local/arm64-v8a/objs/cryptopp/mqv.o ./obj/local/arm64-v8a/objs/cryptopp/nbtheory.o ./obj/local/arm64-v8a/objs/cryptopp/neon-simd.o ./obj/local/arm64-v8a/objs/cryptopp/network.o ./obj/local/arm64-v8a/objs/cryptopp/oaep.o ./obj/local/arm64-v8a/objs/cryptopp/osrng.o ./obj/local/arm64-v8a/objs/cryptopp/padlkrng.o ./obj/local/arm64-v8a/objs/cryptopp/panama.o ./obj/local/arm64-v8a/objs/cryptopp/pkcspad.o ./obj/local/arm64-v8a/objs/cryptopp/poly1305.o ./obj/local/arm64-v8a/objs/cryptopp/polynomi.o ./obj/local/arm64-v8a/objs/cryptopp/ppc-simd.o ./obj/local/arm64-v8a/objs/cryptopp/pssr.o ./obj/local/arm64-v8a/objs/cryptopp/pubkey.o ./obj/local/arm64-v8a/objs/cryptopp/queue.o ./obj/local/arm64-v8a/objs/cryptopp/rabin.o ./obj/local/arm64-v8a/objs/cryptopp/randpool.o ./obj/local/arm64-v8a/objs/cryptopp/rc2.o ./obj/local/arm64-v8a/objs/cryptopp/rc5.o ./obj/local/arm64-v8a/objs/cryptopp/rc6.o ./obj/local/arm64-v8a/objs/cryptopp/rdrand.o ./obj/local/arm64-v8a/objs/cryptopp/rdtables.o ./obj/local/arm64-v8a/objs/cryptopp/rijndael-simd.o ./obj/local/arm64-v8a/objs/cryptopp/rijndael.o ./obj/local/arm64-v8a/objs/cryptopp/ripemd.o ./obj/local/arm64-v8a/objs/cryptopp/rng.o ./obj/local/arm64-v8a/objs/cryptopp/rsa.o ./obj/local/arm64-v8a/objs/cryptopp/rw.o ./obj/local/arm64-v8a/objs/cryptopp/safer.o ./obj/local/arm64-v8a/objs/cryptopp/salsa.o ./obj/local/arm64-v8a/objs/cryptopp/seal.o ./obj/local/arm64-v8a/objs/cryptopp/seed.o ./obj/local/arm64-v8a/objs/cryptopp/serpent.o ./obj/local/arm64-v8a/objs/cryptopp/sha-simd.o ./obj/local/arm64-v8a/objs/cryptopp/sha.o ./obj/local/arm64-v8a/objs/cryptopp/sha3.o ./obj/local/arm64-v8a/objs/cryptopp/shacal2-simd.o ./obj/local/arm64-v8a/objs/cryptopp/shacal2.o ./obj/local/arm64-v8a/objs/cryptopp/shark.o ./obj/local/arm64-v8a/objs/cryptopp/sharkbox.o ./obj/local/arm64-v8a/objs/cryptopp/skipjack.o ./obj/local/arm64-v8a/objs/cryptopp/socketft.o ./obj/local/arm64-v8a/objs/cryptopp/sosemanuk.o ./obj/local/arm64-v8a/objs/cryptopp/square.o ./obj/local/arm64-v8a/objs/cryptopp/squaretb.o ./obj/local/arm64-v8a/objs/cryptopp/strciphr.o ./obj/local/arm64-v8a/objs/cryptopp/tea.o ./obj/local/arm64-v8a/objs/cryptopp/tftables.o ./obj/local/arm64-v8a/objs/cryptopp/threefish.o ./obj/local/arm64-v8a/objs/cryptopp/tiger.o ./obj/local/arm64-v8a/objs/cryptopp/tigertab.o ./obj/local/arm64-v8a/objs/cryptopp/trdlocal.o ./obj/local/arm64-v8a/objs/cryptopp/ttmac.o ./obj/local/arm64-v8a/objs/cryptopp/twofish.o ./obj/local/arm64-v8a/objs/cryptopp/vmac.o ./obj/local/arm64-v8a/objs/cryptopp/wait.o ./obj/local/arm64-v8a/objs/cryptopp/wake.o ./obj/local/arm64-v8a/objs/cryptopp/whrlpool.o ./obj/local/arm64-v8a/objs/cryptopp/xtr.o ./obj/local/arm64-v8a/objs/cryptopp/xtrcrypt.o ./obj/local/arm64-v8a/objs/cryptopp/zdeflate.o ./obj/local/arm64-v8a/objs/cryptopp/zinflate.o ./obj/local/arm64-v8a/objs/cryptopp/zlib.o ./obj/local/arm64-v8a/libcpufeatures.a /home/[username]/android-ndk-r15c/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_static.a /home/[username]/android-ndk-r15c/sources/cxx-stl/llvm-libc++abi/../llvm-libc++/libs/arm64-v8a/libc++abi.a /home/[username]/android-ndk-r15c/sources/android/support/../../cxx-stl/llvm-libc++/libs/arm64-v8a/libandroid_support.a -lgcc -Wl,--exclude-libs,libgcc.a  -gcc-toolchain /home/[username]/android-ndk-r15c/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -target aarch64-none-linux-android -no-canonical-prefixes   -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings  -L/home/[username]/android-ndk-r15c/platforms/android-21/arch-arm64/usr/lib -latomic -ldl -lc -lm -o ./obj/local/arm64-v8a/libcryptopp.so

...suffice it to say, if you look through there, it links in this order: cryptlib.o => cpu.o => integer.o => 3way.o => alpha order. From the things you linked, that appears to be the correct linker order? If so, this should make maintaining this file much easier.

Edit: The above Android.mk works as of commit 7097546 for the record

@Deadpikle
Copy link
Contributor

Deadpikle commented Sep 17, 2017

I will note that removing LOCAL_CFLAGS := -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_SSSE3 -DCRYPTOPP_DISABLE_AESNI causes linker errors when compiling under arm64-v8a:

[arm64-v8a] SharedLibrary  : libcryptopp.so
[really long linker command]
./obj/local/arm64-v8a/objs/cryptopp/gcm.o: In function `CryptoPP::GCM_Base::SetKeyWithoutResync(unsigned char const*, unsigned long, CryptoPP::NameValuePairs const&)':
/home/[username]/cryptopp/./gcm.cpp:176: undefined reference to `CryptoPP::GCM_SetKeyWithoutResync_PMULL(unsigned char const*, unsigned char*, unsigned int)'
./obj/local/arm64-v8a/objs/cryptopp/gcm.o: In function `CryptoPP::GCM_Base::ReverseHashBufferIfNeeded()':
/home/[username]/cryptopp/./gcm.cpp:291: undefined reference to `CryptoPP::GCM_ReverseHashBufferIfNeeded_PMULL(unsigned char*)'
./obj/local/arm64-v8a/objs/cryptopp/gcm.o: In function `CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const*, unsigned long)':
/home/[username]/cryptopp/./gcm.cpp:377: undefined reference to `CryptoPP::GCM_AuthenticateBlocks_PMULL(unsigned char const*, unsigned long, unsigned char const*, unsigned char*)'
./obj/local/arm64-v8a/objs/cryptopp/gcm.o: In function `CryptoPP::GCM_Base::ReverseHashBufferIfNeeded()':
/home/[username]/cryptopp/./gcm.cpp:291: undefined reference to `CryptoPP::GCM_ReverseHashBufferIfNeeded_PMULL(unsigned char*)'
./obj/local/arm64-v8a/objs/cryptopp/rijndael.o: In function `CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const':
/home/[username]/cryptopp/./rijndael.cpp:1147: undefined reference to `CryptoPP::Rijndael_Enc_AdvancedProcessBlocks_ARMV8(unsigned int const*, unsigned long, unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int)'
/home/[username]/cryptopp/./rijndael.cpp:1147: undefined reference to `CryptoPP::Rijndael_Enc_AdvancedProcessBlocks_ARMV8(unsigned int const*, unsigned long, unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int)'
./obj/local/arm64-v8a/objs/cryptopp/rijndael.o: In function `CryptoPP::Rijndael::Dec::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const':
/home/[username]/cryptopp/./rijndael.cpp:1214: undefined reference to `CryptoPP::Rijndael_Dec_AdvancedProcessBlocks_ARMV8(unsigned int const*, unsigned long, unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int)'
/home/[username]/cryptopp/./rijndael.cpp:1214: undefined reference to `CryptoPP::Rijndael_Dec_AdvancedProcessBlocks_ARMV8(unsigned int const*, unsigned long, unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int)'
./obj/local/arm64-v8a/objs/cryptopp/rijndael.o: In function `CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const':
/home/[username]/cryptopp/./rijndael.cpp:1147: undefined reference to `CryptoPP::Rijndael_Enc_AdvancedProcessBlocks_ARMV8(unsigned int const*, unsigned long, unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int)'
./obj/local/arm64-v8a/objs/cryptopp/rijndael.o: In function `CryptoPP::Rijndael::Dec::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const':
/home/[username]/cryptopp/./rijndael.cpp:1214: undefined reference to `CryptoPP::Rijndael_Dec_AdvancedProcessBlocks_ARMV8(unsigned int const*, unsigned long, unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int)'
./obj/local/arm64-v8a/objs/cryptopp/sha.o: In function `CryptoPP::SHA1::Transform(unsigned int*, unsigned int const*)':
/home/[username]/cryptopp/./sha.cpp:176: undefined reference to `CryptoPP::SHA1_HashMultipleBlocks_ARMV8(unsigned int*, unsigned int const*, unsigned long, CryptoPP::ByteOrder)'
./obj/local/arm64-v8a/objs/cryptopp/sha.o: In function `CryptoPP::SHA1::HashMultipleBlocks(unsigned int const*, unsigned long)':
/home/[username]/cryptopp/./sha.cpp:199: undefined reference to `CryptoPP::SHA1_HashMultipleBlocks_ARMV8(unsigned int*, unsigned int const*, unsigned long, CryptoPP::ByteOrder)'
./obj/local/arm64-v8a/objs/cryptopp/sha.o: In function `CryptoPP::SHA256::Transform(unsigned int*, unsigned int const*)':
/home/[username]/cryptopp/./sha.cpp:683: undefined reference to `CryptoPP::SHA256_HashMultipleBlocks_ARMV8(unsigned int*, unsigned int const*, unsigned long, CryptoPP::ByteOrder)'
./obj/local/arm64-v8a/objs/cryptopp/sha.o: In function `CryptoPP::SHA256::HashMultipleBlocks(unsigned int const*, unsigned long)':
/home/[username]/cryptopp/./sha.cpp:714: undefined reference to `CryptoPP::SHA256_HashMultipleBlocks_ARMV8(unsigned int*, unsigned int const*, unsigned long, CryptoPP::ByteOrder)'
./obj/local/arm64-v8a/objs/cryptopp/sha.o: In function `CryptoPP::SHA224::HashMultipleBlocks(unsigned int const*, unsigned long)':
/home/[username]/cryptopp/./sha.cpp:763: undefined reference to `CryptoPP::SHA256_HashMultipleBlocks_ARMV8(unsigned int*, unsigned int const*, unsigned long, CryptoPP::ByteOrder)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

This can be fixed by passing in -march=armv8-a+crypto via LOCAL_CFLAGS rather than those other 3 flags.

There's some other issues on other architectures that seem to pop up via GNUmakefile-cross when you remove those flags, too, so I'll bring the discussion to another issue to keep discussion separate. The code compiles when using all 3 flags.

@noloader
Copy link
Collaborator

Android.mk needs to do one of the following:

  1. Add -march=armv8-a+crc+crypto to CXXFLAGS for all files
  2. Add -march=armv8-a+crc and -march=armv8-a+crypto to specific files

The library uses strategy (2) in GNUmakefile-cross. That's what the block around line 180 does in GNUmakefile-cross:

# ARMv8-a
ifeq ($(IS_ARMv8),1)
  HAVE_NEON := $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a -dM -E - 2>/dev/null | $(EGREP) -i -c __ARM_NEON)
  ifeq ($(HAVE_NEON),1)
    ARIA_FLAG = -march=armv8-a
    BLAKE2_FLAG = -march=armv8-a
    NEON_FLAG = -march=armv8-a
  endif
  HAVE_CRC := $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a+crc -dM -E - 2>/dev/null | $(EGREP) -i -c __ARM_FEATURE_CRC32)
  ifeq ($(HAVE_CRC),1)
    CRC_FLAG = -march=armv8-a+crc
  endif
  HAVE_CRYPTO := $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a+crypto -dM -E - 2>/dev/null | $(EGREP) -i -c __ARM_FEATURE_CRYPTO)
  ifeq ($(HAVE_CRYPTO),1)
    AES_FLAG = -march=armv8-a+crypto
    GCM_FLAG = -march=armv8-a+crypto
    SHA_FLAG = -march=armv8-a+crypto
  endif
endif

@Deadpikle
Copy link
Contributor

Deadpikle commented Sep 29, 2017

Here's a version that doesn't have LOCAL_CFLAGS := -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_SSSE3 -DCRYPTOPP_DISABLE_AESNI. It successfully compiles with ../android-ndk-r15c/ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk. I'm guessing things might have to be tweaked based on the APP_STL and/or APP_PLATFORM parameters, but this at least works for NDK r15c.

Application.mk

APP_ABI := all
APP_STL := c++_static
APP_CPPFLAGS += -fexceptions -frtti
APP_PLATFORM := android-21
APP_OPTIM := release

Android.mk

LOCAL_PATH := $(call my-dir)
 
SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp winpipes.cpp cryptlib_bds.cpp,$(sort $(wildcard *.cpp)))
TESTSRCS := adhoc.cpp test.cpp bench1.cpp bench2.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp datatest.cpp regtest1.cpp regtest2.cpp regtest3.cpp fipsalgt.cpp dlltest.cpp
SRCS := $(filter-out $(TESTSRCS), $(SRCS))

include $(CLEAR_VARS)
LOCAL_MODULE := cryptopp
LOCAL_SRC_FILES := $(SRCS)
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
    LOCAL_CPPFLAGS  := -march=armv8-a+crc+crypto
endif
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    LOCAL_ARM_NEON := true
    LOCAL_CPPFLAGS := -march=armv7-a -DHAVE_NEON=1
endif
ifeq ($(TARGET_ARCH),x86)
    LOCAL_CPPFLAGS := -mssse3 -msse4.2 -mpclmul -maes -msha
endif
ifeq ($(TARGET_ARCH),x86_64)
    LOCAL_CPPFLAGS := -mssse3 -msse4.2 -mpclmul -maes -msha
endif
LOCAL_LDLIBS := -latomic
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := cpufeatures
include $(BUILD_SHARED_LIBRARY)
 
$(call import-module,android/cpufeatures)

Edit: I will note that I haven't actually, you know, tested the actual binaries to work on all the platforms as of this post. 😅

@noloader
Copy link
Collaborator

noloader commented Aug 26, 2018

@cawka, @Deadpikle,

We added a repo to independently provide Android.mk support at Noloader | cryptopp-android. The initial check-in is complete. Now we have to fix it and tune it.

We sent you collaborator invites so you won't be stalled waiting for us to act.

Sorry about dragging our ass on it.

@noloader noloader closed this Aug 26, 2018
@noloader
Copy link
Collaborator

@cawka, @Deadpikle,

The Androidmk source files have gone through a major revision. We got all the build flag issues solved. Also see https://github.com/noloader/cryptopp-android

We are still keeping Application.mk and Android.mk separate from the library. It avoids political problems, like people arguing to get their favorite build system added to the library. If we add one, we need to add them all (and officially support all of them). Keeping them separate avoids the problems.

@noloader
Copy link
Collaborator

noloader commented Oct 18, 2019

@cawka, @Deadpikle,

I sent you guys invites to be Collaborators for cryptopp-android. It is my GitHub.

We need some fallback Collaborators if I get hit by a bus. It should not be a big burden on you. I'll keep it up to date.

@Deadpikle
Copy link
Contributor

@noloader Thanks. I accepted. Although I hope no one gets hit by a bus, I certainly understand wanting to keep things alive if something happens. 😄 Thanks also for the notification of the changes -- been a long while since I've looked at this for the project I was working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants