├── .gitignore
├── .gitmodules
├── CMakeLists.txt
├── CMakePresets.json
├── LICENSE
├── README.md
├── build.py
├── cmake
├── Config.cmake.in
├── buildOptions.cmake
├── findDependancies.cmake
├── install.cmake
├── libPSIConfig.cmake
└── preamble.cmake
├── frontend
├── CMakeLists.txt
├── DrrnPSIMain.cpp
├── OtBinMain.cpp
├── OtBinMain.h
├── bloomFilterMain.cpp
├── bloomFilterMain.h
├── cuckoo
│ ├── SimpleCuckoo.cpp
│ ├── SimpleCuckoo.h
│ ├── bounds.xlsx
│ ├── bounds2.xlsx
│ ├── cuckooTests.cpp
│ ├── cuckooTests.h
│ └── stashSize_2h.txt
├── dcwMain.cpp
├── dcwMain.h
├── dktMain.cpp
├── dktMain.h
├── ecdhMain.cpp
├── ecdhMain.h
├── frontend.vcxproj
├── main.cpp
├── util.cpp
└── util.h
├── libPSI
├── CMakeLists.txt
├── MPSI
│ ├── DKT
│ │ ├── DktMPsiReceiver.cpp
│ │ ├── DktMPsiReceiver.h
│ │ ├── DktMPsiSender.cpp
│ │ └── DktMPsiSender.h
│ ├── Grr18
│ │ ├── Grr18Common.cpp
│ │ ├── Grr18Common.h
│ │ ├── Grr18MPsiReceiver.cpp
│ │ ├── Grr18MPsiReceiver.h
│ │ ├── Grr18MPsiSender.cpp
│ │ ├── Grr18MPsiSender.h
│ │ ├── bayesian.gp
│ │ ├── bayesian.ps1
│ │ ├── bayesian2.gp
│ │ ├── bayesian3.gp
│ │ ├── gp_history.txt
│ │ └── output.txt
│ ├── Rr16
│ │ ├── AknBfMPsiReceiver.cpp
│ │ ├── AknBfMPsiReceiver.h
│ │ ├── AknBfMPsiSender.cpp
│ │ └── AknBfMPsiSender.h
│ └── Rr17
│ │ ├── Rr17MPsiDefines.h
│ │ ├── Rr17a
│ │ ├── Rr17aMPsiReceiver.cpp
│ │ ├── Rr17aMPsiReceiver.h
│ │ ├── Rr17aMPsiSender.cpp
│ │ └── Rr17aMPsiSender.h
│ │ └── Rr17b
│ │ ├── Rr17bMPsiReceiver.cpp
│ │ ├── Rr17bMPsiReceiver.h
│ │ ├── Rr17bMPsiSender.cpp
│ │ └── Rr17bMPsiSender.h
├── PIR
│ ├── BgiPirClient.cpp
│ ├── BgiPirClient.h
│ ├── BgiPirServer.cpp
│ └── BgiPirServer.h
├── PSI
│ ├── Dcw
│ │ ├── DcwRBfPsiReceiver.cpp
│ │ ├── DcwRBfPsiReceiver.h
│ │ ├── DcwRBfPsiSender.cpp
│ │ └── DcwRBfPsiSender.h
│ ├── Drrn
│ │ ├── DrrnPsiClient.cpp
│ │ ├── DrrnPsiClient.h
│ │ ├── DrrnPsiServer.cpp
│ │ └── DrrnPsiServer.h
│ ├── ECDH
│ │ ├── EcdhPsiReceiver.cpp
│ │ ├── EcdhPsiReceiver.h
│ │ ├── EcdhPsiSender.cpp
│ │ └── EcdhPsiSender.h
│ ├── Kkrt
│ │ ├── KkrtPsiReceiver.cpp
│ │ ├── KkrtPsiReceiver.h
│ │ ├── KkrtPsiSender.cpp
│ │ └── KkrtPsiSender.h
│ └── Prty
│ │ ├── Poly
│ │ ├── polyFFT.cpp
│ │ ├── polyFFT.h
│ │ ├── polyFFT2.cpp
│ │ ├── polyFFT2.h
│ │ ├── polyNTL.cpp
│ │ └── polyNTL.h
│ │ ├── PrtyDefines.h
│ │ ├── PrtyReceiver.cpp
│ │ ├── PrtyReceiver.h
│ │ ├── PrtySender.cpp
│ │ └── PrtySender.h
├── Tools
│ ├── BalancedIndex.cpp
│ ├── BalancedIndex.h
│ ├── CuckooHasher.cpp
│ ├── CuckooHasher.h
│ ├── CuckooIndex2.cpp
│ ├── CuckooIndex2.h
│ ├── RandomShuffle.cpp
│ ├── RandomShuffle.h
│ ├── SimpleHasher.cpp
│ ├── SimpleHasher.h
│ ├── SimpleIndex.cpp
│ ├── SimpleIndex.h
│ ├── fileBased.cpp
│ └── fileBased.h
├── Version.cpp
├── Version.h
└── config.h.in
├── libPSI_Tests
├── AknBfPsi_Tests.cpp
├── AknBfPsi_Tests.h
├── BgiPirTests.cpp
├── BgiPirTests.h
├── BinOtPsi_Tests.cpp
├── BinOtPsi_Tests.h
├── CMakeLists.txt
├── Common.cpp
├── Common.h
├── DcwBfPsi_Tests.cpp
├── DcwBfPsi_Tests.h
├── DktMPsi_Tests.cpp
├── DktMPsi_Tests.h
├── DrrnPsi_Tests.cpp
├── DrrnPsi_Tests.h
├── EcdhPsi_Tests.cpp
├── EcdhPsi_Tests.h
├── FileBase_Tests.cpp
├── FileBase_Tests.h
├── Grr18MPSI_Tests.cpp
├── Grr18MPSI_Tests.h
├── ShamirSSScheme_Tests.cpp
├── ShamirSSScheme_Tests.h
├── UnitTests.cpp
└── UnitTests.h
└── thirdparty
├── fetch.cmake
├── getLibOTe.cmake
└── getSparsehash.cmake
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs/
2 | out/
3 | CMakeSettings.json
4 | thirdparty/
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osu-crypto/libPSI/1159df1fecad06570ec384d64ab0724d05b6905b/.gitmodules
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required (VERSION 3.18)
2 |
3 | project("libPSI" VERSION 1.0.0)
4 |
5 | # sets some variables
6 | include(cmake/preamble.cmake)
7 |
8 | # sets build option
9 | include(cmake/buildOptions.cmake)
10 |
11 | # find all the dependancies.
12 | include(cmake/findDependancies.cmake)
13 |
14 | add_definitions(-DSOLUTION_DIR=\"${CMAKE_SOURCE_DIR}\")
15 |
16 | #############################################
17 | # Build libPSI #
18 | #############################################
19 |
20 | add_subdirectory(libPSI)
21 | add_subdirectory(libPSI_Tests)
22 | add_subdirectory(frontend)
23 |
24 |
25 |
26 | # setup the install
27 | include(cmake/install.cmake)
--------------------------------------------------------------------------------
/CMakePresets.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 2,
3 | "configurePresets": [
4 | {
5 | "name": "linux",
6 | "displayName": "Linux",
7 | "description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.",
8 | "generator": "Ninja",
9 | "binaryDir": "${sourceDir}/out/build/${presetName}",
10 | "cacheVariables": {
11 | "CMAKE_BUILD_TYPE": "Release",
12 | "ENABLE_ALL_PSI": true,
13 | "FETCH_AUTO": true,
14 | "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
15 | },
16 | "vendor": {
17 | "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Linux" ] },
18 | "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" }
19 | }
20 | },
21 | {
22 | "name": "x64-Debug",
23 | "displayName": "Windows x64 Debug",
24 | "description": "Target Windows with the Visual Studio development environment.",
25 | "generator": "Ninja",
26 | "binaryDir": "${sourceDir}/out/build/${presetName}",
27 | "architecture": {
28 | "value": "x64",
29 | "strategy": "external"
30 | },
31 | "cacheVariables": {
32 | "CMAKE_BUILD_TYPE": "Debug",
33 | "FETCH_AUTO": true,
34 | "ENABLE_ALL_PSI": true,
35 | "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
36 | },
37 | "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
38 | },
39 | {
40 | "name": "x64-Release",
41 | "displayName": "Windows x64 Release",
42 | "description": "Target Windows with the Visual Studio development environment.",
43 | "generator": "Ninja",
44 | "binaryDir": "${sourceDir}/out/build/${presetName}",
45 | "architecture": {
46 | "value": "x64",
47 | "strategy": "external"
48 | },
49 | "cacheVariables": {
50 | "CMAKE_BUILD_TYPE": "RelWithDebInfo",
51 | "FETCH_AUTO": true,
52 | "ENABLE_ALL_PSI": true,
53 | "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
54 | },
55 | "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
56 | },
57 | {
58 | "name": "osx",
59 | "displayName": "Custom configure preset",
60 | "description": "Sets Ninja generator, build and install directory",
61 | "generator": "Unix Makefiles",
62 | "binaryDir": "${sourceDir}/out/build/${presetName}",
63 | "cacheVariables": {
64 | "FETCH_AUTO": true,
65 | "ENABLE_ALL_PSI": true,
66 | "CMAKE_BUILD_TYPE": "Release",
67 | "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
68 | },
69 | "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "macOS" ] } }
70 | }
71 | ]
72 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Dual-licensed under Unlicense or MIT.
2 |
3 |
4 | ----------------------- Unlicense ---------------------------
5 |
6 | This is free and unencumbered software released into the public domain.
7 |
8 | Anyone is free to copy, modify, publish, use, compile, sell, or
9 | distribute this software, either in source code form or as a compiled
10 | binary, for any purpose, commercial or non-commercial, and by any
11 | means.
12 |
13 | In jurisdictions that recognize copyright laws, the author or authors
14 | of this software dedicate any and all copyright interest in the
15 | software to the public domain. We make this dedication for the benefit
16 | of the public at large and to the detriment of our heirs and
17 | successors. We intend this dedication to be an overt act of
18 | relinquishment in perpetuity of all present and future rights to this
19 | software under copyright law.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | OTHER DEALINGS IN THE SOFTWARE.
28 |
29 | For more information, please refer to
30 |
31 |
32 | ----------------------- MIT ---------------------------
33 | Copyright 2021 Peter Rindal
34 |
35 | Permission is hereby granted, free of charge, to any person obtaining a copy of this
36 | software and associated documentation files (the "Software"), to deal in the Software
37 | without restriction, including without limitation the rights to use, copy, modify,
38 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
39 | permit persons to whom the Software is furnished to do so, subject to the following
40 | conditions:
41 |
42 | The above copyright notice and this permission notice shall be included in all copies
43 | or substantial portions of the Software.
44 |
45 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
46 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
47 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
48 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
49 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
50 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51 |
52 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # libPSI
2 | A repository for private set intersection. Most protocols were written just for benchmarking them while (RR17,KKRT,Mea86=ECDH) can be run from the command line and take a file as input. Run the program for details.
3 |
4 | ## VolePSI
5 | Also consider using https://github.com/Visa-Research/volepsi/ for improved performance.
6 |
7 | ## Introduction
8 | Protocols:
9 |
10 | * Malicious Secure [RR17](https://eprint.iacr.org/2017/769) based on simple hashing and OTs (fastest)
11 | * Malicious Secure [RR16](https://eprint.iacr.org/2016/746) based on Bloom filters and OTs
12 | * Malicious Secure [DKT10](https://eprint.iacr.org/2010/469) based on public key crypto (ECC)
13 | * Semi-Honest Secure [KKRT16](https://eprint.iacr.org/2016/799) based on cuckoo hashing and OTs (fastest)
14 | * Semi-Honest Secure [Mea86](http://ieeexplore.ieee.org/document/6234849/) base on public key crypto (ECC)
15 | * Semi-Honest Secure [DRRT18](https://eprint.iacr.org/2018/579.pdf) based on cuckoo hashing, PIR and OTs (fastest unbalanced)
16 |
17 | ## Install
18 |
19 | Our library is cross platform and has been tested on both Windows and Linux. The library should work on Mac but it has not been tested. There are several library dependencies including [libOTe](https://github.com/osu-crypto/libOte).
20 |
21 |
22 | ```
23 | git clone https://github.com/osu-crypto/libPSI.git
24 | cd libPSI
25 | python build.py
26 | ```
27 |
28 | Unit tests can be run by executing the program.
29 |
30 | ```
31 | /out/build//frontend/frontend.exe -u
32 | ```
33 | Other options can be seen by executing with no arguments.
34 | ## Help
35 |
36 | Contact Peter Rindal `peterrindal@gmail.com` for any assistance on building or running the library.
37 |
--------------------------------------------------------------------------------
/build.py:
--------------------------------------------------------------------------------
1 | import os
2 | import platform
3 | import sys
4 | import multiprocessing
5 | import subprocess
6 | import glob
7 |
8 | # find the ninja generator on windows.
9 | def getGenerator(args):
10 | #osStr = (platform.system())
11 | #
12 | #if osStr == "Windows":
13 | #
14 | # for x in args:
15 | # if x.startswith("-G"):
16 | # break
17 | #
18 | # vswhereArgs = ['C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe', "-prerelease", "-latest", "-property", "installationPath"]
19 | # rootpath = subprocess.check_output(vswhereArgs).decode("utf-8").strip()
20 | #
21 | # ninja = rootpath + "/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/CMAKE/Ninja/ninja.exe"
22 | # cl = rootpath + "/VC/Tools/MSVC/*/bin/Hostx64/x64/cl.exe"
23 | # cls = glob.glob(cl)
24 | # if len(cls) > 0:
25 | # cl = cls[-1];
26 | #
27 | # # use ninja
28 | # if os.path.exists(ninja) and os.path.exists(cl):
29 | # return "-G \"Ninja\" -DCMAKE_MAKE_PROGRAM=\"{0}\" -DCMAKE_C_COMPILER:FILEPATH=\"{1}\" -DCMAKE_CXX_COMPILER:FILEPATH=\"{1}\" ".format(ninja, cl)
30 | # else:
31 | # print("failed to find ninja at: {0}\n or cl".format(ninja))
32 | #
33 | # use the default
34 | return ""
35 |
36 |
37 | def parseInstallArgs(args):
38 | prefix = ""
39 | doInstall = False
40 | for x in args:
41 | if x.startswith("--install="):
42 | prefix = x.split("=",1)[1]
43 | prefix = os.path.abspath(os.path.expanduser(prefix))
44 | idx = args.index(x)
45 | args[idx] = "-DCMAKE_INSTALL_PREFIX=" + prefix
46 | doInstall = True
47 | if x == "--install":
48 | idx = args.index(x)
49 | osStr = (platform.system())
50 | if osStr == "Windows":
51 | args[idx] = "-DCMAKE_INSTALL_PREFIX=c:/lib"
52 | else:
53 | args[idx] = "-DCMAKE_INSTALL_PREFIX=/usr/local"
54 | doInstall = True
55 |
56 | return (args, doInstall)
57 |
58 | def getParallel(args):
59 | par = multiprocessing.cpu_count()
60 | for x in args:
61 | if x.startswith("--par="):
62 | val = x.split("=",1)[1]
63 | par = int(val)
64 | if par < 1:
65 | par = 1
66 | idx = args.index(x)
67 | args[idx] = ""
68 | return (args,par)
69 |
70 |
71 | def replace(list, find, replace):
72 | if find in list:
73 | idx = list.index(find)
74 | list[idx] = replace;
75 | return list
76 |
77 | def Build(projectName, argv):
78 |
79 | osStr = (platform.system())
80 | buildDir = ""
81 | config = ""
82 | buildType = ""
83 |
84 | # use sudo when installing?
85 | sudo = "--sudo" in argv;
86 | argv = replace(argv, "--sudo", "-DSUDO_FETCH=ON")
87 | if not sudo:
88 | argv.append("-DSUDO_FETCH=OFF")
89 |
90 | argv.append("-DENABLE_ALL_PSI=ON")
91 | generator = getGenerator(argv)
92 |
93 | # do not automaticly download dependancies
94 | if "--noauto" in argv:
95 | argv = replace(argv, "--noauto", "")
96 | argv.append("-DFETCH_AUTO=OFF")
97 | else:
98 | argv.append("-DFETCH_AUTO=ON")
99 |
100 | # get install options
101 | argv, install = parseInstallArgs(argv)
102 |
103 | # get parallel build options
104 | argv, par = getParallel(argv)
105 | argv.append("-DPARALLEL_FETCH="+str(par))
106 |
107 | # do not run cmake config
108 | noConfig = "--nc" in argv
109 | argv = replace(argv, "--nc", "")
110 |
111 | # only run cmake config.
112 | setup = "--setup" in argv;
113 | argv = replace(argv, "--setup", "")
114 |
115 | # build type.
116 | if "--debug" in argv:
117 | buildType = "Debug"
118 | else:
119 | buildType = "Release"
120 | argv.append("-DCMAKE_BUILD_TYPE={0}".format(buildType))
121 | argv = replace(argv, "--debug", "")
122 |
123 | # build dir
124 | if osStr == "Windows":
125 | buildDir = "out/build/x64-{0}".format(buildType)
126 | config = "--config {0}".format(buildType)
127 | elif osStr == "Darwin":
128 | buildDir = "out/build/osx"
129 | else:
130 | buildDir = "out/build/linux"
131 |
132 | # convert args to a string.
133 | argStr = ""
134 | for a in argv:
135 | argStr = argStr + " " + a
136 |
137 | # parallel build
138 | parallel = ""
139 | if par != 1:
140 | parallel = " --parallel " + str(par)
141 |
142 |
143 | # build commands
144 | mkDirCmd = "mkdir -p {0}".format(buildDir);
145 | CMakeCmd = "cmake {0} -S . -B {1} {2} ".format(generator, buildDir, argStr)
146 | BuildCmd = "cmake --build {0} {1} {2} ".format(buildDir, config, parallel)
147 | InstallCmd = ""
148 | if sudo:
149 | sudo = "sudo "
150 | else:
151 | sudo = ""
152 | if install:
153 | InstallCmd = sudo
154 | InstallCmd += "cmake --install {0} {1} ".format(buildDir, config)
155 |
156 | # print and execute commands.
157 | print("\n\n====== build.py ("+projectName+") ========")
158 | if not noConfig:
159 | print(mkDirCmd)
160 | print(CMakeCmd)
161 |
162 | if not setup:
163 | print(BuildCmd)
164 | if len(InstallCmd):
165 | print(InstallCmd)
166 | print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\n")
167 |
168 | if not noConfig:
169 | os.system(mkDirCmd)
170 | os.system(CMakeCmd)
171 |
172 | if not setup:
173 | os.system(BuildCmd)
174 |
175 | if len(sudo) > 0:
176 | print("installing "+projectName+": {0}\n".format(InstallCmd))
177 |
178 | os.system(InstallCmd)
179 |
180 |
181 |
182 | def help():
183 |
184 | print(" --install \n\tInstructs the script to install whatever is currently being built to the default location.")
185 | print(" --install=prefix \n\tinstall to the provided predix.")
186 | print(" --sudo \n\twhen installing, use sudo. May require password.")
187 | print(" --par=n \n\twhen building do use parallel builds with n threads. default = num cores.")
188 | print(" --noauto \n\twhen building do not automaticly fetch dependancies.")
189 | print(" --par=n \n\twhen building do use parallel builds with n threads. default = num cores.")
190 | print(" --debug \n\tdebug build.")
191 | print("any additioanl arguments are forwared to cmake.\n")
192 |
193 | print("-build the library")
194 | print(" python build.py")
195 | print("-build the library with cmake configurations")
196 | print(" python build.py --debug -DLIBPSI_ENABLE_X=ON")
197 | print("-build the library and install with sudo")
198 | print(" python build.py --install --sudo")
199 | print("-build the library and install to prefix")
200 | print(" python build.py --install=~/my/install/dir ")
201 |
202 |
203 |
204 | def main(projectName, argv):
205 |
206 | if "--help" in argv:
207 | help()
208 | return
209 |
210 | # build the project.
211 | Build(projectName, argv)
212 |
213 | if __name__ == "__main__":
214 |
215 | main("LIBPSI", sys.argv[1:])
216 |
--------------------------------------------------------------------------------
/cmake/Config.cmake.in:
--------------------------------------------------------------------------------
1 | @PACKAGE_INIT@
2 |
3 | include("${CMAKE_CURRENT_LIST_DIR}/libPSITargets.cmake")
4 |
5 | # when someone finds our project, we must then find our depandancies.
6 | include("${CMAKE_CURRENT_LIST_DIR}/findDependancies.cmake")
7 |
8 | # define any variables you want consumers of your library ro be able to see.
9 | set(LIBPSI_ENABLE_X @LIBPSI_ENABLE_X@)
10 |
11 | # set the library location and header location info from the target.
12 | get_target_property(libPSI_INCLUDE_DIRS oc::libPSI INTERFACE_INCLUDE_DIRECTORIES)
13 | get_target_property(libPSI_LIBRARIES oc::libPSI LOCATION)
14 |
15 | # print helper info on where the project was found.
16 | message("libPSI_INCLUDE_DIRS=${libPSI_INCLUDE_DIRS}")
17 | message("libPSI_LIBRARIES=${libPSI_LIBRARIES}")
18 |
--------------------------------------------------------------------------------
/cmake/buildOptions.cmake:
--------------------------------------------------------------------------------
1 | #helper macro to assign a boolean variable
2 | macro(SET_BOOL var)
3 | if(${ARGN})
4 | set(${var} ON)
5 | else()
6 | set(${var} OFF)
7 | endif()
8 | endmacro()
9 |
10 | option(FETCH_AUTO "automaticly download and build dependancies" OFF)
11 |
12 | # here we have to do some special logic to determine if we should
13 | # automaticly download sparsehash. This is done if we used
14 | #
15 | # does not define FETCH_SPARSEHASH and define FETCH_AUTO
16 | # or
17 | # define FETCH_SPARSEHASH as True/ON
18 | SET_BOOL(FETCH_SPARSEHASH_AUTO
19 | (DEFINED FETCH_SPARSEHASH AND FETCH_SPARSEHASH) OR
20 | ((NOT DEFINED FETCH_SPARSEHASH) AND (FETCH_AUTO)))
21 |
22 | # here we have to do some special logic to determine if we should
23 | # automaticly download sparsehash. This is done if we used
24 | #
25 | # does not define FETCH_LIBOTE and define FETCH_AUTO
26 | # or
27 | # define FETCH_LIBOTE as True/ON
28 | SET_BOOL(FETCH_LIBOTE_AUTO
29 | (DEFINED FETCH_LIBOTE AND FETCH_LIBOTE) OR
30 | ((NOT DEFINED FETCH_LIBOTE) AND (FETCH_AUTO)))
31 |
32 |
33 | message(STATUS "fetch options\n=======================================================")
34 |
35 | message(STATUS "Option: FETCH_AUTO = ${FETCH_AUTO}")
36 | message(STATUS "Option: FETCH_SPARSEHASH = ${FETCH_SPARSEHASH}")
37 | message(STATUS "Option: FETCH_LIBOTE = ${FETCH_LIBOTE}\n")
38 |
39 |
40 | #############################################
41 | # CONFIGURE #
42 | #############################################
43 |
44 | if(DEFINED ENABLE_ALL_PSI)
45 | set(ENABLE_DCW_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
46 | set(ENABLE_DKT_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
47 | set(ENABLE_GRR_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
48 | set(ENABLE_RR16_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
49 | set(ENABLE_RR17_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
50 | set(ENABLE_RR17B_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
51 | set(ENABLE_KKRT_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
52 | set(ENABLE_ECDH_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
53 | set(ENABLE_DRRN_PSI ${ENABLE_ALL_PSI} CACHE BOOL "" FORCE)
54 | unset(ENABLE_ALL_PSI CACHE)
55 | endif()
56 |
57 |
58 | option(ENABLE_DCW_PSI "Build the DCW PSI protocol" OFF)
59 | option(ENABLE_DKT_PSI "Build the DKT PSI protocol" OFF)
60 | option(ENABLE_GRR_PSI "Build the GRR PSI protocol" OFF)
61 | option(ENABLE_RR16_PSI "Build the RR16 PSI protocol" OFF)
62 | option(ENABLE_RR17_PSI "Build the RR17 PSI protocol" OFF)
63 | option(ENABLE_RR17B_PSI "Build the RR17B PSI protocol" OFF)
64 | option(ENABLE_KKRT_PSI "Build the KKRT PSI protocol" OFF)
65 | option(ENABLE_ECDH_PSI "Build the EC DH PSI protocol" OFF)
66 | option(ENABLE_DRRN_PSI "Build the DRRN PSI protocol" OFF)
67 | option(ENABLE_PRTY_PSI "Build the PRTY PSI protocol" OFF)
68 | option(ENABLE_RELIC "Build with relic" ON)
69 | option(ENABLE_SODIUM "Build with sodium" OFF)
70 |
71 | if(NOT DEFINED LIBPSI_STD_VER)
72 | set(LIBPSI_STD_VER 20)
73 | endif()
74 |
75 | message(STATUS "General Options\n=======================================================")
76 | message(STATUS "Option: CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}\n\tRelease\n\tDebug\n\tRELWITHDEBINFO")
77 | message(STATUS "Option: ENABLE_ALL_PSI = ON/OFF\n\n")
78 |
79 | message(STATUS "PSI protocols\n=======================================================")
80 | message(STATUS "Option: ENABLE_DCW_PSI = ${ENABLE_DCW_PSI}")
81 | message(STATUS "Option: ENABLE_DKT_PSI = ${ENABLE_DKT_PSI}")
82 | message(STATUS "Option: ENABLE_GRR_PSI = ${ENABLE_GRR_PSI}")
83 | message(STATUS "Option: ENABLE_RR16_PSI = ${ENABLE_RR16_PSI}")
84 | message(STATUS "Option: ENABLE_RR17_PSI = ${ENABLE_RR17_PSI}")
85 | message(STATUS "Option: ENABLE_RR17B_PSI = ${ENABLE_RR17B_PSI}")
86 | message(STATUS "Option: ENABLE_KKRT_PSI = ${ENABLE_KKRT_PSI}")
87 | message(STATUS "Option: ENABLE_ECDH_PSI = ${ENABLE_ECDH_PSI}")
88 | message(STATUS "Option: ENABLE_DRRN_PSI = ${ENABLE_DRRN_PSI}\n")
89 |
90 | message(STATUS "Option: ENABLE_RELIC = ${ENABLE_RELIC}")
91 | message(STATUS "Option: ENABLE_SODIUM = ${ENABLE_SODIUM}\n")
92 |
93 |
94 | configure_file(libPSI/config.h.in libPSI/config.h)
95 |
96 |
97 |
--------------------------------------------------------------------------------
/cmake/findDependancies.cmake:
--------------------------------------------------------------------------------
1 | include(${CMAKE_CURRENT_LIST_DIR}/preamble.cmake)
2 |
3 |
4 | # here we find out depandancies. This happens when we build our project and
5 | # when someone includes our project via find_project(LIBPSI). As such,
6 | # we also have to make sure this also works when we are installed.
7 |
8 |
9 | message(STATUS "LIBPSI_THIRDPARTY_DIR=${LIBPSI_THIRDPARTY_DIR}")
10 |
11 | # cmake will look for out depandancies at the paths in CMAKE_PREFIX_PATH
12 | # if LIBPSI_THIRDPARTY_DIR is defined, we want this to be the first place
13 | # that is looked at. To make sure only our libraries are looked for here,
14 | # we will resort CMAKE_PREFIX_PATH to its old value at the end if the file.
15 | set(PUSHED_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH})
16 | set(CMAKE_PREFIX_PATH "${LIBPSI_THIRDPARTY_DIR};${CMAKE_PREFIX_PATH}")
17 |
18 |
19 | #######################################
20 | # sparsehash
21 |
22 |
23 | # here we will look for sparsehash and download it if requested.
24 | # sparsehash doesnt supports find_package so we look for it manually.
25 |
26 | # first we will define a macro because we might look for it more than once.
27 | macro(FIND_SPARSEHASH)
28 | # assign any macro arguemnts to the ARGS variable.
29 | set(ARGS ${ARGN})
30 |
31 | # If the user explicitly asked to fetch libOTe, then we dont want to
32 | # look for libOTe at any location other than LIBPSI_THIRDPARTY_DIR.
33 | # this is done with including NO_DEFAULT_PATH as an argument and
34 | # specifying where we want to look using PATHS
35 | if(FETCH_SPARSEHASH)
36 | list(APPEND ARGS NO_DEFAULT_PATH PATHS ${LIBPSI_THIRDPARTY_DIR})
37 | endif()
38 |
39 | # next we need to look for the sparsehash headers. One such header is dense_hash_map.
40 | # we expect this header to be at /include/sparsehash/dense_hash_map. We
41 | # will have cmake look for this file. cmake will look at system locations and paths
42 | # specified in the CMAKE_PREFIX_PATH variable.
43 | find_path(SPARSEHASH_INCLUDE_DIRS "sparsehash/dense_hash_map" PATH_SUFFIXES "include" ${ARGS}
44 | DOC "Use -DFETCH_AUTO=ON to automaticly download dependancies")
45 |
46 | # if you are linking a library you will also need to find that via find_library(...)
47 |
48 | # check if we found sparse hash.
49 | if(EXISTS ${SPARSEHASH_INCLUDE_DIRS})
50 | set(SPARSEHASH_FOUND ON)
51 | else()
52 | set(SPARSEHASH_FOUND OFF)
53 | endif()
54 | endmacro()
55 |
56 |
57 | # FETCH_SPARSEHASH_AUTO is set if we should download sparsehash. If we should,
58 | # then we first check if we already have it via the FIND_SPARSEHASH(QUIET)
59 | # call. Then we call the getSparsehash.cmake script to download sparsehash if
60 | # we dont already have it.
61 | if(FETCH_SPARSEHASH_AUTO)
62 | FIND_SPARSEHASH(QUIET)
63 | include(${CMAKE_CURRENT_LIST_DIR}/../thirdparty/getSparsehash.cmake)
64 | endif()
65 |
66 | FIND_SPARSEHASH(REQUIRED)
67 | message("SPARSEHASH_INCLUDE_DIRS=${SPARSEHASH_INCLUDE_DIRS}")
68 |
69 | # If the sparse ahsh target has not been previously defined, lets define it.
70 | if(NOT TARGET sparsehash)
71 |
72 | # since we didnt build sparse, we declare it as an IMPORTED target.
73 | # moreover, sparsehash is header only so we declare it as INTERFACE.
74 | add_library(sparsehash INTERFACE IMPORTED)
75 |
76 | #if sparsehash had an associated static library which we previously found, then
77 | # we could declare it as:
78 | #
79 | # add_library(sparsehash STATIC IMPORTED)
80 | # set_property(TARGET sparsehash PROPERTY IMPORTED_LOCATION ${SPARSEHASH_LIB})
81 |
82 | # in either case, we set the header directory as
83 | target_include_directories(sparsehash INTERFACE
84 | $
85 | $)
86 | endif()
87 |
88 |
89 |
90 | #######################################
91 | # libOTe
92 |
93 |
94 | # here we will look for libOTe and download it if requested.
95 | # libOTe supports find_package so its pretty easy.
96 |
97 | # first we will define a macro because we might look for it more than once.
98 | macro(FIND_LIBOTE)
99 |
100 | # assign any macro arguemnts to the ARGS variable.
101 | set(ARGS ${ARGN})
102 |
103 | # If the user explicitly asked to fetch libOTe, then we dont want to
104 | # look for libOTe at any location other than LIBPSI_THIRDPARTY_DIR.
105 | # this is done with including NO_DEFAULT_PATH as an argument and
106 | # specifying where we want to look using PATHS
107 | if(FETCH_LIBOTE)
108 | list(APPEND ARGS NO_DEFAULT_PATH PATHS ${LIBPSI_THIRDPARTY_DIR})
109 | endif()
110 |
111 | # look for libOTe. cmake will look at system locations and paths
112 | # specified in the CMAKE_PREFIX_PATH variable.
113 | #
114 | # libOTeConfig.cmake
115 | #
116 | # CMAKE_PREFIX_PATH/lib/cmake/libOTe/libOTeConfig.cmake
117 | # CMAKE_PREFIX_PATH/libOTe/cmake/libOTeConfig.cmake
118 | find_package(libOTe ${ARGS})
119 |
120 | # check if we found it.
121 | if(TARGET oc::libOTe)
122 | set(libOTe_FOUND ON)
123 | else()
124 | set(libOTe_FOUND OFF)
125 | endif()
126 | endmacro()
127 |
128 | # FETCH_LIBOTE_AUTO is set if we should download libOTe. If we should,
129 | # then we first check if we already have it via the FIND_LIBOTE(QUIET)
130 | # call. Then we call the getLibOTe.cmake script to download libOTe if
131 | # we dont already have it.
132 | if(FETCH_LIBOTE_AUTO)
133 | FIND_LIBOTE(QUIET)
134 | include(${CMAKE_CURRENT_LIST_DIR}/../thirdparty/getLibOTe.cmake)
135 | endif()
136 |
137 | # finally, we make sure we have found libOTe.
138 | FIND_LIBOTE(REQUIRED)
139 |
140 |
141 | # resort the previous prefix path
142 | set(CMAKE_PREFIX_PATH ${PUSHED_CMAKE_PREFIX_PATH})
143 |
--------------------------------------------------------------------------------
/cmake/install.cmake:
--------------------------------------------------------------------------------
1 |
2 |
3 | #############################################
4 | # Install #
5 | #############################################
6 |
7 | # we have to install these scripts since the we required
8 | # find our depandancies wheneven someone want to include
9 | # this project.
10 | configure_file("${CMAKE_CURRENT_LIST_DIR}/findDependancies.cmake" "findDependancies.cmake" COPYONLY)
11 | configure_file("${CMAKE_CURRENT_LIST_DIR}/preamble.cmake" "preamble.cmake" COPYONLY)
12 |
13 | # make cache variables for install destinations
14 | include(GNUInstallDirs)
15 | include(CMakePackageConfigHelpers)
16 |
17 | # generate the config file that is includes the exports
18 | configure_package_config_file(
19 | "${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in"
20 | "${CMAKE_CURRENT_BINARY_DIR}/libPSIConfig.cmake"
21 | INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libPSI
22 | NO_SET_AND_CHECK_MACRO
23 | NO_CHECK_REQUIRED_COMPONENTS_MACRO
24 | )
25 |
26 | if(NOT DEFINED libPSI_VERSION_MAJOR)
27 | message("\n\n\n\n warning, libPSI_VERSION_MAJOR not defined ${libPSI_VERSION_MAJOR}")
28 | endif()
29 |
30 | set_property(TARGET libPSI PROPERTY VERSION ${libPSI_VERSION})
31 |
32 | # generate the version file for the config file
33 | write_basic_package_version_file(
34 | "${CMAKE_CURRENT_BINARY_DIR}/libPSIConfigVersion.cmake"
35 | VERSION "${libPSI_VERSION_MAJOR}.${libPSI_VERSION_MINOR}.${libPSI_VERSION_PATCH}"
36 | COMPATIBILITY AnyNewerVersion
37 | )
38 |
39 | # install the configuration file
40 | install(FILES
41 | "${CMAKE_CURRENT_BINARY_DIR}/libPSIConfig.cmake"
42 | "${CMAKE_CURRENT_BINARY_DIR}/libPSIConfigVersion.cmake"
43 | "${CMAKE_CURRENT_BINARY_DIR}/findDependancies.cmake"
44 | "${CMAKE_CURRENT_BINARY_DIR}/preamble.cmake"
45 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libPSI
46 | )
47 |
48 | # install library
49 | install(
50 | TARGETS libPSI
51 | DESTINATION ${CMAKE_INSTALL_LIBDIR}
52 | EXPORT libPSITargets)
53 |
54 | # install headers
55 | install(
56 | DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libPSI"
57 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/"
58 | FILES_MATCHING PATTERN "*.h")
59 |
60 | # install config and use the "namespace" of oc::
61 | install(EXPORT libPSITargets
62 | FILE libPSITargets.cmake
63 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libPSI
64 | NAMESPACE oc::
65 | )
66 | export(EXPORT libPSITargets
67 | FILE "${CMAKE_CURRENT_BINARY_DIR}/libPSITargets.cmake"
68 | NAMESPACE oc::
69 | )
--------------------------------------------------------------------------------
/cmake/libPSIConfig.cmake:
--------------------------------------------------------------------------------
1 | # these are just pass through config file for the ones that are placed in the build directory.
2 |
3 |
4 | include("${CMAKE_CURRENT_LIST_DIR}/preamble.cmake")
5 |
6 | if(NOT EXISTS "${VOLEPSI_BUILD_DIR}")
7 | message(FATAL_ERROR "failed to find the volePSI build directory. Looked at VOLEPSI_BUILD_DIR: ${VOLEPSI_BUILD_DIR}\n Please set it manually.")
8 | endif()
9 |
10 | include("${VOLEPSI_BUILD_DIR}/volePSIConfig.cmake")
--------------------------------------------------------------------------------
/cmake/preamble.cmake:
--------------------------------------------------------------------------------
1 |
2 |
3 | if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
4 |
5 | ############################################
6 | # If top level cmake #
7 | ############################################
8 | if(MSVC)
9 | else()
10 | set(COMMON_FLAGS "-Wall -Wfatal-errors")
11 |
12 | if(NOT DEFINED NO_ARCH_NATIVE)
13 | set(COMMON_FLAGS "${COMMON_FLAGS} -march=native")
14 | endif()
15 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
16 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO " -O2 -g -ggdb")
17 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb")
18 | endif()
19 |
20 |
21 |
22 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
24 |
25 |
26 | ############################################
27 | # Build mode checks #
28 | ############################################
29 |
30 | # Set a default build type for single-configuration
31 | # CMake generators if no build type is set.
32 | if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
33 | SET(CMAKE_BUILD_TYPE Release)
34 | endif()
35 |
36 | if( NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Release"
37 | AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug"
38 | AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" )
39 |
40 | message(WARNING ": Unknown build type - \${CMAKE_BUILD_TYPE}=${CMAKE_BUILD_TYPE}. Please use one of Debug, Release, or RelWithDebInfo. e.g. call\n\tcmake . -DCMAKE_BUILD_TYPE=Release\n" )
41 | endif()
42 | endif()
43 |
44 | if(MSVC)
45 | set(LIBPSI_CONFIG_NAME "${CMAKE_BUILD_TYPE}")
46 | if("${LIBPSI_CONFIG_NAME}" STREQUAL "RelWithDebInfo" OR "${LIBPSI_CONFIG_NAME}" STREQUAL "")
47 | set(LIBPSI_CONFIG_NAME "Release")
48 | endif()
49 | set(LIBPSI_CONFIG "x64-${LIBPSI_CONFIG_NAME}")
50 | elseif(APPLE)
51 | set(LIBPSI_CONFIG "osx")
52 | else()
53 | set(LIBPSI_CONFIG "linux")
54 | endif()
55 |
56 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/install.cmake)
57 | set(LIBPSI_IN_BUILD_TREE ON)
58 | else()
59 | set(LIBPSI_IN_BUILD_TREE OFF)
60 | endif()
61 |
62 | if(LIBPSI_IN_BUILD_TREE)
63 |
64 | # we currenty are in the vole psi source tree, vole-psi/cmake
65 | if(NOT DEFINED LIBPSI_BUILD_DIR)
66 | set(LIBPSI_BUILD_DIR "${CMAKE_CURRENT_LIST_DIR}/../out/build/${LIBPSI_CONFIG}")
67 | get_filename_component(LIBPSI_BUILD_DIR ${LIBPSI_BUILD_DIR} ABSOLUTE)
68 | endif()
69 |
70 | if(NOT (${CMAKE_BINARY_DIR} STREQUAL ${LIBPSI_BUILD_DIR}))
71 | message(WARNING "incorrect build directory. \n\tCMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}\nbut expect\n\tLIBPSI_BUILD_DIR=${LIBPSI_BUILD_DIR}")
72 | endif()
73 |
74 | if(NOT DEFINED LIBPSI_THIRDPARTY_DIR)
75 | set(LIBPSI_THIRDPARTY_DIR "${CMAKE_CURRENT_LIST_DIR}/../out/install/${LIBPSI_CONFIG}")
76 | get_filename_component(LIBPSI_THIRDPARTY_DIR ${LIBPSI_THIRDPARTY_DIR} ABSOLUTE)
77 | endif()
78 | else()
79 | # we currenty are in install tree, /lib/cmake/vole-psi
80 | if(NOT DEFINED LIBPSI_THIRDPARTY_DIR)
81 | set(LIBPSI_THIRDPARTY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../..")
82 | get_filename_component(LIBPSI_THIRDPARTY_DIR ${LIBPSI_THIRDPARTY_DIR} ABSOLUTE)
83 | endif()
84 | endif()
85 |
86 |
--------------------------------------------------------------------------------
/frontend/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | #project(fronend)
3 |
4 |
5 |
6 |
7 | #############################################
8 | # Build fronend.exe #
9 | #############################################
10 |
11 | file(GLOB_RECURSE SRC_FRONTEND ${CMAKE_SOURCE_DIR}/frontend/*.cpp)
12 | include_directories(${CMAKE_SOURCE_DIR}/frontend/)
13 |
14 | add_executable(frontend.exe ${SRC_FRONTEND})
15 |
16 |
17 | #############################################
18 | # Link our libraries #
19 | #############################################
20 |
21 |
22 |
23 | #############################################
24 | # Link libOTe #
25 | #############################################
26 |
27 | target_link_libraries(frontend.exe PUBLIC libPSI libPSI_Tests oc::libOTe_Tests oc::tests_cryptoTools)
28 |
29 |
30 | if(MSVC)
31 | target_compile_options(frontend.exe PRIVATE $<$:/std:c++${LIBPSI_STD_VER}>)
32 | #target_compile_options(libOTe PRIVATE -openmp:experimental)
33 | else()
34 | target_compile_options(frontend.exe PRIVATE $<$:-std=c++${LIBPSI_STD_VER}>)
35 |
36 | endif()
--------------------------------------------------------------------------------
/frontend/DrrnPSIMain.cpp:
--------------------------------------------------------------------------------
1 | #include "bloomFilterMain.h"
2 | #include "cryptoTools/Network/Endpoint.h"
3 |
4 | #include "libPSI/PSI/Drrn/DrrnPsiClient.h"
5 | #include "libPSI/PSI/Drrn/DrrnPsiServer.h"
6 |
7 | #include
8 | using namespace osuCrypto;
9 | #include "util.h"
10 |
11 | #include "cryptoTools/Common/Defines.h"
12 |
13 | #include "cryptoTools/Common/Log.h"
14 | #include "cryptoTools/Common/Timer.h"
15 | #include "cryptoTools/Crypto/PRNG.h"
16 | #include
17 | #include "cuckoo/SimpleCuckoo.h"
18 |
19 | void Drrn17Send(
20 | LaunchParams& params)
21 | {
22 | #ifdef ENABLE_DRRN_PSI
23 | setThreadName("CP_Test_Thread");
24 |
25 | if (params.mIdx < 1 || params.mIdx > 2) throw std::runtime_error("server index must be 1 or 2");
26 |
27 | u64 me = params.mIdx - 1 + 1010;
28 | u64 them;
29 |
30 | PRNG prng(_mm_set_epi32(4253465, 434565, 234435, 23987045));
31 |
32 |
33 |
34 | for (auto serverSetSize : params.mNumItems2)
35 | {
36 | std::unique_ptr setPtr(new block[serverSetSize]);
37 | span set(setPtr.get(), serverSetSize);
38 | prng.get(set.data(), set.size());
39 |
40 |
41 | for (auto clientSetSize : params.mNumItems)
42 | {
43 | for (auto numThreads : params.mNumThreads)
44 | {
45 | std::vector clientChls = params.getChannels(1);
46 | std::vector serverChls = params.getChannels2(1);
47 |
48 | for (auto ss : params.mBinScaler)
49 | {
50 | for (u64 jj = 0; jj < params.mTrials; jj++)
51 | {
52 | try {
53 | DrrnPsiServer srv;
54 | srv.mUseSingleDataPass = params.mCmd->isSet("multiDP") == false;
55 | srv.mNiave = params.mCmd->isSet("niave");
56 | //{
57 | // auto param = CuckooIndex<>::selectParams(set.size(), 20, true, 2);
58 | // //SimpleCuckoo cc;
59 | // //cc.mParams = param;
60 | // //cc.init();
61 | // //cc.insert(set, ZeroBlock);
62 |
63 | // CuckooIndex mm;
64 | // mm.init(param);
65 | // mm.insert(set, ZeroBlock);
66 | //}
67 | Timer tt;
68 | auto s = tt.setTimePoint("s");
69 | srv.setInputs(set, params.mNumHash, 10);
70 | auto e = tt.setTimePoint("e");
71 |
72 | std::this_thread::sleep_for(std::chrono::seconds(1));
73 |
74 | if (params.mCmd->isSet("cuckooTime") && params.mIdx == 1)
75 | std::cout << "ch:" << std::chrono::duration_cast(e - s).count() << "ms " << std::flush;
76 |
77 | clientChls[0].send(me);
78 | clientChls[0].recv(them);
79 | if (them != 10021)
80 | throw RTE_LOC;
81 |
82 | srv.init(u8(params.mIdx - 1), clientChls[0], serverChls[0], serverSetSize, clientSetSize, ZeroBlock, ss, params.mCmd->get("bigBlock"));
83 | srv.send(clientChls[0], serverChls[0], numThreads);
84 |
85 | }
86 | catch (std::exception& e)
87 | {
88 | std::cout << e.what() << std::endl;
89 | }
90 | }
91 | }
92 | }
93 | }
94 | }
95 | #else
96 | std::cout << Color::Red << "DRRN is not enabled " << std::endl << Color::Default;
97 | #endif
98 | }
99 |
100 | void Drrn17Recv(
101 | LaunchParams& params)
102 | {
103 | #ifdef ENABLE_DRRN_PSI
104 | setThreadName("CP_Test_Thread");
105 | //u64 dummy[1];
106 | u64 me = 0 + 10021;
107 | u64 them;
108 |
109 |
110 | PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
111 |
112 |
113 | if (params.mVerbose) std::cout << "\n";
114 |
115 |
116 | for (auto serverSetSize : params.mNumItems2)
117 | {
118 | for (auto clientSetSize : params.mNumItems)
119 | {
120 | for (auto numThreads : params.mNumThreads)
121 | {
122 | auto s0 = params.getChannels(1);
123 | auto s1 = params.getChannels2(1);
124 |
125 | for (auto ss : params.mBinScaler)
126 | {
127 | for (u64 jj = 0; jj < params.mTrials; jj++)
128 | {
129 | try {
130 | std::string tag("Drrn ");
131 |
132 | std::vector recvSet(clientSetSize);
133 | prng.get(recvSet.data(), recvSet.size());
134 | s0[0].send(me);
135 | s1[0].send(me);
136 | s0[0].recv(them);
137 |
138 | if (them != 0 + 1010)
139 | throw RTE_LOC;
140 |
141 | s1[0].recv(them);
142 | if (them != 1 + 1010)
143 | throw RTE_LOC;
144 |
145 |
146 | gTimer.reset();
147 | Timer timer;
148 | auto start = timer.setTimePoint("start");
149 | DrrnPsiClient client;
150 | client.init(s0[0], s1[0], serverSetSize, clientSetSize, ZeroBlock, params.mNumHash, ss, 10, params.mCmd->get("bigBlock"));
151 |
152 | auto mid = timer.setTimePoint("online");
153 |
154 | client.recv(s0[0], s1[0], recvSet);
155 | auto end = timer.setTimePoint("done");
156 |
157 | auto offlineTime = std::chrono::duration_cast(mid - start).count();
158 | auto onlineTime = std::chrono::duration_cast(end - mid).count();
159 |
160 | //auto byteSent = chls[0]->getTotalDataSent() *chls.size();
161 |
162 | printTimings(tag, s0, offlineTime, onlineTime, params, clientSetSize, numThreads, ss, &s1, serverSetSize);
163 |
164 | }
165 | catch (std::exception& e)
166 | {
167 | std::cout << e.what() << std::endl;
168 | }
169 | }
170 | }
171 | }
172 | }
173 | }
174 | #else
175 | std::cout << Color::Red << "DRRN is not enabled " << std::endl << Color::Default;
176 | #endif
177 | }
178 |
179 |
--------------------------------------------------------------------------------
/frontend/OtBinMain.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 |
5 |
6 | #include
7 | #include "cryptoTools/Common/Defines.h"
8 |
9 |
10 | //void otBin();
11 | void rr17aRecv(
12 | LaunchParams& params);
13 |
14 | void rr17aSend(
15 | LaunchParams& params);
16 |
17 |
18 | //void otBin();
19 | void rr17aRecv_StandardModel(
20 | LaunchParams& params);
21 |
22 | void rr17aSend_StandardModel(
23 | LaunchParams& params);
24 |
25 | void rr17bRecv(
26 | LaunchParams& params);
27 |
28 | void rr17bSend(
29 | LaunchParams& params);
30 |
31 |
32 | void kkrtRecv(
33 | LaunchParams& params);
34 |
35 | void kkrtSend(
36 | LaunchParams& params);
37 |
38 | void grr18Recv(
39 | LaunchParams& params);
40 |
41 | void grr18Send(
42 | LaunchParams& params);
43 |
--------------------------------------------------------------------------------
/frontend/bloomFilterMain.cpp:
--------------------------------------------------------------------------------
1 | #include "bloomFilterMain.h"
2 | #include "cryptoTools/Network/Endpoint.h"
3 |
4 |
5 | #include
6 | using namespace osuCrypto;
7 | #include "util.h"
8 |
9 | #include "cryptoTools/Common/Defines.h"
10 | #include "libOTe/TwoChooseOne/KosOtExtReceiver.h"
11 | #include "libOTe/TwoChooseOne/KosOtExtSender.h"
12 |
13 | //#include "libOTe/TwoChooseOne/LzKosOtExtReceiver.h"
14 | //#include "libOTe/TwoChooseOne/LzKosOtExtSender.h"
15 | #include "cryptoTools/Common/Log.h"
16 | #include "cryptoTools/Common/Timer.h"
17 | #include "cryptoTools/Crypto/PRNG.h"
18 | #include
19 |
20 | extern u8 dummy[];
21 | //#define LAZY_OT
22 |
23 | void bfSend(LaunchParams& params)
24 | {
25 | #ifdef ENABLE_RR16_PSI
26 | PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
27 |
28 | for (auto setSize : params.mNumItems)
29 | {
30 | for (auto cc : params.mNumThreads)
31 | {
32 | auto chls = params.getChannels(cc);
33 |
34 | for (u64 jj = 0; jj < params.mTrials; jj++)
35 | {
36 | std::vector set(setSize);
37 | for (u64 i = 0; i < setSize; ++i)
38 | set[i] = prng.get();
39 |
40 | #ifdef LAZY_OT
41 | LzKosOtExtReceiver otRecv;
42 | LzKosOtExtSender otSend;
43 | #else
44 | KosOtExtReceiver otRecv;
45 | KosOtExtSender otSend;
46 | #endif // LAZY_OT
47 |
48 |
49 | AknBfMPsiSender sendPSIs;
50 |
51 | sendPSIs.init(setSize, params.mStatSecParam, otSend, chls, prng.get());
52 |
53 |
54 | chls[0].asyncSend(dummy, 1);
55 | chls[0].recv(dummy, 1);
56 |
57 | sendPSIs.sendInput(set, chls);
58 | }
59 | }
60 | }
61 |
62 | #else
63 | std::cout << Color::Red << "RR16 PSI is not enabled" << std::endl << Color::Default;
64 | #endif
65 | }
66 |
67 |
68 | void bfRecv(LaunchParams& params)
69 | {
70 | #ifdef ENABLE_RR16_PSI
71 | for (u64 g = 0; g < params.mChls.size(); ++g)
72 | params.mChls[g].resetStats();
73 |
74 |
75 | PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
76 |
77 | for (auto setSize : params.mNumItems)
78 | {
79 | for (auto numThreads : params.mNumThreads)
80 | {
81 | auto chls = params.getChannels(numThreads);
82 |
83 | for (u64 jj = 0; jj < params.mTrials; jj++)
84 | {
85 | std::vector set(setSize);
86 | prng.get(set.data(), set.size());
87 |
88 | #ifdef LAZY_OT
89 | LzKosOtExtReceiver otRecv;
90 | LzKosOtExtSender otSend;
91 | #else
92 | KosOtExtReceiver otRecv;
93 | KosOtExtSender otSend;
94 | #endif // LAZY_OT
95 |
96 |
97 | AknBfMPsiReceiver recvPSIs;
98 |
99 |
100 | Timer timer;
101 | auto start = timer.setTimePoint("start");
102 | recvPSIs.init(setSize, params.mStatSecParam, otRecv, chls, ZeroBlock);
103 |
104 |
105 |
106 | chls[0].asyncSend(dummy, 1);
107 | chls[0].recv(dummy, 1);
108 | auto mid = timer.setTimePoint("init");
109 |
110 |
111 | recvPSIs.sendInput(set, chls);
112 | auto end = timer.setTimePoint("done");
113 |
114 | auto offlineTime = std::chrono::duration_cast(mid - start).count();
115 | auto onlineTime = std::chrono::duration_cast(end - mid).count();
116 |
117 | std::string tag("RR16");
118 | printTimings(tag, chls, offlineTime, onlineTime, params, setSize, numThreads);
119 |
120 | }
121 | }
122 | }
123 |
124 | #else
125 | std::cout << Color::Red << "RR16 PSI is not enabled" << std::endl << Color::Default;
126 | #endif
127 | }
128 |
129 |
130 |
--------------------------------------------------------------------------------
/frontend/bloomFilterMain.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "util.h"
5 |
6 | void bfSend(LaunchParams& params);
7 | void bfRecv(LaunchParams& params);
8 |
--------------------------------------------------------------------------------
/frontend/cuckoo/SimpleCuckoo.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "cryptoTools/Common/Defines.h"
3 | #include "cryptoTools/Common/Log.h"
4 | #include "cryptoTools/Common/BitVector.h"
5 |
6 | #include "cryptoTools/Common/Matrix.h"
7 | //#include
8 | #include
9 | //#define THREAD_SAFE_CUCKOO
10 | #include "cryptoTools/Common/CuckooIndex.h"
11 |
12 | namespace osuCrypto
13 | {
14 |
15 | class SimpleCuckoo
16 | {
17 | public:
18 | SimpleCuckoo();
19 | ~SimpleCuckoo();
20 |
21 | struct Bin
22 | {
23 | Bin() :mVal(-1) {}
24 | Bin(u64 idx, u64 hashIdx) : mVal(idx | (hashIdx << 56)) {}
25 |
26 | bool isEmpty() const;
27 | u64 idx() const;
28 | u64 hashIdx() const;
29 |
30 | void swap(u64& idx, u64& hashIdx);
31 | #ifdef THREAD_SAFE_CUCKOO
32 | Bin(const Bin& b) : mVal(b.mVal.load(std::memory_order_relaxed)) {}
33 | Bin(Bin&& b) : mVal(b.mVal.load(std::memory_order_relaxed)) {}
34 | std::atomic mVal;
35 | #else
36 | Bin(const Bin& b) : mVal(b.mVal) {}
37 | Bin(Bin&& b) : mVal(b.mVal) {}
38 | u64 mVal;
39 | #endif
40 | };
41 | struct Workspace
42 | {
43 | Workspace(u64 n, u64 h)
44 | : curAddrs(n)
45 | , curHashIdxs(n)
46 | , oldVals(n)
47 | , findVal(n, h)
48 | {}
49 |
50 | std::vector
51 | curAddrs,
52 | curHashIdxs,
53 | oldVals;
54 |
55 | Matrix findVal;
56 | };
57 |
58 |
59 |
60 | u64 mTotalTries;
61 |
62 | bool operator==(const SimpleCuckoo& cmp)const;
63 | bool operator!=(const SimpleCuckoo& cmp)const;
64 |
65 | //std::mutex mStashx;
66 |
67 | CuckooParam mParams;
68 |
69 | void print() const;
70 | void init();
71 |
72 | void insert(span items, block hashingSeed)
73 | {
74 | std::vector hashs(items.size());
75 | std::vector idxs(items.size());
76 | AES hasher(hashingSeed);
77 |
78 | for (u64 i = 0; i < u64(items.size()); i += u64(hashs.size()))
79 | {
80 | auto min = std::min(items.size() - i, hashs.size());
81 |
82 | hasher.ecbEncBlocks(items.data() + i, min, hashs.data());
83 |
84 | for (u64 j = 0, jj = i; j < min; ++j, ++jj)
85 | {
86 | idxs[j] = jj;
87 | hashs[j] = hashs[j] ^ items[jj];
88 |
89 | //if(jj < 1) std::cout<< IoStream::lock << "item[" << jj << "] = " < " << hashs[j] << std::endl << IoStream::unlock;
90 | }
91 |
92 | insert(idxs, hashs);
93 | }
94 | }
95 |
96 | void insert(span itemIdxs, span hashs)
97 | {
98 | Workspace ws(itemIdxs.size(), mParams.mNumHashes);
99 | std::vector bb(mParams.mNumHashes);
100 | Matrix hh(hashs.size(), mParams.mNumHashes);
101 |
102 | for (i64 i = 0; i < i64(hashs.size()); ++i)
103 | {
104 | AES aes(hashs[i]);
105 | aes.ecbEncCounterMode(0, bb.size(), bb.data());
106 | for (u64 j = 0; j < mParams.mNumHashes; ++j)
107 | {
108 | hh(i, j) = *(u64*)&bb[j];
109 | //hh(i,j) = CuckooIndex<>::getHash(hashs[i], j, mParams.numBins());
110 | }
111 | }
112 |
113 | insertBatch(itemIdxs, hh, ws);
114 | }
115 | void insertBatch(span itemIdxs, MatrixView hashs, Workspace& workspace);
116 |
117 | u64 findBatch(MatrixView hashes,
118 | span idxs,
119 | Workspace& wordkspace);
120 |
121 |
122 | u64 stashUtilization();
123 |
124 | std::vector mHashes;
125 | MatrixView mHashesView;
126 |
127 | std::vector mBins;
128 | std::vector mStash;
129 |
130 | //std::vector mBins;
131 | //std::vector mStash;
132 |
133 |
134 | //void insertItems(std::array,4>& hashs);
135 | };
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/frontend/cuckoo/bounds.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osu-crypto/libPSI/1159df1fecad06570ec384d64ab0724d05b6905b/frontend/cuckoo/bounds.xlsx
--------------------------------------------------------------------------------
/frontend/cuckoo/bounds2.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osu-crypto/libPSI/1159df1fecad06570ec384d64ab0724d05b6905b/frontend/cuckoo/bounds2.xlsx
--------------------------------------------------------------------------------
/frontend/cuckoo/cuckooTests.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 |
5 |
6 | void simpleTest(int argc, char** argv);
7 |
8 | void sweepE(
9 | const osuCrypto::u64 &setSize,
10 | const osuCrypto::u64 &h,
11 | double &e,
12 | const osuCrypto::u64 &t,
13 | const osuCrypto::u64 &numThrds,
14 | bool varyCuckooSize,
15 | const osuCrypto::u64 &stashSize,
16 | std::fstream &out);
17 |
--------------------------------------------------------------------------------
/frontend/dcwMain.cpp:
--------------------------------------------------------------------------------
1 |
2 |
3 | #include "dcwMain.h"
4 |
5 | #include "cryptoTools/Network/Endpoint.h"
6 |
7 |
8 | #include "libPSI/PSI/Dcw/DcwRBfPsiReceiver.h"
9 | #include "libPSI/PSI/Dcw/DcwRBfPsiSender.h"
10 |
11 |
12 |
13 | #include "cryptoTools/Common/Defines.h"
14 | #include "libOTe/TwoChooseOne/IknpOtExtReceiver.h"
15 | #include "libOTe/TwoChooseOne/IknpOtExtSender.h"
16 | #include "libOTe/TwoChooseOne/SilentOtExtReceiver.h"
17 | #include "libOTe/TwoChooseOne/SilentOtExtSender.h"
18 |
19 | #include "cryptoTools/Common/Log.h"
20 | #include "cryptoTools/Common/Timer.h"
21 | #include "cryptoTools/Crypto/PRNG.h"
22 | #include
23 | #include
24 | #include "boost/format.hpp"
25 | extern u8 dummy[];
26 |
27 | using namespace osuCrypto;
28 |
29 |
30 | void DcwRSend(
31 | LaunchParams& params)
32 | {
33 | #ifdef ENABLE_DCW_PSI
34 | PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
35 |
36 | for (auto setSize : params.mNumItems)
37 | {
38 | for (auto tt : params.mNumThreads)
39 | {
40 | if (tt != 1)
41 | {
42 | continue;
43 | }
44 |
45 | auto chls = params.getChannels(tt);
46 |
47 | for (u64 jj = 0; jj < params.mTrials; jj++)
48 | {
49 | std::vector set(setSize);
50 |
51 | for (u64 i = 0; i < setSize; ++i)
52 | set[i] = prng.get();
53 |
54 | SilentOtExtReceiver sRecv;
55 | SilentOtExtSender sSend;
56 | IknpOtExtReceiver iRecv;
57 | IknpOtExtSender iSend;
58 | bool silent = params.mCmd->isSet("silent");
59 | //OtExtReceiver& otRecv = silent ? (OtExtReceiver&)sRecv : iRecv;
60 | OtExtSender& otSend = silent ? (OtExtSender&)sSend : iSend;
61 | DcwRBfPsiSender sendPSIs;
62 |
63 | gTimer.reset();
64 | sendPSIs.init(setSize, params.mStatSecParam, otSend, chls, prng.get());
65 | chls[0].asyncSend(dummy, 1);
66 | sendPSIs.sendInput(set, chls);
67 | }
68 | }
69 | }
70 |
71 | #else
72 | std::cout << Color::Red << "DCW PSI is not enabled" << std::endl << Color::Default;
73 | #endif
74 | }
75 |
76 | void DcwRRecv(
77 | LaunchParams& params)
78 | {
79 | #ifdef ENABLE_DCW_PSI
80 | PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
81 |
82 | for (auto setSize : params.mNumItems)
83 | {
84 | for (u64 numThreads : params.mNumThreads)
85 | {
86 | if (numThreads != 1)
87 | {
88 | std::cout << "dcwr n = " << setSize << " t = " << numThreads << " skipped, t > 1 (multi-thread) not implemented." << std::endl;
89 | continue;
90 | }
91 |
92 | auto chls = params.getChannels(numThreads);
93 |
94 | for (u64 jj = 0; jj < params.mTrials; jj++)
95 | {
96 | std::vector set(setSize);
97 | for (u64 i = 0; i < setSize; ++i)
98 | set[i] =prng.get();
99 |
100 | SilentOtExtReceiver sRecv;
101 | SilentOtExtSender sSend;
102 | IknpOtExtReceiver iRecv;
103 | IknpOtExtSender iSend;
104 | bool silent = params.mCmd->isSet("silent");
105 | OtExtReceiver& otRecv = silent ? (OtExtReceiver&)sRecv : iRecv;
106 | //OtExtSender& otSend = silent ? (OtExtSender&)sSend : iSend;
107 | DcwRBfPsiReceiver recvPSIs;
108 |
109 |
110 |
111 | gTimer.reset();
112 | Timer timer;
113 | auto start = timer.setTimePoint("start");
114 |
115 | recvPSIs.init(setSize, params.mStatSecParam, otRecv, chls, sysRandomSeed());
116 |
117 | chls[0].recv(dummy, 1);
118 | auto mid = timer.setTimePoint("init");
119 |
120 |
121 |
122 | recvPSIs.sendInput(set, chls);
123 | auto end = timer.setTimePoint("done");
124 |
125 | auto offlineTime = std::chrono::duration_cast(mid - start).count();
126 | auto onlineTime = std::chrono::duration_cast(end - mid).count();
127 |
128 |
129 | //std::cout << setSize << " " << offlineTime << " " << online << std::endl;
130 |
131 | std::string tag("DCWR");
132 |
133 | printTimings(tag, chls, offlineTime, onlineTime, params, setSize, numThreads);
134 |
135 | }
136 | }
137 | }
138 | #else
139 | std::cout << Color::Red << "DCW PSI is not enabled" << std::endl << Color::Default;
140 | #endif
141 | }
142 |
--------------------------------------------------------------------------------
/frontend/dcwMain.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 |
5 |
6 |
7 | #include "util.h"
8 |
9 |
10 | #include
11 | #include "cryptoTools/Common/Defines.h"
12 |
13 |
14 |
15 | void DcwRSend(LaunchParams&);
16 | void DcwRRecv(LaunchParams&);
17 |
18 |
--------------------------------------------------------------------------------
/frontend/dktMain.cpp:
--------------------------------------------------------------------------------
1 | #include "dcwMain.h"
2 |
3 | #include "cryptoTools/Network/Endpoint.h"
4 |
5 | #include "libPSI/MPSI/DKT/DktMPsiReceiver.h"
6 | #include "libPSI/MPSI/DKT/DktMPsiSender.h"
7 |
8 |
9 |
10 | #include "cryptoTools/Common/Defines.h"
11 | #include "cryptoTools/Common/Log.h"
12 | #include "cryptoTools/Common/Timer.h"
13 | #include "cryptoTools/Crypto/PRNG.h"
14 | #include
15 | #include "dktMain.h"
16 |
17 | using namespace osuCrypto;
18 |
19 | extern u8 dummy[];
20 |
21 | void DktSend(LaunchParams& params)
22 | {
23 | #ifdef ENABLE_DKT_PSI
24 |
25 | PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
26 |
27 | for (auto setSize : params.mNumItems)
28 | {
29 | for (auto numThreads : params.mNumThreads)
30 | {
31 | auto sendChls = params.getChannels(numThreads);
32 |
33 | for (u64 jj = 0; jj < params.mTrials; jj++)
34 | {
35 | std::vector set(setSize);
36 | prng.get(set.data(), set.size());
37 |
38 |
39 | DktMPsiSender sendPSIs;
40 |
41 | Timer timer;
42 |
43 | sendPSIs.init(setSize, params.mStatSecParam, prng.get());
44 | sendChls[0].asyncSend(dummy, 1);
45 |
46 | sendPSIs.sendInput(set, sendChls);
47 | }
48 | }
49 | }
50 | #else
51 | std::cout < set(setSize);
72 | prng.get(set.data(), set.size());
73 |
74 | DktMPsiReceiver recvPSIs;
75 |
76 | Timer timer;
77 | auto start = timer.setTimePoint("start");
78 | recvPSIs.init(setSize, params.mStatSecParam, ZeroBlock);
79 |
80 | chls[0].recv(dummy, 1);
81 | auto mid = timer.setTimePoint("init");
82 |
83 | recvPSIs.sendInput(set, chls);
84 | auto end = timer.setTimePoint("done");
85 |
86 | auto offlineTime = std::chrono::duration_cast(mid - start).count();
87 | auto onlineTime = std::chrono::duration_cast(end - mid).count();
88 |
89 |
90 | std::string tag("DKT11");
91 | printTimings(tag, chls, offlineTime, onlineTime, params, setSize, numThreads);
92 |
93 | }
94 | }
95 | }
96 | #else
97 | std::cout << Color::Red << "DKT is not enabled " << std::endl << Color::Default;
98 | #endif
99 | }
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/frontend/dktMain.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 |
5 |
6 | #include
7 | #include "cryptoTools/Common/Defines.h"
8 | #include "util.h"
9 |
10 |
11 | void DktSend(LaunchParams& params);
12 | void DktRecv(LaunchParams& params);
13 |
14 |
--------------------------------------------------------------------------------
/frontend/ecdhMain.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "cryptoTools/Network/Endpoint.h"
3 |
4 | #include "libPSI/PSI/ECDH/EcdhPsiReceiver.h"
5 | #include "libPSI/PSI/ECDH/EcdhPsiSender.h"
6 |
7 |
8 |
9 | #include "cryptoTools/Common/Defines.h"
10 | #include "cryptoTools/Common/Log.h"
11 | #include "cryptoTools/Common/Timer.h"
12 | #include "cryptoTools/Crypto/PRNG.h"
13 | #include
14 | #include "ecdhMain.h"
15 |
16 | using namespace osuCrypto;
17 |
18 | extern u8 dummy[];
19 |
20 | void EcdhSend(LaunchParams& params)
21 | {
22 | #ifdef ENABLE_ECDH_PSI
23 |
24 | PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
25 |
26 | for (auto setSize : params.mNumItems)
27 | {
28 | for (auto numThreads : params.mNumThreads)
29 | {
30 | auto sendChls = params.getChannels(numThreads);
31 |
32 | for (u64 jj = 0; jj < params.mTrials; jj++)
33 | {
34 | std::vector set(setSize);
35 | prng.get(set.data(), set.size());
36 |
37 |
38 | EcdhPsiSender sendPSIs;
39 |
40 | gTimer.reset();
41 | Timer timer;
42 |
43 | sendPSIs.init(setSize, params.mStatSecParam, prng.get());
44 | sendChls[0].asyncSend(dummy, 1);
45 |
46 | sendPSIs.sendInput(set, sendChls);
47 | }
48 | }
49 | }
50 | #else
51 | std::cout << Color::Red << "ECDH PSI is not enabled" << std::endl << Color::Default;
52 | #endif
53 | }
54 |
55 |
56 | void EcdhRecv(LaunchParams& params)
57 | {
58 | #ifdef ENABLE_ECDH_PSI
59 |
60 | PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
61 |
62 | for (auto setSize : params.mNumItems)
63 | {
64 | for (auto numThreads : params.mNumThreads)
65 | {
66 | auto chls = params.getChannels(numThreads);
67 |
68 | for (u64 jj = 0; jj < params.mTrials; jj++)
69 | {
70 |
71 | std::vector set(setSize);
72 | prng.get(set.data(), set.size());
73 |
74 | EcdhPsiReceiver recvPSIs;
75 |
76 | gTimer.reset();
77 |
78 | Timer timer;
79 | auto start = timer.setTimePoint("start");
80 | recvPSIs.init(setSize, params.mStatSecParam, ZeroBlock);
81 |
82 | chls[0].recv(dummy, 1);
83 | auto mid = timer.setTimePoint("init");
84 |
85 | recvPSIs.sendInput(set, chls);
86 | auto end = timer.setTimePoint("done");
87 |
88 | auto offlineTime = std::chrono::duration_cast(mid - start).count();
89 | auto onlineTime = std::chrono::duration_cast(end - mid).count();
90 |
91 |
92 | std::string tag("Ecdh_Curve25519");
93 | printTimings(tag, chls, offlineTime, onlineTime, params, setSize, numThreads);
94 |
95 | }
96 | }
97 | }
98 | #else
99 | std::cout << Color::Red << "ECDH PSI is not enabled" << std::endl << Color::Default;
100 | #endif
101 | }
102 |
103 |
104 |
--------------------------------------------------------------------------------
/frontend/ecdhMain.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 |
5 |
6 | #include
7 | #include "cryptoTools/Common/Defines.h"
8 | #include "util.h"
9 |
10 |
11 | void EcdhSend(LaunchParams& params);
12 | void EcdhRecv(LaunchParams& params);
13 |
14 |
--------------------------------------------------------------------------------
/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 |
46 |
47 | false
48 |
49 |
50 |
51 | Level3
52 | Disabled
53 | true
54 | $(ProjectDir)/..;$(ProjectDir);$(libOTeDir);$(libOTeDir)/cryptoTools;$(ProjectDir)../libPSI_Tests;$(ProjectDir)../libPSI;$(ProjectDir)../cryptoTools\thirdparty\win\boost\;$(ProjectDir)../cryptoTools/thirdparty\win\;$(ProjectDir)../cryptoTools/thirdparty/win/NTL/include;$(SolutionDir)thirdparty/win/miracl;C:/libs/boost;C:/libs/;C:/libs/NTL/include;C:/libs/miracl;C:\libs\include;
55 | MultiThreadedDebug
56 | SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions)
57 | true
58 | true
59 | false
60 |
61 |
62 | %(AdditionalLibraryDirectories);$(SolutionDir)\thirdparty\win\boost\stage\lib;C:/libs/boost\stage\lib;$(OutDir);$(SolutionDir)thirdparty\win\;C:/libs/;$(libOTeDir)\x64\$(Configuration);C:/libs/lib
63 | libOTe_Tests.lib;tests_cryptoTools.lib;libOTe.lib;libPSI.lib;libPSI_Tests.lib;cryptoTools.lib;Miracl\x64\$(Configuration)\miracl.lib;%(AdditionalDependencies)
64 |
65 |
66 |
67 |
68 | Level3
69 | MaxSpeed
70 | true
71 | true
72 | true
73 | $(ProjectDir)/..;$(ProjectDir);$(libOTeDir);$(libOTeDir)/cryptoTools;$(ProjectDir)../libPSI_Tests;$(ProjectDir)../libPSI;$(ProjectDir)../cryptoTools\thirdparty\win\boost\;$(ProjectDir)../cryptoTools/thirdparty\win\;$(ProjectDir)../cryptoTools/thirdparty/win/NTL/include;$(SolutionDir)thirdparty/win/miracl;C:/libs/boost;C:/libs/;C:/libs/NTL/include;C:/libs/miracl;C:\libs\include;
74 | MultiThreaded
75 | SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501;DEBUG;_MBCS;%(PreprocessorDefinitions);
76 | true
77 | true
78 |
79 |
80 | true
81 | true
82 | %(AdditionalLibraryDirectories);$(SolutionDir)\thirdparty\win\boost\stage\lib;C:/libs/boost\stage\lib;$(OutDir);$(SolutionDir)thirdparty\win\;C:/libs/;$(libOTeDir)\x64\$(Configuration);C:/libs/lib
83 | libOTe_Tests.lib;tests_cryptoTools.lib;libOTe.lib;libPSI.lib;libPSI_Tests.lib;cryptoTools.lib;Miracl\x64\$(Configuration)\miracl.lib;%(AdditionalDependencies)
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/frontend/util.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "cryptoTools/Network/Channel.h"
3 | #include "cryptoTools/Common/CLP.h"
4 | #include "cryptoTools/Network/Channel.h"
5 |
6 | using namespace osuCrypto;
7 |
8 | template
9 | std::string string_format(const std::string& format, Args ... args)
10 | {
11 | size_t size = std::snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0'
12 | std::unique_ptr buf(new char[size]);
13 | std::snprintf(buf.get(), size, format.c_str(), args ...);
14 | return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
15 | }
16 |
17 |
18 |
19 | struct LaunchParams
20 | {
21 | LaunchParams()
22 | :mVerbose(0),
23 | mTrials(1),
24 | mStatSecParam(40)
25 | {
26 | }
27 |
28 | std::vector getChannels(u64 n) {
29 | return std::vector( mChls.begin(), mChls.begin() + n);
30 | }
31 |
32 | std::vector getChannels2(u64 n) {
33 | return std::vector(mChls2.begin(), mChls2.begin() + n);
34 | }
35 |
36 | std::string mHostName;
37 | std::vector mChls, mChls2;
38 | std::vector mNumItems, mNumItems2;
39 | std::vector mNumThreads;
40 | std::vector mBinScaler;
41 |
42 | u64 mBitSize;
43 | u64 mVerbose;
44 | u64 mTrials;
45 | u64 mStatSecParam;
46 | u64 mIdx;
47 | u64 mNumHash;
48 |
49 | std::string mIP;
50 | CLP* mCmd;
51 | };
52 |
53 |
54 | #include "cryptoTools/Network/Channel.h"
55 | void senderGetLatency(osuCrypto::Channel& chl);
56 |
57 | void recverGetLatency(osuCrypto::Channel& chl);
58 |
59 |
60 |
61 |
62 | void printTimings(
63 | std::string tag,
64 | std::vector chls,
65 | long long offlineTime, long long onlineTime,
66 | LaunchParams & params,
67 | const osuCrypto::u64 &setSize,
68 | const osuCrypto::u64 &numThreads,
69 | double s = 1,
70 | std::vector* chls2 = nullptr,
71 | u64 n2 = -1);
72 |
73 | void printHeader();
74 |
--------------------------------------------------------------------------------
/libPSI/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | #############################################
4 | # Build libPSI #
5 | #############################################
6 |
7 | file(GLOB_RECURSE SRCS *.cpp)
8 |
9 |
10 | add_library(libPSI ${SRCS})
11 |
12 | #############################################
13 | # Link libOTe #
14 | #############################################
15 |
16 | target_link_libraries(libPSI oc::libOTe sparsehash)
17 |
18 | target_include_directories(libPSI PUBLIC
19 | $
20 | $)
21 | target_include_directories(libPSI PUBLIC
22 | $
23 | $)
24 |
25 |
26 | if(MSVC)
27 | target_compile_options(libPSI PRIVATE $<$:/std:c++${LIBPSI_STD_VER}>)
28 | #target_compile_options(libOTe PRIVATE -openmp:experimental)
29 | else()
30 | target_compile_options(libPSI PRIVATE $<$:-std=c++${LIBPSI_STD_VER}>)
31 |
32 | endif()
--------------------------------------------------------------------------------
/libPSI/MPSI/DKT/DktMPsiReceiver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_DKT_PSI
4 |
5 | #include "cryptoTools/Common/Defines.h"
6 | #include "cryptoTools/Network/Channel.h"
7 | #include "cryptoTools/Crypto/PRNG.h"
8 |
9 | namespace osuCrypto
10 | {
11 |
12 | class DktMPsiReceiver
13 | {
14 | public:
15 | DktMPsiReceiver();
16 | ~DktMPsiReceiver();
17 |
18 |
19 | u64 mN, mSecParam;
20 | PRNG mPrng;
21 |
22 | std::vector mIntersection;
23 |
24 | void init(u64 n, u64 secParam, block seed);
25 |
26 |
27 | void sendInput(span inputs, span chl0);
28 |
29 | };
30 | }
31 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/DKT/DktMPsiSender.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_DKT_PSI
4 |
5 | #include "cryptoTools/Common/Defines.h"
6 |
7 | #include "cryptoTools/Network/Channel.h"
8 | #include "cryptoTools/Crypto/PRNG.h"
9 |
10 | namespace osuCrypto
11 | {
12 |
13 |
14 | class DktMPsiSender
15 | {
16 | public:
17 | DktMPsiSender();
18 | ~DktMPsiSender();
19 |
20 |
21 | u64 mN, mSecParam;
22 | PRNG mPrng;
23 |
24 | void init(u64 n, u64 secParam, block seed);
25 | //void init(u64 n, u64 statSecParam);
26 |
27 |
28 | void sendInput(std::vector& inputs, span chl);
29 | //void sendInput(std::vector& inputs, std::vector& chl);
30 | };
31 |
32 |
33 | }
34 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/Grr18Common.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_GRR_PSI
4 |
5 | #include
6 | #include
7 | #include
8 | #include "libPSI/Tools/SimpleHasher.h"
9 |
10 | namespace osuCrypto
11 | {
12 |
13 | extern bool mGrr18PrintWarning;
14 |
15 | u64 computeLoads(
16 | std::vector& loads,
17 | PRNG & prng,
18 | u64 binStart,
19 | bool oneSided,
20 | bool lapPlusBuffer,
21 | u64 n,
22 | SimpleHasher& bins,
23 | double eps,
24 | i64 cwThreshold = -1,
25 | bool print = false);
26 |
27 | }
28 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/Grr18MPsiReceiver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_GRR_PSI
4 | #ifndef ENABLE_OOS
5 | static_assert(0, "ENABLE_OOS must be defined in libOTe");
6 | #endif
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | #include "libOTe/NChooseOne/Oos/OosNcoOtReceiver.h"
13 | #include "libOTe/NChooseOne/Oos/OosNcoOtSender.h"
14 | #include
15 |
16 | namespace osuCrypto
17 | {
18 |
19 | class Grr18MPsiReceiver : public TimerAdapter
20 | {
21 | public:
22 | Grr18MPsiReceiver();
23 | ~Grr18MPsiReceiver();
24 |
25 | //static const u64 CodeWordSize = 7;
26 | //static const u64 hasherStepSize;
27 |
28 | bool mHashToSmallerDomain, mOneSided = false, mLapPlusBuff = false;
29 | double mEpsBins = 0.9, mEpsMasks= 0.1;
30 | u64 mN, mStatSecParam;// , mNumOTsUpperBound;// , mOtMsgBlkSize;
31 | block mHashingSeed;
32 | std::vector mIntersection;
33 | std::unique_ptr> mTotalLoad;
34 |
35 | std::vector mOtSends;
36 | std::vector mOtRecvs;
37 |
38 | SimpleHasher mBins;
39 | PRNG mPrng;
40 |
41 | void init(u64 n, u64 statSecParam, Channel& chl0, OosNcoOtReceiver& otRecv, OosNcoOtSender& otSend, block seed,
42 | double binScaler = 4.0, u64 inputBitSize = -1);
43 | void init(u64 n, u64 statSecParam, span chls, OosNcoOtReceiver& ots, OosNcoOtSender& otSend, block seed,
44 | double binScaler = 4.0, u64 inputBitSize = -1);
45 |
46 | void sendInput(std::vector& inputs, Channel& chl);
47 | void sendInput(std::vector& inputs, span chls);
48 |
49 | };
50 |
51 |
52 |
53 |
54 | }
55 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/Grr18MPsiSender.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_GRR_PSI
4 | #ifndef ENABLE_OOS
5 | static_assert(0, "ENABLE_OOS must be defined in libOTe");
6 | #endif
7 |
8 |
9 | #include "cryptoTools/Common/Defines.h"
10 | #include "cryptoTools/Common/Timer.h"
11 | #include "cryptoTools/Network/Channel.h"
12 | #include "libOTe/NChooseOne/Oos/OosNcoOtSender.h"
13 | #include "libOTe/NChooseOne/Oos/OosNcoOtReceiver.h"
14 | #include "libPSI/Tools/SimpleHasher.h"
15 |
16 | namespace osuCrypto
17 | {
18 |
19 |
20 | class Grr18MPsiSender : public TimerAdapter
21 | {
22 | public:
23 |
24 |
25 | //static const u64 CodeWordSize = 7;
26 | //static const u64 hasherStepSize;
27 |
28 | Grr18MPsiSender();
29 | ~Grr18MPsiSender();
30 |
31 | bool mHashToSmallerDomain, mOneSided = false, mLapPlusBuff = false;
32 | double mEpsBins = 0.9, mEpsMasks = 0.1;
33 | u64 mN, mStatSecParam, mOtMsgBlkSize, mCWThreshold = -1;//, mNumOTsUpperBound;
34 | block mHashingSeed;
35 | SimpleHasher mBins;
36 | PRNG mPrng;
37 |
38 | std::vector mOtSends;
39 | std::vector mOtRecvs;
40 |
41 | void init(u64 n, u64 statSecParam,
42 | span chls,
43 | OosNcoOtSender& ots,
44 | OosNcoOtReceiver& otRecv,
45 | block seed,
46 | double binScaler = 4.0,
47 | u64 inputBitSize = -1);
48 |
49 | void init(u64 n, u64 statSecParam,
50 | Channel & chl0,
51 | OosNcoOtSender& ots,
52 | OosNcoOtReceiver& otRecv,
53 | block seed,
54 | double binScaler = 4.0,
55 | u64 inputBitSize = -1);
56 |
57 | void sendInput(std::vector& inputs, Channel& chl);
58 | void sendInput(std::vector& inputs, span chls);
59 |
60 |
61 | u64 mReporting_totalMaskCount, mReporting_totalRealMaskCount;
62 | };
63 |
64 | }
65 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/bayesian.gp:
--------------------------------------------------------------------------------
1 | default(realprecision, 100);
2 | default(parisizemax, 800000000);
3 |
4 | bdist(n,k,p) = 0.0+binomial(n,k)*(p^k)*(1-p)^(n-k);
5 | bdistleq(n,k,p) = sum(i=0,k, 0.0 + bdist(n,i,p));
6 | log2(x) = log(x)/log(2);
7 | overflowprob(n,m,B) = m * (1- bdistleq(n,B,1/m));
8 | lappdf(x, eps) = (eps/2)*exp(-abs(x)*eps);
9 | \\n = 2^16; \\ number of items
10 | \\m = n/4; \\ number of bins
11 |
12 | err = 1/(2^40); \\ acceptable overall error probability
13 | binerror = err/m ; \\implied acceptable error probability per bin
14 | stop = 120; \\ignore bin sizes above this
15 | prior = listcreate(stop);
16 | for (z=0, stop+1, listput(prior, bdist(n, z, 1/m)))
17 | prior;
18 | remainingprobprint(dist) =
19 | {
20 | a = 1;
21 | for(i=1, stop+1, a = a - dist[i]; print(i-1 " " a))
22 | for(i=1, stop+1, a = a - dist[i]; print(i-1 " " a))
23 | for(i=1, stop+1, a = a - dist[i]; print(i-1 " " a))
24 | };
25 | remainingprob(dist) =
26 | {
27 | a = 1;
28 | out = listcreate(stop);
29 | for(i=1, stop+1, a = a - dist[i]; listput(out, a));
30 | return(out)
31 | };
32 | \\ remainingprob(prior)
33 | postat(prior, evid, eps, x) =
34 | \\returns the posterior likelihood of a given real bin size
35 | {
36 | total = 0; \\total = total probability of seeing estimate evid
37 | for(i=0, stop+1, total = total + prior[i+1]*lappdf(abs(evid-i),eps));
38 | new = prior[x+1] * lappdf(abs(evid-x),eps) / total;
39 | \\print("total " total);
40 | \\print("pdf " lappdf(abs(evid-x),eps));
41 | return(new)
42 | };
43 | p = listcreate(stop);
44 | for (z=0, stop+1, listput(p, postat(prior, estimate, 1, z)) );
45 | posterior(prior, estimate, eps) =
46 | \\ calculates a posterior distribution when 'estimate' is the private bin size estimate
47 | {
48 | post = listcreate(stop);
49 | for (z=0, stop+1, listput(post, postat(prior, estimate, eps, z)) );
50 | return(post)
51 | };
52 | binsneeded(dist) =
53 | {
54 | flag = 1;
55 | a = 1;
56 | bin = 0;
57 | while(a>binerror,
58 | a = a-dist[bin+1];
59 | bin++
60 | );
61 | return(bin-1);
62 | };
63 | \\binsneeded(prior) \\testing
64 | createtable(mina, maxa, inc, prior, eps) = \\exclusive of 'max' value
65 | {
66 | est = mina;
67 | print("n = " n);
68 | print("m = " m);
69 | print("epsilon = " eps);
70 | print("error probability = " err);
71 | print("If estimated bin size is ____ then pad with dummies up to _____");
72 |
73 | write1("C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18/output.txt","Lookup{" n ", " floor(m) ", " eps ", " mina ", {");
74 | while(est < maxa,
75 | post = posterior(prior, est, eps);
76 | needed = binsneeded(post);
77 | print(est ", " needed);
78 | write1("C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18/output.txt", needed);
79 | est = est + inc;
80 | if(est < maxa,
81 | write1("C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18/output.txt", ", ");
82 | );
83 | );
84 |
85 | write("C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18//output.txt", "}},");
86 | };
87 | createtable(-10, 50, 1, prior, eps);
88 |
89 |
90 | \\quit
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/bayesian.ps1:
--------------------------------------------------------------------------------
1 |
2 | $psi = New-Object System.Diagnostics.ProcessStartInfo;
3 | $psi.FileName = "C:\Program Files (x86)\Pari64-2-9-4\gp.exe"; #process file
4 | $psi.WorkingDirectory = $pwd;
5 | $psi.UseShellExecute = $false; #start the process from it's own executable file
6 | $psi.RedirectStandardInput = $true; #enable the process to read from standard input
7 |
8 | $p = [System.Diagnostics.Process]::Start($psi);
9 |
10 | Start-Sleep -s 2 #wait 2 seconds so that the process can be up and running
11 |
12 |
13 |
14 |
15 | For($nn = 16; $nn -lt 21; $nn= $nn + 4)
16 | {
17 | for($mm = 12; $mm -lt 13; $mm = $mm + 2)
18 | {
19 | $n= [math]::pow(2, $nn)
20 | $m = $n/$mm
21 |
22 |
23 | $p.StandardInput.WriteLine("n=$n;");
24 | $p.StandardInput.WriteLine("m=$m;");
25 | $p.StandardInput.WriteLine("\r C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18/bayesian2.gp;");
26 | }
27 | }
28 |
29 |
30 | $p.StandardInput.WriteLine("quit");
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/bayesian2.gp:
--------------------------------------------------------------------------------
1 | \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
2 | log2(x) = log(x)/log(2);
3 | \\ Pr[ Binom = k ]
4 | bdist_(n,k,p) = 0.0+binomial(n,k)*(p^k)*(1-p)^(n-k);
5 | build_bdist_table(n,m) = {
6 | bdist_tbl = vector(201);
7 | p = 1/m;
8 | for(k=0,200,
9 | bdist_tbl[k+1] = bdist_(n,k,p)
10 | );
11 | }
12 | \\ Pr[ Binom = i ]
13 | bdist(k) = bdist_tbl[k+1]
14 | \\ Pr[ Binom = i ]
15 | bdistleq(k) = sum(i=0,k, bdist(i))
16 | \\ Pr[ Lap <= d ]
17 | eps = 1
18 | lapleq(d) = if(d<0, exp(eps*d)/2, 1 - exp(-eps*d)/2)
19 | \\ Pr[ Binom <= k AND Binom + Lap <= d ]
20 | \\ Pr[ Binom <= k AND Lap <= d-Binom ]
21 | bothevents(k,d) = sum(B=0,k, bdist(B) * lapleq(d-B))
22 | \\ Pr[ B <= k | B + Lap <= d ]
23 | \\ = Pr[ B <= k AND B + Lap <= d ] / Pr[ B + Lap <= d ]
24 | \\ computed as B<=200 AND ...
25 | conditional(k,d) = bothevents(k,d) / bothevents(200,d)
26 | posterior(d,lambda) = {
27 | k = 1;
28 | while( log2(1 - conditional(k,d)) > -lambda,
29 | k = k+1
30 | );
31 | return(k-1);
32 | }
33 | nicetable(lambda) = {
34 | print("bayesian corrections for eps = ", eps);
35 |
36 | mina = -10;
37 | maxa = 50;
38 |
39 | write1("C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18/output.txt",
40 | "Lookup{" n ", " floor(m) ", " eps ", " mina ", {");
41 |
42 |
43 | for(i=mina, maxa,
44 | needed = posterior(i,lambda);
45 | print(i, " => ", needed);
46 |
47 | write1("C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18//output.txt", needed );
48 |
49 | if(i < maxa,
50 | write1("C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18/output.txt", ", ");
51 | );
52 | );
53 |
54 |
55 |
56 | write("C:/Users/Peter/repo/libPSI/libPSI/MPSI/Grr18//output.txt", "}},")
57 | }
58 | \\\\\\\\\\\\\\\\\\\\
59 | \\\\\\\\\\\\\\\\\\\\
60 | \\\\\\\\\\\\\\\\\\\\
61 | allocatemem();
62 | \\n = 2^20;
63 | \\m = n/4;
64 |
65 | lambda = 40;
66 | print("all calculations for n = ", n, "; m = ", m, "; lambda = ", lambda);
67 | build_bdist_table(n,m); \\ takes a long time
68 |
69 | \\eps=0.2; nicetable(lambda + log2(m))
70 | eps=0.01; nicetable(lambda + log2(m))
71 | \\eps=0.05; nicetable(lambda + log2(m))
72 | \\eps=0.005; nicetable(lambda + log2(m))
73 | \\eps=4; nicetable(lambda + log2(m))
74 |
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/bayesian3.gp:
--------------------------------------------------------------------------------
1 | \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
2 | log2(x) = log(x)/log(2);
3 | \\ Pr[ Binom = k ]
4 | bdist_(n,k,p) = 0.0+binomial(n,k)*(p^k)*(1-p)^(n-k);
5 | build_bdist_table(n,m) = {
6 | bdist_tbl = vector(201);
7 | p = 1/m;
8 | for(k=0,200,
9 | bdist_tbl[k+1] = bdist_(n,k,p)
10 | );
11 | }
12 | \\ Pr[ Binom = i ]
13 | bdist(k) = bdist_tbl[k+1]
14 | \\ Pr[ Binom = i ]
15 | bdistleq(k) = sum(i=0,k, bdist(i))
16 | \\ Pr[ Lap <= d ]
17 | eps = 1
18 | lapleq(d) = if(d<0, exp(eps*d)/2, 1 - exp(-eps*d)/2)
19 | \\ Pr[ Binom <= k AND Binom + Lap <= d ]
20 | \\ Pr[ Binom <= k AND Lap <= d-Binom ]
21 | bothevents(k,d) = sum(B=0,k, bdist(B) * lapleq(d-B))
22 | \\ Pr[ B <= k | B + Lap <= d ]
23 | \\ = Pr[ B <= k AND B + Lap <= d ] / Pr[ B + Lap <= d ]
24 | \\ computed as B<=200 AND ...
25 | conditional(k,d) = bothevents(k,d) / bothevents(200,d)
26 | posterior(d,lambda) = {
27 | k = 1;
28 | while( log2(1 - conditional(k,d)) > -lambda,
29 | k = k+1
30 | );
31 | return(k-1);
32 | }
33 | nicetable(lambda) = {
34 | print("bayesian corrections for eps = ", eps);
35 | for(i=-10, 50,
36 | print(i, " => ", posterior(i,lambda))
37 | );
38 | }
39 | \\\\\\\\\\\\\\\\\\\\
40 | \\\\\\\\\\\\\\\\\\\\
41 | \\\\\\\\\\\\\\\\\\\\
42 | allocatemem();
43 | n = 2^20;
44 | m = n/4;
45 | lambda = 40;
46 | print("all calculations for n = ", n, "; m = ", m, "; lambda = ", lambda);
47 | build_bdist_table(n,m); \\ takes a long time
48 | eps=0.5; nicetable(lambda + log2(m))
49 | eps=1; nicetable(lambda + log2(m))
50 | eps=2; nicetable(lambda + log2(m))
51 | eps=4; nicetable(lambda + log2(m))
52 |
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/gp_history.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osu-crypto/libPSI/1159df1fecad06570ec384d64ab0724d05b6905b/libPSI/MPSI/Grr18/gp_history.txt
--------------------------------------------------------------------------------
/libPSI/MPSI/Grr18/output.txt:
--------------------------------------------------------------------------------
1 | Lookup{65536, 5461, 0.0050000000000000000000000000000000000000, -10, {49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49}},
2 | Lookup{1048576, 87381, 0.0050000000000000000000000000000000000000, -10, {51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51}},
3 | Lookup{1048576, 131072, 0.0050000000000000000000000000000000000000, -10, {41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41}},
4 | Lookup{1048576, 104857, 0.0050000000000000000000000000000000000000, -10, {46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46}},
5 | Lookup{1048576, 87381, 0.0050000000000000000000000000000000000000, -10, {51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51}},
6 | Lookup{1048576, 74898, 0.0050000000000000000000000000000000000000, -10, {55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55}},
7 | Lookup{65536, 5461, 0.010000000000000000000000000000000000000, -10, {48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49}},
8 | Lookup{1048576, 87381, 0.010000000000000000000000000000000000000, -10, {50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}},
9 |
--------------------------------------------------------------------------------
/libPSI/MPSI/Rr16/AknBfMPsiReceiver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_RR16_PSI
4 |
5 | #ifndef ENABLE_AKN
6 | #pragma error("ENABLE_AKN must be defined in libOTe")
7 | #endif
8 |
9 | #include "cryptoTools/Common/Defines.h"
10 | #include "cryptoTools/Common/Timer.h"
11 | #include "cryptoTools/Network/Channel.h"
12 | #include "libOTe/NChooseK/AknOtReceiver.h"
13 |
14 |
15 | namespace osuCrypto
16 | {
17 |
18 | void computeAknBfParams(u64 n, u64 statSecParam, u64& totalOtCount, u64& totalOnesCount, u64& cncOnesThreshold, double& cncProb, u64& numHashFunctions, u64& bfBitCount);
19 |
20 |
21 | class AknBfMPsiReceiver : public TimerAdapter
22 | {
23 | public:
24 | typedef u32 LogOtCount_t;
25 |
26 |
27 | AknBfMPsiReceiver();
28 | ~AknBfMPsiReceiver();
29 |
30 | AknOtReceiver mAknOt;
31 | //SHA1 mHash;
32 | u64 mMyInputSize, mTheirInputSize, mBfBitCount, mStatSecParam, mTotalOtCount, mNumHashFunctions;
33 | block mHashingSeed, mSeed;
34 | std::vector mIntersection;
35 |
36 | void init(u64 n, u64 statSecParam, OtExtReceiver& otExt, Channel& chl0, block seed);
37 | void init(u64 n, u64 statSecParam, OtExtReceiver& otExt, span chl0, block seed);
38 | void sendInput(std::vector& inputs, Channel& chl);
39 | void sendInput(std::vector& inputs, span chl0);
40 | };
41 |
42 | }
43 |
44 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Rr16/AknBfMPsiSender.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_RR16_PSI
4 |
5 | #ifndef ENABLE_AKN
6 | #pragma error("ENABLE_AKN must be defined in libOTe")
7 | #endif
8 |
9 | #include "cryptoTools/Common/Defines.h"
10 | #include "cryptoTools/Common/Timer.h"
11 | #include "cryptoTools/Network/Channel.h"
12 | #include "libOTe/NChooseK/AknOtSender.h"
13 |
14 | namespace osuCrypto {
15 |
16 | extern void computeAknBfParams(u64 n, u64 statSecParam, u64& totalOtCount, u64& totalOnesCount, u64& cncOnesThreshold, double& cncProb, u64& numHashFunctions, u64& bfBitCount);
17 |
18 |
19 | class AknBfMPsiSender : public TimerAdapter
20 | {
21 | public:
22 | typedef u32 LogOtCount_t;
23 |
24 |
25 | AknBfMPsiSender();
26 | ~AknBfMPsiSender();
27 |
28 | //void computeParameters(u64 n, u64 statSecParam, u64& totalOtCount, u64& cncOnesThreshold, double& cncProb, u64& numHashFunctions, u64& bfBitCount);
29 |
30 | u64 mN, mStatSecParam, mBfBitCount, mNumHashFunctions;
31 | AknOtSender mAknOt;
32 | block mHashingSeed, mSeed;
33 |
34 | void init(u64 n, u64 statSecParam, OtExtSender& otExt, Channel& chl, block seed);
35 | void init(u64 n, u64 statSecParam, OtExtSender& otExt, spanchl, block seed);
36 |
37 |
38 | void sendInput(std::vector& inputs, Channel& chl);
39 | void sendInput(std::vector& inputs, span chl);
40 | };
41 |
42 | }
43 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Rr17/Rr17MPsiDefines.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "cryptoTools/Common/Defines.h"
3 |
4 | namespace osuCrypto
5 | {
6 |
7 |
8 | static const u64 stepSize(512);
9 | }
--------------------------------------------------------------------------------
/libPSI/MPSI/Rr17/Rr17a/Rr17aMPsiReceiver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_RR17_PSI
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | namespace osuCrypto
12 | {
13 |
14 | class Rr17aMPsiReceiver : public TimerAdapter
15 | {
16 | public:
17 | Rr17aMPsiReceiver();
18 | ~Rr17aMPsiReceiver();
19 |
20 | //static const u64 CodeWordSize = 7;
21 | //static const u64 hasherStepSize;
22 |
23 | bool mHashToSmallerDomain;
24 | u64 mN, mStatSecParam;// , mOtMsgBlkSize;
25 | block mHashingSeed;
26 | std::vector mIntersection;
27 |
28 |
29 | std::vector> mOtSends;
30 | std::vector> mOtRecvs;
31 |
32 | SimpleHasher mBins;
33 | PRNG mPrng;
34 |
35 | void init(u64 n, u64 statSecParam, Channel& chl0, NcoOtExtReceiver& otRecv, NcoOtExtSender& otSend, block seed,
36 | double binScaler = 1.0, u64 inputBitSize = -1);
37 | void init(u64 n, u64 statSecParam, span chls, NcoOtExtReceiver& ots, NcoOtExtSender& otSend, block seed,
38 | double binScaler = 1.0, u64 inputBitSize = -1);
39 |
40 | void sendInput(std::vector& inputs, Channel& chl);
41 | void sendInput(std::vector& inputs, span chls);
42 |
43 | };
44 |
45 |
46 |
47 |
48 | }
49 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Rr17/Rr17a/Rr17aMPsiSender.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_RR17_PSI
4 |
5 |
6 | #include "cryptoTools/Common/Defines.h"
7 | #include "cryptoTools/Common/Timer.h"
8 | #include "cryptoTools/Network/Channel.h"
9 | #include "libOTe/NChooseOne/NcoOtExt.h"
10 | #include "libPSI/Tools/SimpleHasher.h"
11 |
12 | namespace osuCrypto
13 | {
14 |
15 |
16 | class Rr17aMPsiSender : public TimerAdapter
17 | {
18 | public:
19 |
20 |
21 | //static const u64 CodeWordSize = 7;
22 | //static const u64 hasherStepSize;
23 |
24 | Rr17aMPsiSender();
25 | ~Rr17aMPsiSender();
26 |
27 | bool mHashToSmallerDomain;
28 | u64 mN, mStatSecParam, mOtMsgBlkSize;
29 | block mHashingSeed;
30 | SimpleHasher mBins;
31 | PRNG mPrng;
32 |
33 | std::vector> mOtSends;
34 | std::vector> mOtRecvs;
35 |
36 | void init(u64 n, u64 statSecParam,
37 | span chls,
38 | NcoOtExtSender& ots,
39 | NcoOtExtReceiver& otRecv,
40 | block seed,
41 | double binScaler = 1.0,
42 | u64 inputBitSize = -1);
43 |
44 | void init(u64 n, u64 statSecParam,
45 | Channel & chl0,
46 | NcoOtExtSender& ots,
47 | NcoOtExtReceiver& otRecv,
48 | block seed,
49 | double binScaler = 1.0,
50 | u64 inputBitSize = -1);
51 |
52 | void sendInput(std::vector& inputs, Channel& chl);
53 | void sendInput(std::vector& inputs, span chls);
54 |
55 | };
56 |
57 | }
58 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Rr17/Rr17b/Rr17bMPsiReceiver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_RR17B_PSI
4 |
5 | #include "cryptoTools/Common/Defines.h"
6 | #include "cryptoTools/Common/Timer.h"
7 | #include "cryptoTools/Network/Channel.h"
8 | #include "libOTe/NChooseOne/NcoOtExt.h"
9 | #include "libPSI/Tools/SimpleHasher.h"
10 |
11 | namespace osuCrypto
12 | {
13 |
14 | class Rr17bMPsiReceiver : public TimerAdapter
15 | {
16 | public:
17 | Rr17bMPsiReceiver();
18 | ~Rr17bMPsiReceiver();
19 |
20 | bool mHashToSmallerDomain;
21 | u64 mN, mStatSecParam;
22 | block mHashingSeed;
23 | std::vector mIntersection;
24 |
25 |
26 | std::vector> mOtRecvs;
27 |
28 | SimpleHasher mBins;
29 | PRNG mPrng;
30 |
31 | void init(u64 n, u64 statSecParam, Channel& chl0, NcoOtExtReceiver& otRecv, block seed,
32 | double binScaler = 1.0, u64 inputBitSize = -1);
33 | void init(u64 n, u64 statSecParam, span chls, NcoOtExtReceiver& ots, block seed,
34 | double binScaler = 1.0, u64 inputBitSize = -1);
35 |
36 | void sendInput(std::vector& inputs, Channel& chl);
37 | void sendInput(std::vector& inputs, span chls);
38 |
39 | };
40 |
41 |
42 |
43 |
44 | }
45 | #endif
--------------------------------------------------------------------------------
/libPSI/MPSI/Rr17/Rr17b/Rr17bMPsiSender.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_RR17B_PSI
4 |
5 | #include "cryptoTools/Common/Defines.h"
6 | #include "cryptoTools/Common/Timer.h"
7 | #include "cryptoTools/Network/Channel.h"
8 | #include "libOTe/NChooseOne/NcoOtExt.h"
9 | #include "libPSI/Tools/SimpleHasher.h"
10 |
11 | namespace osuCrypto
12 | {
13 |
14 |
15 | class Rr17bMPsiSender : public TimerAdapter
16 | {
17 | public:
18 |
19 |
20 | //static const u64 CodeWordSize = 7;
21 | //static const u64 hasherStepSize;
22 |
23 | Rr17bMPsiSender();
24 | ~Rr17bMPsiSender();
25 |
26 | bool mHashToSmallerDomain;
27 | u64 mN, mStatSecParam;
28 | block mHashingSeed;
29 | SimpleHasher mBins;
30 | PRNG mPrng;
31 |
32 | std::vector> mOtSends;
33 |
34 | void init(u64 n, u64 statSecParam,
35 | span chls,
36 | NcoOtExtSender& ots,
37 | block seed,
38 | double binScaler = 1.0,
39 | u64 inputBitSize = -1);
40 |
41 | void init(u64 n, u64 statSecParam,
42 | Channel & chl0,
43 | NcoOtExtSender& ots,
44 | block seed,
45 | double binScaler = 1.0,
46 | u64 inputBitSize = -1);
47 |
48 | void sendInput(std::vector& inputs, Channel& chl);
49 | void sendInput(std::vector& inputs, span chls);
50 |
51 | };
52 |
53 | }
54 | #endif
--------------------------------------------------------------------------------
/libPSI/PIR/BgiPirClient.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_DRRN_PSI
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | namespace osuCrypto
10 | {
11 | class BgiPirClient
12 | {
13 | public:
14 | typedef boost::multiprecision::uint128_t uint128_t;
15 |
16 | static uint128_t bytesToUint128_t(const span& data);
17 |
18 | u64 mDatasetSize;
19 | u64 mKDepth, mGroupBlkSize;
20 |
21 | void init(u64 dataSetSize, u64 groupByteSize);
22 | block query(span idx, Channel srv0, Channel Srv1, block seed);
23 | block query(uint128_t idx, Channel srv0, Channel Srv1, block seed);
24 |
25 | static void keyGen(span idx, block seed, span k0, span g0, span k1, span g1);
26 | static void keyGen(uint128_t idx, block seed, span k0, span g0, span k1, span g1);
27 | };
28 |
29 | }
30 | #endif
--------------------------------------------------------------------------------
/libPSI/PIR/BgiPirServer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "libPSI/config.h"
4 | #ifdef ENABLE_DRRN_PSI
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | namespace osuCrypto
12 | {
13 |
14 | class BgiPirServer
15 | {
16 | public:
17 | typedef boost::multiprecision::uint128_t uint128_t;
18 |
19 | u64 mKDepth, mGroupBlkSize;
20 |
21 | void init(u64 depth, u64 groupByteSize);
22 |
23 | void serve(Channel chan, span data);
24 |
25 | static u8 evalOne(span idx, span k, span g, block* = nullptr, block* = nullptr, u8* tt = nullptr);
26 | static u8 evalOne(uint128_t idx, span k, span g, block* = nullptr, block* = nullptr, u8* tt = nullptr);
27 | static block traversePath(u64 depth, uint128_t idx, span k);
28 | static block traverseOne(const block &s, const block&k, const osuCrypto::u8 &keep, bool print = false);
29 | static block fullDomainNaive(span data, span k, span g);
30 | static block fullDomain(span data, span k, span g);
31 | //static BitVector BgiPirServer_bv;
32 |
33 |
34 |
35 | struct FullDomainGenerator
36 | {
37 | span k, g;
38 | u64 kDepth;
39 | std::vector prev, next;
40 | bool mHasMore;
41 |
42 |
43 | struct State
44 | {
45 | State()
46 | : kIdx(0)
47 | , d(0)
48 | {}
49 |
50 | u64 kIdx, d, dEnd;
51 | std::vector expandedS;// (8 * g.size());
52 | std::vector>> mByteView;
53 |
54 | std::vector> ss;
55 |
56 | std::array aes;
57 |
58 | std::vector> temp, enc;
59 | std::vector> t_cw;
60 |
61 | };
62 |
63 | State state;
64 |
65 | void init(span kk, span gg);
66 |
67 |
68 |
69 | u64 size();
70 | bool hasMore() { return mHasMore; }
71 | span>> yeild();
72 | };
73 |
74 | struct MultiKey
75 | {
76 | void init(span> kk, span> gg);
77 | void init(u64 numKeys, u64 kSize, u64 gSize);
78 | void setKey(u64 i, spank, span g);
79 | void setKey(u64 i, spankg);
80 | void setKeys(MatrixViewkg);
81 |
82 | span yeild();
83 |
84 | std::array aes;
85 |
86 |
87 |
88 |
89 | u64 mD, mLeafIdx, mGIdx, mBIdx, mNumKeysRound8, mDEnd;
90 | Matrix mBuff;
91 | Matrix mS, mK, mG;
92 | Matrix> mTcw;
93 |
94 |
95 |
96 | std::vector getK(u64 i);
97 | };
98 | };
99 |
100 | }
101 | #endif
--------------------------------------------------------------------------------
/libPSI/PSI/Dcw/DcwRBfPsiReceiver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_DCW_PSI
4 | #include "cryptoTools/Common/Defines.h"
5 | #include "cryptoTools/Network/Channel.h"
6 |
7 | #include "cryptoTools/Common/BitVector.h"
8 | #include "libOTe/TwoChooseOne/OTExtInterface.h"
9 | namespace osuCrypto
10 | {
11 |
12 |
13 |
14 | class DcwRBfPsiReceiver
15 | {
16 | public:
17 |
18 | u64 mMyInputSize, mTheirInputSize, mBfBitCount, mNumHashFunctions;
19 | block mHashingSeed;
20 | std::vector mIntersection;
21 | std::vector mMessages;
22 | BitVector mRandChoices;
23 | block mSeed;
24 |
25 | void init(u64 n, u64 statSecParam, OtExtReceiver& otExt, Channel& chl0, block seed);
26 | void init(u64 n, u64 statSecParam, OtExtReceiver& otExt, span chl0, block seed);
27 | void sendInput(std::vector& inputs, Channel& chl);
28 | void sendInput(std::vector& inputs, span chl0);
29 | };
30 |
31 | }
32 |
33 |
34 | #endif
--------------------------------------------------------------------------------
/libPSI/PSI/Dcw/DcwRBfPsiSender.cpp:
--------------------------------------------------------------------------------
1 | #include "DcwRBfPsiSender.h"
2 | #ifdef ENABLE_DCW_PSI
3 | #include "libOTe/TwoChooseOne/KosOtExtSender.h"
4 | #include "cryptoTools/Crypto/PRNG.h"
5 | #include "cryptoTools/Crypto/Commit.h"
6 | #include "cryptoTools/Common/Log.h"
7 | //#include "cryptoTools/Crypto/ShamirSSScheme2.h"
8 | #include "libOTe/Base/BaseOT.h"
9 | #include "libOTe/TwoChooseOne/SilentOtExtSender.h"
10 |
11 |
12 | namespace osuCrypto {
13 |
14 | void DcwRBfPsiSender::init(u64 n, u64 statSecParam, OtExtSender& otExt, Channel& chl, block seed)
15 | {
16 | init(n, statSecParam, otExt, { &chl, 1 }, seed);
17 | }
18 |
19 | void DcwRBfPsiSender::init(u64 n, u64 statSecParam, OtExtSender& otExt, span chls, block seed)
20 | {
21 |
22 | gTimer.setTimePoint("init.start");
23 |
24 | mN = n;
25 | PRNG prng(seed);
26 | mSeed = prng.get();
27 | auto myHashSeed = prng.get();
28 | auto& chl0 = chls[0];
29 |
30 | mNumHashFunctions = 128;
31 | mBfBitCount = (u64)(n * mNumHashFunctions * 1.5);
32 |
33 | mSendOtMessages.resize(mBfBitCount);
34 |
35 | chl0.asyncSendCopy(myHashSeed);
36 | block theirHashingSeed;
37 | chl0.recv(theirHashingSeed);
38 | gTimer.setTimePoint("init.commitDone");
39 |
40 | mHashSeed = myHashSeed ^ theirHashingSeed;
41 |
42 | //if (dynamic_cast(&otExt))
43 | //{
44 | // auto rBefore = chls[0].getTotalDataRecv();
45 | // auto sBefore = chls[0].getTotalDataSent();
46 |
47 | // //std::cout << "silent" << std::endl;
48 | // auto& ot = dynamic_cast(otExt);
49 | // ot.silentSend(mSendOtMessages, prng, chls);
50 |
51 | // char c;
52 | // chls[0].send(c);
53 | // chls[0].recv(c);
54 |
55 | // auto rAfter = chls[0].getTotalDataRecv();
56 | // auto sAfter = chls[0].getTotalDataSent();
57 |
58 | // std::cout << "1 before sent " << sBefore << std::endl;
59 | // std::cout << "1 before recv " << rBefore << std::endl;
60 |
61 | // std::cout << "1 after sent " << sAfter << std::endl;
62 | // std::cout << "1 after recv " << rAfter << std::endl;
63 | //}
64 | //else
65 | {
66 |
67 | if (otExt.hasBaseOts() == false)
68 | {
69 | otExt.genBaseOts(prng, chl0);
70 | }
71 |
72 | // this is a lambda function that does part of the OT extension where i am the sender. Again
73 | // malicious PSI does OTs in both directions.
74 | auto sendOtRountine = [this](u64 i, u64 total, OtExtSender& ots, block seed, Channel& chl)
75 | {
76 | // compute the region of the OTs im going to do
77 | u64 start = std::min(roundUpTo(i * mSendOtMessages.size() / total, 128), mSendOtMessages.size());
78 | u64 end = std::min(roundUpTo((i + 1) * mSendOtMessages.size() / total, 128), mSendOtMessages.size());
79 |
80 | //std::cout << IoStream::lock << "send Chl " << chl.getName() <<" "<< i << "/"<< total << " get " << start << " - " << end << std::endl << IoStream::unlock;
81 |
82 | if (end - start)
83 | {
84 |
85 | // get a view of where the messages should be stored.
86 | span> range(
87 | mSendOtMessages.begin() + start,
88 | mSendOtMessages.begin() + end);
89 | PRNG prng(seed);
90 |
91 | // do the extension.
92 | ots.send(range, prng, chl);
93 | }
94 |
95 | };
96 |
97 |
98 | // compute how many threads we want to do for each direction.
99 | // the current thread will do one of the OT receives so -1 for that.
100 | u64 numSendThreads = chls.size() - 1;
101 |
102 | std::vector> sendOts(numSendThreads);
103 |
104 | // where we will store the threads that are doing the extension
105 | std::vector thrds(numSendThreads);
106 |
107 | // some iters to help giving out resources.
108 | auto thrdIter = thrds.begin();
109 | auto chlIter = chls.begin() + 1;
110 |
111 |
112 | // do the same thing but for the send OT extensions
113 | for (u64 i = 0; i < numSendThreads; ++i)
114 | {
115 | auto seed = prng.get();
116 | sendOts[i] = std::move(otExt.split());
117 |
118 | *thrdIter++ = std::thread([&, i, chlIter]()
119 | {
120 | //std::cout << IoStream::lock << "r sendOt " << i << " " << (**chlIter).getName() << std::endl << IoStream::unlock;
121 | sendOtRountine(i + 1, numSendThreads + 1, *sendOts[i].get(), seed, *chlIter);
122 | });
123 |
124 | ++chlIter;
125 | }
126 |
127 | seed = prng.get();
128 | sendOtRountine(0, numSendThreads + 1, otExt, seed, chl0);
129 |
130 |
131 | gTimer.setTimePoint("init.OtExtDone");
132 |
133 | for (auto& thrd : thrds)
134 | thrd.join();
135 | }
136 |
137 | gTimer.setTimePoint("init.Done");
138 |
139 | }
140 |
141 |
142 | void DcwRBfPsiSender::sendInput(std::vector& inputs, Channel & chl)
143 | {
144 | std::vector cc{ chl };
145 |
146 | sendInput(inputs, cc);
147 | }
148 |
149 | void DcwRBfPsiSender::sendInput(std::vector& inputs, span chls)
150 | {
151 |
152 | if (inputs.size() != mN)
153 | throw std::runtime_error(LOCATION);
154 |
155 | gTimer.setTimePoint("online.start");
156 | PRNG prng(mSeed);
157 | auto & chl = chls[0];
158 |
159 | BitVector otCorrection(mBfBitCount);
160 | chl.recv(otCorrection);
161 |
162 | gTimer.setTimePoint("online.otCorrectionRecv");
163 |
164 | auto start = 0;
165 | auto end = inputs.size();
166 |
167 | PRNG hashSeedGen(mHashSeed);
168 | std::vector mHashs(mNumHashFunctions / 2);
169 |
170 | for (u64 i = 0; i < mHashs.size(); ++i)
171 | {
172 | mHashs[i].setKey(hashSeedGen.get());
173 | }
174 |
175 | std::vector myMasks(inputs.size());
176 |
177 | for (u64 i = start, k = 0; i < end; ++i, ++k)
178 | {
179 | myMasks[i] = ZeroBlock;
180 |
181 | for (u64 j = 0; j < mHashs.size(); ++j)
182 | {
183 | auto hashOut = mHashs[j].ecbEncBlock(inputs[i]) ^ inputs[i];
184 | auto idx = hashOut.get();
185 | idx[0] %= mBfBitCount;
186 | idx[1] %= mBfBitCount;
187 |
188 | myMasks[i] = myMasks[i] ^ mSendOtMessages[idx[0]][otCorrection[idx[0]] ^ 1];
189 | myMasks[i] = myMasks[i] ^ mSendOtMessages[idx[1]][otCorrection[idx[1]] ^ 1];
190 | }
191 | }
192 |
193 | chl.asyncSend(std::move(myMasks));
194 | gTimer.setTimePoint("online.masksSent");
195 | }
196 | }
197 | #endif
198 |
--------------------------------------------------------------------------------
/libPSI/PSI/Dcw/DcwRBfPsiSender.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "libPSI/config.h"
3 | #ifdef ENABLE_DCW_PSI
4 |
5 | #include "cryptoTools/Common/Defines.h"
6 | #include "cryptoTools/Network/Channel.h"
7 | #include "cryptoTools/Crypto/RandomOracle.h"
8 | #include "libOTe/TwoChooseOne/OTExtInterface.h"
9 |
10 | namespace osuCrypto {
11 |
12 |
13 |
14 | class DcwRBfPsiSender
15 | {
16 | public:
17 |
18 | u64 mN, mBfBitCount, mNumHashFunctions;
19 |
20 | std::vector> mSendOtMessages;
21 | block mSeed, mHashSeed;
22 |
23 | void init(u64 n, u64 statSecParam, OtExtSender& otExt, Channel& chl, block seed);
24 | void init(u64 n, u64 statSecParam, OtExtSender& otExt, span chl, block seed);
25 |
26 | void sendInput(std::vector& inputs, Channel& chl);
27 | void sendInput(std::vector& inputs, span chl);
28 | };
29 |
30 | }
31 |
32 |
33 | #endif
--------------------------------------------------------------------------------
/libPSI/PSI/Drrn/DrrnPsiClient.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "libPSI/config.h"
4 | #ifdef ENABLE_DRRN_PSI
5 |
6 | #ifndef ENABLE_KKRT_PSI
7 | #pragma error("ENABLE_KKRT_PSI must be defined.");
8 | #endif
9 |
10 | #ifndef ENABLE_KKRT
11 | #pragma error("ENABLE_KKRT must be defined in libOTe.");
12 | #endif
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include