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

Android Support #157

Open
wants to merge 1 commit into
base: public
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ docs/*

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

# CMake
CMakeCache.txt
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[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
62 changes: 10 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
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")
cmake_minimum_required(VERSION 3.13)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
include(ABYCacheVariables)
if(ANDROID)
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD 17)
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)

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 @@ -28,42 +18,10 @@ 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)
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/test)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this?

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).
8 changes: 5 additions & 3 deletions cmake/ABYConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
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)
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()
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(DEPENDENCY_NAME "@DEPENDENCY_NAME@")
if(ANDROID AND ANDROID_ARM_NEON)
set(PREFIX "${DEPENDENCY_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}-NEON")
elseif(ANDROID AND NOT ANDROID_ARM_NEON)
set(PREFIX "${DEPENDENCY_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}")
else()
set(PREFIX "${DEPENDENCY_NAME}")
endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake")
else()
set(${DEPENDENCY_NAME}_FOUND FALSE)
endif()
33 changes: 33 additions & 0 deletions cmake/GMPConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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
)
33 changes: 33 additions & 0 deletions cmake/GMPXXConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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
)
19 changes: 19 additions & 0 deletions cmake/ImportIntoAndroidStudio.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

set(TARGETS "@DEPENDENCY_TARGETS@")
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()
88 changes: 88 additions & 0 deletions cmake/Modules/ABYCacheVariables.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
option(ABY_BUILD_EXE "Build executables" OFF)
set(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)

#Cache Variables related to ENCRYPTO_utils dependency
set(ENCRYPTO_utils_SOURCE
CACHE PATH "Path to ENCRYPTO_utils source.")
set(ENCRYPTO_utils_REPOSITORY https://github.com/oliver-schick/ENCRYPTO_utils.git
CACHE STRING "Git repository of ENCRYPTO_utils project.")
set(ENCRYPTO_utils_TAG origin/master
CACHE STRING "Git tag of downloaded ENCRYPTO_utils project.")

#Cache Variables related to OTExtension dependency
set(OTExtension_SOURCE
CACHE PATH "Path to OTExtension source.")
set(OTExtension_REPOSITORY https://github.com/oliver-schick/OTExtension.git
CACHE STRING "Git repository of OTExtension project.")
set(OTExtension_TAG origin/master
CACHE STRING "Git tag of downloaded OTExtension project.")

#Cache Variables related to BOOST dependency
option(DOWNLOAD_BOOST "Set to download boost libraries." OFF)
set(BOOST_SOURCE
CACHE PATH "Path to boost source location.")
set(BOOST_URL https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2
CACHE STRING "Boost download URL.")
set(BOOST_URL_HASH SHA256=8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406
CACHE STRING "Boost download URL SHA256 checksum.")

#Cache Variables related to BOOST_CMAKE dependency
set(BOOST_CMAKE_SOURCE
CACHE PATH "Path to boost-cmake source.")
set(BOOST_CMAKE_REPOSITORY https://github.com/Orphis/boost-cmake.git
CACHE STRING "Repository to boost-cmake project.")
set(BOOST_CMAKE_TAG 70b12f62da331dd402b78102ec8f6a15d59a7af9
CACHE STRING "Git tag of boost-cmake")

#Cache Variables related to GMP dependency
option(BUILD_GMP "Build GMP library if none is found." OFF)
option(FORCE_GMP_BUILD "Force building of GMP library (use if installed GMP library is not compatible with build)." OFF)
set(GMP_LIBRARY_DIR
CACHE PATH "Path to GMP library.")
set(GMP_INCLUDES
CACHE PATH "Path to GMP include directories.")
set(GMP_SOURCE
CACHE PATH "Path to GMP source (If building GMP).")
set(GMP_URL https://gmplib.org/download/gmp/gmp-6.2.0.tar.lz
CACHE STRING "URL of GMP source.")
set(GMP_URL_HASH SHA512=9975e8766e62a1d48c0b6d7bbdd2fccb5b22243819102ca6c8d91f0edd2d3a1cef21c526d647c2159bb29dd2a7dcbd0d621391b2e4b48662cf63a8e6749561cd
CACHE STRING "Hash of GMP source archive.")
set(GMP_LIBRARY_TYPE
CACHE STRING "[SHARED | STATIC]: Type of GMP library linked to project.")
set_property(CACHE GMP_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED)
mark_as_advanced(FORCE_GMP_BUILD)

include(AndroidCacheVariables)
13 changes: 13 additions & 0 deletions cmake/Modules/AddBOOST_CMAKE.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.13)

set(BOOST_INSTALL_INCLUDE "${${PROJECT_NAME}_INSTALL_INCLUDE}")
set(USE_ANDROID ANDROID)
file(GLOB BOOST_CMAKE_FILE_LIST "${PROJECT_SOURCE_DIR}/extern/boost-cmake/*")
list(LENGTH BOOST_CMAKE_FILE_LIST BOOST_CMAKE_NUM_FILES)
#if boost-cmake directory is empty
if(BOOST_CMAKE_NUM_FILES EQUAL 0)
include(FetchBOOST_CMAKE)
else()
set(BOOST_CMAKE_SOURCE "${PROJECT_SOURCE_DIR}/extern/BOOST_CMAKE" CACHE PATH "Path to boost-cmake source." FORCE)
include(FetchBOOST_CMAKE)
endif()
Loading