From 3fe57d3ae040e95678b3c327de655aac1d5bb709 Mon Sep 17 00:00:00 2001 From: Martin Kromm Date: Tue, 20 Aug 2019 10:03:54 +0200 Subject: [PATCH 1/2] Added the graycode implementation needed for the LowMC example in ABY. --- src/CMakeLists.txt | 1 + src/ENCRYPTO_utils/graycode.cpp | 45 +++++++++++++++++++++++++++++++++ src/ENCRYPTO_utils/graycode.h | 22 ++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/ENCRYPTO_utils/graycode.cpp create mode 100644 src/ENCRYPTO_utils/graycode.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e80478..d978842 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,7 @@ add_library(encrypto_utils ${PROJECT_NAME}/thread.cpp ${PROJECT_NAME}/timer.cpp ${PROJECT_NAME}/utils.cpp + ${PROJECT_NAME}/graycode.cpp ) add_library(ENCRYPTO_utils::encrypto_utils ALIAS encrypto_utils) diff --git a/src/ENCRYPTO_utils/graycode.cpp b/src/ENCRYPTO_utils/graycode.cpp new file mode 100644 index 0000000..f323dfc --- /dev/null +++ b/src/ENCRYPTO_utils/graycode.cpp @@ -0,0 +1,45 @@ +/** + \file graycode.cpp + \author Martin Kromm + \copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation + Copyright (C) 2019 ENCRYPTO Group, TU Darmstadt + This program is free software: you can redistribute it and/or modify + 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 . + \brief Gray-Code implementation + */ + +#include "./graycode.h" +#include + +uint32_t* BuildGrayCode(uint32_t length) { + uint32_t* gray_code = (uint32_t*) malloc(sizeof(uint32_t) * length); + for(uint32_t i = 0; i < length; ++i) { + gray_code[i] = i ^ (i >> 1); + } + return gray_code; +} + +uint32_t* BuildGrayCodeIncrement(uint32_t length) { + uint32_t* gray_code_increment = (uint32_t*) malloc(sizeof(uint32_t) * length); + for(uint32_t i = 0; i < length; ++i) { + gray_code_increment[i] = 0; + } + uint32_t length_inc = 2; + while(length_inc < length) { + uint32_t length_count = length_inc - 1; + while(length_count <= length) { + (gray_code_increment[length_count])++; + length_count += length_inc; + } + length_inc = length_inc << 1; + } + return gray_code_increment; +} diff --git a/src/ENCRYPTO_utils/graycode.h b/src/ENCRYPTO_utils/graycode.h new file mode 100644 index 0000000..afe1f9b --- /dev/null +++ b/src/ENCRYPTO_utils/graycode.h @@ -0,0 +1,22 @@ +/** + \file graycode.h + \author Martin Kromm + \copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation + Copyright (C) 2019 ENCRYPTO Group, TU Darmstadt + This program is free software: you can redistribute it and/or modify + 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 . + \brief Gray-Code implementation + */ + +#include + +uint32_t* BuildGrayCode(uint32_t length); +uint32_t* BuildGrayCodeIncrement(uint32_t length); From d084930313dc74be6177b8171408980f90f82bcd Mon Sep 17 00:00:00 2001 From: Martin Kromm Date: Tue, 20 Aug 2019 12:01:13 +0200 Subject: [PATCH 2/2] Changed the method to include the ECCLVL constant to be defined (which is dependent on cmake settings since it is used for the relic library too). --- src/CMakeLists.txt | 8 ++++++-- src/ENCRYPTO_utils/cmake_constants.h.in | 2 ++ src/ENCRYPTO_utils/constants.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/ENCRYPTO_utils/cmake_constants.h.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d978842..a0e95d6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,13 +25,17 @@ add_library(ENCRYPTO_utils::encrypto_utils ALIAS encrypto_utils) target_compile_features(encrypto_utils PUBLIC cxx_std_17) target_compile_options(encrypto_utils PRIVATE "-Wall" "-Wextra") -#Maybe it is better to create a ecc-pk-crypti.h.in file, since the ecclvl is only needed there -target_compile_definitions(encrypto_utils PUBLIC ECCLVL=${ecclvl}) + +configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}/ENCRYPTO_utils/cmake_constants.h.in" + "${PROJECT_BINARY_DIR}/include/cmake_constants.h" +) target_include_directories(encrypto_utils PUBLIC $ $ + $ ) diff --git a/src/ENCRYPTO_utils/cmake_constants.h.in b/src/ENCRYPTO_utils/cmake_constants.h.in new file mode 100644 index 0000000..86e7769 --- /dev/null +++ b/src/ENCRYPTO_utils/cmake_constants.h.in @@ -0,0 +1,2 @@ +//the security parameter for public crypto +#define ECCLVL @ecclvl@ diff --git a/src/ENCRYPTO_utils/constants.h b/src/ENCRYPTO_utils/constants.h index 6ecf101..95eda78 100644 --- a/src/ENCRYPTO_utils/constants.h +++ b/src/ENCRYPTO_utils/constants.h @@ -21,6 +21,7 @@ #include "typedefs.h" #include +#include #define BATCH //#define FIXED_KEY_AES_HASHING