Skip to content

Commit

Permalink
GMP and OpenSSL are only built, when corresponding options are activa…
Browse files Browse the repository at this point in the history
…ted (default: deactivated) and Boost libraries are only downloaded when corresponding variable is set.
  • Loading branch information
oliver-schick committed Feb 3, 2020
1 parent 5f6f3f3 commit da9d860
Show file tree
Hide file tree
Showing 106 changed files with 4,001 additions and 3,844 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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)
Expand All @@ -12,8 +13,10 @@ endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif()
if(ANDROID)
add_definitions(-DANDROID)
endif()

include(AddENCRYPTO_utils)
add_subdirectory(src/abycore)

if(ABY_BUILD_EXE)
Expand Down
818 changes: 161 additions & 657 deletions LICENSE

Large diffs are not rendered by default.

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).
10 changes: 9 additions & 1 deletion cmake/ABYConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ include(CMakeFindDependencyMacro)

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(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${ABY_LIBRARY_TYPE}" STREQUAL "SHARED")
set(ABY_LIBRARY_TYPE "@ABY_LIBRARY_TYPE@")
endif()
set(LIB_PREFIX "${CMAKE_${ABY_LIBRARY_TYPE}_LIBRARY_PREFIX}")
set(LIB_SUFFIX "${CMAKE_${ABY_LIBRARY_TYPE}_LIBRARY_SUFFIX}")

set(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}aby${LIB_SUFFIX}")
set(LIB_NAME "ABY")
31 changes: 31 additions & 0 deletions cmake/GMPConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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}")

find_path(GMP_INCLUDE_DIR gmp.h PATHS "@ANDROID_NDK@/@ABY_INSTALL_INCLUDE@")

set(GMP_LIBRARY "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmp${LIB_SUFFIX}")
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 UNKNOWN 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(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmp${LIB_SUFFIX}")
set(LIB_NAME "GMP")
31 changes: 31 additions & 0 deletions cmake/GMPXXConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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}")

find_path(GMPXX_INCLUDE_DIR gmpxx.h PATHS "@ANDROID_NDK@/@ABY_INSTALL_INCLUDE@")

set(GMPXX_LIBRARY "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmpxx${LIB_SUFFIX}")
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 UNKNOWN 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(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmpxx${LIB_SUFFIX}")
set(LIB_NAME "GMP")
15 changes: 15 additions & 0 deletions cmake/ImportIntoAndroidStudio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

function(import_into_android_studio IMPORT_LOCATION)
if(ANDROID AND "${${LIB_NAME}_LIBRARY_TYPE}" STREQUAL "SHARED" AND EXISTS "${IMPORT_LOCATION}")
foreach(lib IN LISTS LIBRARIES_FULL_PATH)
get_filename_component(lib_name "${lib}" NAME)
file(COPY "${lib}" DESTINATION "${IMPORT_LOCATION}")
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()
13 changes: 7 additions & 6 deletions cmake/Modules/ABYCacheVariables.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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: SHARED"
"[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)
Expand All @@ -16,11 +16,12 @@ elseif(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND
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 "" AND EXISTS "${PROJECT_SOURCE_DIR}/dependencies")
set(DEPENDENCY_DIR "${PROJECT_SOURCE_DIR}/dependencies")
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:
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/AndroidCacheVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ endif()
if(ANDROID)
set(CMAKE_TOOLCHAIN_FILE ${ANDROID_TOOLCHAIN_FILE})
endif(ANDROID)
if(ANDROID AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(ANDROID AND NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${ANDROID_NDK}"
CACHE PATH
"Default install directory for android builds."
Expand Down
16 changes: 16 additions & 0 deletions cmake/Modules/ImportSharedLibs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


function(import_shared_libs)
set(DEFAULT_IMPORT_LOCATION "${PROJECT_SOURCE_DIR}/../jniLibs")
if(${ARGC} LESS 1)
set(IMPORT_LOCATION "${DEFAULT_IMPORT_LOCATION}")
else()
set(IMPORT_LOCATION "${ARGV0}")
endif()
if(NOT EXISTS "${IMPORT_LOCATION}")
file(MAKE_DIRECTORY "${IMPORT_LOCATION}")
endif()
foreach(lib IN LISTS SHARED_LIBS)
file(COPY "${lib}" DESTINATION "${IMPORT_LOCATION}")
endforeach()
endfunction()
1 change: 0 additions & 1 deletion extern/boost-cmake
Submodule boost-cmake deleted from f0f64a
36 changes: 20 additions & 16 deletions src/abycore/ABY_utils/ABYconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
\file ABYconstants.h
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
Copyright (C) 2017 Engineering Cryptographic Protocols Group, TU Darmstadt
Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ABY is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
\brief File containing all ABY constants used throughout the source
*/

Expand Down Expand Up @@ -64,6 +64,10 @@

#define USE_MULTI_MUX_GATES

// default directory containing ABY circuit files.
// can also be passed to ABYParty constructor at runtime
#define ABY_CIRCUIT_DIR "../../bin/circ/"

/**
\enum e_role
\brief Defines the role of the party or the source / target for certain operations (e.g., input/output)
Expand Down Expand Up @@ -208,7 +212,7 @@ typedef struct {
std::string opname;
} aby_ops_t;

static std::string get_circuit_type_name(e_circuit c) {
inline std::string get_circuit_type_name(e_circuit c) {
switch(c) {
case C_BOOLEAN:
return "BOOLEAN";
Expand All @@ -219,7 +223,7 @@ static std::string get_circuit_type_name(e_circuit c) {
}
}

static std::string get_role_name(e_role r) {
inline std::string get_role_name(e_role r) {
switch(r) {
case SERVER:
return "SERVER";
Expand All @@ -232,7 +236,7 @@ static std::string get_role_name(e_role r) {
}
}

static std::string get_sharing_name(e_sharing s) {
inline std::string get_sharing_name(e_sharing s) {
switch (s) {
case S_BOOL:
return "Bool";
Expand All @@ -249,7 +253,7 @@ static std::string get_sharing_name(e_sharing s) {
}
}

static std::string get_gate_type_name(e_gatetype g) {
inline std::string get_gate_type_name(e_gatetype g) {
switch (g) {
case G_LIN: return "Linear";
case G_NON_LIN: return "Non-Linear";
Expand Down Expand Up @@ -279,13 +283,13 @@ typedef enum op_t{
ADD, MUL, SUB, DIV, SIN, SQRT, EXP, EXP2, CMP, LN, LOG2, COS, SQR
}op_t;

// Floating point operation cinfiguration.
// Floating point operation cinfiguration.
typedef enum fp_op_setting{
ieee, no_status
}fp_op_setting;


static std::string get_op_name(e_operation op) {
inline std::string get_op_name(e_operation op) {
switch (op) {
case OP_XOR:
return "XOR";
Expand Down
Loading

0 comments on commit da9d860

Please sign in to comment.