├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── ExternalDependancies.props ├── Ivory-Runtime ├── .gitignore ├── CMakeLists.txt ├── ExternalDependancies.props ├── Ivory.sln ├── README.md ├── SPDZ │ ├── CopeOtExtDefines.h │ ├── CopeOtExtReceiver.cpp │ ├── CopeOtExtReceiver.h │ ├── CopeOtExtSender.cpp │ ├── CopeOtExtSender.h │ ├── Math │ │ ├── ZpField.cpp │ │ └── ZpField.h │ ├── SPDZ.vcxproj │ └── SPDZ.vcxproj.filters ├── copySourceToLinux.ps1 ├── frontend │ ├── frontend.vcxproj │ ├── frontend.vcxproj.filters │ └── main.cpp ├── icon.jpg ├── ivory │ ├── CMakeLists.txt │ ├── Circuit │ │ ├── BetaCircuit.cpp │ │ ├── BetaCircuit.h │ │ ├── Circuit.cpp │ │ ├── Circuit.h │ │ ├── CircuitLibrary.cpp │ │ ├── CircuitLibrary.h │ │ └── Gate.h │ ├── Runtime.zip │ ├── Runtime │ │ ├── Party.cpp │ │ ├── Party.h │ │ ├── Public │ │ │ ├── PublicInt.cpp │ │ │ └── PublicInt.h │ │ ├── Runtime.cpp │ │ ├── Runtime.h │ │ ├── ShGc │ │ │ ├── ShGcInt.cpp │ │ │ ├── ShGcInt.h │ │ │ ├── ShGcRuntime.cpp │ │ │ ├── ShGcRuntime.h │ │ │ ├── utils.cpp │ │ │ └── utils.h │ │ ├── sInt.cpp │ │ └── sInt.h │ ├── ivory.vcxproj │ └── ivory.vcxproj.filters ├── ivoryTestVS │ ├── Circuit_Tests_VS.cpp │ ├── ClassicGarbledCircuit_Tests_VS.cpp │ ├── Cope_TestsVS.cpp │ ├── HalfGtGarbledCircuit_Tests_VS.cpp │ ├── ShGcRuntime_TestsVs.cpp │ ├── ZpNumber_TestVS.cpp │ ├── ivoryTestVS.vcxproj │ ├── ivoryTestVS.vcxproj.filters │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h ├── ivoryTests │ ├── CMakeLists.txt │ ├── Circuit_Tests.cpp │ ├── Circuit_Tests.h │ ├── Common.cpp │ ├── Common.h │ ├── Cope_Tests.cpp │ ├── Cope_Tests.h │ ├── DebugCircuits.cpp │ ├── DebugCircuits.h │ ├── ShGcRuntime_tests.cpp │ ├── ShGcRuntime_tests.h │ ├── ZpNumber_Tests.cpp │ ├── ZpNumber_Tests.h │ ├── ivoryTests.vcxproj │ └── ivoryTests.vcxproj.filters └── thirdparty │ └── linux │ └── ntl.get ├── Python accurracy ├── PythonApplication1 │ ├── PlainTextCluster_sizes1.arff.txt │ ├── PythonApplication1.py │ ├── PythonApplication1.pyproj │ ├── PythonApplication1.sln │ ├── SecureCluster_sizes1.arff.txt │ ├── raw_sizes1.arff.txt │ ├── sizes1.arff.txt │ └── unitTest_sizes1.arff.txt ├── PythonApplication_accuracy │ ├── PlainTextCluster_sizes1.arff.txt │ ├── PythonApplication1.py │ ├── PythonApplication1.pyproj │ ├── PythonApplication1.sln │ ├── SecureCluster_sizes1.arff.txt │ ├── raw_sizes1.arff.txt │ ├── sizes1.arff.txt │ └── unitTest_sizes1.arff.txt └── color │ ├── PythonApplication1.py │ └── sizes1.arff.txt ├── README.md ├── TestsVS ├── TestsVS.cpp ├── TestsVS.filters ├── TestsVS.vcxproj ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── buildAll.ps1 ├── copySourceToLinux.ps1 ├── dataset ├── LsunKmeans.txt ├── s1-groundtruth-plot.xls ├── s1.txt ├── s1c.txt └── sizes1.arff.txt ├── frontend ├── CLP.cpp ├── CLP.h ├── CMakeLists.txt ├── frontend.vcxproj ├── frontend.vcxproj.filters ├── main.cpp ├── main.h ├── signalHandle.cpp ├── signalHandle.h ├── util.cpp └── util.h ├── graph presentation ├── 3Cluster.csv ├── 4Cluster.csv ├── PlainTextCluster.csv ├── SecureCluster.csv ├── SecureClusterSign.csv ├── lable.PNG ├── nCluster.csv └── s1-groundtruth-plot.xls ├── libCluster ├── Accuracy.h ├── CMakeLists.txt ├── Common.cpp ├── Common.h ├── DataShare.cpp ├── DataShare.h ├── Tests.cpp ├── Tests.h ├── libCluster.vcxproj.filters ├── libCluster.vcxproj.vcxproj ├── progCircuit.h └── testData │ ├── code1280_BCH511.h │ ├── code1280_BCH511.txt │ ├── code128_BCH511.h │ ├── code128_BCH511.txt │ ├── code256_BCH511.h │ ├── code256_BCH511.txt │ ├── code384_BCH511.h │ ├── code384_BCH511.txt │ ├── code640_BCH511.h │ └── code640_BCH511.txt ├── libOTe_config ├── CMakeLists.txt └── libOTe │ ├── Base │ └── SimplestOT.h │ └── CMakeLists.txt ├── main.sln ├── script.get └── script_compr.get /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | *.vs 9 | 10 | CMakeFiles/* 11 | */CMakeFiles/* 12 | *cmake_install.cmake 13 | 14 | CMakeCache.txt 15 | */CMakeCache.txt 16 | 17 | *.a 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | x64/ 24 | build/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | 29 | # Roslyn cache directories 30 | *.ide/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | #NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding addin-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | ## TODO: Comment the next line if you want to checkin your 137 | ## web deploy settings but do note that will include unencrypted 138 | ## passwords 139 | #*.pubxml 140 | 141 | # NuGet Packages Directory 142 | packages/* 143 | ## TODO: If the tool you use requires repositories.config 144 | ## uncomment the next line 145 | #!packages/repositories.config 146 | 147 | # Enable "build/" folder in the NuGet Packages folder since 148 | # NuGet packages use it for MSBuild targets. 149 | # This line needs to be after the ignore of the build folder 150 | # (and the packages folder if the line above has been uncommented) 151 | !packages/build/ 152 | 153 | # Windows Azure Build Output 154 | csx/ 155 | *.build.csdef 156 | 157 | # Windows Store app package directory 158 | AppPackages/ 159 | 160 | # Others 161 | sql/ 162 | *.Cache 163 | ClientBin/ 164 | [Ss]tyle[Cc]op.* 165 | ~$* 166 | *~ 167 | *.dbmdl 168 | *.dbproj.schemaview 169 | *.pfx 170 | *.publishsettings 171 | node_modules/ 172 | 173 | # RIA/Silverlight projects 174 | Generated_Code/ 175 | 176 | # Backup & report files from converting an old project file 177 | # to a newer Visual Studio version. Backup files are not needed, 178 | # because we have git ;-) 179 | _UpgradeReport_Files/ 180 | Backup*/ 181 | UpgradeLog*.XML 182 | UpgradeLog*.htm 183 | 184 | # SQL Server files 185 | *.mdf 186 | *.ldf 187 | 188 | # Business Intelligence projects 189 | *.rdl.data 190 | *.bim.layout 191 | *.bim_*.settings 192 | 193 | # Microsoft Fakes 194 | FakesAssemblies/ 195 | 196 | # LightSwitch generated files 197 | GeneratedArtifacts/ 198 | _Pvt_Extensions/ 199 | ModelManifest.xml 200 | /WeGarbleTests__ 201 | /thirdparty 202 | kProbe_* 203 | 204 | CodeDB 205 | LinuxFrontEnd/VisualGDBCache 206 | *.opendb 207 | *.pdf 208 | *.db 209 | 210 | mpsi.VC* 211 | 212 | /psir_8s.txt 213 | /psis_8s.txt 214 | 215 | testout.txt 216 | online.txt 217 | offline.txt 218 | Makefile 219 | 220 | [path to project]/node_modules/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cryptoTools"] 2 | path = cryptoTools 3 | url = https://github.com/ladnir/cryptoTools 4 | [submodule "libOTe"] 5 | path = libOTe 6 | url = git@github.com:osu-crypto/libOTe.git -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8) 2 | 3 | project(main) 4 | 5 | if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") 6 | 7 | ############################################ 8 | # If top level cmake # 9 | ############################################ 10 | 11 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin) 12 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) 13 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) 14 | 15 | ############################################ 16 | # Flag and #defines # 17 | ############################################ 18 | add_definitions(-DSOLUTION_DIR=\"${CMAKE_SOURCE_DIR}\") 19 | set(CMAKE_C_FLAGS "-ffunction-sections -Wall -maes -msse2 -msse4.1 -mpclmul -Wfatal-errors -pthread -Wno-strict-overflow -fPIC -Wno-ignored-attributes") 20 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14") 21 | 22 | # Select flags. 23 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") 24 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO " -O2 -g -ggdb -rdynamic") 25 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb -rdynamic") 26 | 27 | ############################################ 28 | # Build mode checks # 29 | ############################################ 30 | 31 | # Set a default build type for single-configuration 32 | # CMake generators if no build type is set. 33 | if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) 34 | SET(CMAKE_BUILD_TYPE Release) 35 | endif() 36 | 37 | if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Release") 38 | message(WARNING "\nConfiguration NOT set to Release. Please call cmake with -DCMAKE_BUILD_TYPE=Release instead of ${CMAKE_BUILD_TYPE}") 39 | 40 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") 41 | #message(WARNING "Debug build.") 42 | elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") 43 | #message(WARNING "Release build.") 44 | elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO") 45 | #message(WARNING "RELWITHDEBINFO=Release with debug info build.") 46 | else() 47 | message(ERROR ": Unknown build type - ${CMAKE_BUILD_TYPE} Please use one of Debug, Release, or RELWITHDEBINFO\n\n" ) 48 | endif() 49 | endif() 50 | 51 | 52 | endif() 53 | 54 | ############################################ 55 | # Library/includes locations # 56 | ############################################# 57 | 58 | # default location for libOTe 59 | set(libOTe_Dirs "${CMAKE_SOURCE_DIR}/libOTe/") 60 | 61 | # default location for NTL 62 | set(NTL_Dirs "${CMAKE_SOURCE_DIR}/Ivory-Runtime/thirdparty/linux/ntl/") 63 | 64 | 65 | ############################################# 66 | # Build cryptoTools (common utilities) # 67 | ############################################# 68 | #include_directories(cryptoTools) 69 | add_subdirectory(libOTe/cryptoTools) 70 | 71 | 72 | ############################################# 73 | # Build libOTe # 74 | ############################################# 75 | include_directories(libOTe) 76 | add_subdirectory(libOTe/libOTe) 77 | 78 | ############################################# 79 | # Build ivory # 80 | ############################################# 81 | include_directories(Ivory-Runtime) 82 | add_subdirectory(Ivory-Runtime/ivory) 83 | 84 | ############################################# 85 | # Build Tests # 86 | ############################################# 87 | include_directories(libCluster) 88 | add_subdirectory(libCluster) 89 | 90 | ############################################# 91 | # Build ivoryTests # 92 | ############################################# 93 | #include_directories(Ivory-Runtime/ivoryTests) 94 | #add_subdirectory(Ivory-Runtime/ivoryTests) 95 | 96 | 97 | 98 | ############################################# 99 | # Build Frontend # 100 | ############################################# 101 | add_subdirectory(frontend) -------------------------------------------------------------------------------- /ExternalDependancies.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | $(SolutionDir)../libOTe 6 | 7 | 8 | 9 | 10 | 11 | $(libOTeDir) 12 | 13 | 14 | -------------------------------------------------------------------------------- /Ivory-Runtime/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | .vs/* 9 | 10 | CMakeFiles/ 11 | thirdparty/linux/ntl/ 12 | # Build results 13 | [Dd]ebug/ 14 | [Dd]ebugPublic/ 15 | [Rr]elease/ 16 | x64/ 17 | build/ 18 | bld/ 19 | [Bb]in/ 20 | [Oo]bj/ 21 | 22 | # Roslyn cache directories 23 | *.ide/ 24 | 25 | # MSTest test Results 26 | [Tt]est[Rr]esult*/ 27 | [Bb]uild[Ll]og.* 28 | 29 | #NUNIT 30 | *.VisualState.xml 31 | TestResult.xml 32 | 33 | # Build Results of an ATL Project 34 | [Dd]ebugPS/ 35 | [Rr]eleasePS/ 36 | dlldata.c 37 | *.opendb 38 | 39 | *_i.c 40 | *_p.c 41 | *_i.h 42 | *.ilk 43 | *.meta 44 | *.obj 45 | *.pch 46 | *.pdb 47 | *.pgc 48 | *.pgd 49 | *.rsp 50 | *.sbr 51 | *.tlb 52 | *.tli 53 | *.tlh 54 | *.tmp 55 | *.tmp_proj 56 | *.log 57 | *.vspscc 58 | *.vssscc 59 | .builds 60 | *.pidb 61 | *.svclog 62 | *.scc 63 | 64 | # Chutzpah Test files 65 | _Chutzpah* 66 | 67 | # Visual C++ cache files 68 | ipch/ 69 | *.aps 70 | *.ncb 71 | *.opensdf 72 | *.sdf 73 | *.cachefile 74 | 75 | # Visual Studio profiler 76 | *.psess 77 | *.vsp 78 | *.vspx 79 | 80 | # TFS 2012 Local Workspace 81 | $tf/ 82 | 83 | # Guidance Automation Toolkit 84 | *.gpState 85 | 86 | # ReSharper is a .NET coding add-in 87 | _ReSharper*/ 88 | *.[Rr]e[Ss]harper 89 | *.DotSettings.user 90 | 91 | # JustCode is a .NET coding addin-in 92 | .JustCode 93 | 94 | # TeamCity is a build add-in 95 | _TeamCity* 96 | 97 | # DotCover is a Code Coverage Tool 98 | *.dotCover 99 | 100 | # NCrunch 101 | _NCrunch_* 102 | .*crunch*.local.xml 103 | 104 | # MightyMoose 105 | *.mm.* 106 | AutoTest.Net/ 107 | 108 | # Web workbench (sass) 109 | .sass-cache/ 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.[Pp]ublish.xml 129 | *.azurePubxml 130 | ## TODO: Comment the next line if you want to checkin your 131 | ## web deploy settings but do note that will include unencrypted 132 | ## passwords 133 | #*.pubxml 134 | 135 | # NuGet Packages Directory 136 | packages/* 137 | ## TODO: If the tool you use requires repositories.config 138 | ## uncomment the next line 139 | #!packages/repositories.config 140 | 141 | # Enable "build/" folder in the NuGet Packages folder since 142 | # NuGet packages use it for MSBuild targets. 143 | # This line needs to be after the ignore of the build folder 144 | # (and the packages folder if the line above has been uncommented) 145 | !packages/build/ 146 | 147 | # Windows Azure Build Output 148 | csx/ 149 | *.build.csdef 150 | 151 | # Windows Store app package directory 152 | AppPackages/ 153 | 154 | # Others 155 | sql/ 156 | *.Cache 157 | ClientBin/ 158 | [Ss]tyle[Cc]op.* 159 | ~$* 160 | *~ 161 | *.dbmdl 162 | *.dbproj.schemaview 163 | *.pfx 164 | *.publishsettings 165 | node_modules/ 166 | 167 | # RIA/Silverlight projects 168 | Generated_Code/ 169 | 170 | # Backup & report files from converting an old project file 171 | # to a newer Visual Studio version. Backup files are not needed, 172 | # because we have git ;-) 173 | _UpgradeReport_Files/ 174 | Backup*/ 175 | UpgradeLog*.XML 176 | UpgradeLog*.htm 177 | 178 | # SQL Server files 179 | *.mdf 180 | *.ldf 181 | 182 | # Business Intelligence projects 183 | *.rdl.data 184 | *.bim.layout 185 | *.bim_*.settings 186 | 187 | # Microsoft Fakes 188 | FakesAssemblies/ 189 | 190 | # LightSwitch generated files 191 | GeneratedArtifacts/ 192 | _Pvt_Extensions/ 193 | ModelManifest.xml 194 | /WeGarbleTests__ 195 | /thirdparty 196 | kProbe_data_* 197 | 198 | *.VC.db 199 | 200 | CodeDB 201 | LinuxFrontEnd/VisualGDBCache 202 | /unitTest.txt 203 | -------------------------------------------------------------------------------- /Ivory-Runtime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.6) 2 | 3 | project("ivory") 4 | 5 | 6 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin) 7 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) 8 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) 9 | 10 | 11 | ############################################# 12 | # Flag and #defines # 13 | ############################################# 14 | add_definitions(-DSOLUTION_DIR=\"${CMAKE_SOURCE_DIR}\") 15 | set(CMAKE_C_FLAGS "-ffunction-sections -O3 -Wall -maes -msse2 -msse4.1 -mpclmul -Wfatal-errors -pthread") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14") 17 | 18 | 19 | 20 | ############################################# 21 | # Library/includes locations # 22 | ############################################# 23 | 24 | # default location for libOTe 25 | set(libOTe_Dirs "${CMAKE_SOURCE_DIR}/../libOTe/") 26 | #include_directories("${libOTe_Dirs}/libOTe/") 27 | #link_directories("${libOTe_Dirs}/lib/") 28 | 29 | # default location for miracl 30 | #set(Miracl_Dirs "${CMAKE_SOURCE_DIR}/thirdparty/linux/miracl/") 31 | #include_directories("${Miracl_Dirs}") 32 | #link_directories("${Miracl_Dirs}/miracl/source/") 33 | 34 | # default location for NTL 35 | set(NTL_Dirs "${CMAKE_SOURCE_DIR}/thirdparty/linux/ntl/") 36 | #include_directories("${NTL_Dirs}/include/") 37 | #link_directories("${NTL_Dirs}/src/") 38 | 39 | # default location for Boost 40 | #set(BOOST_ROOT "${CMAKE_SOURCE_DIR}/thirdparty/linux/boost/") 41 | 42 | 43 | ############################################# 44 | # Build cryptoTools # 45 | ############################################# 46 | #add_subdirectory(../libOTe) 47 | #include_directories(cryptoTools) 48 | 49 | 50 | ############################################# 51 | # Build ivory # 52 | ############################################# 53 | 54 | include_directories(${CMAKE_SOURCE_DIR}) 55 | add_subdirectory(ivory) 56 | 57 | 58 | ############################################# 59 | # Build ivory Tests # 60 | ############################################# 61 | add_subdirectory(ivoryTests) 62 | include_directories(ivoryTests) 63 | 64 | 65 | ############################################# 66 | # Build Frontend # 67 | ############################################# 68 | #add_subdirectory(frontend) 69 | file(GLOB_RECURSE SRC_FRONTEND ${CMAKE_SOURCE_DIR}/frontend/*.cpp) 70 | add_executable(frontend.exe ${SRC_FRONTEND}) 71 | target_link_libraries(frontend.exe ivoryTests) 72 | target_link_libraries(frontend.exe ivory) 73 | 74 | -------------------------------------------------------------------------------- /Ivory-Runtime/ExternalDependancies.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | $(SolutionDir)../libOTe 6 | 7 | 8 | 9 | 10 | 11 | $(libOTeDir) 12 | 13 | 14 | -------------------------------------------------------------------------------- /Ivory-Runtime/Ivory.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26228.9 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ivory", "ivory\ivory.vcxproj", "{8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {242D233A-6862-4767-8247-80AE3FDACB09} = {242D233A-6862-4767-8247-80AE3FDACB09} 9 | {D159E2F9-226C-4B19-905E-CC1EA0EB013F} = {D159E2F9-226C-4B19-905E-CC1EA0EB013F} 10 | EndProjectSection 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ivoryTests", "ivoryTests\ivoryTests.vcxproj", "{D3E2E0BC-D52A-494F-8C7A-C204C164EFD0}" 13 | ProjectSection(ProjectDependencies) = postProject 14 | {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6} = {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6} 15 | EndProjectSection 16 | EndProject 17 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ivoryTestVS", "ivoryTestVS\ivoryTestVS.vcxproj", "{5E8855B4-27DA-40EB-A9B5-B4BD6439315F}" 18 | ProjectSection(ProjectDependencies) = postProject 19 | {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0} = {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0} 20 | EndProjectSection 21 | EndProject 22 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "frontend", "frontend\frontend.vcxproj", "{CC0F3170-6E61-488D-8C74-FC423E9B2D1A}" 23 | ProjectSection(ProjectDependencies) = postProject 24 | {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0} = {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0} 25 | {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6} = {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6} 26 | EndProjectSection 27 | EndProject 28 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6194E977-4CDD-4280-A7C5-903448CF2B35}" 29 | ProjectSection(SolutionItems) = preProject 30 | CMakeLists.txt = CMakeLists.txt 31 | copySourceToLinux.ps1 = copySourceToLinux.ps1 32 | ExternalDependancies.props = ExternalDependancies.props 33 | README.md = README.md 34 | EndProjectSection 35 | EndProject 36 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libOTe", "..\libOTe\libOTe\libOTe.vcxproj.vcxproj", "{D159E2F9-226C-4B19-905E-CC1EA0EB013F}" 37 | EndProject 38 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SPDZ", "SPDZ\SPDZ.vcxproj", "{242D233A-6862-4767-8247-80AE3FDACB09}" 39 | EndProject 40 | Global 41 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 42 | Debug|x64 = Debug|x64 43 | Release|x64 = Release|x64 44 | EndGlobalSection 45 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 46 | {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6}.Debug|x64.ActiveCfg = Debug|x64 47 | {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6}.Debug|x64.Build.0 = Debug|x64 48 | {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6}.Release|x64.ActiveCfg = Release|x64 49 | {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6}.Release|x64.Build.0 = Release|x64 50 | {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0}.Debug|x64.ActiveCfg = Debug|x64 51 | {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0}.Debug|x64.Build.0 = Debug|x64 52 | {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0}.Release|x64.ActiveCfg = Release|x64 53 | {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0}.Release|x64.Build.0 = Release|x64 54 | {5E8855B4-27DA-40EB-A9B5-B4BD6439315F}.Debug|x64.ActiveCfg = Debug|x64 55 | {5E8855B4-27DA-40EB-A9B5-B4BD6439315F}.Debug|x64.Build.0 = Debug|x64 56 | {5E8855B4-27DA-40EB-A9B5-B4BD6439315F}.Release|x64.ActiveCfg = Release|x64 57 | {5E8855B4-27DA-40EB-A9B5-B4BD6439315F}.Release|x64.Build.0 = Release|x64 58 | {CC0F3170-6E61-488D-8C74-FC423E9B2D1A}.Debug|x64.ActiveCfg = Debug|x64 59 | {CC0F3170-6E61-488D-8C74-FC423E9B2D1A}.Debug|x64.Build.0 = Debug|x64 60 | {CC0F3170-6E61-488D-8C74-FC423E9B2D1A}.Release|x64.ActiveCfg = Release|x64 61 | {CC0F3170-6E61-488D-8C74-FC423E9B2D1A}.Release|x64.Build.0 = Release|x64 62 | {D159E2F9-226C-4B19-905E-CC1EA0EB013F}.Debug|x64.ActiveCfg = Debug|x64 63 | {D159E2F9-226C-4B19-905E-CC1EA0EB013F}.Debug|x64.Build.0 = Debug|x64 64 | {D159E2F9-226C-4B19-905E-CC1EA0EB013F}.Release|x64.ActiveCfg = Release|x64 65 | {D159E2F9-226C-4B19-905E-CC1EA0EB013F}.Release|x64.Build.0 = Release|x64 66 | {242D233A-6862-4767-8247-80AE3FDACB09}.Debug|x64.ActiveCfg = Debug|x64 67 | {242D233A-6862-4767-8247-80AE3FDACB09}.Debug|x64.Build.0 = Debug|x64 68 | {242D233A-6862-4767-8247-80AE3FDACB09}.Release|x64.ActiveCfg = Release|x64 69 | {242D233A-6862-4767-8247-80AE3FDACB09}.Release|x64.Build.0 = Release|x64 70 | EndGlobalSection 71 | GlobalSection(SolutionProperties) = preSolution 72 | HideSolutionNode = FALSE 73 | EndGlobalSection 74 | EndGlobal 75 | -------------------------------------------------------------------------------- /Ivory-Runtime/README.md: -------------------------------------------------------------------------------- 1 | # The Ivory Secure Computation Runtime 2 | 3 | 4 | 5 | 6 |
7 | Ivory Logo 8 |
9 | 10 | 11 | The Ivory Runtime is a C++ library that aims to make secure computation easier to use. At a high level, Ivory acheives this by bringing together the protocol and the binary/arithmetic circuit compiler into a single integrated system. 12 | 13 | Instead of requiring the user provide the circuit to be computed, the runtime pre-compiles many of the most useful opertions into mini-circuits/operations, e.g. addition, subtraction, multiplication, etc. The runtime then provides easy to use abstrations for declaring input variables, and computing with them. 14 | 15 | While at of this push, only semi-honest garbled circuit is supported, eventually other paradigms will be supported in a generic way. That is, you will be able to write a program that builds on Ivory's generic MPC API and then select the desired protocol to run in the background. E.g. semi-honest, malicious, garbled circuit, lego, mascot, etc... 16 | 17 | Consider the following code snippet. It takes 64 bit input from two parties and adds, subtracts, multiplies, etc them together. Each party is then revealed a different set of the computation. 18 | 19 | ```c++ 20 | void program(std::array parties, i64 myInput) 21 | { 22 | // declare some secret inputs, one for each party 23 | sInt input0 = parties[0].isLocalParty() ? 24 | parties[0].input(myInput, 64) : 25 | parties[0].input(64); 26 | 27 | sInt input1 = parties[1].isLocalParty() ? 28 | parties[1].input(myInput, 64) : 29 | parties[1].input(64); 30 | 31 | // perform some generic secure computation 32 | auto add = input1 + input0; 33 | auto sub = input1 - input0; 34 | auto mul = input1 * input0; 35 | auto div = input1 / input0; 36 | 37 | // logical operations 38 | auto gteq = input1 >= input0; 39 | auto lt = input1 < input0; 40 | 41 | // conditional operation 42 | auto max = gteq.ifelse(input1, input0); 43 | 44 | 45 | // mark these values as being revealed to party 0 46 | // at some point in the future (asynchronous). 47 | parties[0].reveal(add); 48 | parties[0].reveal(sub); 49 | parties[0].reveal(mul); 50 | parties[0].reveal(div); 51 | 52 | // and these ones to party 1 53 | parties[1].reveal(gteq); 54 | parties[1].reveal(lt); 55 | parties[1].reveal(max); 56 | 57 | // The parties now waits for their results and prints them. 58 | if (parties[0].isLocalParty()) 59 | { 60 | std::cout << "add " << add.getValue() << std::endl; 61 | std::cout << "sub " << sub.getValue() << std::endl; 62 | std::cout << "mul " << mul.getValue() << std::endl; 63 | std::cout << "div " << div.getValue() << std::endl; 64 | } else { 65 | std::cout << "gteq " << gteq.getValue() << std::endl; 66 | std::cout << "lt " << lt.getValue() << std::endl; 67 | std::cout << "max " << max.getValue() << std::endl; 68 | } 69 | 70 | } 71 | ``` 72 | 73 | 74 | 75 | ## Building 76 | 77 | To build the library, [libOTe](https://github.com/osu-crypto/libOTe) must be built. Follow the instructions on the associated readme. Once build, ensure that Ivory-Runtime and libOTe are contained in the same parent directory. 78 | ``` 79 | [libOTe setup] 80 | git clone https://github.com/ladnir/Ivory-Runtime.git 81 | cd Ivory-Runtime/thirdparty/linux 82 | bash ./ntl.get 83 | cd ../.. 84 | cmake -G"Unix Makefiles" 85 | make 86 | ``` 87 | 88 | 89 | This will produce produce several libraries which will need to be linked. In the libOTe directory, the `bin` folder will contain `liblibOTe.a` and `libcryptoTools.a`. In addition to these libraries, the other third party libraries need to be linked. Namely miracl located at `/libOTe/cryptoTools/thirdparty/linux/miracl/miracl/source/libmiracl.a` and boost libraries folder at `libOTe/cryptoTools/thirdparty/linux/boost/stage/lib/`. Finally, the ivory library at `Ivory-Runtime/bin` should also be linked. 90 | 91 | With regards to includes folders, the boost and miracl folders should be included. The top level of `libOTe` and `libOTe/cryptoTools` must be included and finally `Ivory-Runtime/ivory` should also be included. 92 | 93 | 94 | Similar instruction on windows can be followed with the exception that visual studio solutions are provided in lue of cmake. -------------------------------------------------------------------------------- /Ivory-Runtime/SPDZ/CopeOtExtDefines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cryptoTools/Common/Defines.h" 3 | 4 | namespace osuCrypto 5 | { 6 | static const u64 copeCommStepSize(512); 7 | static const u64 copeSuperBlkSize(8); 8 | } 9 | #pragma once 10 | -------------------------------------------------------------------------------- /Ivory-Runtime/SPDZ/CopeOtExtReceiver.cpp: -------------------------------------------------------------------------------- 1 | #include "CopeOtExtReceiver.h" 2 | #include "libOTe/Tools/Tools.h" 3 | #include "cryptoTools/Common/Log.h" 4 | 5 | #include "cryptoTools/Common/BitVector.h" 6 | #include "cryptoTools/Crypto/PRNG.h" 7 | #include "cryptoTools/Crypto/Commit.h" 8 | #include "CopeOtExtDefines.h" 9 | 10 | using namespace std; 11 | 12 | namespace osuCrypto 13 | { 14 | void CopeOtExtReceiver::setBaseOts(span> baseOTs) 15 | { 16 | if (baseOTs.size() != gOtExtBaseOtCount) 17 | throw std::runtime_error(LOCATION); 18 | 19 | for (u64 i = 0; i < gOtExtBaseOtCount; i++) 20 | { 21 | mGens[i][0].SetSeed(baseOTs[i][0]); 22 | mGens[i][1].SetSeed(baseOTs[i][1]); 23 | } 24 | 25 | 26 | mHasBase = true; 27 | } 28 | std::unique_ptr CopeOtExtReceiver::split() 29 | { 30 | std::array, gOtExtBaseOtCount>baseRecvOts; 31 | 32 | for (u64 i = 0; i < mGens.size(); ++i) 33 | { 34 | baseRecvOts[i][0] = mGens[i][0].get(); 35 | baseRecvOts[i][1] = mGens[i][1].get(); 36 | } 37 | 38 | std::unique_ptr ret(new CopeOtExtReceiver()); 39 | 40 | ret->setBaseOts(baseRecvOts); 41 | 42 | return std::move(ret); 43 | } 44 | 45 | 46 | void CopeOtExtReceiver::receive( 47 | span inVal, 48 | span share, 49 | PRNG& prng, 50 | Channel& chl) 51 | { 52 | 53 | throw std::runtime_error("NOT Implemented " LOCATION); 54 | //if (mHasBase == false) 55 | // throw std::runtime_error("rt error at " LOCATION); 56 | 57 | //auto fieldSize = inVal[0].mField->bitCount(); 58 | 59 | //// we are going to process OTs in blocks of 128 * copeSuperBlkSize messages. 60 | //u64 numOtExt = inVal.size() * fieldSize; 61 | //u64 numSuperBlocks = (numOtExt / 128 + copeSuperBlkSize - 1) / copeSuperBlkSize; 62 | //u64 numBlocks = numSuperBlocks * copeSuperBlkSize; 63 | 64 | //// this will be used as temporary buffers of 128 columns, 65 | //// each containing 1024 bits. Once transposed, they will be copied 66 | //// into the T1, T0 buffers for long term storage. 67 | //std::array, 128> t0; 68 | 69 | //// the index of the OT that has been completed. 70 | ////u64 doneIdx = 0; 71 | //auto* inIter = inVal.data(); 72 | //auto* sIter = share.data(); 73 | 74 | //u64 step = std::min(numSuperBlocks, (u64)copeCommStepSize); 75 | //std::unique_ptr uBuff(new ByteStream(step * 128 * copeSuperBlkSize * sizeof(block))); 76 | 77 | //// get an array of blocks that we will fill. 78 | //auto uIter = (block*)uBuff->data(); 79 | //auto uEnd = uIter + step * 128 * copeSuperBlkSize; 80 | 81 | //auto& field = *inVal[0].mField; 82 | //ZpNumber t0Num(field); 83 | //ZpNumber uNum(field); 84 | 85 | //std::vector g; 86 | //g.reserve(field.bitCount()); 87 | //for (u64 i = 0; i < field.bitCount(); ++i) 88 | //{ 89 | // g.emplace_back(field, 2); 90 | // g[i].powEq(i); 91 | //} 92 | 93 | //for (u64 superBlkIdx = 0; superBlkIdx < numSuperBlocks; ++superBlkIdx) 94 | //{ 95 | 96 | // // this will store the next 128 rows of the matrix u 97 | // block* tIter = (block*)t0.data(); 98 | 99 | // std::cout << IoStream::lock; 100 | 101 | // for (u64 j = 0; j < copeSuperBlkSize; ++j) 102 | // { 103 | // sIter[j] = 0; 104 | // } 105 | 106 | // for (u64 colIdx = 0; colIdx < 128; ++colIdx) 107 | // { 108 | // // generate the column indexed by colIdx. This is done with 109 | // // AES in counter mode acting as a PRNG. We don'tIter use the normal 110 | // // PRNG interface because that would result in a data copy when 111 | // // we move it into the T0,T1 matrices. Instead we do it directly. 112 | // mGens[colIdx][0].mAes.ecbEncCounterMode(mGens[colIdx][0].mBlockIdx, copeSuperBlkSize, tIter); 113 | // mGens[colIdx][1].mAes.ecbEncCounterMode(mGens[colIdx][1].mBlockIdx, copeSuperBlkSize, uIter); 114 | 115 | // // increment the counter mode idx. 116 | // mGens[colIdx][0].mBlockIdx += copeSuperBlkSize; 117 | // mGens[colIdx][1].mBlockIdx += copeSuperBlkSize; 118 | 119 | // for (u64 i = 0; i < copeSuperBlkSize; ++i) 120 | // { 121 | // t0Num.fromBytes((u8*)&tIter[i]); 122 | // uNum.fromBytes((u8*)&uIter[i]); 123 | 124 | // uNum -= t0Num; 125 | // uNum -= inIter[i]; 126 | 127 | // uNum.toBytes((u8*)&uIter[i]); 128 | 129 | // std::cout << "t0 [" << colIdx << "][" << i << "] = " << t0Num << " (-"<< t0Num <<")" << std::endl; 130 | // //std::cout << "t0x[" << i << "][" << colIdx << "] = " << t0Num + inIter[i] << std::endl; 131 | // //std::cout << "t1x[" << i << "][" << colIdx << "] = " << uNum << std::endl; 132 | 133 | // t0Num *= g[colIdx]; 134 | // sIter[i] -= t0Num; 135 | // } 136 | 137 | // uIter += 8; 138 | // tIter += 8; 139 | // } 140 | // 141 | // //for (u64 j = 0; j < copeSuperBlkSize; ++j) 142 | // //{ 143 | // // sIter[j] = -sIter[j]; 144 | // //} 145 | 146 | // inIter += 8; 147 | // sIter += 8; 148 | 149 | // std::cout << IoStream::unlock; 150 | 151 | // if (uIter == uEnd) 152 | // { 153 | // // send over u buffer 154 | // chl.asyncSend(std::move(uBuff)); 155 | 156 | // u64 step = std::min(numSuperBlocks - superBlkIdx - 1, (u64)copeCommStepSize); 157 | 158 | // if (step) 159 | // { 160 | // uBuff.reset(new ByteStream(step * 128 * copeSuperBlkSize * sizeof(block))); 161 | 162 | // uIter = (block*)uBuff->data(); 163 | // uEnd = uIter + step * 128 * copeSuperBlkSize; 164 | // } 165 | // } 166 | 167 | //} 168 | 169 | 170 | 171 | static_assert(gOtExtBaseOtCount == 128, "expecting 128"); 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /Ivory-Runtime/SPDZ/CopeOtExtReceiver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use. 3 | #include "libOTe/TwoChooseOne/OTExtInterface.h" 4 | #include "cryptoTools/Network/Channel.h" 5 | #include 6 | #include "cryptoTools/Crypto/PRNG.h" 7 | #include "Math/ZpField.h" 8 | 9 | namespace osuCrypto 10 | { 11 | 12 | class CopeOtExtReceiver 13 | { 14 | public: 15 | CopeOtExtReceiver() 16 | :mHasBase(false) 17 | {} 18 | 19 | bool hasBaseOts() const 20 | { 21 | return mHasBase; 22 | } 23 | 24 | bool mHasBase; 25 | std::array, gOtExtBaseOtCount> mGens; 26 | 27 | void setBaseOts( 28 | span> baseSendOts); 29 | std::unique_ptr split() ; 30 | 31 | 32 | void receive( 33 | span messages, 34 | span share, 35 | PRNG& prng, 36 | Channel& chl); 37 | 38 | }; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Ivory-Runtime/SPDZ/CopeOtExtSender.cpp: -------------------------------------------------------------------------------- 1 | #include "CopeOtExtSender.h" 2 | 3 | #include "CopeOtExtDefines.h" 4 | #include "cryptoTools/Crypto/Commit.h" 5 | #include "libOTe/Tools/Tools.h" 6 | #include "Math/ZpField.h" 7 | 8 | #include "cryptoTools/Common/Log.h" 9 | #include "cryptoTools/Network/Channel.h" 10 | 11 | namespace osuCrypto 12 | { 13 | 14 | std::unique_ptr CopeOtExtSender::split() 15 | { 16 | 17 | std::unique_ptr ret(new CopeOtExtSender()); 18 | 19 | std::array baseRecvOts; 20 | 21 | for (u64 i = 0; i < mGens.size(); ++i) 22 | { 23 | baseRecvOts[i] = mGens[i].get(); 24 | } 25 | 26 | ret->setBaseOts(baseRecvOts, mBaseChoiceBits); 27 | 28 | return std::move(ret); 29 | } 30 | 31 | void CopeOtExtSender::setBaseOts(span baseRecvOts, const BitVector & choices) 32 | { 33 | if (baseRecvOts.size() != gOtExtBaseOtCount || choices.size() != gOtExtBaseOtCount) 34 | throw std::runtime_error("not supported/implemented"); 35 | 36 | 37 | mBaseChoiceBits = choices; 38 | for (u64 i = 0; i < gOtExtBaseOtCount; i++) 39 | { 40 | mGens[i].SetSeed(baseRecvOts[i]); 41 | } 42 | } 43 | 44 | void CopeOtExtSender::send( 45 | span messages, 46 | Channel& chl) 47 | { 48 | auto fieldSize = messages[0].mField->bitCount(); 49 | 50 | // round up 51 | u64 numOtExt = roundUpTo(messages.size() * fieldSize, 128); 52 | u64 numSuperBlocks = (numOtExt / 128 + copeSuperBlkSize - 1) / copeSuperBlkSize; 53 | //u64 numBlocks = numSuperBlocks * copeSuperBlkSize; 54 | 55 | // a uNum that will be used to transpose the sender's matrix 56 | std::array t; 57 | std::vector> u(128 * copeCommStepSize); 58 | 59 | //std::array choiceMask; 60 | block delta = *(block*)mBaseChoiceBits.data(); 61 | 62 | //for (u64 i = 0; i < 128; ++i) 63 | //{ 64 | // if (mBaseChoiceBits[i]) choiceMask[i] = AllOneBlock; 65 | // else choiceMask[i] = ZeroBlock; 66 | //} 67 | 68 | 69 | auto* mIter = messages.data(); 70 | 71 | block * uIter = (block*)u.data() + copeSuperBlkSize * 128 * copeCommStepSize; 72 | block * uEnd = uIter; 73 | 74 | ZpField field; 75 | field.setParameters(ZpParam128); 76 | 77 | std::vector g; 78 | //qq.reserve(copeSuperBlkSize * field.bitCount()); 79 | //for (u64 i = 0; i < copeSuperBlkSize * field.bitCount(); ++i) 80 | // qq.emplace_back(field); 81 | 82 | std::cout << IoStream::lock; 83 | g.reserve(field.bitCount()); 84 | for (u64 i = 0; i < field.bitCount(); ++i) 85 | { 86 | g.emplace_back(field, 2); 87 | g[i].powEq(i); 88 | std::cout << "g[" << i << "] " << g[i] << std::endl; 89 | } 90 | 91 | std::cout << IoStream::unlock; 92 | 93 | std::array q 94 | { 95 | ZpNumber(field),ZpNumber(field),ZpNumber(field),ZpNumber(field), 96 | ZpNumber(field), ZpNumber(field), ZpNumber(field), ZpNumber(field) 97 | }; 98 | 99 | ZpNumber uNum(field); 100 | 101 | for (u64 superBlkIdx = 0; superBlkIdx < numSuperBlocks; ++superBlkIdx) 102 | { 103 | 104 | if (uIter == uEnd) 105 | { 106 | u64 step = std::min(numSuperBlocks - superBlkIdx, (u64)copeCommStepSize); 107 | chl.recv((u8*)u.data(), step * copeSuperBlkSize * 128 * sizeof(block)); 108 | uIter = (block*)u.data(); 109 | } 110 | 111 | for (u64 j = 0; j < copeSuperBlkSize; ++j) 112 | { 113 | //qq[j] = 0; 114 | mIter[j] = 0; 115 | } 116 | std::cout << IoStream::lock; 117 | 118 | // transpose 128 columns at at time. Each column will be 128 * copeSuperBlkSize = 1024 bits long. 119 | for (u64 colIdx = 0; colIdx < 128; ++colIdx) 120 | { 121 | // generate the columns using AES-NI in counter mode. 122 | mGens[colIdx].mAes.ecbEncCounterMode(mGens[colIdx].mBlockIdx, copeSuperBlkSize, t.data()); 123 | mGens[colIdx].mBlockIdx += copeSuperBlkSize; 124 | 125 | for (u64 i = 0; i < copeSuperBlkSize; ++i) 126 | { 127 | q[i].fromBytes((u8*)&t[i]); 128 | } 129 | 130 | if (this->mBaseChoiceBits[colIdx]) 131 | { 132 | for (u64 i = 0; i < copeSuperBlkSize; ++i) 133 | { 134 | uNum.fromBytes((u8*)&uIter[i]); 135 | q[i] -= uNum; 136 | } 137 | } 138 | 139 | 140 | 141 | for (u64 i = 0; i < copeSuperBlkSize; ++i) 142 | { 143 | //std::cout << (mBaseChoiceBits[colIdx]? "t0x" : "t0 ") <<"[" << i << "][" << colIdx << "] = " << q[i] <<" " << mBaseChoiceBits[colIdx] << "\n\n"< mGens; 21 | BitVector mBaseChoiceBits; 22 | 23 | bool hasBaseOts() const 24 | { 25 | return mBaseChoiceBits.size() > 0; 26 | } 27 | 28 | std::unique_ptr split(); 29 | 30 | void setBaseOts( 31 | span baseRecvOts, 32 | const BitVector& choices); 33 | 34 | 35 | void send( 36 | span messages, 37 | Channel& chl); 38 | 39 | }; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Ivory-Runtime/SPDZ/Math/ZpField.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "miracl/include/miracl.h" 4 | #include "cryptoTools/Common/Defines.h" 5 | #include "cryptoTools/Crypto/PRNG.h" 6 | 7 | 8 | namespace osuCrypto 9 | { 10 | struct ZpParam 11 | { 12 | u32 bitCount; 13 | // prime 14 | const char* p; 15 | }; 16 | 17 | 18 | const ZpParam ZpParam5_INSECURE 19 | { 20 | 5, 21 | "17", 22 | }; 23 | 24 | 25 | 26 | const ZpParam ZpParam128 27 | { 28 | 128, 29 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF61", 30 | }; 31 | 32 | 33 | class ZpField; 34 | 35 | class ZpNumber 36 | { 37 | public: 38 | ZpNumber(const ZpNumber& num); 39 | ZpNumber(ZpNumber&& num); 40 | ZpNumber(ZpField& field); 41 | ZpNumber(ZpField& field, const ZpNumber& num); 42 | ZpNumber(ZpField& field, PRNG& prng); 43 | ZpNumber(ZpField& field, i32 val); 44 | 45 | ~ZpNumber(); 46 | 47 | ZpNumber& operator=(const ZpNumber& c); 48 | ZpNumber& operator=(big c); 49 | ZpNumber& operator=(int i); 50 | 51 | 52 | ZpNumber& operator++(); 53 | ZpNumber& operator--(); 54 | ZpNumber& operator+=(int i); 55 | ZpNumber& operator-=(int i); 56 | ZpNumber& operator+=(const ZpNumber& b); 57 | ZpNumber& operator-=(const ZpNumber& b); 58 | ZpNumber& operator*=(const ZpNumber& b); 59 | ZpNumber& operator*=(int i); 60 | ZpNumber& operator/=(const ZpNumber& b); 61 | ZpNumber& operator/=(int i); 62 | ZpNumber& negate(); 63 | 64 | ZpNumber& powEq(int pow); 65 | ZpNumber pow(int pow); 66 | 67 | //ZpNumber& powEq(ZpNumber pow); 68 | //ZpNumber pow(ZpNumber pow); 69 | 70 | 71 | bool operator==(const ZpNumber& cmp) const; 72 | bool operator==(const int& cmp)const; 73 | friend bool operator==(const int& cmp1, const ZpNumber& cmp2); 74 | bool operator!=(const ZpNumber& cmp)const; 75 | bool operator!=(const int& cmp)const; 76 | friend bool operator!=(const int& cmp1, const ZpNumber& cmp2); 77 | 78 | bool operator>=(const ZpNumber& cmp)const; 79 | bool operator>=(const int& cmp)const; 80 | 81 | bool operator<=(const ZpNumber& cmp)const; 82 | bool operator<=(const int& cmp)const; 83 | 84 | bool operator>(const ZpNumber& cmp)const; 85 | bool operator>(const int& cmp)const; 86 | 87 | bool operator<(const ZpNumber& cmp)const; 88 | bool operator<(const int& cmp)const; 89 | 90 | 91 | BOOL iszero() const; 92 | 93 | 94 | friend ZpNumber operator-(const ZpNumber&); 95 | friend ZpNumber operator+(const ZpNumber&, int); 96 | friend ZpNumber operator+(int, const ZpNumber&); 97 | friend ZpNumber operator+(const ZpNumber&, const ZpNumber&); 98 | 99 | friend ZpNumber operator-(const ZpNumber&, int); 100 | friend ZpNumber operator-(int, const ZpNumber&); 101 | friend ZpNumber operator-(const ZpNumber&, const ZpNumber&); 102 | 103 | friend ZpNumber operator*(const ZpNumber&, int); 104 | friend ZpNumber operator*(int, const ZpNumber&); 105 | friend ZpNumber operator*(const ZpNumber&, const ZpNumber&); 106 | 107 | friend ZpNumber operator/(const ZpNumber&, int); 108 | friend ZpNumber operator/(int, const ZpNumber&); 109 | friend ZpNumber operator/(const ZpNumber&, const ZpNumber&); 110 | 111 | u64 sizeBytes() const; 112 | void toBits(u8* dest) const; 113 | void toBytes(u8* dest) const; 114 | void fromBits(u8* src); 115 | void fromBytes(u8* src); 116 | void fromHex(char* src); 117 | void fromDec(char* src); 118 | 119 | void randomize(PRNG& prng); 120 | void randomize(const block& seed); 121 | 122 | 123 | private: 124 | 125 | void init(); 126 | //void reduce(); 127 | 128 | big data(); 129 | public: 130 | //struct bigtype mData; 131 | big mVal; 132 | ZpField* mField; 133 | 134 | friend std::ostream& operator<<(std::ostream& out, const ZpNumber& val); 135 | }; 136 | std::ostream& operator<<(std::ostream& out, const ZpNumber& val); 137 | 138 | 139 | class ZpField 140 | { 141 | friend ZpNumber; 142 | friend std::ostream& operator<<(std::ostream& out, const ZpNumber& val); 143 | 144 | public: 145 | ZpField(const ZpParam& params); 146 | ZpField(); 147 | ~ZpField(); 148 | 149 | void setParameters(const ZpParam& params); 150 | 151 | const ZpNumber& getFieldPrime() const; 152 | 153 | u64 bitCount(); 154 | 155 | private: 156 | u64 mBitCount; 157 | 158 | std::unique_ptr mFieldPrime, mOne; 159 | 160 | miracl* mMiracl; 161 | }; 162 | 163 | } 164 | -------------------------------------------------------------------------------- /Ivory-Runtime/SPDZ/SPDZ.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {242D233A-6862-4767-8247-80AE3FDACB09} 15 | SPDZ 16 | 10.0 17 | 18 | 19 | 20 | StaticLibrary 21 | true 22 | v142 23 | MultiByte 24 | 25 | 26 | StaticLibrary 27 | false 28 | v142 29 | true 30 | MultiByte 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Level3 50 | Disabled 51 | true 52 | $(libOTeDir)/cryptoTools;$(libOTeDir);$(ProjectDir);$(libOTeDir)/cryptoTools/thirdparty/win/boost;$(libOTeDir)/cryptoTools/thirdparty/win/;$(libOTeDir)/cryptoTools/thirdparty/win/miracl;C:/libs/boost;C:/libs/miracl;%(AdditionalIncludeDirectories) 53 | MultiThreadedDebug 54 | 55 | 56 | 57 | 58 | Level3 59 | MaxSpeed 60 | true 61 | true 62 | true 63 | $(libOTeDir)/cryptoTools;$(libOTeDir);$(ProjectDir);$(libOTeDir)/cryptoTools/thirdparty/win/boost;$(libOTeDir)/cryptoTools/thirdparty/win/;$(libOTeDir)/cryptoTools/thirdparty/win/miracl;C:/libs/boost;C:/libs/miracl;%(AdditionalIncludeDirectories) 64 | MultiThreaded 65 | 66 | 67 | true 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Ivory-Runtime/SPDZ/SPDZ.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | -------------------------------------------------------------------------------- /Ivory-Runtime/copySourceToLinux.ps1: -------------------------------------------------------------------------------- 1 | $RemoteUserName='rindalp' 2 | $RemoteHostName='eve.eecs.oregonstate.edu' 3 | $PrivateKey='C:\keys\key.ppk' 4 | $SolutionDir=$PWD 5 | $RemoteWorkingDir='/scratch/repo/ivory' 6 | 7 | # only files with these extensions will be copied 8 | $FileMasks='**.cpp;**.c;**.h;*.bin,*.S;*CMakeLists.txt;thirdparty/linux/**.get' 9 | 10 | # everything in these folders will be skipped 11 | $ExcludeDirs='.git/;thirdparty/;Debug/;Release/;x64/;ipch/;.vs/' 12 | 13 | C:\tools\WinSCP.com /command ` 14 | "open $RemoteUserName@$RemoteHostName -privatekey=""$PrivateKey"""` 15 | "call mkdir -p $RemoteWorkingDir"` 16 | "synchronize Remote $SolutionDir $RemoteWorkingDir -filemask=""$FileMasks|$ExcludeDirs;"""` 17 | "call mkdir -p $RemoteWorkingDir/thirdparty/"` 18 | "call mkdir -p $RemoteWorkingDir/thirdparty/linux/"` 19 | "synchronize remote $SolutionDir/thirdparty/linux/ $RemoteWorkingDir/thirdparty/linux/ -filemask=""**.get"""` 20 | "exit" -------------------------------------------------------------------------------- /Ivory-Runtime/frontend/frontend.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {CC0F3170-6E61-488D-8C74-FC423E9B2D1A} 15 | frontend 16 | 10.0 17 | 18 | 19 | 20 | Application 21 | true 22 | v142 23 | MultiByte 24 | 25 | 26 | Application 27 | false 28 | v142 29 | true 30 | MultiByte 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Level3 50 | Disabled 51 | true 52 | $(libOTeDir);$(libOTeDir)\cryptoTools;$(ProjectDir)/../;$(ProjectDir)/../;C:\libs\NTL\include;C:\libs;C:\libs\boost;C:\libs\miracl 53 | MultiThreadedDebug 54 | _MBCS;%(PreprocessorDefinitions) 55 | 56 | 57 | libOTe.lib;Miracl.lib;NTL.lib;ivoryTests.lib;ivory.lib;cryptoTools.lib;%(AdditionalDependencies) 58 | $(OutputPath);%(AdditionalLibraryDirectories);$(libOTeDir)\x64\$(Configuration);C:\libs;C:\libs\cryptopp\x64\Output\$(Configuration);C:\libs\boost\stage\lib\;$(ProjectDir)/../thirdparty/win/NTL/x64/$(Configuration);C:\libs\NTL\x64\$(Configuration);C:\libs\miracl\x64\$(Configuration) 59 | 60 | 61 | 62 | 63 | Level3 64 | MaxSpeed 65 | true 66 | true 67 | true 68 | $(libOTeDir);$(libOTeDir)\cryptoTools;$(ProjectDir)/../;$(ProjectDir)/../;C:\libs\NTL\include;C:\libs;C:\libs\boost;C:\libs\miracl 69 | MultiThreaded 70 | _MBCS;%(PreprocessorDefinitions) 71 | 72 | 73 | true 74 | true 75 | libOTe.lib;Miracl.lib;NTL.lib;ivoryTests.lib;ivory.lib;cryptoTools.lib;%(AdditionalDependencies) 76 | $(OutputPath);%(AdditionalLibraryDirectories);$(libOTeDir)\x64\$(Configuration);C:\libs;C:\libs\cryptopp\x64\Output\$(Configuration);C:\libs\boost\stage\lib\;$(ProjectDir)/../thirdparty/win/NTL/x64/$(Configuration);C:\libs\NTL\x64\$(Configuration);C:\libs\miracl\x64\$(Configuration) 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Ivory-Runtime/frontend/frontend.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /Ivory-Runtime/frontend/main.cpp: -------------------------------------------------------------------------------- 1 | #include "cryptoTools/Network/IOService.h" 2 | #include "cryptoTools/Network/Session.h" 3 | 4 | #include 5 | #include 6 | #include "cryptoTools/Common/Log.h" 7 | #include "cryptoTools/Common/Timer.h" 8 | #include "ivory/Runtime/ShGc/ShGcRuntime.h" 9 | //#include "ivory/Runtime/ClearRuntime.h" 10 | #include "ivory/Runtime/sInt.h" 11 | #include "ivory/Runtime/Party.h" 12 | 13 | #include 14 | #include "cryptoTools/Crypto/PRNG.h" 15 | 16 | using namespace osuCrypto; 17 | 18 | i32 program(std::array parties, i64 myInput) 19 | { 20 | // choose how large the arithmetic should be. 21 | u64 bitCount = 16; 22 | 23 | // get the two input variables. If this party is the local party, then 24 | // lets use our input value. Otherwise the remote party will provide the value. 25 | // In addition, the bitCount parameter means a value with that many bits 26 | // will fit into this secure variable. However, the runtime reserver the right 27 | // to increase the bits or to use something like a prime feild, in which case 28 | // the exact wrap around point is undefined. However, the binary circuit base runtimes 29 | // will always use exactly that many bits. 30 | auto input0 = parties[0].isLocalParty() ? 31 | parties[0].input(myInput, bitCount) : 32 | parties[0].input(bitCount); 33 | 34 | auto input1 = parties[1].isLocalParty() ? 35 | parties[1].input(myInput, bitCount) : 36 | parties[1].input(bitCount); 37 | 38 | 39 | 40 | 41 | // perform some computation 42 | auto add = input1 + input0; 43 | auto sub = input1 - input0; 44 | auto mul = input1 * input0; 45 | auto div = input1 / input0; 46 | 47 | //auto pubAdd = add + 22; 48 | 49 | auto gteq = input1 >= input0; 50 | auto lt = input1 < input0; 51 | 52 | 53 | auto max = gteq.ifelse(input1, input0); 54 | 55 | input0 = input0 + input1; 56 | 57 | 58 | // reveal this output to party 0. 59 | parties[0].reveal(add); 60 | parties[0].reveal(sub); 61 | parties[0].reveal(mul); 62 | parties[0].reveal(div); 63 | parties[0].reveal(gteq); 64 | parties[0].reveal(lt); 65 | parties[0].reveal(max); 66 | 67 | 68 | if (parties[0].isLocalParty()) 69 | { 70 | std::cout << "add " << add.getValue() << std::endl; 71 | std::cout << "sub " << sub.getValue() << std::endl; 72 | std::cout << "mul " << mul.getValue() << std::endl; 73 | std::cout << "div " << div.getValue() << std::endl; 74 | std::cout << "gteq " << gteq.getValue() << std::endl; 75 | std::cout << "lt " << lt.getValue() << std::endl; 76 | std::cout << "max " << max.getValue() << std::endl; 77 | } 78 | 79 | // operations can get queued up in the background. Eventually this call should not 80 | // be required but in the mean time, if one party does not call getValue(), then 81 | // processesQueue() should be called. 82 | parties[1].getRuntime().processesQueue(); 83 | 84 | 85 | return 0; 86 | } 87 | 88 | int main(int argc, char**argv) 89 | { 90 | u64 tries(2); 91 | PRNG prng(OneBlock); 92 | bool debug = false; 93 | 94 | // IOSerive will perform the networking operations in the background 95 | IOService ios; 96 | 97 | // We need each party to be in its own thread. 98 | std::thread thrd([&]() { 99 | 100 | // Session represents one end of a connection. It facilitates the 101 | // creation of sockets that all bind to this port. First we pass it the 102 | // IOSerive and then the server's IP:port number. Next we state that 103 | // this Session should act as a server (listens to the provided port). 104 | Session ep1(ios, "127.0.0.1:1212", SessionMode::Server); 105 | 106 | // We can now create a socket. This is done with addChannel. This operation 107 | // is asynchronous. If additional connections are needed between the 108 | // two parties, call addChannel again. 109 | Channel chl1 = ep1.addChannel(); 110 | 111 | // this is an opertional call that blocks until the socket has successfully 112 | // been set up. 113 | chl1.waitForConnection(); 114 | 115 | // We will need a random number generator. Should pas it a real seed. 116 | PRNG prng(ZeroBlock); 117 | 118 | // In this example, we will use the semi-honest Garbled Circuit 119 | // runtime. Once constructed, init should be called. We need to 120 | // provide the runtime the channel that it will use to communicate 121 | // with the other party, a seed, what mode it should run in, and 122 | // the local party index. 123 | ShGcRuntime rt1; 124 | rt1.mDebugFlag = debug; 125 | rt1.init(chl1, prng.get(), ShGcRuntime::Evaluator, 1); 126 | 127 | // We can then instantiate the parties that will be running the protocol. 128 | std::array parties{ 129 | Party(rt1, 0), 130 | Party(rt1, 1) 131 | }; 132 | 133 | // Next, lets call the main "program" several times. 134 | for (u64 i = 0; i < tries; ++i) 135 | { 136 | // the prgram take the parties that are participating and the input 137 | // of the local party, in this case its 44. 138 | program(parties, 44); 139 | } 140 | }); 141 | 142 | 143 | // set up networking. See above for details 144 | Session ep0(ios, "127.0.0.1:1212", SessionMode::Client); 145 | Channel chl0 = ep0.addChannel(); 146 | 147 | // set up the runtime, see above for details 148 | ShGcRuntime rt0; 149 | rt0.mDebugFlag = debug; 150 | rt0.init(chl0, prng.get(), ShGcRuntime::Garbler, 0); 151 | 152 | // instantiate the parties 153 | std::array parties{ 154 | Party(rt0, 0), 155 | Party(rt0, 1) 156 | }; 157 | 158 | // run the program serveral time, with time with 23 as the input value 159 | for (u64 i = 0; i < tries; ++i) 160 | { 161 | program(parties, 23); 162 | } 163 | 164 | thrd.join(); 165 | return 0; 166 | } 167 | 168 | -------------------------------------------------------------------------------- /Ivory-Runtime/icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osu-crypto/secure-kmean-clustering/cd9fd7145fd0d0349beae9ff1370dcece2239767/Ivory-Runtime/icon.jpg -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | project(ivory) 3 | 4 | ############################################# 5 | # Build ivory # 6 | ############################################# 7 | 8 | file(GLOB_RECURSE SRCS *.cpp) 9 | add_library(ivory ${SRCS}) 10 | target_include_directories(ivory PUBLIC ${CMAKE_SOURCE_DIR}/ivory) 11 | 12 | 13 | 14 | ########################################################################### 15 | # Link external libraries # 16 | # ----------------------- # 17 | # # 18 | # Define the expected location for miracl and boost. # 19 | # Boost will be found using the findBoost module in CMake # 20 | # It should look in the location specified and then look elsewhere # 21 | # # 22 | ########################################################################### 23 | 24 | 25 | # Link libOTe 26 | ########################################################################### 27 | 28 | if(NOT IS_DIRECTORY ${libOTe_Dirs}) 29 | message(FATAL_ERROR "Bad libOTe location. libOTe_Dirs=${libOTe_Dirs}" ) 30 | endif() 31 | 32 | 33 | find_library( 34 | libOTe_LIB 35 | NAMES libOTe 36 | HINTS "${libOTe_Dirs}/lib/") 37 | 38 | 39 | find_library( 40 | cryptoTools_LIB 41 | NAMES cryptoTools 42 | HINTS "${libOTe_Dirs}/lib/") 43 | 44 | if(NOT EXISTS "${libOTe_LIB}") 45 | message(FATAL_ERROR "Failed to find libOTe at ${libOTe_LIB}" ) 46 | else() 47 | target_include_directories(ivory PUBLIC ${libOTe_Dirs}) 48 | target_include_directories(ivory PUBLIC ${libOTe_Dirs}/cryptoTools) 49 | endif() 50 | 51 | 52 | 53 | ## Miracl 54 | ########################################################################### 55 | 56 | set(Miracl_Dirs "${libOTe_Dirs}/cryptoTools/thirdparty/linux/miracl/") 57 | 58 | set(Miracl_Lib_Dirs "${Miracl_Dirs}/miracl/source/") 59 | find_library(MIRACL_LIB NAMES miracl HINTS "${Miracl_Lib_Dirs}") 60 | 61 | # if we cant fint it, throw an error 62 | if(NOT MIRACL_LIB) 63 | message(FATAL_ERROR "Failed to find miracl at " ${Miracl_Lib_Dirs}) 64 | endif() 65 | message(STATUS "MIRACL_LIB: ${MIRACL_LIB}") 66 | 67 | #include_directories("${Miracl_Dirs}") 68 | 69 | target_include_directories(ivory PUBLIC "${Miracl_Dirs}") 70 | #target_link_libraries(ivory ${MIRACL_LIB}) 71 | 72 | 73 | ## Boost 74 | ########################################################################### 75 | 76 | set(BOOST_ROOT "${libOTe_Dirs}/cryptoTools/thirdparty/linux/boost/") 77 | 78 | set(Boost_USE_STATIC_LIBS ON) # only find static libs 79 | set(Boost_USE_MULTITHREADED ON) 80 | set(Boost_USE_STATIC_RUNTIME ON) 81 | 82 | find_package(Boost COMPONENTS system thread) 83 | 84 | if(NOT Boost_FOUND) 85 | message(FATAL_ERROR "Failed to find boost at " ${Boost_Lib_Dirs} " Need system thread") 86 | endif() 87 | 88 | #include_directories(${Boost_INCLUDE_DIR}) 89 | 90 | target_include_directories(ivory PUBLIC ${Boost_INCLUDE_DIR}) 91 | #target_link_libraries(ivory ${Boost_LIBRARIES}) 92 | 93 | message(STATUS "Boost_LIBS ${Boost_LIBRARIES}" ) 94 | 95 | 96 | # Link NTL 97 | ########################################################################### 98 | set(NTL_Lib_Dirs "${NTL_Dirs}/src/") 99 | set(NTL_Include_Dirs "${NTL_Dirs}/include/") 100 | 101 | # default location for NTL 102 | set(NTL_LIB "${NTL_Lib_Dirs}libntl.a") 103 | 104 | 105 | if(NOT EXISTS "${NTL_LIB}") 106 | # we failed to find it, try using find_library 107 | find_library( 108 | NTL_LIB 109 | NAMES ntl 110 | HINTS NTL_Lib_Dirs) 111 | 112 | # if we still cant fint it, throw an error 113 | if(NOT NTL_LIB) 114 | Message(${NTL_LIB}) 115 | message(FATAL_ERROR "Failed to find NTL at ${NTL_Lib_Dirs} or at system locations." ) 116 | endif() 117 | else() 118 | target_include_directories(ivory PUBLIC ${NTL_Include_Dirs}) 119 | #message(" ---- NTL ----- ${NTL_Include_Dirs}") 120 | endif() 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | target_link_libraries(ivory ${libOTe_LIB} ${cryptoTools_LIB} ${NTL_LIB} ${Boost_LIBRARIES} ${MIRACL_LIB}) 129 | 130 | 131 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Circuit/BetaCircuit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ivory/Circuit/Gate.h" 5 | #include "cryptoTools/Common/Defines.h" 6 | #include "cryptoTools/Common/BitVector.h" 7 | #include 8 | 9 | 10 | namespace osuCrypto 11 | { 12 | 13 | typedef u32 BetaWire; 14 | 15 | enum class BetaWireFlag 16 | { 17 | Zero, 18 | One, 19 | Wire, 20 | InvWire 21 | }; 22 | 23 | struct BetaGate 24 | { 25 | BetaGate(const BetaWire& in0, const BetaWire& in1, const GateType& gt, const BetaWire& out) 26 | : mInput({in0, in1}) 27 | , mOutput(out) 28 | , mType(gt) 29 | , mAAlpha(gt == GateType::Nor || gt == GateType::na_And || gt == GateType::nb_Or || gt == GateType::Or) 30 | , mBAlpha(gt == GateType::Nor || gt == GateType::nb_And || gt == GateType::na_Or || gt == GateType::Or) 31 | , mCAlpha(gt == GateType::Nand || gt == GateType::nb_Or || gt == GateType::na_Or || gt == GateType::Or) 32 | {} 33 | 34 | void setType(osuCrypto::GateType gt) 35 | { 36 | mType = gt; 37 | // compute the gate modifier variables 38 | mAAlpha = (gt == GateType::Nor || gt == GateType::na_And || gt == GateType::nb_Or || gt == GateType::Or); 39 | mBAlpha = (gt == GateType::Nor || gt == GateType::nb_And || gt == GateType::na_Or || gt == GateType::Or); 40 | mCAlpha = (gt == GateType::Nand || gt == GateType::nb_Or || gt == GateType::na_Or || gt == GateType::Or); 41 | } 42 | 43 | std::array mInput; 44 | BetaWire mOutput; 45 | GateType mType; 46 | u8 mAAlpha, mBAlpha, mCAlpha; 47 | }; 48 | 49 | 50 | struct BetaLevel 51 | { 52 | std::vector mXorGates, mAndGates; 53 | }; 54 | 55 | static_assert(sizeof(GateType) == 1, ""); 56 | static_assert(sizeof(BetaGate) == 16, ""); 57 | 58 | struct BetaBundle 59 | { 60 | BetaBundle() {} 61 | BetaBundle(u64 s) :mWires(s) {} 62 | std::vector mWires; 63 | }; 64 | 65 | 66 | class BetaCircuit 67 | { 68 | public: 69 | BetaCircuit(); 70 | ~BetaCircuit(); 71 | 72 | 73 | 74 | u64 mNonXorGateCount; 75 | BetaWire mWireCount; 76 | std::vector mGates; 77 | std::vector> mPrints; 78 | std::vector mLevelGates; 79 | std::vector mWireFlags; 80 | 81 | void addTempWireBundle(BetaBundle& in); 82 | void addInputBundle(BetaBundle& in); 83 | void addOutputBundle(BetaBundle& in); 84 | void addConstBundle(BetaBundle& in, const BitVector& val); 85 | 86 | void addGate(BetaWire in0, BetaWire in2, GateType gt, BetaWire out); 87 | void addConst(BetaWire wire, u8 val); 88 | void addInvert(BetaWire wire); 89 | void addCopy(BetaWire src, BetaWire dest); 90 | void addCopy(BetaBundle& src, BetaBundle& dest); 91 | 92 | bool isConst(BetaWire wire); 93 | bool isInvert(BetaWire wire); 94 | u8 constVal(BetaWire wire); 95 | 96 | void addPrint(BetaBundle in); 97 | void addPrint(BetaWire wire); 98 | void addPrint(std::string); 99 | 100 | std::vector mInputs, mOutputs; 101 | 102 | void evaluate(span input, span output, bool print = true); 103 | 104 | void levelize(); 105 | }; 106 | 107 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Circuit/Circuit.cpp: -------------------------------------------------------------------------------- 1 | #include "Circuit.h" 2 | #include "Gate.h" 3 | #include "cryptoTools/Common/Log.h" 4 | #include 5 | #include 6 | #include 7 | //#include "Circuit/DagCircuit.h" 8 | 9 | namespace osuCrypto { 10 | 11 | 12 | 13 | Circuit::Circuit() 14 | :mHasMore(1) 15 | { 16 | mWireCount = mNonXorGateCount = mOutputCount = 0; 17 | } 18 | Circuit::Circuit(std::array inputs) 19 | : mHasMore(1),mInputs(inputs) 20 | { 21 | mWireCount = mInputs[0] + mInputs[1]; 22 | mNonXorGateCount = mOutputCount = 0; 23 | 24 | //mIndexArray.resize(InputWireCount()); 25 | //for (u64 i = 0; i < InputWireCount(); ++i) 26 | //{ 27 | // mIndexArray[i] = _mm_set_epi64x(0, i); 28 | //} 29 | } 30 | 31 | 32 | Circuit::~Circuit() 33 | { 34 | } 35 | 36 | 37 | void Circuit::init() 38 | { 39 | 40 | //mIndexArray.resize(std::max(WireCount(), NonXorGateCount() * 2)); 41 | //for (u64 i = 0; i < mIndexArray.size(); ++i) 42 | //{ 43 | // mIndexArray[i] = _mm_set1_epi64x(i); 44 | //} 45 | } 46 | 47 | 48 | 49 | u64 Circuit::AddGate(u64 input0, u64 input1, GateType gt) 50 | { 51 | if (input0 > mWireCount) 52 | throw std::runtime_error(""); 53 | if (input1 > mWireCount && (gt != GateType::na || input1 != (u64)-1)) 54 | throw std::runtime_error(""); 55 | 56 | if (gt == GateType::a || 57 | gt == GateType::b || 58 | gt == GateType::nb || 59 | gt == GateType::One || 60 | gt == GateType::Zero) 61 | throw std::runtime_error(""); 62 | 63 | if (gt != GateType::Xor && gt != GateType::Nxor) ++mNonXorGateCount; 64 | mGates.emplace_back(input0, input1, mWireCount, gt); 65 | return mWireCount++; 66 | } 67 | 68 | //void Circuit::readBris(std::istream & in, bool reduce) 69 | //{ 70 | // if (in.eof()) 71 | // throw std::runtime_error("Circuit::readBris input istream is emprty"); 72 | 73 | // DagCircuit dag; 74 | // dag.readBris(in); 75 | 76 | // if (reduce) 77 | // dag.removeInvertGates(); 78 | 79 | // dag.toCircuit(*this); 80 | 81 | // if (reduce) 82 | // { 83 | // if (mGates.size() != dag.mNonInvertGateCount) 84 | // throw std::runtime_error(""); 85 | // } 86 | // else 87 | // { 88 | // if (mGates.size() != dag.mGates.size()) 89 | // throw std::runtime_error(""); 90 | // } 91 | 92 | // init(); 93 | //} 94 | 95 | 96 | 97 | //void Circuit::evaluate(std::vector& labels) 98 | //{ 99 | // labels.resize(mWireCount); 100 | 101 | // //std::cout << "in " << labels << std::endl; 102 | 103 | // for (auto& gate : mGates) 104 | // { 105 | // u8 a = labels[gate.mInput[0]] ? 1 : 0; 106 | // u8 b = labels[gate.mInput[1]] ? 2 : 0; 107 | // labels[gate.mOutput] = gate.eval(a | b); 108 | // } 109 | //} 110 | 111 | //void Circuit::translate(std::vector& labels, std::vector& output) 112 | //{ 113 | // output.resize(mOutputCount); 114 | // for (u64 i = 0; i < mOutputs.size(); i++) 115 | // { 116 | // auto& wireIdx = mOutputs[i]; 117 | // output[i] = labels[wireIdx]; 118 | // } 119 | //} 120 | 121 | void Circuit::evaluate(BitVector& labels) 122 | { 123 | labels.resize(mWireCount); 124 | 125 | //std::cout << "in " << labels << std::endl; 126 | 127 | for (auto& gate : mGates) 128 | { 129 | u8 a = labels[gate.mInput[0]] ? 1 : 0; 130 | u8 b = labels[gate.mInput[1]] ? 2 : 0; 131 | labels[gate.mWireIdx] = gate.eval(a | b); 132 | } 133 | } 134 | 135 | void Circuit::translate(BitVector& labels, BitVector& output) 136 | { 137 | output.reset(mOutputCount); 138 | for (u64 i = 0; i < mOutputs.size(); i++) 139 | { 140 | auto& wireIdx = mOutputs[i]; 141 | output[i] = labels[wireIdx]; 142 | 143 | //if (output[i] != labels[wireIdx]) 144 | // throw std::runtime_error(""); 145 | } 146 | } 147 | 148 | 149 | void Circuit::xorShareInputs() 150 | { 151 | 152 | u64 wiresAdded = mInputs[0] + mInputs[1]; 153 | 154 | std::array oldInputs = mInputs; 155 | std::vector oldGates(std::move(mGates)); 156 | 157 | mInputs[0] += mInputs[1]; 158 | mInputs[1] = mInputs[0]; 159 | 160 | 161 | u64 inIter0 = 0; 162 | u64 inIter1 = mInputs[0]; 163 | u64 outIter = mInputs[0] + mInputs[1]; 164 | 165 | mGates.reserve(oldGates.size() + wiresAdded); 166 | 167 | for (u64 i = 0; i < oldInputs[0]; ++i) 168 | { 169 | mGates.emplace_back(inIter0++, inIter1++, outIter++, GateType::Xor); 170 | } 171 | 172 | for (u64 i = 0; i < oldInputs[1]; ++i) 173 | { 174 | mGates.emplace_back(inIter0++, inIter1++, outIter++, GateType::Xor); 175 | } 176 | 177 | u64 offset = 2 * wiresAdded; 178 | mWireCount = mWireCount + offset; 179 | 180 | for (auto& gate : oldGates) 181 | { 182 | mGates.emplace_back( 183 | gate.mInput[0] + offset, 184 | gate.mInput[1] + offset, 185 | gate.mWireIdx + offset, 186 | gate.Type()); 187 | } 188 | 189 | for (auto& output : mOutputs) 190 | output += offset; 191 | } 192 | 193 | bool Circuit::hasMoreGates() 194 | { 195 | return mHasMore++ & 1; 196 | } 197 | 198 | span Circuit::getMoreGates() 199 | { 200 | return span(mGates.begin(), mGates.end()); 201 | } 202 | span Circuit::getOutputIndices() 203 | { 204 | return span(mOutputs.begin(), mOutputs.end()); 205 | } 206 | std::vector Circuit::getInputIndices() 207 | { 208 | auto begin = std::vector(mInputs[0] + mInputs[1]); 209 | for (u64 i = 0; i < mInputs[0] + mInputs[1]; ++i) 210 | begin[i] = i; 211 | 212 | return begin; 213 | //return span(mInputs.begin(), mInputs.end()); 214 | } 215 | u64 Circuit::getInternalWireBuffSize() const 216 | { 217 | return mWireCount; 218 | } 219 | u64 Circuit::getInputWireBuffSize() const 220 | { 221 | return Inputs().size(); 222 | } 223 | u64 Circuit::getNonXorGateCount() const 224 | { 225 | return NonXorGateCount(); 226 | } 227 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Circuit/Circuit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Gate.h" 6 | #include "cryptoTools/Common/Defines.h" 7 | #include "cryptoTools/Common/BitVector.h" 8 | //#include "Circuit/CircuitStream.h" 9 | 10 | namespace osuCrypto { 11 | 12 | class DagCircuit; 13 | 14 | class Circuit// : public CircuitStream 15 | { 16 | public: 17 | friend class DagCircuit; 18 | 19 | Circuit(); 20 | Circuit(std::array inputs); 21 | ~Circuit(); 22 | 23 | //void readBris(std::istream& in, bool reduce = true); 24 | 25 | void evaluate(BitVector& input); 26 | void translate(BitVector& labels, BitVector& output); 27 | 28 | void init(); 29 | 30 | u64 AddGate(u64 input0, u64 input1, GateType gt); 31 | 32 | 33 | inline void AddOutputWire(u64 i) 34 | { 35 | if (i >= mWireCount) 36 | throw std::runtime_error(""); 37 | mOutputs.push_back(i); 38 | ++mOutputCount; 39 | } 40 | 41 | inline const u64 InputWireCount() const 42 | { 43 | return mInputs[0] + mInputs[1]; 44 | } 45 | inline const u64& WireCount()const 46 | { 47 | return mWireCount; 48 | } 49 | inline const u64& NonXorGateCount()const 50 | { 51 | return mNonXorGateCount; 52 | } 53 | inline const u64& OutputCount()const 54 | { 55 | return mOutputCount; 56 | } 57 | 58 | inline const std::array& Inputs() const 59 | { 60 | return mInputs; 61 | } 62 | inline const std::vector& Gates() const 63 | { 64 | return mGates; 65 | } 66 | inline const std::vector& Outputs() const 67 | { 68 | return mOutputs; 69 | } 70 | 71 | void xorShareInputs(); 72 | 73 | // CircuitStream interface 74 | u8 mHasMore; 75 | bool hasMoreGates() ; 76 | span getMoreGates() ; 77 | span getOutputIndices() ; 78 | std::vector getInputIndices() ; 79 | 80 | u64 getInternalWireBuffSize() const ; 81 | u64 getInputWireBuffSize() const ; 82 | u64 getNonXorGateCount() const ; 83 | 84 | 85 | private: 86 | 87 | u64 mWireCount, mNonXorGateCount, mOutputCount; 88 | std::array mInputs; 89 | std::vector mGates; 90 | std::vector mOutputs; 91 | }; 92 | 93 | } 94 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Circuit/CircuitLibrary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BetaCircuit.h" 3 | #include "cryptoTools/Common/Defines.h" 4 | #include 5 | #include "cryptoTools/Common/BitVector.h" 6 | 7 | namespace osuCrypto 8 | { 9 | class CircuitLibrary 10 | { 11 | public: 12 | CircuitLibrary(); 13 | ~CircuitLibrary(); 14 | 15 | 16 | std::unordered_map mCirMap; 17 | 18 | BetaCircuit* int_int_add(u64 aSize, u64 bSize, u64 cSize); 19 | BetaCircuit* uint_uint_add(u64 aSize, u64 bSize, u64 cSize); 20 | BetaCircuit* int_intConst_add(u64 aSize, u64 bSize, i64 bVal, u64 cSize); 21 | BetaCircuit* int_int_subtract(u64 aSize, u64 bSize, u64 cSize); 22 | BetaCircuit* uint_uint_subtract(u64 aSize, u64 bSize, u64 cSize); 23 | 24 | BetaCircuit* int_intConst_subtract(u64 aSize, u64 bSize, i64 bVal, u64 cSize); 25 | BetaCircuit* int_int_mult(u64 aSize, u64 bSize, u64 cSize); 26 | BetaCircuit* int_int_div(u64 aSize, u64 bSize, u64 cSize); 27 | 28 | BetaCircuit* int_int_lt(u64 aSize, u64 bSize); 29 | BetaCircuit* int_int_gteq(u64 aSize, u64 bSize); 30 | 31 | BetaCircuit* uint_uint_lt(u64 aSize, u64 bSize); 32 | BetaCircuit* uint_uint_gteq(u64 aSize, u64 bSize); 33 | 34 | BetaCircuit* int_int_multiplex(u64 aSize); 35 | 36 | BetaCircuit* int_removeSign(u64 aSize); 37 | BetaCircuit* int_addSign(u64 aSize); 38 | BetaCircuit* int_negate(u64 aSize); 39 | 40 | BetaCircuit* int_bitInvert(u64 aSize); 41 | BetaCircuit* int_int_bitwiseAnd(u64 aSize, u64 bSize, u64 cSize); 42 | BetaCircuit* int_int_bitwiseOr(u64 aSize, u64 bSize, u64 cSize); 43 | 44 | 45 | BetaCircuit* int_int_equal(u64 aSize, u64 bSize); 46 | 47 | void int_int_add_build( 48 | BetaCircuit& cd, 49 | BetaBundle & a1, 50 | BetaBundle & a2, 51 | BetaBundle & sum, 52 | BetaBundle & temps); 53 | 54 | void uint_uint_add_build( 55 | BetaCircuit& cd, 56 | BetaBundle & a1, 57 | BetaBundle & a2, 58 | BetaBundle & sum, 59 | BetaBundle & temps); 60 | 61 | void int_int_subtract_build( 62 | BetaCircuit& cd, 63 | BetaBundle & a1, 64 | BetaBundle & a2, 65 | BetaBundle & diff, 66 | BetaBundle & temps); 67 | 68 | 69 | void uint_uint_subtract_build( 70 | BetaCircuit& cd, 71 | BetaBundle & a1, 72 | BetaBundle & a2, 73 | BetaBundle & diff, 74 | BetaBundle & temps); 75 | 76 | void int_int_mult_build( 77 | BetaCircuit& cd, 78 | BetaBundle & a1, 79 | BetaBundle & a2, 80 | BetaBundle & prod); 81 | 82 | void int_int_div_rem_build( 83 | BetaCircuit& cd, 84 | BetaBundle& a1, 85 | BetaBundle& a2, 86 | BetaBundle& quot, 87 | BetaBundle& rem 88 | //,BetaBundle & divByZero, 89 | //bool checkDivByZero 90 | ); 91 | void uint_uint_div_rem_build( 92 | BetaCircuit& cd, 93 | BetaBundle& a1, 94 | BetaBundle& a2, 95 | BetaBundle& quot, 96 | BetaBundle& rem 97 | //,BetaBundle & divByZero, 98 | //bool checkDivByZero 99 | ); 100 | 101 | void int_int_lt_build( 102 | BetaCircuit& cd, 103 | BetaBundle & a1, 104 | BetaBundle & a2, 105 | BetaBundle & out); 106 | 107 | void int_int_gteq_build( 108 | BetaCircuit& cd, 109 | BetaBundle & a1, 110 | BetaBundle & a2, 111 | BetaBundle & out); 112 | 113 | void uint_uint_lt_build( 114 | BetaCircuit& cd, 115 | BetaBundle & a1, 116 | BetaBundle & a2, 117 | BetaBundle & out); 118 | 119 | void int_int_equal_build( 120 | BetaCircuit & cd, 121 | BetaBundle & a1, 122 | BetaBundle & a2, 123 | BetaBundle & out); 124 | 125 | void uint_uint_gteq_build( 126 | BetaCircuit& cd, 127 | BetaBundle & a1, 128 | BetaBundle & a2, 129 | BetaBundle & out); 130 | 131 | void int_removeSign_build( 132 | BetaCircuit& cd, 133 | BetaBundle & a1, 134 | BetaBundle & out, 135 | BetaBundle & temp); 136 | 137 | void int_addSign_build( 138 | BetaCircuit& cd, 139 | BetaBundle & a1, 140 | BetaBundle & sign, 141 | BetaBundle & out, 142 | BetaBundle & temp); 143 | 144 | void int_bitInvert_build( 145 | BetaCircuit& cd, 146 | BetaBundle & a1, 147 | BetaBundle & out); 148 | 149 | void int_negate_build( 150 | BetaCircuit& cd, 151 | BetaBundle & a1, 152 | BetaBundle & out, 153 | BetaBundle & temp); 154 | 155 | void int_int_bitwiseAnd_build( 156 | BetaCircuit& cd, 157 | BetaBundle & a1, 158 | BetaBundle & a2, 159 | BetaBundle & out); 160 | 161 | void int_int_bitwiseOr_build( 162 | BetaCircuit& cd, 163 | BetaBundle & a1, 164 | BetaBundle & a2, 165 | BetaBundle & out); 166 | 167 | void int_int_multiplex_build( 168 | BetaCircuit& cd, 169 | BetaBundle & a1, 170 | BetaBundle & a2, 171 | BetaBundle & choice, 172 | BetaBundle & out, 173 | BetaBundle & temp); 174 | 175 | bool areDistint(BetaBundle& a1, BetaBundle& a2); 176 | //u64 aSize, u64 bSize, u64 cSize); 177 | 178 | }; 179 | 180 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Circuit/Gate.h: -------------------------------------------------------------------------------- 1 | #ifndef Gate_H // header guard 2 | #define Gate_H 3 | 4 | #pragma once 5 | #include 6 | #include "cryptoTools/Common/Defines.h" 7 | #include 8 | 9 | namespace osuCrypto { 10 | 11 | typedef u64 Wire; 12 | 13 | inline u8 PermuteBit(const block& b) 14 | { 15 | return *(u8*)&(b)& 1; 16 | } 17 | 18 | enum class GateType : u8 19 | { 20 | Zero = 0, //0000, 21 | Nor = 1, //0001 22 | nb_And = 2, //0010 23 | nb = 3, //0011 24 | na_And = 4, //0100 25 | na = 5, //0101 26 | Xor = 6, //0110 27 | Nand = 7, //0111 28 | And = 8, //1000 29 | Nxor = 9, //1001 30 | a = 10, //1010 31 | nb_Or = 11, //1011 32 | b = 12, //1100 33 | na_Or = 13,//1101 34 | Or = 14,//1110 35 | One = 15 //1111 36 | }; 37 | 38 | 39 | inline std::string gateToString(GateType type) 40 | { 41 | if(type == GateType::Zero )return "Zero "; 42 | if(type == GateType::Nor )return "Nor "; 43 | if(type == GateType::nb_And)return "nb_And"; 44 | if(type == GateType::nb )return "nb "; 45 | if(type == GateType::na_And)return "na_And"; 46 | if(type == GateType::na )return "na "; 47 | if(type == GateType::Xor )return "Xor "; 48 | if(type == GateType::Nand )return "Nand "; 49 | if(type == GateType::And )return "And "; 50 | if(type == GateType::Nxor )return "Nxor "; 51 | if(type == GateType::a )return "a "; 52 | if(type == GateType::nb_Or )return "nb_Or "; 53 | if(type == GateType::b )return "b "; 54 | if(type == GateType::na_Or )return "na_Or "; 55 | if(type == GateType::Or )return "Or "; 56 | if(type == GateType::One )return "One "; 57 | return ""; 58 | } 59 | 60 | inline u8 GateEval(GateType type, bool a, bool b) 61 | { 62 | u8 v = ((u8(a) & 1) | (u8(b) <<1)); 63 | return ((u8)type & (1 << v)) ? 1 : 0; 64 | } 65 | 66 | struct Gate 67 | { 68 | u8 eval(u64 i) const 69 | { 70 | return ((u8)mType & (1 << i))? 1 : 0; 71 | } 72 | 73 | Gate(u64 input0, u64 input1, u64 output, GateType gt) 74 | { 75 | mInput = { { input0, input1 } }; 76 | mType = gt; 77 | //mLgicTable = 78 | //{ { 79 | // static_cast(static_cast(gt) & static_cast(1)), 80 | // static_cast(static_cast(gt) & static_cast(2)), 81 | // static_cast(static_cast(gt) & static_cast(4)), 82 | // static_cast(static_cast(gt) & static_cast(8)) 83 | //} }; 84 | mWireIdx = output; 85 | 86 | 87 | // compute the gate modifier variables 88 | mAAlpha = (gt == GateType::Nor || gt == GateType::na_And || gt == GateType::nb_Or || gt == GateType::Or); 89 | mBAlpha = (gt == GateType::Nor || gt == GateType::nb_And || gt == GateType::na_Or || gt == GateType::Or); 90 | mCAlpha = (gt == GateType::Nand || gt == GateType::nb_Or || gt == GateType::na_Or || gt == GateType::Or); 91 | } 92 | 93 | //// returns the gate type i.e. and, or, ... 94 | //inline GateType Type() const 95 | //{ 96 | // return mType;// (GateType)( 97 | // //(mLgicTable[0] ? 1 : 0) | 98 | // //(mLgicTable[1] ? 2 : 0) | 99 | // //(mLgicTable[2] ? 4 : 0) | 100 | // //(mLgicTable[3] ? 8 : 0)); 101 | //} 102 | 103 | // truth table padded to be 64 bits 104 | //std::array mLgicTable; 105 | std::array mInput; 106 | u64 mWireIdx; 107 | inline const GateType& Type() const { return mType; } 108 | inline const u8& AAlpha() const { return mAAlpha; } 109 | inline const u8& BAlpha() const { return mBAlpha; } 110 | inline const u8& CAlpha() const { return mCAlpha; } 111 | private: 112 | GateType mType; 113 | u8 mAAlpha, mBAlpha, mCAlpha; 114 | }; 115 | 116 | 117 | template 118 | struct GarbledGate// : public Gate 119 | { 120 | public: 121 | std::array mGarbledTable; 122 | //GarbledGate(const Gate& gate) 123 | // : Gate(gate) 124 | //{} 125 | }; 126 | } 127 | #endif -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osu-crypto/secure-kmean-clustering/cd9fd7145fd0d0349beae9ff1370dcece2239767/Ivory-Runtime/ivory/Runtime.zip -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/Party.cpp: -------------------------------------------------------------------------------- 1 | #include "Party.h" 2 | 3 | 4 | namespace osuCrypto 5 | { 6 | 7 | 8 | Party::Party(Runtime & runtime, u64 partyIdx) 9 | : mRuntime(runtime) 10 | , mPartyIdx(partyIdx) 11 | { } 12 | 13 | template<> 14 | sInt Party::input(const sInt::ValueType& value, BitCount bitCount) 15 | { 16 | return mRuntime.sIntInput(value, bitCount); 17 | } 18 | 19 | template<> 20 | sInt Party::input(BitCount bitCount) 21 | { 22 | return mRuntime.sIntInput(bitCount, mPartyIdx); 23 | } 24 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/Party.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ivory/Runtime/Runtime.h" 3 | #include "cryptoTools/Common/Defines.h" 4 | #include 5 | #include "ivory/Runtime/sInt.h" 6 | namespace osuCrypto 7 | { 8 | 9 | class Party 10 | { 11 | public: 12 | Party(Runtime& runtime, u64 partyIdx); 13 | 14 | template 15 | T input(const typename T::ValueType&, BitCount bitCount); 16 | 17 | template 18 | T input(BitCount bitCount); 19 | 20 | //template 21 | //sInt sIntInput(sInt::ValueType& v, BitCount bitCount = sizeof(sInt::ValueType) * 8) 22 | //{ 23 | // mRuntime.sIntInput(v, bitCount); 24 | //} 25 | 26 | //sInt sIntInput(BitCount bitCount); 27 | 28 | template 29 | void reveal(const T&); 30 | 31 | u64 getPartyIdx() { return mPartyIdx; } 32 | 33 | bool isLocalParty() { return mPartyIdx == mRuntime.getPartyIdx(); } 34 | 35 | Runtime& getRuntime() 36 | { 37 | return mRuntime; 38 | } 39 | 40 | private: 41 | Runtime& mRuntime; 42 | u64 mPartyIdx; 43 | }; 44 | 45 | 46 | template<> 47 | sInt Party::input(const sInt::ValueType& value, BitCount bitCount); 48 | template<> 49 | sInt Party::input(BitCount bitCount); 50 | 51 | //template 52 | //T Party::input(typename const T::ValueType& value, BitCount bitCount) 53 | //{ 54 | // //return mRuntime.sInt(value, bitCount, mPartyIdx); 55 | // return T; 56 | //} 57 | 58 | 59 | //template 60 | //T Party::input(u64 bitCount) 61 | //{ 62 | // T ret(mRuntime, bitCount); 63 | // mRuntime.scheduleInput(ret.mData.get(), mPartyIdx); 64 | // return ret; 65 | //} 66 | 67 | template 68 | inline void Party::reveal(const T& var) 69 | { 70 | // cast the const away... 71 | auto& v = *(T*)&var; 72 | std::array p{ mPartyIdx }; 73 | v.reveal(p); 74 | 75 | //if (isLocalParty()) 76 | //{ 77 | // v.mValFut.reset(new std::future()); 78 | // mRuntime.scheduleOutput(v.mData.get(), *v.mValFut.get()); 79 | //} 80 | //else 81 | //{ 82 | // mRuntime.scheduleOutput(v.mData.get(), mPartyIdx); 83 | //} 84 | } 85 | 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/Public/PublicInt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ivory/Runtime/sInt.h" 3 | 4 | 5 | namespace osuCrypto 6 | { 7 | 8 | class PublicInt 9 | : public sIntBase 10 | { 11 | public: 12 | sInt::ValueType mValue = 0; 13 | u64 mBitCount = 0; 14 | 15 | PublicInt() {} 16 | PublicInt(sInt::ValueType v, u64 bits) : mValue(v), mBitCount(bits) {} 17 | ~PublicInt() override {} 18 | 19 | void copy(sIntBasePtr& c)override; 20 | sIntBasePtr copy()override; 21 | u64 bitCount()override; 22 | Runtime& getRuntime()override; 23 | //i64 signExtend(i64 v, u64 bitIdx); 24 | 25 | sIntBasePtr add(sIntBasePtr& a, sIntBasePtr& b)override; 26 | sIntBasePtr subtract(sIntBasePtr& a, sIntBasePtr& b)override; 27 | sIntBasePtr multiply(sIntBasePtr& a, sIntBasePtr& b)override; 28 | sIntBasePtr divide(sIntBasePtr& a, sIntBasePtr& b)override; 29 | 30 | sIntBasePtr negate()override; 31 | sIntBasePtr abs()override; 32 | 33 | sIntBasePtr gteq(sIntBasePtr& a, sIntBasePtr& b)override; 34 | sIntBasePtr gt(sIntBasePtr& a, sIntBasePtr& b)override; 35 | 36 | sIntBasePtr bitwiseInvert()override; 37 | sIntBasePtr bitwiseAnd(sIntBasePtr& a, sIntBasePtr& b)override; 38 | sIntBasePtr bitwiseOr(sIntBasePtr& a, sIntBasePtr& b)override; 39 | 40 | sIntBasePtr ifelse(sIntBasePtr& a, sIntBasePtr& ifTrue, sIntBasePtr& ifFalse)override; 41 | sIntBasePtr ifequal(sIntBasePtr& ifTrue, sIntBasePtr& ifFalse)override; 42 | 43 | void reveal(u64 partyIdx)override { throw std::runtime_error(" cant reveal public value" LOCATION); } 44 | void reveal(span partyIdxs)override { throw std::runtime_error(" cant reveal public value" LOCATION); } 45 | ValueType getValue()override { return mValue; } 46 | }; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/Runtime.cpp: -------------------------------------------------------------------------------- 1 | #include "Runtime.h" 2 | #include "ivory/Runtime/Public/PublicInt.h" 3 | //#include "Clear/" 4 | 5 | namespace osuCrypto 6 | { 7 | Runtime::Runtime() 8 | { 9 | } 10 | 11 | 12 | Runtime::~Runtime() 13 | { 14 | } 15 | sIntBasePtr Runtime::getPublicInt(i64 v, u64 size) 16 | { 17 | return sIntBasePtr(new PublicInt(v, size)); 18 | } 19 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/Runtime.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cryptoTools/Common/Defines.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace osuCrypto 9 | { 10 | 11 | 12 | class Runtime 13 | { 14 | public: 15 | Runtime(); 16 | ~Runtime(); 17 | 18 | 19 | // initVar(...) should be used to initialize a new RuntimeData object 20 | // which has bitCount number of bits. 21 | // Result: data = derived type of RuntimeData for this runtime. This call may be 22 | // asynchronous but will be performed before the next call to processesQueue() returns. 23 | //virtual RtData initVar(u64 bitCount) = 0; 24 | 25 | static sIntBasePtr getPublicInt(i64 v, u64 size); 26 | 27 | 28 | // copyVar(...) should be used to initialize a new RuntimeData object 29 | // which is a copy of another RuntimeData. E.g. for GC based runtimes, 30 | // copy the wire labels. 31 | // Assumption: copy != nullptr 32 | // Result: data = derived type of RuntimeData for this runtime and has 33 | // the same value as copy. This call may be asynchronous but will be performed 34 | // before the next call to processesQueue() returns. 35 | //virtual void copy(sIntBase& data, const sIntBase& copy) = 0; 36 | 37 | // This scheduleInput(...) should be used to assign a variable a value. 38 | // This will be called in the case that the variable is known to the local party 39 | // Assumption: copy != nullptr, value.size() == data.size() 40 | // Result: value will be internally record and eventually the ecrypted version 41 | // of value will be placed inside the data variable. This encryption operation 42 | // may be asynchronous but it will be performed before the next call to processesQueue() returns. 43 | 44 | virtual sInt sIntInput(BitCount bitCount, u64 partyIdx) = 0; 45 | virtual sInt sIntInput(sInt::ValueType data, BitCount bitCount) = 0; 46 | 47 | // This scheduleInput(...) should be used to assign a variable a value 48 | // known to party[pIdx]. The encrypted version/meta data of the value will be 49 | // stored in data. 50 | // Assumptions: data != nullptr, pIdx = remote party index. 51 | // result: At some point, data will hold the encrypted version/meta data of this 52 | // varaible. This operation may be asychronously, but will be completed before the next 53 | // call to processesQueue() returns. 54 | //virtual void scheduleInput(sIntBase* data, u64 pIdx) = 0; 55 | 56 | // scheduleOp(...) should be called to schedule a new operation that should be performed on the 57 | // data provided by the io parameter. e.g. c = a + b where op = add, io = {a,b,c}. 58 | // Assumptions: io contains the correct number of variables to perform the operation. 59 | // Each value in io has been innitialized. 60 | // Result: The output variable(s) of io will be assigned the [encrypted] value of the operation. 61 | // The input variables of io should remain unchanged. This operation may be performed 62 | // asynchronously in that it may be performed at some later time but before the next 63 | // call to processesQueue() returns. 64 | //virtual void scheduleOp(Op op, span io) = 0; 65 | 66 | // This scheduleOutput(...) marks the current state of data as being ready to 67 | // be revealed to party[pIdx]. 68 | // Assumptions: data != nullptr, pIdx = remote party index 69 | // Result: The current state of data will be revealed to pIdx. This operation may be 70 | // asynchronous but will be completed before the next call to processesQueue() returns. 71 | //virtual void scheduleOutput(sIntBase* data, u64 pIdx) = 0; 72 | 73 | // This scheduleOutput(...) marks the current state of data as being ready to 74 | // be revealed to the local party. 75 | // Assumptions: data != nullptr 76 | // Result: The current state of data will be revealed to pIdx. This operation may be 77 | // asynchronous but will be completed before the next call to processesQueue() returns. 78 | //virtual void scheduleOutput(sIntBase* data, std::future& future) = 0; 79 | 80 | // processesQueue() will ensure that all scheduled operations have been completed 81 | // before returning. This should be called before any the future from 82 | // scheduleOutput(...) is received. 83 | // Assumptions: None 84 | // Result: Upon return, all operations are either in process or completed. 85 | virtual void processesQueue() = 0; 86 | 87 | 88 | // getPartyIdx() returns the index of the local party. 89 | virtual u64 getPartyIdx() = 0; 90 | }; 91 | 92 | } 93 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/ShGc/ShGcInt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ivory/Runtime/sInt.h" 3 | #include "ivory/Runtime/ShGc/utils.h" 4 | 5 | namespace osuCrypto 6 | { 7 | class ShGcRuntime; 8 | 9 | class ShGcInt : 10 | public sIntBase 11 | { 12 | public: 13 | 14 | ShGc::GarbledMem mLabels; 15 | std::shared_future mFutr; 16 | ShGcRuntime& mRt; 17 | 18 | ShGcInt(ShGcRuntime& rt, u64 bitCount); 19 | ShGcInt(ShGcInt&& m) = default; 20 | ShGcInt(const ShGcInt& s) = default; 21 | 22 | ~ShGcInt() override; 23 | 24 | void copy(sIntBasePtr& c)override; 25 | sIntBasePtr copy()override; 26 | u64 bitCount()override; 27 | Runtime& getRuntime()override; 28 | 29 | sIntBasePtr add(sIntBasePtr& a, sIntBasePtr& b)override; 30 | sIntBasePtr subtract(sIntBasePtr& a, sIntBasePtr& b)override; 31 | sIntBasePtr multiply(sIntBasePtr& a, sIntBasePtr& b)override; 32 | sIntBasePtr divide(sIntBasePtr& a, sIntBasePtr& b)override; 33 | 34 | sIntBasePtr negate()override; 35 | sIntBasePtr abs()override; 36 | 37 | sIntBasePtr gteq(sIntBasePtr& a, sIntBasePtr& b)override; 38 | sIntBasePtr gt(sIntBasePtr& a, sIntBasePtr& b)override; 39 | 40 | sIntBasePtr bitwiseInvert()override; 41 | sIntBasePtr bitwiseAnd(sIntBasePtr& a, sIntBasePtr& b)override; 42 | sIntBasePtr bitwiseOr(sIntBasePtr& a, sIntBasePtr& b)override; 43 | 44 | sIntBasePtr ifelse(sIntBasePtr& a, sIntBasePtr& ifTrue, sIntBasePtr& ifFalse)override; 45 | sIntBasePtr ifequal(sIntBasePtr& ifTrue, sIntBasePtr& ifFalse)override; 46 | 47 | void reveal(u64 partyIdx)override; 48 | void reveal(span partyIdxs)override; 49 | ValueType getValue()override; 50 | 51 | 52 | ShGc::GarbledMem getMemory(sIntBasePtr& a); 53 | 54 | }; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/ShGc/ShGcRuntime.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ivory/Runtime/Runtime.h" 3 | #include "ivory/Circuit/Circuit.h" 4 | #include "ivory/Circuit/BetaCircuit.h" 5 | #include "ivory/Circuit/CircuitLibrary.h" 6 | 7 | 8 | 9 | 10 | #include "libOTe/TwoChooseOne/IknpOtExtSender.h" 11 | #include "libOTe/TwoChooseOne/IknpOtExtReceiver.h" 12 | 13 | #include 14 | #include 15 | 16 | 17 | namespace osuCrypto 18 | { 19 | //typedef std::vector ShGcLabelVec; 20 | 21 | //struct ShGcRuntimeData :public RuntimeData 22 | //{ 23 | // ShGcRuntimeData(u64 bitCount) 24 | // : mLabels(std::make_shared(bitCount)) 25 | // { } 26 | 27 | // std::shared_ptr mLabels; 28 | //}; 29 | 30 | class ShGcRuntime : public Runtime 31 | { 32 | public: 33 | enum Role 34 | { 35 | Garbler, 36 | Evaluator 37 | }; 38 | static const std::array mPublicLabels; 39 | 40 | ShGcRuntime(); 41 | ~ShGcRuntime(); 42 | 43 | void init(Channel& chl, block seed, Role role, u64 partyIdx); 44 | 45 | ShGc::GarbledMem getNewMem(u64 size); 46 | void freeMem(const ShGc::GarbledMem& mem); 47 | 48 | sInt sIntInput(BitCount bc, u64 partyIdx) override; 49 | sInt sIntInput(sInt::ValueType v, BitCount bc) override; 50 | 51 | 52 | 53 | 54 | u64 getPartyIdx() override { return mPartyIdx; } 55 | 56 | CircuitLibrary mLibrary; 57 | 58 | 59 | 60 | Role mRole; 61 | u64 mPartyIdx; 62 | bool mDebugFlag = false; 63 | 64 | u64 mBytesSent; 65 | std::array mZeroAndGlobalOffset; 66 | block mGlobalOffset; 67 | AES mAes; 68 | PRNG mPrng; 69 | u64 mInputIdx; 70 | Channel* mChannel; 71 | 72 | IknpOtExtReceiver mOtExtRecver; 73 | IknpOtExtSender mOtExtSender; 74 | 75 | std::vector sharedMem; 76 | //std::vector> sharedGates; 77 | std::vector shareAuxBits; 78 | std::vector sharedBuff; 79 | std::arraymTweaks; 80 | 81 | ShGc::GarbledMem getPublicGarbledMem(u8* data, u64 bitCount); 82 | 83 | void enqueue(ShGc::InputItem&& item); 84 | void enqueue(ShGc::CircuitItem&& item); 85 | void enqueue(ShGc::OutputItem&& item); 86 | void processesQueue() override; 87 | 88 | void garblerOutput(); 89 | void garblerCircuit(); 90 | void garblerInput(); 91 | 92 | void evaluatorInput(); 93 | void evaluatorCircuit(); 94 | void evaluatorOutput(); 95 | 96 | BitVector mOtChoices; 97 | u64 mMaxQueueSize; 98 | u64 mOtCount; 99 | std::queue mCrtQueue; 100 | std::queue mInputQueue; 101 | std::queue mOutputQueue; 102 | 103 | static bool isConstLabel(const block& b); 104 | 105 | //std::queue mWorkQueue; 106 | //boost::lockfree::spsc_queue mWorkQueue; 107 | 108 | static block evaluateConstGate(bool constA, bool constB, const std::array& in, const GateType& gt); 109 | static block garbleConstGate(bool constA, bool constB, const std::array& in, const GateType& gt, const block& xorOffset); 110 | 111 | std::function mRecvBit; 112 | static void evaluate( 113 | const BetaCircuit& cir, 114 | const span& memory, 115 | std::array& tweaks, 116 | const span>& garbledGates, 117 | const std::function& getAuxilaryBit, 118 | block* DEBUG_labels = nullptr); 119 | 120 | 121 | static void garble( 122 | const BetaCircuit& cir, 123 | const span& memory, 124 | std::array& tweaks, 125 | const span>& garbledGateIter, 126 | const std::array& zeroAndGlobalOffset, 127 | std::vector& auxilaryBits, 128 | block* DEBUG_labels = nullptr 129 | ); 130 | 131 | }; 132 | 133 | 134 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/ShGc/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/ShGc/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace osuCrypto 10 | { 11 | namespace ShGc 12 | { 13 | typedef std::shared_ptr> GarbledMem; 14 | 15 | struct CircuitItem 16 | { 17 | CircuitItem() :mCircuit(nullptr), mDebugFlag(false) {} 18 | CircuitItem(CircuitItem&&) = default; 19 | 20 | BetaCircuit* mCircuit; 21 | std::vector mLabels; 22 | 23 | bool mDebugFlag; 24 | u64 mInputBundleCount; 25 | }; 26 | 27 | struct InputItem 28 | { 29 | InputItem() = default; 30 | InputItem(InputItem&&) = default; 31 | 32 | BitVector mInputVal; 33 | GarbledMem mLabels; 34 | }; 35 | 36 | struct OutputItem 37 | { 38 | OutputItem() = default; 39 | OutputItem(OutputItem&&) = default; 40 | 41 | GarbledMem mLabels; 42 | std::vector mOutPartyIdxs; 43 | std::unique_ptr> mOutputProm; 44 | }; 45 | 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/sInt.cpp: -------------------------------------------------------------------------------- 1 | #include "sInt.h" 2 | #include 3 | namespace osuCrypto 4 | { 5 | 6 | sInt::sInt(const i64 & val) 7 | : mData(Runtime::getPublicInt(val, 64)) 8 | { } 9 | 10 | sInt::sInt(const i32 & val) 11 | : mData(Runtime::getPublicInt(val, 32)) 12 | { } 13 | 14 | sInt::sInt(const i16 & val) 15 | : mData(Runtime::getPublicInt(val, 16)) 16 | { } 17 | 18 | sInt::sInt(const i8 & val) 19 | : mData(Runtime::getPublicInt(val, 8)) 20 | { } 21 | 22 | sInt::~sInt() 23 | { } 24 | 25 | sInt& sInt::operator=(const sInt & c) 26 | { 27 | sIntBasePtr& s = (sIntBasePtr&)c.mData; 28 | mData->copy(s); 29 | return *this; 30 | } 31 | 32 | sInt & sInt::operator=(sInt && mv) 33 | { 34 | mData = std::move(mv.mData); 35 | return *this; 36 | } 37 | 38 | /*void sInt::bitwiseInvert11() 39 | { 40 | return mData->bitwiseInvert(); 41 | }*/ 42 | 43 | sInt sInt::operator~() 44 | { 45 | return mData->bitwiseInvert(); 46 | } 47 | 48 | sInt sInt::operator+(const sInt& in2) const 49 | { 50 | return mData->add((sIntBasePtr&)mData, (sIntBasePtr&)in2.mData); 51 | } 52 | 53 | sInt sInt::operator-(const sInt & in2) const 54 | { 55 | return mData->subtract((sIntBasePtr&)mData, (sIntBasePtr&)in2.mData); 56 | } 57 | 58 | sInt sInt::operator>=(const sInt & in2) 59 | { 60 | return mData->gteq((sIntBasePtr&)mData, (sIntBasePtr&)in2.mData); 61 | } 62 | 63 | sInt sInt::operator>(const sInt &in2) 64 | { 65 | return mData->gt((sIntBasePtr&)mData, (sIntBasePtr&)in2.mData); 66 | } 67 | 68 | sInt sInt::operator<=(const sInt &in2) 69 | { 70 | return in2.mData->gteq((sIntBasePtr&)in2.mData, (sIntBasePtr&)mData); 71 | } 72 | 73 | sInt sInt::operator<(const sInt & in2) 74 | { 75 | return in2.mData->gt((sIntBasePtr&)in2.mData, mData); 76 | } 77 | 78 | sInt sInt::operator&(const sInt &in2) 79 | { 80 | return mData->bitwiseAnd((sIntBasePtr&)mData, (sIntBasePtr&)in2.mData); 81 | } 82 | 83 | sInt sInt::ifelse(const sInt & ifTrue, const sInt & ifFalse) 84 | { 85 | return mData->ifelse((sIntBasePtr&)mData, (sIntBasePtr&)ifTrue.mData, (sIntBasePtr&)ifFalse.mData); 86 | } 87 | 88 | 89 | sInt sInt::ifequal(const sInt & in2) 90 | { 91 | return mData->ifequal((sIntBasePtr&)in2.mData, (sIntBasePtr&)mData); 92 | } 93 | 94 | sInt sInt::abs() 95 | { 96 | return mData->abs(); 97 | } 98 | 99 | sInt& sInt::operator+=(const sInt& in2) 100 | { 101 | mData = mData->add((sIntBasePtr&)mData, (sIntBasePtr&)in2.mData); 102 | return *this; 103 | } 104 | 105 | sInt sInt::operator*(const sInt& in2) const 106 | { 107 | return mData->multiply((sIntBasePtr&)mData, (sIntBasePtr&)in2.mData); 108 | } 109 | 110 | sInt sInt::operator/(const sInt & in2) const 111 | { 112 | return mData->divide((sIntBasePtr&)mData, (sIntBasePtr&)in2.mData); 113 | } 114 | 115 | sInt::ValueType sInt::getValue() 116 | { 117 | return mData->getValue(); 118 | } 119 | 120 | void sInt::reveal(span partyIdxs) 121 | { 122 | mData->reveal(partyIdxs); 123 | } 124 | 125 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/Runtime/sInt.h: -------------------------------------------------------------------------------- 1 | #ifndef sInt_H // header guard 2 | #define sInt_H 3 | 4 | #pragma once 5 | //#include "Runtime/CrtModulal.h" 6 | 7 | #include "ivory/Circuit/Circuit.h" 8 | 9 | 10 | namespace osuCrypto 11 | { 12 | struct BitCount 13 | { 14 | u64 mBitCount; 15 | BitCount(const u64& b) : mBitCount(b) {} 16 | }; 17 | 18 | 19 | 20 | class Runtime; 21 | class sIntBase; 22 | typedef uPtr sIntBasePtr; 23 | class sIntBase 24 | { 25 | public: 26 | 27 | virtual ~sIntBase() {} 28 | 29 | typedef i64 ValueType; 30 | 31 | enum class Op 32 | { 33 | Add, 34 | Subtract, 35 | Multiply, 36 | Divide, 37 | LT, 38 | GTEq, 39 | Mod, 40 | And, 41 | Or, 42 | Not, 43 | BitwiseAnd, 44 | BitWiseOr, 45 | BitwiseNot, 46 | IfElse 47 | }; 48 | 49 | virtual void copy(sIntBasePtr& b) = 0; 50 | virtual sIntBasePtr copy() = 0; 51 | virtual u64 bitCount() = 0; 52 | virtual Runtime& getRuntime() = 0; 53 | 54 | virtual sIntBasePtr add(sIntBasePtr& a, sIntBasePtr& b) = 0; 55 | virtual sIntBasePtr subtract(sIntBasePtr& a, sIntBasePtr& b) = 0; 56 | virtual sIntBasePtr multiply(sIntBasePtr& a, sIntBasePtr& b) = 0; 57 | virtual sIntBasePtr divide(sIntBasePtr& a, sIntBasePtr& b) = 0; 58 | 59 | virtual sIntBasePtr negate() = 0; 60 | virtual sIntBasePtr abs() = 0; 61 | 62 | virtual sIntBasePtr gteq(sIntBasePtr& a, sIntBasePtr& b) = 0; 63 | virtual sIntBasePtr gt(sIntBasePtr& a, sIntBasePtr& b) = 0; 64 | 65 | virtual sIntBasePtr bitwiseInvert() = 0; 66 | virtual sIntBasePtr bitwiseAnd(sIntBasePtr& a, sIntBasePtr& b) = 0; 67 | virtual sIntBasePtr bitwiseOr(sIntBasePtr& a, sIntBasePtr& b) = 0; 68 | 69 | virtual sIntBasePtr ifelse(sIntBasePtr& selectBit, sIntBasePtr& ifTrue, sIntBasePtr& ifFalse) = 0; 70 | virtual sIntBasePtr ifequal( sIntBasePtr& ifTrue, sIntBasePtr& ifFalse) = 0; 71 | 72 | virtual void reveal(u64 partyIdx) = 0; 73 | virtual void reveal(span partyIdxs) = 0; 74 | virtual ValueType getValue() = 0; 75 | }; 76 | 77 | 78 | 79 | class sInt 80 | { 81 | public: 82 | typedef sIntBase::ValueType ValueType; 83 | 84 | //sInt(Runtime& rt, const BitCount& bitCount); 85 | 86 | sInt() = default; 87 | sInt(const sInt&) = default; 88 | sInt(sInt&&) = default; 89 | sInt(sIntBasePtr&& data) : mData(std::move(data)) {} 90 | 91 | sInt(const i64& val); 92 | sInt(const i32& val); 93 | sInt(const i16& val); 94 | sInt(const i8& val); 95 | 96 | ~sInt(); 97 | 98 | sInt& operator=(const sInt&); 99 | sInt& operator=(sInt&&); 100 | 101 | //void bitwiseInvert11(); 102 | 103 | sInt operator~(); 104 | 105 | sInt operator+(const sInt&) const; 106 | sInt operator-(const sInt&) const; 107 | sInt operator*(const sInt&) const; 108 | sInt operator/(const sInt&) const; 109 | 110 | 111 | //sInt operator+(const i64&); 112 | //sInt operator-(const i64&); 113 | //sInt operator*(const i64&); 114 | //sInt operator/(const i64&); 115 | //friend sInt operator+(const sInt&, const i64&); 116 | //friend sInt operator-(const sInt&, const i64&); 117 | //friend sInt operator*(const sInt&, const i64&); 118 | //friend sInt operator/(const sInt&, const i64&); 119 | 120 | sInt& operator+=(const sInt&); 121 | //sInt operator-=(const sInt&); 122 | //sInt operator*=(const sInt&); 123 | //sInt operator/=(const sInt&); 124 | 125 | sInt operator>=(const sInt&); 126 | sInt operator>(const sInt&); 127 | sInt operator<=(const sInt&); 128 | sInt operator<(const sInt&); 129 | 130 | 131 | sInt operator&(const sInt&); 132 | 133 | sInt ifelse(const sInt&, const sInt&); 134 | sInt ifequal(const sInt&); 135 | 136 | sInt abs(); 137 | 138 | 139 | ValueType getValue(); 140 | 141 | 142 | void reveal(span partyIdxs); 143 | 144 | //BitVector valueToBV(const ValueType& val); 145 | //ValueType valueFromBV(const BitVector& val); 146 | 147 | 148 | 149 | sIntBasePtr mData; 150 | //Runtime& mRuntime; 151 | //GUI mGUI; 152 | //u64 mBitCount; 153 | //std::unique_ptr mData; 154 | //std::unique_ptr> mValFut; 155 | //BitVector mVal; 156 | }; 157 | 158 | 159 | } 160 | #endif -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/ivory.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {8C3AF3C3-2ABF-43A7-8B72-C674E64BD0D6} 15 | ivory 16 | 10.0 17 | 18 | 19 | 20 | StaticLibrary 21 | true 22 | v142 23 | MultiByte 24 | 25 | 26 | StaticLibrary 27 | false 28 | v142 29 | true 30 | MultiByte 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Level3 50 | Disabled 51 | true 52 | $(ProjectDir)/../;$(libOTeDir);$(libOTeDir)/cryptoTools;$(ProjectDir)/../thirdparty/win/NTL/include;C:\libs\NTL\include;C:\libs;C:\libs\boost;C:\libs\miracl;%(AdditionalIncludeDirectories) 53 | _WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions) 54 | MultiThreadedDebug 55 | 56 | 57 | 58 | 59 | Level3 60 | MaxSpeed 61 | true 62 | true 63 | true 64 | $(ProjectDir)/../;$(libOTeDir);$(libOTeDir)/cryptoTools;$(ProjectDir)/../thirdparty/win/NTL/include;C:\libs\NTL\include;C:\libs;C:\libs\boost;C:\libs\miracl;%(AdditionalIncludeDirectories) 65 | _WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions) 66 | MultiThreaded 67 | 68 | 69 | true 70 | true 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivory/ivory.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/Circuit_Tests_VS.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CppUnitTest.h" 3 | #include "Common.h" 4 | 5 | #include "Circuit_Tests.h" 6 | 7 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 8 | 9 | namespace libBDXTests 10 | { 11 | TEST_CLASS(Circuit_Tests) 12 | { 13 | public: 14 | 15 | TEST_METHOD(Circuit_SequentialOp) 16 | { 17 | InitDebugPrinting(); 18 | Circuit_SequentialOp_Test(); 19 | } 20 | 21 | 22 | TEST_METHOD(Circuit_int_Adder) 23 | { 24 | InitDebugPrinting(); 25 | Circuit_int_Adder_Test(); 26 | } 27 | 28 | TEST_METHOD(Circuit_uint_Adder) 29 | { 30 | InitDebugPrinting(); 31 | Circuit_uint_Adder_Test(); 32 | } 33 | 34 | TEST_METHOD(Circuit_int_Adder_const) 35 | { 36 | InitDebugPrinting(); 37 | Circuit_int_Adder_const_Test(); 38 | } 39 | 40 | TEST_METHOD(Circuit_int_Subtractor) 41 | { 42 | InitDebugPrinting(); 43 | Circuit_int_Subtractor_Test(); 44 | } 45 | 46 | TEST_METHOD(Circuit_int_Subtractor_const) 47 | { 48 | InitDebugPrinting(); 49 | Circuit_int_Subtractor_const_Test(); 50 | } 51 | 52 | TEST_METHOD(Circuit_uint_Subtractor) 53 | { 54 | InitDebugPrinting(); 55 | Circuit_uint_Subtractor_Test(); 56 | } 57 | 58 | TEST_METHOD(Circuit_int_Multiply) 59 | { 60 | InitDebugPrinting(); 61 | Circuit_int_Multiply_Test(); 62 | } 63 | 64 | TEST_METHOD(Circuit_int_Divide) 65 | { 66 | InitDebugPrinting(); 67 | Circuit_int_Divide_Test(); 68 | } 69 | 70 | TEST_METHOD(Circuit_int_LessThan) 71 | { 72 | InitDebugPrinting(); 73 | Circuit_int_LessThan_Test(); 74 | } 75 | 76 | TEST_METHOD(Circuit_int_GreaterThanEq) 77 | { 78 | InitDebugPrinting(); 79 | Circuit_int_GreaterThanEq_Test(); 80 | } 81 | 82 | TEST_METHOD(Circuit_uint_LessThan) 83 | { 84 | InitDebugPrinting(); 85 | Circuit_uint_LessThan_Test(); 86 | } 87 | 88 | 89 | TEST_METHOD(Circuit_uint_GreaterThanEq) 90 | { 91 | InitDebugPrinting(); 92 | Circuit_uint_GreaterThanEq_Test(); 93 | } 94 | 95 | 96 | TEST_METHOD(Circuit_multiplex) 97 | { 98 | InitDebugPrinting(); 99 | Circuit_multiplex_Test(); 100 | } 101 | 102 | 103 | TEST_METHOD(Circuit_bitInvert) 104 | { 105 | InitDebugPrinting(); 106 | Circuit_bitInvert_Test(); 107 | } 108 | 109 | TEST_METHOD(Circuit_int_negate) 110 | { 111 | InitDebugPrinting(); 112 | Circuit_negate_Test(); 113 | } 114 | 115 | TEST_METHOD(Circuit_int_removeSign) 116 | { 117 | InitDebugPrinting(); 118 | Circuit_removeSign_Test(); 119 | } 120 | 121 | TEST_METHOD(Circuit_int_addSign) 122 | { 123 | InitDebugPrinting(); 124 | Circuit_addSign_Test(); 125 | } 126 | }; 127 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/ClassicGarbledCircuit_Tests_VS.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CppUnitTest.h" 3 | //#include "Circuit/GarbledCircuit.h" 4 | //#include "Circuit/ClassicGarbledCircuit.h" 5 | //#include "Circuit/Circuit.h" 6 | //#include "MyAssert.h" 7 | //#include 8 | //#include "Common.h" 9 | //#include "Common/Logger.h" 10 | 11 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 12 | 13 | namespace libBDXTests 14 | { 15 | //using namespace libBDX; 16 | TEST_CLASS(ClassicGarbledCircuit_Tests) 17 | { 18 | public: 19 | 20 | // TEST_METHOD(ClassicGC_BasicGates_Test) 21 | // { 22 | // block seed = _mm_set_epi32(4253465, 3434565, 234435, 23987045); 23 | 24 | // InitDebugPrinting("..\\test.out"); 25 | 26 | // for (u8 gate = 0; gate < 16; ++gate) 27 | // { 28 | // GateType gt((GateType)gate); 29 | 30 | //if (gt == GateType::a || 31 | // gt == GateType::b || 32 | // gt == GateType::na || 33 | // gt == GateType::nb || 34 | // gt == GateType::One || 35 | // gt == GateType::Zero) 36 | // continue; 37 | 38 | // Circuit cd = OneGateCircuit(gt); 39 | 40 | // ClassicGarbledCircuit gc(cd); 41 | // gc.Garble(cd, seed); 42 | 43 | // BitVector out; 44 | // std::vector labels; 45 | 46 | // for (u8 i = 0; i < 4; ++i) 47 | // { 48 | // labels.clear(); 49 | // block a = (i & 1) ? gc.mWires[0].Label1(gc.mGlobalOffset) : gc.mWires[0].Label0; 50 | // block b = (i & 2) ? gc.mWires[1].Label1(gc.mGlobalOffset) : gc.mWires[1].Label0; 51 | // 52 | // labels.push_back(a); 53 | // labels.push_back(b); 54 | 55 | // gc.evaluate(cd, labels); 56 | // gc.translate(cd, labels, out); 57 | 58 | // u8 expected = cd.Gates()[0].eval(i); 59 | // if(expected != out[0]) 60 | // throw UnitTestFail(); 61 | // } 62 | // } 63 | // } 64 | 65 | 66 | // void ToBitVector(BitVector & vec, u64 input, u64 bits) 67 | // { 68 | // vec.reset(bits); 69 | // for (u64 i = 0, mask = 1; i < bits; ++i, mask <<= 1) 70 | // { 71 | // vec[i] = ((input & mask) != 0); 72 | // } 73 | // } 74 | 75 | // TEST_METHOD(ClassicGC_BitAdder_Test) 76 | // { 77 | // InitDebugPrinting("..\\test.out"); 78 | // u32 bits{ 4 }; 79 | // block seed = _mm_set_epi32(4253465, 3434565, 234435, 23987045); 80 | 81 | 82 | // Circuit cd = AdderCircuit(bits); 83 | // ClassicGarbledCircuit gc(cd); 84 | // gc.Garble(cd, seed); 85 | 86 | // for (u64 input0 = 0; input0 < ((u64)1 << bits); ++input0) 87 | // { 88 | // for (u64 input1 = 0; input1 < ((u64)1 <labels; 99 | // for (u64 i = 0; i < inputVec.size(); ++i) 100 | // { 101 | // if (inputVec[i]) 102 | // { 103 | // labels.push_back(gc.mWires[i].Label1(gc.mGlobalOffset)); 104 | // } 105 | // else 106 | // labels.push_back(gc.mWires[i].Label0); 107 | // } 108 | 109 | // gc.evaluate(cd, labels); 110 | // BitVector outputVec; 111 | // gc.translate(cd, labels, outputVec); 112 | 113 | // BitVector expectedOut; 114 | // ToBitVector(expectedOut, input0 + input1, bits + 1); 115 | 116 | // cd.evaluate(inputVec); 117 | // BitVector outputVec2; 118 | // cd.translate(inputVec, outputVec2); 119 | 120 | // if(outputVec.size() != expectedOut.size()) 121 | // throw UnitTestFail(); 122 | 123 | // for (auto i = 0; i < outputVec.size(); ++i) 124 | // { 125 | // if (outputVec[i] != expectedOut[i]) 126 | // throw UnitTestFail(); 127 | // //Assert::AreEqual(true, true, L"Output bits dont match"); 128 | // } 129 | // } 130 | // } 131 | // } 132 | }; 133 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/Cope_TestsVS.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef _MSC_VER 3 | #include "CppUnitTest.h" 4 | 5 | #include "Cope_Tests.h" 6 | 7 | #include "Common.h" 8 | 9 | 10 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 11 | 12 | 13 | TEST_CLASS(cope_Tests) 14 | { 15 | public: 16 | 17 | TEST_METHOD(Cope_TestVS) 18 | { 19 | InitDebugPrinting(); 20 | cope_test(); 21 | } 22 | 23 | }; 24 | #endif 25 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/HalfGtGarbledCircuit_Tests_VS.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CppUnitTest.h" 3 | #include "HalfGtGarbledCircuit_Tests.h" 4 | #include "Common.h" 5 | 6 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 7 | 8 | namespace libBDXTests 9 | { 10 | TEST_CLASS(HalfGtGarbledCircuit_Tests) 11 | { 12 | public: 13 | 14 | 15 | TEST_METHOD(HalfGtGC_BasicGates_Test) 16 | { 17 | InitDebugPrinting("../test.out"); 18 | HalfGtGC_BasicGates_Test_Impl(); 19 | } 20 | 21 | TEST_METHOD(HalfGtGC_BitAdder_Test) 22 | { 23 | HalfGtGC_BitAdder_Test_Impl(); 24 | } 25 | 26 | TEST_METHOD(HalfGtGC_BitAdder_Validate_Test) 27 | { 28 | HalfGtGC_BitAdder_Validate_Test_Impl(); 29 | } 30 | 31 | TEST_METHOD(HalfGtGC_Stream_BitAdder_Test) 32 | { 33 | InitDebugPrinting("../test.out"); 34 | HalfGtGC_Stream_BitAdder_Test_Impl(); 35 | } 36 | }; 37 | } -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/ShGcRuntime_TestsVs.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef _MSC_VER 3 | #include "CppUnitTest.h" 4 | 5 | #include "Common.h" 6 | #include "ShGcRuntime_tests.h" 7 | 8 | 9 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 10 | 11 | 12 | TEST_CLASS(ShGcRuntime_Tests) 13 | { 14 | public: 15 | 16 | 17 | TEST_METHOD(ShGcRuntime_publicGateGarble) 18 | { 19 | InitDebugPrinting(); 20 | ShGcRuntime_publicGateGarble_Test(); 21 | } 22 | 23 | 24 | TEST_METHOD(ShGcRuntime_BasicArithetic) 25 | { 26 | InitDebugPrinting(); 27 | ShGcRuntime_basicArith_Test(); 28 | } 29 | 30 | 31 | TEST_METHOD(ShGcRuntime_SequentialOp) 32 | { 33 | InitDebugPrinting(); 34 | ShGcRuntime_SequentialOp_Test(); 35 | } 36 | 37 | 38 | TEST_METHOD(ShGcRuntime_CircuitInvert) 39 | { 40 | InitDebugPrinting(); 41 | ShGcRuntime_CircuitInvert_Test(); 42 | } 43 | 44 | TEST_METHOD(ShGcRuntime_CircuitAdd) 45 | { 46 | InitDebugPrinting(); 47 | ShGcRuntime_CircuitAdd_Test(); 48 | } 49 | 50 | TEST_METHOD(ShGcRuntime_CircuitMult) 51 | { 52 | InitDebugPrinting(); 53 | ShGcRuntime_CircuitMult_Test(); 54 | } 55 | 56 | TEST_METHOD(ShGcRuntime_CircuitEval) 57 | { 58 | InitDebugPrinting(); 59 | shGcRuntime_CircuitEval_Test(); 60 | } 61 | 62 | 63 | }; 64 | #endif 65 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/ZpNumber_TestVS.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef _MSC_VER 3 | #include "CppUnitTest.h" 4 | 5 | #include "ZpNumber_Tests.h" 6 | 7 | #include "Common.h" 8 | 9 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 10 | 11 | 12 | TEST_CLASS(LocalChannel_Tests) 13 | { 14 | public: 15 | 16 | TEST_METHOD(ZpNumber_Basic) 17 | { 18 | InitDebugPrinting(); 19 | ZpNumber_Basic_Test(); 20 | } 21 | 22 | TEST_METHOD(ZpNumber_BasicLarge) 23 | { 24 | InitDebugPrinting(); 25 | ZpNumber_BasicLarge_Test(); 26 | } 27 | 28 | TEST_METHOD(ZpNumber_ToBits) 29 | { 30 | InitDebugPrinting(); 31 | ZpNumber_ToBits_Test(); 32 | } 33 | 34 | }; 35 | #endif 36 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/ivoryTestVS.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // dGarbleTestVS.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | // Headers for CppUnitTest 11 | #include "CppUnitTest.h" 12 | 13 | // TODO: reference additional headers your program requires here 14 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTestVS/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #project(ivoryTests) 3 | 4 | 5 | 6 | ############################################# 7 | # Build ivoryTests # 8 | ############################################# 9 | 10 | file(GLOB_RECURSE SRCS *.cpp) 11 | 12 | include_directories(${CMAKE_SOURCE_DIR}/ivoryTests) 13 | 14 | 15 | add_library(ivoryTests ${SRCS}) 16 | 17 | target_link_libraries(ivoryTests ivory) 18 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/Circuit_Tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | 5 | void Circuit_SequentialOp_Test(); 6 | void Circuit_int_Adder_Test(); 7 | void Circuit_int_Adder_const_Test(); 8 | void Circuit_int_Subtractor_Test(); 9 | void Circuit_int_Subtractor_const_Test(); 10 | 11 | void Circuit_uint_Adder_Test(); 12 | void Circuit_uint_Subtractor_Test(); 13 | 14 | void Circuit_int_Multiply_Test(); 15 | void Circuit_int_Divide_Test(); 16 | 17 | void Circuit_int_LessThan_Test(); 18 | void Circuit_int_GreaterThanEq_Test(); 19 | void Circuit_uint_LessThan_Test(); 20 | void Circuit_uint_GreaterThanEq_Test(); 21 | 22 | void Circuit_multiplex_Test(); 23 | void Circuit_negate_Test(); 24 | void Circuit_bitInvert_Test(); 25 | 26 | 27 | void Circuit_removeSign_Test(); 28 | void Circuit_addSign_Test(); 29 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/Common.cpp: -------------------------------------------------------------------------------- 1 | #include "Common.h" 2 | #include 3 | #include 4 | #include "cryptoTools/Common/Log.h" 5 | 6 | using namespace osuCrypto; 7 | 8 | static std::fstream* file = nullptr; 9 | std::string testData("../.."); 10 | 11 | void InitDebugPrinting(std::string filePath) 12 | { 13 | std::cout << "changing sink" << std::endl; 14 | 15 | if (file == nullptr) 16 | { 17 | file = new std::fstream; 18 | } 19 | else 20 | { 21 | file->close(); 22 | } 23 | 24 | file->open(filePath, std::ios::trunc | std::ofstream::out); 25 | if (!file->is_open()) 26 | throw std::runtime_error(""); 27 | 28 | 29 | //time_t now = time(0); 30 | 31 | //Log::SetSink(*file); 32 | 33 | std::cout.rdbuf(file->rdbuf()); 34 | std::cerr.rdbuf(file->rdbuf()); 35 | 36 | //std::cout << "Test - " << ctime(&now) << std::endl; 37 | } 38 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "cryptoTools/Common/Defines.h" 5 | 6 | void InitDebugPrinting(std::string file = SOLUTION_DIR"/unitTest.txt"); 7 | 8 | extern std::string testData; 9 | 10 | class UnitTestFail : public std::exception 11 | { 12 | std::string mWhat; 13 | public: 14 | explicit UnitTestFail(std::string reason) 15 | :std::exception(), 16 | mWhat(reason) 17 | {} 18 | 19 | explicit UnitTestFail() 20 | :std::exception(), 21 | mWhat("unitTestFailed exception") 22 | { 23 | } 24 | 25 | virtual const char* what() const throw() 26 | { 27 | return mWhat.c_str(); 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/Cope_Tests.cpp: -------------------------------------------------------------------------------- 1 | #include "Cope_Tests.h" 2 | 3 | //#include "CopeOtExtReceiver.h" 4 | //#include "CopeOtExtSender.h" 5 | 6 | #include "libOTe/Tools/Tools.h" 7 | #include "cryptoTools/Network/Channel.h" 8 | #include "cryptoTools/Network/Session.h" 9 | #include "cryptoTools/Common/Log.h" 10 | #include "cryptoTools/Common/BitVector.h" 11 | #include "Common.h" 12 | using namespace osuCrypto; 13 | 14 | void cope_test() 15 | { 16 | 17 | return; 18 | 19 | //setThreadName("Sender"); 20 | 21 | //IOService ios(0); 22 | //Session ep0(ios, "127.0.0.1", 1212, SessionMode::Server, "ep"); 23 | //Session ep1(ios, "127.0.0.1", 1212, SessionMode::Client, "ep"); 24 | //Channel& senderChannel = ep1.addChannel("chl", "chl"); 25 | //Channel& recvChannel = ep0.addChannel("chl", "chl"); 26 | 27 | //PRNG prng0(_mm_set_epi32(4253465, 3434565, 234435, 23987045)); 28 | //PRNG prng1(_mm_set_epi32(4253233465, 334565, 0, 235)); 29 | 30 | //u64 numShares = 1; 31 | 32 | //ZpField field(ZpParam128); 33 | 34 | //std::vector 35 | // recvShare(numShares, ZpNumber(field)), 36 | // recvChoice(numShares, ZpNumber(field)), 37 | // sendShare(numShares, ZpNumber(field)); 38 | 39 | //std::vector baseRecv(128); 40 | //std::vector> baseSend(128); 41 | //BitVector baseChoice(128); 42 | //baseChoice.randomize(prng0); 43 | ////baseChoice[0] = 1; 44 | 45 | //for (u64 i = 0; i < 128; ++i) 46 | //{ 47 | // baseSend[i][0] = prng0.get(); 48 | // baseSend[i][1] = prng0.get(); 49 | // baseRecv[i] = baseSend[i][baseChoice[i]]; 50 | //} 51 | 52 | 53 | //for (u64 i = 0; i < numShares; ++i) 54 | //{ 55 | // recvChoice[i].randomize(prng0); 56 | //} 57 | 58 | //CopeOtExtSender sender; 59 | //CopeOtExtReceiver recv; 60 | 61 | //std::thread thrd = std::thread([&]() { 62 | // setThreadName("receiver"); 63 | 64 | // recv.setBaseOts(baseSend); 65 | // recv.receive(recvChoice, recvShare, prng0, recvChannel); 66 | //}); 67 | 68 | //sender.setBaseOts(baseRecv, baseChoice); 69 | 70 | //sender.send(sendShare, senderChannel); 71 | //thrd.join(); 72 | 73 | 74 | 75 | //senderChannel.close(); 76 | //recvChannel.close(); 77 | 78 | 79 | //ep1.stop(); 80 | //ep0.stop(); 81 | 82 | //ios.stop(); 83 | 84 | 85 | //ZpNumber delta(field); 86 | //delta.fromBits(baseChoice.data()); 87 | 88 | //for (u64 i = 0; i < numShares; ++i) 89 | //{ 90 | 91 | 92 | // if (sendShare[i] + recvShare[i] != recvChoice[i] * delta) 93 | // { 94 | // std::cout << "i = " << i << "\n"; 95 | // std::cout << "sendShare[i] = " << sendShare[i] << " (- " << -sendShare[i] <<")\n"; 96 | // std::cout << "recvShare[i] = " << recvShare[i] << "\n"; 97 | // std::cout << " + ___________________________________\n"; 98 | // std::cout << " " << sendShare[i] + recvShare[i] << "\n\n"; 99 | // std::cout << "detla = " << delta << "\n"; 100 | // std::cout << "recvChoice[i] = " << recvChoice[i] << "\n"; 101 | // std::cout << " * ___________________________________\n"; 102 | // std::cout << " " << recvChoice[i] * delta << "\n\n"; 103 | 104 | // throw UnitTestFail(); 105 | // } 106 | //} 107 | 108 | } 109 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/Cope_Tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | void cope_test(); -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/DebugCircuits.cpp: -------------------------------------------------------------------------------- 1 | #include "DebugCircuits.h" 2 | 3 | using namespace osuCrypto; 4 | 5 | Circuit OneGateCircuit(GateType gt) 6 | { 7 | Circuit cd(std::array{ {1, 1} }); 8 | //cd.SetInputWireCount(Role::First, 1); 9 | //cd.SetInputWireCount(Role::Second, 1); 10 | cd.AddGate(0, 1, gt); 11 | cd.AddOutputWire(2); 12 | return cd; 13 | } 14 | 15 | 16 | Circuit AdderCircuit(u64 bits) 17 | { 18 | std::vector carrys; 19 | u64 diff = 0; 20 | 21 | Circuit cd(std::array{ {bits + diff, bits} }); 22 | /* cd.SetInputWireCount(Role::First, bits); 23 | cd.SetInputWireCount(Role::Second, bits);*/ 24 | 25 | 26 | cd.AddOutputWire(cd.AddGate(0, bits + diff, GateType::Xor)); 27 | carrys.push_back(cd.AddGate(0, bits + diff, GateType::And)); 28 | 29 | for (u64 i = 1; i < bits; ++i) 30 | { 31 | auto xorIn = cd.AddGate(i, i + bits + diff, GateType::Xor); 32 | cd.AddOutputWire(cd.AddGate(xorIn, carrys.back(), GateType::Xor)); 33 | auto carry0 = cd.AddGate(xorIn, carrys.back(), GateType::And); 34 | auto carry1 = cd.AddGate(i, i + bits + diff, GateType::And); 35 | carrys.push_back(cd.AddGate(carry0, carry1, GateType::Or)); 36 | } 37 | cd.AddOutputWire(carrys.back()); 38 | cd.init(); 39 | return cd; 40 | } 41 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/DebugCircuits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ivory/Circuit/Circuit.h" 3 | 4 | osuCrypto::Circuit OneGateCircuit(osuCrypto::GateType gt); 5 | osuCrypto::Circuit AdderCircuit(osuCrypto::u64 bits); 6 | 7 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/ShGcRuntime_tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void ShGcRuntime_publicGateGarble_Test(); 4 | 5 | 6 | void ShGcRuntime_basicArith_Test(); 7 | void ShGcRuntime_SequentialOp_Test(); 8 | 9 | 10 | void ShGcRuntime_CircuitInvert_Test(); 11 | void ShGcRuntime_CircuitAdd_Test(); 12 | void ShGcRuntime_CircuitMult_Test(); 13 | void shGcRuntime_CircuitEval_Test(); 14 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/ZpNumber_Tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | void ZpNumber_ToBits_Test(); 5 | void ZpNumber_Basic_Test(); 6 | void ZpNumber_BasicLarge_Test(); 7 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/ivoryTests.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {D3E2E0BC-D52A-494F-8C7A-C204C164EFD0} 15 | ivoryTests 16 | 10.0 17 | 18 | 19 | 20 | StaticLibrary 21 | true 22 | v142 23 | MultiByte 24 | 25 | 26 | StaticLibrary 27 | false 28 | v142 29 | true 30 | MultiByte 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Level3 50 | Disabled 51 | true 52 | $(libOTeDir);$(libOTeDir)/cryptoTools;$(ProjectDir)/../SPDZ;$(ProjectDir)/../;$(ProjectDir);C:\libs\NTL\include;C:\libs;C:\libs\boost;C:\libs\miracl 53 | SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions) 54 | MultiThreadedDebug 55 | 56 | 57 | $(OutDir)/ivory.lib;%(AdditionalDependencies) 58 | 59 | 60 | 61 | 62 | Level3 63 | MaxSpeed 64 | true 65 | true 66 | true 67 | $(libOTeDir);$(libOTeDir)/cryptoTools;$(ProjectDir)/../SPDZ;$(ProjectDir)/../;$(ProjectDir);C:\libs\NTL\include;C:\libs;C:\libs\boost;C:\libs\miracl 68 | SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions) 69 | MultiThreaded 70 | 71 | 72 | true 73 | true 74 | $(OutDir)/ivory.lib;%(AdditionalDependencies) 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Ivory-Runtime/ivoryTests/ivoryTests.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Ivory-Runtime/thirdparty/linux/ntl.get: -------------------------------------------------------------------------------- 1 | wget http://www.shoup.net/ntl/ntl-9.3.0.tar.gz 2 | tar -zxvf ntl-9.3.0.tar.gz 3 | mv ntl-9.3.0 ntl 4 | rm ntl-9.3.0.tar.gz 5 | 6 | 7 | cd ntl/src 8 | ./configure 9 | make 10 | 11 | mv ./ntl.a ./libntl.a -------------------------------------------------------------------------------- /Python accurracy/PythonApplication1/PythonApplication1.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | 5 | N = 5 6 | menMeans = (20, 35, 30, 35, 27) 7 | womenMeans = (25, 32, 34, 20, 25) 8 | womenMeans1 = (25, 32, 34, 20, 25) 9 | menStd = (2, 3, 4, 1, 2) 10 | womenStd = (3, 5, 2, 3, 3) 11 | ind = np.arange(N) # the x locations for the groups 12 | width = 0.35 # the width of the bars: can also be len(x) sequence 13 | 14 | p1 = plt.bar(ind, menMeans, width, yerr=menStd) 15 | p2 = plt.bar(ind, womenMeans, width, 16 | bottom=menMeans, yerr=womenStd) 17 | p3 = plt.bar(ind, womenMeans, width, 18 | bottom=menMeans, yerr=womenMeans1) 19 | 20 | plt.ylabel('Scores') 21 | plt.title('Scores by group and gender') 22 | plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5')) 23 | plt.yticks(np.arange(0, 81, 10)) 24 | plt.legend((p1[0], p2[0], p3[0]), ('Men', 'Women','fsd')) 25 | 26 | plt.show() -------------------------------------------------------------------------------- /Python accurracy/PythonApplication1/PythonApplication1.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Debug 4 | 2.0 5 | c3ca0385-31b9-4db3-839e-734fe959323f 6 | . 7 | PythonApplication1.py 8 | 9 | 10 | . 11 | . 12 | PythonApplication1 13 | PythonApplication1 14 | 15 | 16 | true 17 | false 18 | 19 | 20 | true 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Python accurracy/PythonApplication1/PythonApplication1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PythonApplication1", "PythonApplication1.pyproj", "{C3CA0385-31B9-4DB3-839E-734FE959323F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C3CA0385-31B9-4DB3-839E-734FE959323F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C3CA0385-31B9-4DB3-839E-734FE959323F}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ExtensibilityGlobals) = postSolution 21 | SolutionGuid = {9C0D54AD-C61D-4865-819F-BFA7982528CE} 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /Python accurracy/PythonApplication_accuracy/PythonApplication1.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | # # Create data 5 | # N = 60 6 | # g1 = (0.6 + 0.6 * np.random.rand(N), np.random.rand(N)) 7 | # g2 = (0.4+0.3 * np.random.rand(N), 0.5*np.random.rand(N)) 8 | # g3 = (0.3*np.random.rand(N),0.3*np.random.rand(N)) 9 | 10 | # read from txt file 11 | data = [[], [], [],[]] 12 | #with open('SecureCluster_sizes1.arff.txt', 'r') as f: 13 | with open('raw_sizes1.arff.txt', 'r') as f: 14 | for line in f.readlines(): 15 | line = line.strip() 16 | x, y, g = line.split(',') 17 | x = float(x) 18 | y = float(y) 19 | g = int(g) 20 | data[g].append((x,y)) 21 | 22 | # data = (g1, g2, g3) 23 | colors = ("red", "green", "blue","purple") 24 | #colors = ("blue", "purple", "red","green") 25 | groups = ("coffee", "tea", "water", "water") 26 | 27 | # Create plot 28 | fig = plt.figure() 29 | ax = fig.add_subplot(1, 1, 1) 30 | 31 | for data, color in zip(data, colors): 32 | x, y = np.array(data).T 33 | ax.scatter(x, y, alpha=0.8, c=color, edgecolors='none', s=30) 34 | 35 | plt.title('') 36 | plt.legend(loc=2) 37 | plt.show() -------------------------------------------------------------------------------- /Python accurracy/PythonApplication_accuracy/PythonApplication1.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Debug 4 | 2.0 5 | c3ca0385-31b9-4db3-839e-734fe959323f 6 | . 7 | PythonApplication1.py 8 | 9 | 10 | . 11 | . 12 | PythonApplication1 13 | PythonApplication1 14 | 15 | 16 | true 17 | false 18 | 19 | 20 | true 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Python accurracy/PythonApplication_accuracy/PythonApplication1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PythonApplication1", "PythonApplication1.pyproj", "{C3CA0385-31B9-4DB3-839E-734FE959323F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C3CA0385-31B9-4DB3-839E-734FE959323F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C3CA0385-31B9-4DB3-839E-734FE959323F}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ExtensibilityGlobals) = postSolution 21 | SolutionGuid = {9C0D54AD-C61D-4865-819F-BFA7982528CE} 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /Python accurracy/color/PythonApplication1.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | # # Create data 5 | # N = 60 6 | # g1 = (0.6 + 0.6 * np.random.rand(N), np.random.rand(N)) 7 | # g2 = (0.4+0.3 * np.random.rand(N), 0.5*np.random.rand(N)) 8 | # g3 = (0.3*np.random.rand(N),0.3*np.random.rand(N)) 9 | 10 | # read from txt file 11 | data = [[], [], [],[]] 12 | with open('sizes1.arff.txt', 'r') as f: 13 | for line in f.readlines(): 14 | line = line.strip() 15 | x, y, g = line.split(',') 16 | x = float(x) 17 | y = float(y) 18 | g = int(g) 19 | data[g].append((x,y)) 20 | 21 | # data = (g1, g2, g3) 22 | colors = ("red", "green", "blue","yellow") 23 | groups = ("coffee", "tea", "water", "water") 24 | 25 | # Create plot 26 | fig = plt.figure() 27 | ax = fig.add_subplot(1, 1, 1) 28 | 29 | for data, color, group in zip(data, colors, groups): 30 | x, y = np.array(data).T 31 | ax.scatter(x, y, alpha=0.8, c=color, edgecolors='none', s=30, label=group) 32 | 33 | plt.title('Matplot scatter plot') 34 | plt.legend(loc=2) 35 | plt.show() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Practical Privacy-Preserving K-means Clustering 2 | This is the implementation of our [PETS 2020](https://petsymposium.org/cfp20.php) paper: **Practical Privacy-Preserving K-means Clustering**([ePrint](https://eprint.iacr.org/2019/1158)). 3 | 4 | Evaluating on a single server (`2 36-cores Intel Xeon CPU E5-2699 v3 @ 2.30GHz and 256GB of RAM`) with a single thread per party, our scheme requires `18` minutes to cluster 100,000 data samples into 2 groups. 5 | 6 | ## Installations 7 | ### Clone project 8 | ``` 9 | git clone --recursive git@github.com:osu-crypto/secure-kmean-clustering.git 10 | ``` 11 | 12 | ### Required libraries 13 | C++ compiler with C++14 support. There are several library dependencies including [`Boost`](https://sourceforge.net/projects/boost/), [`Miracl`](https://github.com/miracl/MIRACL), [`libOTe`](https://github.com/osu-crypto/libOTe), and [`Ivory-Runtime`](https://github.com/nitrieu/Ivory-Runtime/tree/e4bb8350e6ad6fdfa5a51994fff1db86d25527a0). For `libOTe`, it requires CPU supporting `PCLMUL`, `AES-NI`, and `SSE4.1`. Optional: `nasm` for improved SHA1 performance. Our code has been tested on both Windows (Microsoft Visual Studio) and Linux. To install the required libraries: 14 | * For building boost, miracl and libOTe, please follow the more instructions at [`libOTe`](https://github.com/osu-crypto/libOTe). A quick try for linux: `cd libOTe/cryptoTools/thirdparty/linux/`, `bash all.get`, `cd` back to `libOTe`, `cmake .` and then `make -j` 15 | * For Ivory-Runtime, `cd Ivory-Runtime/thirdparty/linux`, and `bash ./ntl.get`. Then, you can run `cmake -G"Unix Makefiles"` in Ivory-Runtime folder, and then `make -j` 16 | 17 | NOTE: if you meet problem with NTL, try to do the following and read [`Building and using NTL with GMP`](https://www.shoup.net/ntl/doc/tour-gmp.html). If you see an error message `cmd.exe not found`, try to install https://www.nasm.us/ 18 | 19 | ### Building the Project 20 | After recursively cloning project from git `git clone --recursive `, 21 | ##### Windows: 22 | 1. build cryptoTools,libOTe, Ivory-Runtime, libCluster, frontend projects in order. 23 | 2. run frontend project 24 | 25 | ##### Linux: 26 | 1. make (requirements: `CMake`, `Make`, `g++` or similar) 27 | 2. for test: 28 | ./bin/frontend.exe 29 | 30 | 31 | ## Running the code 32 | 33 | ##### 1. Unit test: 34 | ./bin/frontend.exe -t 35 | 36 | #### 2. Simulation: 37 | Using two terminals, (For now, the kmean parameters are hardcoding in the main.cpp file, we will add more flags soon) 38 | 39 | On the terminal 1, run: 40 | 41 | ./bin/frontend -r 0 42 | 43 | On the terminal 2, run: 44 | 45 | ./bin/frontend -r 1 46 | 47 | 48 | ## Help 49 | For any questions on building or running the library, please contact [`Ni Trieu`](http://people.oregonstate.edu/~trieun/) at trieun at oregonstate dot edu 50 | -------------------------------------------------------------------------------- /TestsVS/TestsVS.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #ifdef _MSC_VER 3 | #include "CppUnitTest.h" 4 | #include "Common.h" 5 | #include "Tests.h" 6 | #include "Circuit_Tests.h" 7 | 8 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 9 | 10 | namespace osuCrypto 11 | { 12 | TEST_CLASS(nOPRF_Tests) 13 | { 14 | public: 15 | 16 | 17 | TEST_METHOD(AdaptiveMUL_Zn_testVS) 18 | { 19 | InitDebugPrinting(); 20 | AdaptiveMUL_Zn_test(); 21 | } 22 | 23 | TEST_METHOD(AdaptiveMUL_testVS) 24 | { 25 | InitDebugPrinting(); 26 | AdaptiveMUL_test(); 27 | } 28 | 29 | TEST_METHOD(Circuit_int_LessThan_testVS) 30 | { 31 | InitDebugPrinting(); 32 | Circuit_int_LessThan_Test(); 33 | } 34 | 35 | TEST_METHOD(readData_testVS) 36 | { 37 | InitDebugPrinting(); 38 | readData_test(); 39 | } 40 | 41 | 42 | 43 | 44 | 45 | TEST_METHOD(MulTesttVS) 46 | { 47 | InitDebugPrinting(); 48 | MulTest(); 49 | } 50 | 51 | TEST_METHOD(CircuiTesttVS) 52 | { 53 | InitDebugPrinting(); 54 | testCircuit(); 55 | } 56 | 57 | TEST_METHOD(DistTesttVS) 58 | { 59 | InitDebugPrinting(); 60 | DistTest(); 61 | } 62 | 63 | TEST_METHOD(MinDistFirstLevelTesttVS) 64 | { 65 | InitDebugPrinting(); 66 | testMinDistFirstLevel(); 67 | } 68 | 69 | TEST_METHOD(MinDistTesttVS) 70 | { 71 | InitDebugPrinting(); 72 | testMinDist(); 73 | } 74 | 75 | /*TEST_METHOD(plaintextTesttVS) 76 | { 77 | InitDebugPrinting(); 78 | plaintextClustering(); 79 | }*/ 80 | 81 | 82 | TEST_METHOD(AccurancyTesttVS) 83 | { 84 | InitDebugPrinting(); 85 | testAccurancy(); 86 | } 87 | TEST_METHOD(AccurancyNewTesttVS) 88 | { 89 | InitDebugPrinting(); 90 | testAccurancy_new(); 91 | } 92 | 93 | 94 | TEST_METHOD(MinDistBaseLineVS) 95 | { 96 | InitDebugPrinting(); 97 | testMinDist_Baseline(); 98 | } 99 | 100 | 101 | TEST_METHOD(ClusteringTesttVS) 102 | { 103 | InitDebugPrinting(); 104 | ClusteringTest(); 105 | } 106 | 107 | 108 | TEST_METHOD(UpdateCTesttVS) 109 | { 110 | InitDebugPrinting(); 111 | testUpdateCluster(); 112 | } 113 | #if 0 114 | TEST_METHOD(DecAESTesttVS) 115 | { 116 | InitDebugPrinting(); 117 | testDecAES(); 118 | } 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | #endif 128 | 129 | 130 | }; 131 | } 132 | #endif -------------------------------------------------------------------------------- /TestsVS/TestsVS.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | -------------------------------------------------------------------------------- /TestsVS/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // tests_libOTeVS.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /TestsVS/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | // This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use. 8 | 9 | #include "targetver.h" 10 | 11 | // Headers for CppUnitTest 12 | #include "CppUnitTest.h" 13 | 14 | // TODO: reference additional headers your program requires here 15 | -------------------------------------------------------------------------------- /TestsVS/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use. 3 | 4 | // Including SDKDDKVer.h defines the highest available Windows platform. 5 | 6 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 7 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 8 | 9 | #include 10 | -------------------------------------------------------------------------------- /buildAll.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop" 2 | 3 | # Update this if needed 4 | $MSBuild = 'C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe' 5 | #$MSBuild = 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe' 6 | 7 | if(!(Test-Path $MSBuild)) 8 | { 9 | 10 | 11 | Write-Host "Could not find MSBuild as" 12 | Write-Host " $MSBuild" 13 | Write-Host "" 14 | Write-Host "Please update its location in the script" 15 | 16 | exit 17 | 18 | } 19 | 20 | cd ./cryptoTools/thirdparty/win 21 | 22 | & ./getBoost.ps1 23 | & ./getMiracl.ps1 24 | 25 | cd ../../.. 26 | 27 | & $MSBuild libOTe.sln /p:Configuration=Release /p:Platform=x64 28 | & $MSBuild libOTe.sln /p:Configuration=Debug /p:Platform=x64 29 | 30 | 31 | -------------------------------------------------------------------------------- /copySourceToLinux.ps1: -------------------------------------------------------------------------------- 1 | $RemoteUserName='trieun' 2 | $RemoteHostName='eve.eecs.oregonstate.edu' 3 | $PrivateKey='C:\EvePrivatekey.ppk' 4 | $SolutionDir=$PWD 5 | $RemoteWorkingDir='/scratch/nini/kmean-impl' 6 | 7 | # only files with these extensions will be copied 8 | $FileMasks='**.cpp;**.c;**.h;*.bin,*.S,*.sh,*CMake*;*/Tools/*.txt;*/gsl/*;**.mak;thirdparty/linux/**.get;*/libOTe_Tests/testData/*.txt' 9 | 10 | # everything in these folders will be skipped 11 | $ExcludeDirs='.git/;thirdparty/;Debug/;Release/;x64/;ipch/;.vs/' 12 | 13 | C:\tools\WinSCP.com /command ` 14 | "open $RemoteUserName@$RemoteHostName -privatekey=""$PrivateKey"""` 15 | "call mkdir -p $RemoteWorkingDir"` 16 | "synchronize Remote $SolutionDir $RemoteWorkingDir -filemask=""$FileMasks|$ExcludeDirs;"" -transfer=binary"` 17 | "call mkdir -p $RemoteWorkingDir/cryptoTools/thirdparty/"` 18 | "call mkdir -p $RemoteWorkingDir/cryptoTools/thirdparty/linux/"` 19 | "synchronize remote $SolutionDir/cryptoTools/thirdparty/linux/ $RemoteWorkingDir/cryptoTools/thirdparty/linux/ -filemask=""**.get"" -transfer=binary"` 20 | "exit" -------------------------------------------------------------------------------- /dataset/LsunKmeans.txt: -------------------------------------------------------------------------------- 1 | 1 3 2 | 2 1 3 | 3 1 4 | 4 1 5 | 5 1 6 | 6 3 7 | 7 1 8 | 8 3 9 | 9 3 10 | 10 1 11 | 11 1 12 | 12 3 13 | 13 3 14 | 14 1 15 | 15 1 16 | 16 3 17 | 17 1 18 | 18 1 19 | 19 1 20 | 20 1 21 | 21 1 22 | 22 3 23 | 23 1 24 | 24 1 25 | 25 1 26 | 26 1 27 | 27 3 28 | 28 3 29 | 29 3 30 | 30 3 31 | 31 3 32 | 32 3 33 | 33 1 34 | 34 3 35 | 35 1 36 | 36 3 37 | 37 1 38 | 38 1 39 | 39 3 40 | 40 1 41 | 41 3 42 | 42 1 43 | 43 1 44 | 44 3 45 | 45 1 46 | 46 1 47 | 47 1 48 | 48 1 49 | 49 3 50 | 50 1 51 | 51 1 52 | 52 1 53 | 53 3 54 | 54 1 55 | 55 1 56 | 56 3 57 | 57 1 58 | 58 1 59 | 59 1 60 | 60 1 61 | 61 1 62 | 62 1 63 | 63 3 64 | 64 1 65 | 65 3 66 | 66 1 67 | 67 1 68 | 68 1 69 | 69 1 70 | 70 1 71 | 71 1 72 | 72 1 73 | 73 1 74 | 74 3 75 | 75 1 76 | 76 3 77 | 77 3 78 | 78 1 79 | 79 1 80 | 80 1 81 | 81 1 82 | 82 1 83 | 83 1 84 | 84 1 85 | 85 3 86 | 86 3 87 | 87 3 88 | 88 1 89 | 89 3 90 | 90 1 91 | 91 1 92 | 92 3 93 | 93 1 94 | 94 1 95 | 95 1 96 | 96 3 97 | 97 1 98 | 98 1 99 | 99 3 100 | 100 3 101 | 101 3 102 | 102 1 103 | 103 1 104 | 104 3 105 | 105 1 106 | 106 3 107 | 107 1 108 | 108 1 109 | 109 3 110 | 110 3 111 | 111 1 112 | 112 1 113 | 113 1 114 | 114 3 115 | 115 1 116 | 116 1 117 | 117 1 118 | 118 1 119 | 119 1 120 | 120 1 121 | 121 3 122 | 122 1 123 | 123 1 124 | 124 1 125 | 125 3 126 | 126 1 127 | 127 1 128 | 128 1 129 | 129 1 130 | 130 1 131 | 131 1 132 | 132 3 133 | 133 1 134 | 134 1 135 | 135 1 136 | 136 1 137 | 137 1 138 | 138 3 139 | 139 3 140 | 140 3 141 | 141 3 142 | 142 1 143 | 143 1 144 | 144 3 145 | 145 1 146 | 146 1 147 | 147 1 148 | 148 3 149 | 149 3 150 | 150 1 151 | 151 1 152 | 152 3 153 | 153 1 154 | 154 1 155 | 155 1 156 | 156 1 157 | 157 1 158 | 158 3 159 | 159 1 160 | 160 1 161 | 161 1 162 | 162 1 163 | 163 1 164 | 164 3 165 | 165 3 166 | 166 1 167 | 167 3 168 | 168 1 169 | 169 3 170 | 170 1 171 | 171 1 172 | 172 3 173 | 173 1 174 | 174 1 175 | 175 3 176 | 176 1 177 | 177 1 178 | 178 3 179 | 179 3 180 | 180 1 181 | 181 3 182 | 182 3 183 | 183 1 184 | 184 3 185 | 185 1 186 | 186 3 187 | 187 1 188 | 188 1 189 | 189 1 190 | 190 1 191 | 191 3 192 | 192 3 193 | 193 1 194 | 194 1 195 | 195 1 196 | 196 3 197 | 197 1 198 | 198 1 199 | 199 1 200 | 200 1 201 | 201 2 202 | 202 2 203 | 203 2 204 | 204 2 205 | 205 1 206 | 206 2 207 | 207 1 208 | 208 2 209 | 209 2 210 | 210 2 211 | 211 2 212 | 212 2 213 | 213 2 214 | 214 2 215 | 215 2 216 | 216 2 217 | 217 2 218 | 218 1 219 | 219 2 220 | 220 2 221 | 221 1 222 | 222 2 223 | 223 2 224 | 224 2 225 | 225 2 226 | 226 2 227 | 227 2 228 | 228 2 229 | 229 1 230 | 230 2 231 | 231 2 232 | 232 1 233 | 233 2 234 | 234 2 235 | 235 2 236 | 236 2 237 | 237 2 238 | 238 2 239 | 239 2 240 | 240 2 241 | 241 2 242 | 242 1 243 | 243 2 244 | 244 2 245 | 245 2 246 | 246 2 247 | 247 2 248 | 248 2 249 | 249 2 250 | 250 2 251 | 251 1 252 | 252 2 253 | 253 2 254 | 254 2 255 | 255 2 256 | 256 2 257 | 257 1 258 | 258 2 259 | 259 1 260 | 260 2 261 | 261 1 262 | 262 1 263 | 263 2 264 | 264 2 265 | 265 2 266 | 266 1 267 | 267 1 268 | 268 1 269 | 269 2 270 | 270 1 271 | 271 2 272 | 272 2 273 | 273 2 274 | 274 2 275 | 275 2 276 | 276 2 277 | 277 2 278 | 278 1 279 | 279 2 280 | 280 2 281 | 281 2 282 | 282 1 283 | 283 1 284 | 284 2 285 | 285 2 286 | 286 2 287 | 287 1 288 | 288 2 289 | 289 2 290 | 290 2 291 | 291 2 292 | 292 2 293 | 293 2 294 | 294 1 295 | 295 2 296 | 296 2 297 | 297 2 298 | 298 1 299 | 299 1 300 | 300 2 301 | 301 3 302 | 302 3 303 | 303 3 304 | 304 3 305 | 305 2 306 | 306 3 307 | 307 3 308 | 308 3 309 | 309 3 310 | 310 3 311 | 311 3 312 | 312 3 313 | 313 3 314 | 314 3 315 | 315 3 316 | 316 3 317 | 317 3 318 | 318 3 319 | 319 3 320 | 320 3 321 | 321 3 322 | 322 3 323 | 323 3 324 | 324 3 325 | 325 3 326 | 326 3 327 | 327 3 328 | 328 3 329 | 329 3 330 | 330 3 331 | 331 3 332 | 332 3 333 | 333 3 334 | 334 3 335 | 335 3 336 | 336 3 337 | 337 2 338 | 338 3 339 | 339 3 340 | 340 3 341 | 341 3 342 | 342 3 343 | 343 3 344 | 344 3 345 | 345 2 346 | 346 3 347 | 347 3 348 | 348 3 349 | 349 3 350 | 350 3 351 | 351 3 352 | 352 3 353 | 353 3 354 | 354 3 355 | 355 3 356 | 356 3 357 | 357 3 358 | 358 3 359 | 359 3 360 | 360 3 361 | 361 3 362 | 362 3 363 | 363 3 364 | 364 3 365 | 365 3 366 | 366 3 367 | 367 3 368 | 368 3 369 | 369 3 370 | 370 3 371 | 371 3 372 | 372 3 373 | 373 3 374 | 374 3 375 | 375 3 376 | 376 3 377 | 377 3 378 | 378 3 379 | 379 3 380 | 380 3 381 | 381 3 382 | 382 3 383 | 383 3 384 | 384 3 385 | 385 3 386 | 386 3 387 | 387 3 388 | 388 3 389 | 389 3 390 | 390 3 391 | 391 3 392 | 392 3 393 | 393 3 394 | 394 3 395 | 395 3 396 | 396 3 397 | 397 3 398 | 398 3 399 | 399 3 400 | 400 3 401 | -------------------------------------------------------------------------------- /dataset/s1-groundtruth-plot.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osu-crypto/secure-kmean-clustering/cd9fd7145fd0d0349beae9ff1370dcece2239767/dataset/s1-groundtruth-plot.xls -------------------------------------------------------------------------------- /dataset/s1c.txt: -------------------------------------------------------------------------------- 1 | 604328 574379 2 | 801908 318382 3 | 416383 786204 4 | 822771 732034 5 | 850993 157873 6 | 338586 563537 7 | 169274 348574 8 | 619259 397671 9 | 241071 844424 10 | 321801 165319 11 | 139493 557352 12 | 508785 174800 13 | 398934 404142 14 | 860858 546059 15 | 674365 860464 16 | -------------------------------------------------------------------------------- /frontend/CLP.cpp: -------------------------------------------------------------------------------- 1 | #include "CLP.h" 2 | #include 3 | #include 4 | 5 | 6 | 7 | void CLP::parse(int argc, char** argv) 8 | { 9 | if (argc > 0) 10 | { 11 | std::stringstream ss; 12 | while (*argv[0] != 0) 13 | ss << *argv[0]++; 14 | mProgramName = ss.str(); 15 | } 16 | 17 | for (int i = 1; i < argc;) 18 | { 19 | if (*argv[i]++ != '-') 20 | { 21 | throw CommandLineParserError(); 22 | } 23 | 24 | std::stringstream ss; 25 | 26 | while (*argv[i] != 0) 27 | ss << *argv[i]++; 28 | 29 | ++i; 30 | 31 | std::pair> keyValues; 32 | keyValues.first = ss.str();; 33 | 34 | while (i < argc && argv[i][0] != '-') 35 | { 36 | ss.str(""); 37 | 38 | while (*argv[i] != 0) 39 | ss << *argv[i]++; 40 | 41 | keyValues.second.push_back(ss.str()); 42 | 43 | ++i; 44 | } 45 | 46 | mKeyValues.emplace(keyValues); 47 | } 48 | } 49 | 50 | void CLP::setDefault(std::string key, std::string value) 51 | { 52 | if (hasValue(key) == false) 53 | { 54 | mKeyValues.emplace(std::make_pair(key, std::list{ value })); 55 | } 56 | 57 | } 58 | void CLP::setDefault(std::vector keys, std::string value) 59 | { 60 | if (hasValue(keys) == false) 61 | { 62 | setDefault(keys[0], value); 63 | } 64 | 65 | } 66 | 67 | bool CLP::isSet(std::string name) 68 | { 69 | return mKeyValues.find(name) != mKeyValues.end(); 70 | } 71 | bool CLP::isSet(std::vector names) 72 | { 73 | for (auto name : names) 74 | { 75 | if (isSet(name)) 76 | { 77 | return true; 78 | } 79 | } 80 | return false; 81 | } 82 | 83 | bool CLP::hasValue(std::string name) 84 | { 85 | return mKeyValues.find(name) != mKeyValues.end() && mKeyValues[name].size(); 86 | } 87 | bool CLP::hasValue(std::vector names) 88 | { 89 | for (auto name : names) 90 | { 91 | if (hasValue(name)) 92 | { 93 | return true; 94 | } 95 | } 96 | return false; 97 | } 98 | 99 | int CLP::getInt(std::string name) 100 | { 101 | std::stringstream ss; 102 | ss << *mKeyValues[name].begin(); 103 | 104 | int ret; 105 | ss >> ret; 106 | 107 | return ret; 108 | } 109 | 110 | int CLP::getInt(std::vector names, std::string failMessage) 111 | { 112 | for (auto name : names) 113 | { 114 | if (hasValue(name)) 115 | { 116 | return getInt(name); 117 | } 118 | } 119 | 120 | if (failMessage != "") 121 | std::cout << failMessage << std::endl; 122 | 123 | throw CommandLineParserError(); 124 | } 125 | 126 | std::string CLP::getString(std::string name) 127 | { 128 | return *mKeyValues[name].begin(); 129 | } 130 | 131 | std::list CLP::getStrings(std::string name) 132 | { 133 | return mKeyValues[name]; 134 | } 135 | 136 | std::list CLP::getStrings(std::vector names, std::string failMessage) 137 | { 138 | for (auto name : names) 139 | { 140 | if (hasValue(name)) 141 | { 142 | return getStrings(name); 143 | } 144 | } 145 | 146 | if (failMessage != "") 147 | std::cout << failMessage << std::endl; 148 | 149 | throw CommandLineParserError(); 150 | } 151 | 152 | 153 | std::string CLP::getString(std::vector names, std::string failMessage) 154 | { 155 | for (auto name : names) 156 | { 157 | if (hasValue(name)) 158 | { 159 | return getString(name); 160 | } 161 | } 162 | 163 | if (failMessage != "") 164 | std::cout << failMessage << std::endl; 165 | 166 | throw CommandLineParserError(); 167 | } 168 | 169 | -------------------------------------------------------------------------------- /frontend/CLP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class CommandLineParserError : public std::exception 10 | { 11 | 12 | }; 13 | 14 | class CLP 15 | { 16 | public: 17 | 18 | std::string mProgramName; 19 | std::unordered_map> mKeyValues; 20 | 21 | void parse(int argc, char** argv); 22 | 23 | void setDefault(std::string key, std::string value); 24 | void setDefault(std::vector keys, std::string value); 25 | 26 | bool isSet(std::string name); 27 | bool isSet(std::vector names); 28 | 29 | bool hasValue(std::string name); 30 | bool hasValue(std::vector names); 31 | 32 | int getInt(std::string name); 33 | int getInt(std::vector names, std::string failMessage = ""); 34 | 35 | std::string getString(std::string name); 36 | std::list getStrings(std::string name); 37 | 38 | std::string getString(std::vector names, std::string failMessage = ""); 39 | std::list getStrings(std::vector names, std::string failMessage = ""); 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /frontend/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #project(frontend) 2 | 3 | 4 | file(GLOB_RECURSE SRCS *.cpp) 5 | 6 | include_directories(${CMAKE_SOURCE_DIR}) 7 | 8 | 9 | add_executable(frontend ${SRCS}) 10 | 11 | target_link_libraries(frontend libOTe libCluster cryptoTools ivory) -------------------------------------------------------------------------------- /frontend/frontend.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {C81DC04B-A0F0-4B77-8DCE-C8190E629467} 15 | frontend 16 | 10.0 17 | 18 | 19 | 20 | Application 21 | true 22 | v142 23 | MultiByte 24 | 25 | 26 | Application 27 | false 28 | v142 29 | true 30 | MultiByte 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | false 46 | 47 | 48 | 49 | Level3 50 | Disabled 51 | true 52 | $(ProjectDir)/../Ivory-Runtime/;$(ProjectDir)/../Ivory-Runtime/ivory;$(ProjectDir)/../Ivory-Runtime/ivoryTests;$(SolutionDir);$(SolutionDir)/libOTe/libOTe;$(SolutionDir)/libOTe/;$(SolutionDir)/Tests;$(SolutionDir)/libOTe/cryptoTools/;$(SolutionDir)/libOTe//cryptoTools/thirdparty\win\boost\;$(SolutionDir)/libOTe/cryptoTools/thirdparty\win\;$(SolutionDir)/libOTe/cryptoTools/thirdparty/win/NTL/include;$(SolutionDir)/libOTe/cryptoTools/thirdparty/win/miracl;C:/libs/boost;C:/libs/;C:/libs/NTL/include;C:/libs/miracl 53 | MultiThreadedDebug 54 | SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501 ;_MBCS;%(PreprocessorDefinitions) 55 | true 56 | true 57 | 58 | 59 | $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(ProjectDir)..\cryptoTools\thirdparty\win\boost\stage\lib;C:/libs/boost\stage\lib;$(OutDir);$(ProjectDir)..\cryptoTools/thirdparty\win\;C:/libs/ 60 | cryptoTools.lib;libOTe.lib;Tests.lib;Miracl\x64\$(Configuration)\miracl.lib;ivoryTests.lib;ivory.lib;%(AdditionalDependencies) 61 | 62 | 63 | 64 | 65 | Level3 66 | MaxSpeed 67 | true 68 | true 69 | true 70 | $(SolutionDir);$(SolutionDir)/cryptoTools/;$(SolutionDir)/cryptoTools/thirdparty\win\boost\;$(SolutionDir)/cryptoTools/thirdparty\win\;$(SolutionDir)/cryptoTools/thirdparty/win/NTL/include;$(SolutionDir)/cryptoTools/thirdparty/win/miracl;C:/libs/boost;C:/libs/;C:/libs/NTL/include;C:/libs/miracl 71 | MultiThreaded 72 | SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501 ;_MBCS;%(PreprocessorDefinitions) 73 | true 74 | true 75 | 76 | 77 | true 78 | true 79 | $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(ProjectDir)..\cryptoTools\thirdparty\win\boost\stage\lib;C:/libs/boost\stage\lib;$(OutDir);$(ProjectDir)..\cryptoTools/thirdparty\win\;C:/libs/ 80 | cryptoTools.lib;libOTe.lib;libOTe_Tests.lib;Miracl\x64\$(Configuration)\miracl.lib;%(AdditionalDependencies) 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /frontend/frontend.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 10 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 11 | 12 | 13 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 14 | h;hh;hpp;hxx;hm;inl;inc;xsd 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /frontend/main.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osu-crypto/secure-kmean-clustering/cd9fd7145fd0d0349beae9ff1370dcece2239767/frontend/main.h -------------------------------------------------------------------------------- /frontend/signalHandle.cpp: -------------------------------------------------------------------------------- 1 | 2 | #if !defined _MSC_VER & defined SHOW_BACK_TRACE 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | char* exe = 0; 13 | 14 | int initialiseExecutableName() 15 | { 16 | char link[1024]; 17 | exe = new char[1024]; 18 | snprintf(link, sizeof link, "/proc/%d/exe", getpid()); 19 | if (readlink(link, exe, sizeof link) == -1) { 20 | fprintf(stderr, "ERRORRRRR\n"); 21 | exit(1); 22 | } 23 | printf("Executable name initialised: %s\n", exe); 24 | } 25 | 26 | const char* getExecutableName() 27 | { 28 | if (exe == 0) 29 | initialiseExecutableName(); 30 | return exe; 31 | } 32 | 33 | /* get REG_EIP from ucontext.h */ 34 | #define __USE_GNU 35 | #include 36 | #ifdef __x86_64__ 37 | #define REG_EIP REG_RIP 38 | #endif 39 | 40 | void bt_sighandler(int sig, siginfo_t *info, 41 | void *secret) { 42 | 43 | void *trace[16]; 44 | char **messages = (char **)NULL; 45 | int i, trace_size = 0; 46 | ucontext_t *uc = (ucontext_t *)secret; 47 | 48 | /* Do something useful with siginfo_t */ 49 | if (sig == SIGSEGV) 50 | printf("Got signal %d, faulty address is %p, " 51 | "from %p\n", sig, info->si_addr, 52 | uc->uc_mcontext.gregs[REG_EIP]); 53 | else 54 | printf("Got signal %d#92;\n", sig); 55 | 56 | trace_size = backtrace(trace, 16); 57 | /* overwrite sigaction with caller's address */ 58 | trace[1] = (void *)uc->uc_mcontext.gregs[REG_EIP]; 59 | 60 | messages = backtrace_symbols(trace, trace_size); 61 | /* skip first stack frame (points here) */ 62 | printf("[bt] Execution path:#92;\n"); 63 | for (i = 1; i 5 | #include 6 | #include 7 | #define tryCount 2 8 | 9 | void senderGetLatency(Channel& chl) 10 | { 11 | 12 | u8 dummy[1]; 13 | 14 | chl.asyncSend(dummy, 1); 15 | 16 | 17 | 18 | chl.recv(dummy, 1); 19 | chl.asyncSend(dummy, 1); 20 | 21 | 22 | std::vector oneMbit((1 << 20) / 8); 23 | for (u64 i = 0; i < tryCount; ++i) 24 | { 25 | chl.recv(dummy, 1); 26 | 27 | for(u64 j =0; j < (1<<10); ++j) 28 | chl.asyncSend(oneMbit.data(), oneMbit.size()); 29 | } 30 | chl.recv(dummy, 1); 31 | 32 | } 33 | 34 | void recverGetLatency(Channel& chl) 35 | { 36 | 37 | u8 dummy[1]; 38 | chl.recv(dummy, 1); 39 | Timer timer; 40 | auto start = timer.setTimePoint(""); 41 | chl.asyncSend(dummy, 1); 42 | 43 | 44 | chl.recv(dummy, 1); 45 | 46 | auto mid = timer.setTimePoint(""); 47 | auto recvStart = mid; 48 | auto recvEnd = mid; 49 | 50 | auto rrt = mid - start; 51 | std::cout << "latency: " << std::chrono::duration_cast(rrt).count() << " ms" << std::endl; 52 | 53 | std::vector oneMbit((1 << 20) / 8); 54 | for (u64 i = 0; i < tryCount; ++i) 55 | { 56 | recvStart = timer.setTimePoint(""); 57 | chl.asyncSend(dummy, 1); 58 | 59 | for (u64 j = 0; j < (1 << 10); ++j) 60 | chl.recv(oneMbit); 61 | 62 | recvEnd = timer.setTimePoint(""); 63 | 64 | // nanoseconds per GegaBit 65 | auto uspGb = std::chrono::duration_cast(recvEnd - recvStart - rrt / 2).count(); 66 | 67 | // nanoseconds per second 68 | double usps = std::chrono::duration_cast(std::chrono::seconds(1)).count(); 69 | 70 | // MegaBits per second 71 | auto Mbps = usps / uspGb * (1 << 10); 72 | 73 | std::cout << "bandwidth: " << Mbps << " Mbps" << std::endl; 74 | } 75 | 76 | chl.asyncSend(dummy, 1); 77 | 78 | } 79 | -------------------------------------------------------------------------------- /frontend/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use. 3 | 4 | 5 | 6 | #include 7 | void senderGetLatency(osuCrypto::Channel& chl); 8 | 9 | void recverGetLatency(osuCrypto::Channel& chl); 10 | -------------------------------------------------------------------------------- /graph presentation/lable.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osu-crypto/secure-kmean-clustering/cd9fd7145fd0d0349beae9ff1370dcece2239767/graph presentation/lable.PNG -------------------------------------------------------------------------------- /graph presentation/s1-groundtruth-plot.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osu-crypto/secure-kmean-clustering/cd9fd7145fd0d0349beae9ff1370dcece2239767/graph presentation/s1-groundtruth-plot.xls -------------------------------------------------------------------------------- /libCluster/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #project(libOTe_Tests) 3 | 4 | file(GLOB_RECURSE SRCS *.cpp) 5 | add_library(libCluster STATIC ${SRCS}) 6 | 7 | target_include_directories(libCluster PUBLIC ${CMAKE_SOURCE_DIR}) 8 | target_link_libraries(libCluster libOTe cryptoTools ivory) 9 | -------------------------------------------------------------------------------- /libCluster/Common.cpp: -------------------------------------------------------------------------------- 1 | //#include "stdafx.h" 2 | #include "Common.h" 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | //using namespace osuCrypto; 9 | 10 | namespace osuCrypto 11 | { 12 | static std::fstream* file = nullptr; 13 | std::string SolutionDir = "../../"; 14 | 15 | void InitDebugPrinting(std::string filePath) 16 | { 17 | std::cout << "changing sink" << std::endl; 18 | 19 | if (file == nullptr) 20 | { 21 | file = new std::fstream; 22 | } 23 | else 24 | { 25 | file->close(); 26 | } 27 | 28 | file->open(filePath, std::ios::trunc | std::ofstream::out); 29 | 30 | if (!file->is_open()) 31 | throw UnitTestFail(); 32 | 33 | //time_t now = time(0); 34 | 35 | std::cout.rdbuf(file->rdbuf()); 36 | std::cerr.rdbuf(file->rdbuf()); 37 | //Log::SetSink(*file); 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /libCluster/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use. 3 | #include 4 | 5 | namespace osuCrypto 6 | { 7 | // 8 | void InitDebugPrinting(std::string file = "../../testout.txt"); 9 | // 10 | extern std::string SolutionDir; 11 | 12 | class UnitTestFail : public std::exception 13 | { 14 | std::string mWhat; 15 | public: 16 | explicit UnitTestFail(std::string reason) 17 | :std::exception(), 18 | mWhat(reason) 19 | {} 20 | 21 | explicit UnitTestFail() 22 | :std::exception(), 23 | mWhat("UnitTestFailed exception") 24 | { 25 | } 26 | 27 | virtual const char* what() const throw() 28 | { 29 | return mWhat.c_str(); 30 | } 31 | }; 32 | 33 | } -------------------------------------------------------------------------------- /libCluster/Tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use. 3 | 4 | namespace osuCrypto 5 | { 6 | 7 | void AdaptiveMUL_Zn_test(); 8 | void AdaptiveMUL_test(); 9 | void readData_test(); 10 | 11 | 12 | void MulTest(); 13 | void DistTest(); 14 | 15 | void testCircuit(); 16 | void testMinDistFirstLevel(); 17 | void testMinDist(); 18 | void ClusteringTest(); 19 | void testMinDist_Baseline(); 20 | //void plaintextClustering(); 21 | void testAccurancy(); 22 | //void testDecAES(); 23 | void testAccurancy_new(); 24 | 25 | 26 | void testUpdateCluster(); 27 | } -------------------------------------------------------------------------------- /libCluster/libCluster.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | -------------------------------------------------------------------------------- /libCluster/libCluster.vcxproj.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {3009BA72-CE9A-404F-83F4-C72AD4DC0240} 15 | libOTe_Tests 16 | libCluster 17 | 10.0 18 | 19 | 20 | 21 | StaticLibrary 22 | true 23 | v142 24 | MultiByte 25 | 26 | 27 | StaticLibrary 28 | false 29 | v142 30 | true 31 | MultiByte 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Level3 49 | Disabled 50 | true 51 | $(ProjectDir)../Ivory-Runtime/;$(ProjectDir)../Ivory-Runtime;$(ProjectDir)../Ivory-Runtime/ivory;$(ProjectDir)..;$(ProjectDir)../libOTe/;$(ProjectDir)../libOTe/libOTe/;$(ProjectDir)../libOTe/cryptoTools/;$(ProjectDir)../libOTe/cryptoTools/cryptoTools;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\boost\;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\;$(ProjectDir)../libOTe/cryptoTools/thirdparty/win/miracl;C:/libs/boost;C:/libs/;C:/libs/miracl 52 | MultiThreadedDebug 53 | SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501;_MBCS;_CRT_SECURE_NO_WARNINGS;-D_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 54 | true 55 | true 56 | false 57 | 58 | 59 | 60 | 61 | Level3 62 | MaxSpeed 63 | true 64 | true 65 | true 66 | $(ProjectDir)../libOTe;$(ProjectDir)../libOTe/cryptoTools/;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\boost\;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\;$(ProjectDir)../libOTe/cryptoTools/thirdparty/win/miracl;C:/libs/boost;C:/libs/;C:/libs/miracl 67 | MultiThreaded 68 | SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions) 69 | true 70 | true 71 | 72 | 73 | true 74 | true 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /libOTe_config/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8) 2 | 3 | project(libOTe) 4 | 5 | if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") 6 | 7 | ############################################ 8 | # If top level cmake # 9 | ############################################ 10 | 11 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin) 12 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) 13 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) 14 | 15 | ############################################ 16 | # Flag and #defines # 17 | ############################################ 18 | add_definitions(-DSOLUTION_DIR='${CMAKE_SOURCE_DIR}') 19 | set(CMAKE_C_FLAGS "-ffunction-sections -Wall -maes -msse2 -msse4.1 -mpclmul -Wfatal-errors -pthread -Wno-strict-overflow -Wno-ignored-attributes") 20 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14") 21 | 22 | # Select flags. 23 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG") 24 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO " -O2 -g -ggdb -rdynamic") 25 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb -rdynamic") 26 | 27 | ############################################ 28 | # Build mode checks # 29 | ############################################ 30 | 31 | # Set a default build type for single-configuration 32 | # CMake generators if no build type is set. 33 | if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) 34 | SET(CMAKE_BUILD_TYPE Release) 35 | endif() 36 | 37 | if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Release") 38 | message(WARNING "\nConfiguration NOT set to Release. Please call cmake with -DCMAKE_BUILD_TYPE=Release instead of ${CMAKE_BUILD_TYPE}") 39 | 40 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") 41 | #message(WARNING "Debug build.") 42 | elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") 43 | #message(WARNING "Release build.") 44 | elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO") 45 | #message(WARNING "RELWITHDEBINFO=Release with debug info build.") 46 | else() 47 | message(ERROR ": Unknown build type - ${CMAKE_BUILD_TYPE} Please use one of Debug, Release, or RELWITHDEBINFO\n\n" ) 48 | endif() 49 | endif() 50 | 51 | 52 | endif() 53 | 54 | 55 | ############################################# 56 | # Build cryptoTools (common utilities) # 57 | ############################################# 58 | #include_directories(cryptoTools) 59 | add_subdirectory(cryptoTools) 60 | 61 | 62 | ############################################# 63 | # Build libOTe # 64 | ############################################# 65 | add_subdirectory(libOTe) 66 | add_subdirectory(libOTe_Tests) 67 | 68 | ############################################# 69 | # Build Frontend # 70 | ############################################# 71 | #add_subdirectory(frontend) 72 | 73 | #add_subdirectory(SimplestOT) 74 | -------------------------------------------------------------------------------- /libOTe_config/libOTe/Base/SimplestOT.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use. 3 | 4 | #define NO_SIMPLEST_OT 5 | 6 | #if defined(__linux__) && not defined(NO_SIMPLEST_OT) 7 | #define ENABLE_SIMPLEST_OT 8 | #endif 9 | 10 | 11 | #ifdef ENABLE_SIMPLEST_OT 12 | #include "libOTe/TwoChooseOne/OTExtInterface.h" 13 | #include 14 | #include 15 | 16 | 17 | 18 | namespace osuCrypto 19 | { 20 | 21 | 22 | class SimplestOT : public OtReceiver, public OtSender 23 | { 24 | public: 25 | 26 | 27 | void receive( 28 | const BitVector& choices, 29 | span messages, 30 | PRNG& prng, 31 | Channel& chl, 32 | u64 numThreads) 33 | { 34 | receive(choices, messages, prng, chl); 35 | } 36 | 37 | void send( 38 | span> messages, 39 | PRNG& prng, 40 | Channel& chl, 41 | u64 numThreads) 42 | { 43 | send(messages, prng, chl); 44 | } 45 | 46 | void receive( 47 | const BitVector& choices, 48 | span messages, 49 | PRNG& prng, 50 | Channel& chl) override; 51 | 52 | void send( 53 | span> messages, 54 | PRNG& prng, 55 | Channel& chl) override; 56 | }; 57 | } 58 | 59 | #endif -------------------------------------------------------------------------------- /libOTe_config/libOTe/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #project(libOTe) 3 | 4 | file(GLOB_RECURSE SRCS *.cpp) 5 | #include_directories(${CMAKE_SOURCE_DIR}) 6 | add_library(libOTe STATIC ${SRCS}) 7 | 8 | target_include_directories(libOTe PUBLIC ${CMAKE_SOURCE_DIR}) 9 | target_link_libraries(libOTe cryptoTools) 10 | 11 | ############################################# 12 | # Install # 13 | ############################################# 14 | 15 | # install library 16 | install(TARGETS libOTe DESTINATION lib) 17 | 18 | # install headers 19 | install(DIRECTORY . DESTINATION include/libOTe FILES_MATCHING PATTERN "*.h") 20 | -------------------------------------------------------------------------------- /script_compr.get: -------------------------------------------------------------------------------- 1 | /scratch/setup-network status >> output_comprCryptoSub 2 | 3 | echo "=======================================================" >> output_comprCryptoSub 4 | 5 | ./bin/frontend.exe -r 1 -n 8 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 8 -t 8 >> output_comprCryptoSub 6 | sleep 10 7 | 8 | echo "=================================" >> output_comprCryptoSub 9 | 10 | ./bin/frontend.exe -r 1 -n 8 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 8 -t 8 >> output_comprCryptoSub 11 | sleep 10 12 | 13 | echo "=======================================================" >> output_comprCryptoSub 14 | echo "=======================================================" >> output_comprCryptoSub 15 | 16 | 17 | ./bin/frontend.exe -r 1 -n 10 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 10 -t 8 >> output_comprCryptoSub 18 | sleep 10 19 | 20 | echo "=================================" >> output_comprCryptoSub 21 | 22 | ./bin/frontend.exe -r 1 -n 10 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 10 -t 8 >> output_comprCryptoSub 23 | sleep 10 24 | 25 | 26 | 27 | echo "=======================================================" >> output_comprCryptoSub 28 | echo "=======================================================" >> output_comprCryptoSub 29 | 30 | ./bin/frontend.exe -r 1 -n 12 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 12 -t 8 >> output_comprCryptoSub 31 | sleep 10 32 | 33 | echo "=================================" >> output_comprCryptoSub 34 | 35 | ./bin/frontend.exe -r 1 -n 12 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 12 -t 8 >> output_comprCryptoSub 36 | sleep 10 37 | 38 | echo "=======================================================" >> output_comprCryptoSub 39 | echo "=======================================================" >> output_comprCryptoSub 40 | 41 | ./bin/frontend.exe -r 1 -n 14 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 14 -t 8 >> output_comprCryptoSub 42 | sleep 10 43 | 44 | echo "=================================" >> output_comprCryptoSub 45 | 46 | ./bin/frontend.exe -r 1 -n 14 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 14 -t 8 >> output_comprCryptoSub 47 | sleep 10 48 | 49 | 50 | echo "=======================================================" >> output_comprCryptoSub 51 | echo "=======================================================" >> output_comprCryptoSub 52 | 53 | ./bin/frontend.exe -r 1 -n 16 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 16 -t 8 >> output_comprCryptoSub 54 | sleep 10 55 | 56 | echo "=================================" >> output_comprCryptoSub 57 | 58 | ./bin/frontend.exe -r 1 -n 16 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 16 -t 8 >> output_comprCryptoSub 59 | sleep 10 60 | 61 | echo "=======================================================" >> output_comprCryptoSub 62 | echo "=======================================================" >> output_comprCryptoSub 63 | 64 | ./bin/frontend.exe -r 1 -n 18 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 18 -t 8 >> output_comprCryptoSub 65 | sleep 10 66 | 67 | echo "=================================" >> output_comprCryptoSub 68 | 69 | ./bin/frontend.exe -r 1 -n 18 -t 8 >> output_comprCryptoSub & ./bin/frontend.exe -r 0 -n 18 -t 8 >> output_comprCryptoSub 70 | sleep 10 71 | 72 | 73 | --------------------------------------------------------------------------------