Skip to content

Commit

Permalink
Added cross-compilation support for Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-schick committed May 3, 2020
1 parent bae46a0 commit 5fb70c7
Show file tree
Hide file tree
Showing 34 changed files with 1,105 additions and 160 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
README.html
docs/*
*.dump

*.bak

# build directory
build*/
# extern directory
extern/*

# CMake
CMakeCache.txt
Expand Down
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "extern/ENCRYPTO_utils"]
path = extern/ENCRYPTO_utils
url = https://github.com/encryptogroup/ENCRYPTO_utils.git
[submodule "extern/OTExtension"]
path = extern/OTExtension
url = https://github.com/encryptogroup/OTExtension.git
[submodule "extern/boost-cmake"]
path = extern/boost-cmake
url = https://github.com/Orphis/boost-cmake.git
59 changes: 8 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(ABY LANGUAGES CXX)

if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
message(FATAL_ERROR "ABY requires at least g++-8")
endif()

option(ABY_BUILD_EXE "Build executables" OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

# Set build type to `Release` if non was specified:
# (cf. https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-change-the-default-build-mode-and-see-it-reflected-in-the-gui)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)

cmake_minimum_required(VERSION 3.13)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
include(ABYCacheVariables)
set(CMAKE_CXX_STANDARD 14)
project(ABY LANGUAGES C CXX)
# Write built executables and libraries to bin/ and lib/, respectively.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
Expand All @@ -27,43 +13,14 @@ endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif()

find_package(ENCRYPTO_utils QUIET)
if(ENCRYPTO_utils_FOUND)
message(STATUS "Found ENCRYPTO_utils")
elseif(NOT ENCRYPTO_utils_FOUND AND NOT TARGET ENCRYPTO_utils::encrypto_utils)
message("ENCRYPTO_utils was not found: add ENCRYPTO_utils subdirectory")
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils/CMakeLists.txt")
find_package(Git REQUIRED)
message("initialize Git submodule: extern/ENCRYPTO_utils")
execute_process(COMMAND git submodule update --init extern/ENCRYPTO_utils
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif()
add_subdirectory(extern/ENCRYPTO_utils)
endif()

find_package(OTExtension QUIET)
if(OTExtension_FOUND)
message(STATUS "Found OTExtension")
elseif (NOT OTExtension_FOUND AND NOT TARGET OTExtension::otextension)
message("OTExtension was not found: add OTExtension subdirectory")
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/OTExtension/CMakeLists.txt")
find_package(Git REQUIRED)
message("initialize Git submodule: extern/OTExtension")
execute_process(COMMAND git submodule update --init extern/OTExtension
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif()
add_subdirectory(extern/OTExtension)
if(ANDROID)
add_definitions(-DANDROID)
endif()

find_package(GMP REQUIRED)
find_package(Threads REQUIRED)
find_package(Boost 1.66.0 REQUIRED COMPONENTS thread system)

add_subdirectory(src/abycore)


if(ABY_BUILD_EXE)
add_subdirectory(src/test)
add_subdirectory(src/examples)
endif(ABY_BUILD_EXE)

32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ By *Daniel Demmler, Thomas Schneider and Michael Zohner* ([ENCRYPTO](http://www.
- [Build Options](#build-options)
- [Cleaning the Build Directory](#cleaning-the-build-directory)
- [Installation](#installation)
- [Developer Guide and Documentation](#developer-guide-and-documentation)
- [Building for Android](#building-for-android)
- [Developer Guide and Documentation](#developer-guide-and-documentation)
- [ABY Applications](#aby-applications)
- [Included Example Applications](#included-example-applications)
- [Running Applications](#running-applications)
- [Creating and Building your own ABY Application](#creating-and-building-your-own-aby-application)


### Features
---
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.
Expand Down Expand Up @@ -182,12 +182,36 @@ make
make install
```


#### Developer Guide and Documentation
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.

Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.io/ABY/docs/index.html) for further information and comments on the code.

## Building for Android

1. Clone the ABY git repository by running:
```
git clone https://github.com/encryptogroup/ABY.git
```

2. Enter the Framework directory: `cd ABY/`

3. Create and enter the build directory: `mkdir build && cd build`

4. Use CMake to configure the build and setting android variables:
```
cmake -DANDROID_NDK=<path/to/ndk> -DANDROID_NATIVE_API_LEVEL=<TargetAPI> -DANDROID_ABI=<TargetABI> ..
```
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).

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).


5. Call `make` in the build directory.
You can find the build executables and libraries in the directories `bin/`
and `lib/`, respectively.

6. Call `make install` after the build has finished. This will install the libraries into the provided NDK.

### ABY Applications
---
Expand Down Expand Up @@ -234,6 +258,8 @@ Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.
add_executable(my_application my_application.cpp)
target_link_libraries(my_application ABY::aby)
```
* 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.

* Otherwise, setup the include path such that the headers of ABY and its
dependencies can be found and link your application to the `libaby.a`
library and the other dependencies (see above).
11 changes: 8 additions & 3 deletions cmake/ABYConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
get_filename_component(ABY_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

list(APPEND CMAKE_MODULE_PATH "${ABY_CMAKE_DIR}")

include(CMakeFindDependencyMacro)

find_dependency(Boost)
find_dependency(OTExtension)
find_dependency(ENCRYPTO_utils)
find_dependency(MIRACL)
find_dependency(GMP)
find_dependency(Threads)

if(NOT TARGET ABY::aby)
include("${ABY_CMAKE_DIR}/ABYTargets.cmake")
endif()

if(TARGET ABY::aby)
set(ABY_FOUND TRUE)
set(TARGETS ABY::aby)
endif()


5 changes: 5 additions & 0 deletions cmake/BoostConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
get_filename_component(Boost_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

if(NOT TARGET Boost::boost)
include("${Boost_CMAKE_DIR}/BoostTargets.cmake")
endif()
27 changes: 0 additions & 27 deletions cmake/FindGMP.cmake

This file was deleted.

27 changes: 0 additions & 27 deletions cmake/FindGMPXX.cmake

This file was deleted.

14 changes: 14 additions & 0 deletions cmake/ForwardConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include(CMakeFindDependencyMacro)
set(INSTALL_NAME "@INSTALL_NAME@")
if(ANDROID AND ANDROID_ARM_NEON)
set(PREFIX "${INSTALL_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}-NEON")
elseif(ANDROID AND NOT ANDROID_ARM_NEON)
set(PREFIX "${INSTALL_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}")
else()
set(PREFIX "${INSTALL_NAME}")
endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake")
else()
set(${INSTALL_NAME}_FOUND FALSE)
endif()
35 changes: 35 additions & 0 deletions cmake/GMPConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if(NOT "${GMP_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${GMP_LIBRARY_TYPE}" STREQUAL "SHARED")
set(GMP_LIBRARY_TYPE "@GMP_LIBRARY_TYPE@")
endif()
set(LIB_PREFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_PREFIX}")
set(LIB_SUFFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_SUFFIX}")

set(GMP_INCLUDE_PATHS "@INSTALL_CONFIG_INCLUDE_PATHS@")
set(GMP_LIB_PATHS "@INSTALL_CONFIG_LIB_PATHS@")

unset(GMP_INCLUDE_DIR CACHE)
unset(GMP_LIBRARY CACHE)

find_path(GMP_INCLUDE_DIR gmp.h PATHS ${GMP_INCLUDE_PATHS})
find_library(GMP_LIBRARY NAMES ${LIB_PREFIX}gmp${LIB_SUFFIX} PATHS ${GMP_LIB_PATHS})

if(EXISTS "${GMP_INCLUDE_DIR}" AND EXISTS "${GMP_LIBRARY}")
set(GMP_FOUND TRUE)
else()
set(GMP_LIBRARY )
set(GMP_FOUND FALSE)
endif()

if(GMP_FOUND AND NOT TARGET GMP::GMP)
add_library(GMP::GMP "${GMP_LIBRARY_TYPE}" IMPORTED)
set_target_properties(GMP::GMP PROPERTIES
IMPORTED_LOCATION "${GMP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}")
endif()

mark_as_advanced(
GMP_INCLUDE_DIR
GMP_LIBRARY
)

set(TARGETS GMP::GMP)
35 changes: 35 additions & 0 deletions cmake/GMPXXConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if(NOT "${GMP_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${GMP_LIBRARY_TYPE}" STREQUAL "SHARED")
set(GMP_LIBRARY_TYPE "@GMP_LIBRARY_TYPE@")
endif()
set(LIB_PREFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_PREFIX}")
set(LIB_SUFFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_SUFFIX}")

set(GMPXX_INCLUDE_PATHS "@INSTALL_CONFIG_INCLUDE_PATHS@")
set(GMPXX_LIB_PATHS "@INSTALL_CONFIG_LIB_PATHS@")

unset(GMPXX_INCLUDE_DIR CACHE)
unset(GMPXX_LIBRARY CACHE)

find_path(GMPXX_INCLUDE_DIR gmpxx.h PATHS ${GMPXX_INCLUDE_PATHS})
find_library(GMPXX_LIBRARY NAMES ${LIB_PREFIX}gmpxx${LIB_SUFFIX} PATHS ${GMPXX_LIB_PATHS})

if(EXISTS "${GMPXX_INCLUDE_DIR}" AND EXISTS "${GMPXX_LIBRARY}")
set(GMPXX_FOUND TRUE)
else()
set(GMPXX_LIBRARY )
set(GMPXX_FOUND FALSE)
endif()

if(GMPXX_FOUND AND NOT TARGET GMP::GMPXX)
add_library(GMP::GMPXX "${GMP_LIBRARY_TYPE}" IMPORTED)
set_target_properties(GMP::GMPXX PROPERTIES
IMPORTED_LOCATION "${GMPXX_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GMPXX_INCLUDE_DIR}")
endif()

mark_as_advanced(
GMPXX_INCLUDE_DIR
GMPXX_LIBRARY
)

set(TARGETS GMP::GMPXX)
18 changes: 18 additions & 0 deletions cmake/ImportIntoAndroidStudio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

function(import_into_android_studio IMPORT_LOCATION)
if(ANDROID AND EXISTS "${IMPORT_LOCATION}")
foreach(target ${TARGETS})
get_target_property(library_type ${target} TYPE)
if("${library_type}" STREQUAL "SHARED_LIBRARY")
get_target_property(lib_location ${target} LOCATION)
file(COPY "${lib_location}" DESTINATION "${IMPORT_LOCATION}")
endif()
endforeach()
endif()
endfunction()

if(NOT IMPORT_LOCATION)
import_into_android_studio("${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}")
else()
import_into_android_studio("${IMPORT_LOCATION}")
endif()
38 changes: 38 additions & 0 deletions cmake/Modules/ABYCacheVariables.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
option(ABY_BUILD_EXE "Build executables" OFF)
set(ABY_LIBRARY_TYPE "${ABY_LIBRARY_TYPE}" CACHE STRING
"[STATIC | SHARED | MODULE] The type of library in which ABY will be built. Default: STATIC"
)
set_property(CACHE ABY_LIBRARY_TYPE PROPERTY STRINGS "STATIC" "SHARED" "MODULE")
string(TOUPPER "${ABY_LIBRARY_TYPE}" ABY_LIBRARY_TYPE)
if("${ABY_LIBRARY_TYPE}" STREQUAL "")
set(ABY_LIBRARY_TYPE "SHARED")
elseif(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND
NOT "${ABY_LIBRARY_TYPE}" STREQUAL "SHARED" AND
NOT "${ABY_LIBRARY_TYPE}" STREQUAL "MODULE")
message(WARNING
"Unknown library type: ${ABY_LIBRARY_TYPE}. "
"Setting ABY_LIBRARY_TYPE to default value."
)
set(ABY_LIBRARY_TYPE "SHARED")
endif()

set(DEPENDENCY_DIR "${DEPENDENCY_DIR}" CACHE PATH "Path to directory, where dependencies will be downloaded.")
if(DEPENDENCY_DIR STREQUAL "")
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/extern/dependencies")
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/extern/dependencies")
endif()
set(DEPENDENCY_DIR "${CMAKE_SOURCE_DIR}/extern/dependencies")
endif()

# Set build type to `Release` if none was specified:
# (cf. https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-change-the-default-build-mode-and-see-it-reflected-in-the-gui)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build."
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"None" "Debug" "Release" "RelWithDebInfo" "MinSizeRel"
)
endif(NOT CMAKE_BUILD_TYPE)

include(AndroidCacheVariables)
Loading

0 comments on commit 5fb70c7

Please sign in to comment.