Skip to content

Commit a4273b4

Browse files
committed
Added build support for Android platforms
1 parent 08baa85 commit a4273b4

32 files changed

+1135
-112
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ docs/*
1515

1616
# build directory
1717
build*/
18+
# extern directory
19+
extern/*
1820

1921
# CMake
2022
CMakeCache.txt

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "extern/OTExtension"]
55
path = extern/OTExtension
66
url = https://github.com/encryptogroup/OTExtension.git
7+
[submodule "extern/boost-cmake"]
8+
path = extern/boost-cmake
9+
url = https://github.com/Orphis/boost-cmake.git

CMakeLists.txt

+10-52
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
cmake_minimum_required(VERSION 3.12)
2-
project(ABY LANGUAGES CXX)
3-
4-
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
5-
message(FATAL_ERROR "ABY requires at least g++-8")
1+
cmake_minimum_required(VERSION 3.13)
2+
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
3+
include(ABYCacheVariables)
4+
if(ANDROID)
5+
set(CMAKE_CXX_STANDARD 14)
6+
else()
7+
set(CMAKE_CXX_STANDARD 17)
68
endif()
7-
8-
option(ABY_BUILD_EXE "Build executables" OFF)
9-
10-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
11-
12-
# Set build type to `Release` if non was specified:
13-
# (cf. https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-change-the-default-build-mode-and-see-it-reflected-in-the-gui)
14-
if(NOT CMAKE_BUILD_TYPE)
15-
set(CMAKE_BUILD_TYPE Release CACHE STRING
16-
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
17-
FORCE)
18-
endif(NOT CMAKE_BUILD_TYPE)
19-
9+
project(ABY LANGUAGES C CXX)
2010
# Write built executables and libraries to bin/ and lib/, respectively.
2111
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
2212
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
@@ -28,42 +18,10 @@ if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
2818
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
2919
endif()
3020

31-
find_package(ENCRYPTO_utils QUIET)
32-
if(ENCRYPTO_utils_FOUND)
33-
message(STATUS "Found ENCRYPTO_utils")
34-
elseif(NOT ENCRYPTO_utils_FOUND AND NOT TARGET ENCRYPTO_utils::encrypto_utils)
35-
message("ENCRYPTO_utils was not found: add ENCRYPTO_utils subdirectory")
36-
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils/CMakeLists.txt")
37-
find_package(Git REQUIRED)
38-
message("initialize Git submodule: extern/ENCRYPTO_utils")
39-
execute_process(COMMAND git submodule update --init extern/ENCRYPTO_utils
40-
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
41-
endif()
42-
add_subdirectory(extern/ENCRYPTO_utils)
43-
endif()
44-
45-
find_package(OTExtension QUIET)
46-
if(OTExtension_FOUND)
47-
message(STATUS "Found OTExtension")
48-
elseif (NOT OTExtension_FOUND AND NOT TARGET OTExtension::otextension)
49-
message("OTExtension was not found: add OTExtension subdirectory")
50-
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/OTExtension/CMakeLists.txt")
51-
find_package(Git REQUIRED)
52-
message("initialize Git submodule: extern/OTExtension")
53-
execute_process(COMMAND git submodule update --init extern/OTExtension
54-
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
55-
endif()
56-
add_subdirectory(extern/OTExtension)
57-
endif()
58-
59-
find_package(GMP REQUIRED)
60-
find_package(Threads REQUIRED)
61-
find_package(Boost 1.66.0 REQUIRED COMPONENTS thread system)
62-
6321
add_subdirectory(src/abycore)
6422

65-
6623
if(ABY_BUILD_EXE)
67-
add_subdirectory(src/test)
24+
#add_subdirectory(src/test)
6825
add_subdirectory(src/examples)
6926
endif(ABY_BUILD_EXE)
27+

README.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ By *Daniel Demmler, Thomas Schneider and Michael Zohner* ([ENCRYPTO](http://www.
2020
- [Build Options](#build-options)
2121
- [Cleaning the Build Directory](#cleaning-the-build-directory)
2222
- [Installation](#installation)
23-
- [Developer Guide and Documentation](#developer-guide-and-documentation)
23+
- [Building for Android](#building-for-android)
24+
- [Developer Guide and Documentation](#developer-guide-and-documentation)
2425
- [ABY Applications](#aby-applications)
2526
- [Included Example Applications](#included-example-applications)
2627
- [Running Applications](#running-applications)
2728
- [Creating and Building your own ABY Application](#creating-and-building-your-own-aby-application)
2829

29-
3030
### Features
3131
---
3232
ABY efficiently combines secure computation schemes based on **Arithmetic sharing**, **Boolean sharing**, and **Yao’s garbled circuits** and makes available best-practice solutions in secure two-party computation.
@@ -182,12 +182,36 @@ make
182182
make install
183183
```
184184
185-
186185
#### Developer Guide and Documentation
187186
We provide an extensive [developer guide](https://www.informatik.tu-darmstadt.de/media/encrypto/encrypto_code/abydevguide.pdf) with many examples and explanations of how to use ABY.
188187
189188
Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.io/ABY/docs/index.html) for further information and comments on the code.
190189
190+
## Building for Android
191+
192+
1. Clone the ABY git repository by running:
193+
```
194+
git clone https://github.com/encryptogroup/ABY.git
195+
```
196+
197+
2. Enter the Framework directory: `cd ABY/`
198+
199+
3. Create and enter the build directory: `mkdir build && cd build`
200+
201+
4. Use CMake to configure the build and setting android variables:
202+
```
203+
cmake -DANDROID_NDK=<path/to/ndk> -DANDROID_NATIVE_API_LEVEL=<TargetAPI> -DANDROID_ABI=<TargetABI> ..
204+
```
205+
where `<TargetAPI>` is a number between 16 and the latest Android API and `<TargetABI>` is the target platform (one of armeabi-v7a, arm64-v8a, x86 and x86_64 respectively).
206+
207+
Please note that when using ABY with Android Studio that `<path/to/ndk>` needs to be the path to the NDK used by Android Studio (often located at $HOME/Android/Sdk/ndk-bundle on Linux).
208+
209+
210+
5. Call `make` in the build directory.
211+
You can find the build executables and libraries in the directories `bin/`
212+
and `lib/`, respectively.
213+
214+
6. Call `make install` after the build has finished. This will install the libraries into the provided NDK.
191215
192216
### ABY Applications
193217
---
@@ -234,6 +258,8 @@ Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.
234258
add_executable(my_application my_application.cpp)
235259
target_link_libraries(my_application ABY::aby)
236260
```
261+
* If you are using ABY for Android in Android Studio and you encounter the "library libc++_shared.so not found" error, make sure to pass '-DANDROID_STL=c++_shared' as an argument to cmake within the gradle script. Setting ANDROID_STL within the cmake script won't work.
262+
237263
* Otherwise, setup the include path such that the headers of ABY and its
238264
dependencies can be found and link your application to the `libaby.a`
239265
library and the other dependencies (see above).

cmake/ABYConfig.cmake.in

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
get_filename_component(ABY_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
22

3-
list(APPEND CMAKE_MODULE_PATH "${ABY_CMAKE_DIR}")
4-
53
include(CMakeFindDependencyMacro)
64

5+
find_dependency(Boost)
76
find_dependency(OTExtension)
87
find_dependency(ENCRYPTO_utils)
9-
find_dependency(MIRACL)
108
find_dependency(GMP)
119
find_dependency(Threads)
1210

1311
if(NOT TARGET ABY::aby)
1412
include("${ABY_CMAKE_DIR}/ABYTargets.cmake")
1513
endif()
14+
15+
if(TARGET ABY::aby)
16+
set(ABY_FOUND TRUE)
17+
endif()

cmake/BoostConfig.cmake.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
get_filename_component(Boost_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
2+
3+
if(NOT TARGET Boost::boost)
4+
include("${Boost_CMAKE_DIR}/BoostTargets.cmake")
5+
endif()

cmake/ForwardConfig.cmake.in

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include(CMakeFindDependencyMacro)
2+
set(DEPENDENCY_NAME "@DEPENDENCY_NAME@")
3+
if(ANDROID AND ANDROID_ARM_NEON)
4+
set(PREFIX "${DEPENDENCY_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}-NEON")
5+
elseif(ANDROID AND NOT ANDROID_ARM_NEON)
6+
set(PREFIX "${DEPENDENCY_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}")
7+
else()
8+
set(PREFIX "${DEPENDENCY_NAME}")
9+
endif()
10+
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake")
11+
include("${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake")
12+
else()
13+
set(${DEPENDENCY_NAME}_FOUND FALSE)
14+
endif()

cmake/GMPConfig.cmake.in

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
if(NOT "${GMP_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${GMP_LIBRARY_TYPE}" STREQUAL "SHARED")
2+
set(GMP_LIBRARY_TYPE "@GMP_LIBRARY_TYPE@")
3+
endif()
4+
set(LIB_PREFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_PREFIX}")
5+
set(LIB_SUFFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_SUFFIX}")
6+
7+
set(GMP_INCLUDE_PATHS "@INSTALL_CONFIG_INCLUDE_PATHS@")
8+
set(GMP_LIB_PATHS "@INSTALL_CONFIG_LIB_PATHS@")
9+
10+
unset(GMP_INCLUDE_DIR CACHE)
11+
unset(GMP_LIBRARY CACHE)
12+
13+
find_path(GMP_INCLUDE_DIR gmp.h PATHS ${GMP_INCLUDE_PATHS})
14+
find_library(GMP_LIBRARY NAMES ${LIB_PREFIX}gmp${LIB_SUFFIX} PATHS ${GMP_LIB_PATHS})
15+
16+
if(EXISTS "${GMP_INCLUDE_DIR}" AND EXISTS "${GMP_LIBRARY}")
17+
set(GMP_FOUND TRUE)
18+
else()
19+
set(GMP_LIBRARY )
20+
set(GMP_FOUND FALSE)
21+
endif()
22+
23+
if(GMP_FOUND AND NOT TARGET GMP::GMP)
24+
add_library(GMP::GMP "${GMP_LIBRARY_TYPE}" IMPORTED)
25+
set_target_properties(GMP::GMP PROPERTIES
26+
IMPORTED_LOCATION "${GMP_LIBRARY}"
27+
INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}")
28+
endif()
29+
30+
mark_as_advanced(
31+
GMP_INCLUDE_DIR
32+
GMP_LIBRARY
33+
)

cmake/GMPXXConfig.cmake.in

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
if(NOT "${GMP_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${GMP_LIBRARY_TYPE}" STREQUAL "SHARED")
2+
set(GMP_LIBRARY_TYPE "@GMP_LIBRARY_TYPE@")
3+
endif()
4+
set(LIB_PREFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_PREFIX}")
5+
set(LIB_SUFFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_SUFFIX}")
6+
7+
set(GMPXX_INCLUDE_PATHS "@INSTALL_CONFIG_INCLUDE_PATHS@")
8+
set(GMPXX_LIB_PATHS "@INSTALL_CONFIG_LIB_PATHS@")
9+
10+
unset(GMPXX_INCLUDE_DIR CACHE)
11+
unset(GMPXX_LIBRARY CACHE)
12+
13+
find_path(GMPXX_INCLUDE_DIR gmpxx.h PATHS ${GMPXX_INCLUDE_PATHS})
14+
find_library(GMPXX_LIBRARY NAMES ${LIB_PREFIX}gmpxx${LIB_SUFFIX} PATHS ${GMPXX_LIB_PATHS})
15+
16+
if(EXISTS "${GMPXX_INCLUDE_DIR}" AND EXISTS "${GMPXX_LIBRARY}")
17+
set(GMPXX_FOUND TRUE)
18+
else()
19+
set(GMPXX_LIBRARY )
20+
set(GMPXX_FOUND FALSE)
21+
endif()
22+
23+
if(GMPXX_FOUND AND NOT TARGET GMP::GMPXX)
24+
add_library(GMP::GMPXX "${GMP_LIBRARY_TYPE}" IMPORTED)
25+
set_target_properties(GMP::GMPXX PROPERTIES
26+
IMPORTED_LOCATION "${GMPXX_LIBRARY}"
27+
INTERFACE_INCLUDE_DIRECTORIES "${GMPXX_INCLUDE_DIR}")
28+
endif()
29+
30+
mark_as_advanced(
31+
GMPXX_INCLUDE_DIR
32+
GMPXX_LIBRARY
33+
)
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
set(TARGETS "@DEPENDENCY_TARGETS@")
3+
function(import_into_android_studio IMPORT_LOCATION)
4+
if(ANDROID AND EXISTS "${IMPORT_LOCATION}")
5+
foreach(target ${TARGETS})
6+
get_target_property(library_type ${target} TYPE)
7+
if("${library_type}" STREQUAL "SHARED_LIBRARY")
8+
get_target_property(lib_location ${target} LOCATION)
9+
file(COPY "${lib_location}" DESTINATION "${IMPORT_LOCATION}")
10+
endif()
11+
endforeach()
12+
endif()
13+
endfunction()
14+
15+
if(NOT IMPORT_LOCATION)
16+
import_into_android_studio("${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}")
17+
else()
18+
import_into_android_studio("${IMPORT_LOCATION}")
19+
endif()

cmake/Modules/ABYCacheVariables.cmake

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
option(ABY_BUILD_EXE "Build executables" OFF)
2+
set(ABY_LIBRARY_TYPE
3+
CACHE STRING "[STATIC | SHARED | MODULE] The type of library in which ABY will be built. Default: STATIC"
4+
)
5+
set_property(CACHE ABY_LIBRARY_TYPE PROPERTY STRINGS "STATIC" "SHARED" "MODULE")
6+
7+
string(TOUPPER "${ABY_LIBRARY_TYPE}" ABY_LIBRARY_TYPE)
8+
if("${ABY_LIBRARY_TYPE}" STREQUAL "")
9+
set(ABY_LIBRARY_TYPE "SHARED")
10+
elseif(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND
11+
NOT "${ABY_LIBRARY_TYPE}" STREQUAL "SHARED" AND
12+
NOT "${ABY_LIBRARY_TYPE}" STREQUAL "MODULE")
13+
message(WARNING
14+
"Unknown library type: ${ABY_LIBRARY_TYPE}. "
15+
"Setting ABY_LIBRARY_TYPE to default value."
16+
)
17+
set(ABY_LIBRARY_TYPE "SHARED")
18+
endif()
19+
20+
set(DEPENDENCY_DIR "${DEPENDENCY_DIR}" CACHE PATH "Path to directory, where dependencies will be downloaded.")
21+
if(DEPENDENCY_DIR STREQUAL "")
22+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/extern/dependencies")
23+
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/extern/dependencies")
24+
endif()
25+
set(DEPENDENCY_DIR "${CMAKE_SOURCE_DIR}/extern/dependencies")
26+
endif()
27+
28+
# Set build type to `Release` if none was specified:
29+
# (cf. https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-change-the-default-build-mode-and-see-it-reflected-in-the-gui)
30+
if(NOT CMAKE_BUILD_TYPE)
31+
set(CMAKE_BUILD_TYPE Release
32+
CACHE STRING "Choose the type of build." FORCE)
33+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
34+
"None" "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
35+
endif(NOT CMAKE_BUILD_TYPE)
36+
37+
#Cache Variables related to ENCRYPTO_utils dependency
38+
set(ENCRYPTO_utils_SOURCE
39+
CACHE PATH "Path to ENCRYPTO_utils source.")
40+
set(ENCRYPTO_utils_REPOSITORY https://github.com/oliver-schick/ENCRYPTO_utils.git
41+
CACHE STRING "Git repository of ENCRYPTO_utils project.")
42+
set(ENCRYPTO_utils_TAG origin/master
43+
CACHE STRING "Git tag of downloaded ENCRYPTO_utils project.")
44+
45+
#Cache Variables related to OTExtension dependency
46+
set(OTExtension_SOURCE
47+
CACHE PATH "Path to OTExtension source.")
48+
set(OTExtension_REPOSITORY https://github.com/oliver-schick/OTExtension.git
49+
CACHE STRING "Git repository of OTExtension project.")
50+
set(OTExtension_TAG origin/master
51+
CACHE STRING "Git tag of downloaded OTExtension project.")
52+
53+
#Cache Variables related to BOOST dependency
54+
option(DOWNLOAD_BOOST "Set to download boost libraries." OFF)
55+
set(BOOST_SOURCE
56+
CACHE PATH "Path to boost source location.")
57+
set(BOOST_URL https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2
58+
CACHE STRING "Boost download URL.")
59+
set(BOOST_URL_HASH SHA256=8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406
60+
CACHE STRING "Boost download URL SHA256 checksum.")
61+
62+
#Cache Variables related to BOOST_CMAKE dependency
63+
set(BOOST_CMAKE_SOURCE
64+
CACHE PATH "Path to boost-cmake source.")
65+
set(BOOST_CMAKE_REPOSITORY https://github.com/Orphis/boost-cmake.git
66+
CACHE STRING "Repository to boost-cmake project.")
67+
set(BOOST_CMAKE_TAG 70b12f62da331dd402b78102ec8f6a15d59a7af9
68+
CACHE STRING "Git tag of boost-cmake")
69+
70+
#Cache Variables related to GMP dependency
71+
option(BUILD_GMP "Build GMP library if none is found." OFF)
72+
option(FORCE_GMP_BUILD "Force building of GMP library (use if installed GMP library is not compatible with build)." OFF)
73+
set(GMP_LIBRARY_DIR
74+
CACHE PATH "Path to GMP library.")
75+
set(GMP_INCLUDES
76+
CACHE PATH "Path to GMP include directories.")
77+
set(GMP_SOURCE
78+
CACHE PATH "Path to GMP source (If building GMP).")
79+
set(GMP_URL https://gmplib.org/download/gmp/gmp-6.2.0.tar.lz
80+
CACHE STRING "URL of GMP source.")
81+
set(GMP_URL_HASH SHA512=9975e8766e62a1d48c0b6d7bbdd2fccb5b22243819102ca6c8d91f0edd2d3a1cef21c526d647c2159bb29dd2a7dcbd0d621391b2e4b48662cf63a8e6749561cd
82+
CACHE STRING "Hash of GMP source archive.")
83+
set(GMP_LIBRARY_TYPE
84+
CACHE STRING "[SHARED | STATIC]: Type of GMP library linked to project.")
85+
set_property(CACHE GMP_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED)
86+
mark_as_advanced(FORCE_GMP_BUILD)
87+
88+
include(AndroidCacheVariables)

cmake/Modules/AddBOOST_CMAKE.cmake

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
set(BOOST_INSTALL_INCLUDE "${${PROJECT_NAME}_INSTALL_INCLUDE}")
4+
set(USE_ANDROID ANDROID)
5+
file(GLOB BOOST_CMAKE_FILE_LIST "${PROJECT_SOURCE_DIR}/extern/boost-cmake/*")
6+
list(LENGTH BOOST_CMAKE_FILE_LIST BOOST_CMAKE_NUM_FILES)
7+
#if boost-cmake directory is empty
8+
if(BOOST_CMAKE_NUM_FILES EQUAL 0)
9+
include(FetchBOOST_CMAKE)
10+
else()
11+
set(BOOST_CMAKE_SOURCE "${PROJECT_SOURCE_DIR}/extern/BOOST_CMAKE" CACHE PATH "Path to boost-cmake source." FORCE)
12+
include(FetchBOOST_CMAKE)
13+
endif()

0 commit comments

Comments
 (0)