Skip to content

Commit 657f6da

Browse files
authored
shared library (#176)
added shared library support and fixed a bug with aligned vectors
1 parent d21bc4d commit 657f6da

File tree

8 files changed

+146
-29
lines changed

8 files changed

+146
-29
lines changed

.github/workflows/build-test.yml

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@ jobs:
2727
- uses: actions/checkout@v2
2828
with:
2929
submodules: recursive
30-
31-
# Runs a set of commands using the runners shell
32-
33-
#- name: build relic
34-
# run: python3 build.py -DENABLE_BOOST=OFF -DENABLE_SODIUM=OFF -DENABLE_ASAN=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
35-
36-
#- name: build bitpolymul
37-
# run: python3 build.py --bitpolymul --par=4 -DVERBOSE_FETCH=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
38-
30+
3931
- name: build libOTe
4032
run: python3 build.py --par=4 -D ENABLE_ALL_OT=ON -DENABLE_CIRCUITS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_ASAN=ON -DENABLE_MOCK_OT=true
4133

@@ -83,10 +75,22 @@ jobs:
8375
rm -rf out/
8476
cd ../..
8577
86-
78+
79+
# This workflow contains a single job called "build"
80+
build-ubuntu-sodium:
81+
# The type of runner that the job will run on
82+
runs-on: ubuntu-latest
83+
timeout-minutes: 30
84+
85+
# Steps represent a sequence of tasks that will be executed as part of the job
86+
steps:
87+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
88+
- uses: actions/checkout@v2
89+
with:
90+
submodules: recursive
91+
8792
- name: build libOTe w/ sodium
8893
run: |
89-
rm ./out/build/linux/frontend/frontend_libOTe
9094
python3 build.py --par=4 -D ENABLE_ALL_OT=ON -D ENABLE_SODIUM=ON -DENABLE_RELIC=OFF -DPRINT_LOG_ON_FAIL=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
9195
9296
- name: unit tests
@@ -132,6 +136,69 @@ jobs:
132136
rm -rf out/
133137
cd ../..
134138
139+
140+
141+
# This workflow contains a single job called "build"
142+
build-ubuntu-shared:
143+
# The type of runner that the job will run on
144+
runs-on: ubuntu-latest
145+
timeout-minutes: 30
146+
147+
# Steps represent a sequence of tasks that will be executed as part of the job
148+
steps:
149+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
150+
- uses: actions/checkout@v2
151+
with:
152+
submodules: recursive
153+
154+
- name: build libOTe
155+
run: |
156+
python3 build.py --par=4 -D ENABLE_ALL_OT=ON -DENABLE_CIRCUITS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_MOCK_OT=true -DENABLE_PIC=ON -DENABLE_SHARED=ON
157+
158+
- name: unit tests
159+
run: ./out/build/linux/frontend/frontend_libOTe -u
160+
161+
162+
- name: find source tree
163+
run: |
164+
cd libOTe_Tests/cmakeTests
165+
cmake -S . -B out/ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSODIUM=ON -D CMAKE_PREFIX_PATH=../../
166+
cmake --build out/
167+
./out/main
168+
rm -rf out/
169+
cd ../..
170+
171+
- name: hint test
172+
run: |
173+
cd libOTe_Tests/cmakeTests
174+
cmake -S . -B out/ -DSODIUM=ON -D LIBOTE_HINT=../..
175+
cmake --build out/
176+
./out/main
177+
rm -rf out/
178+
cd ../..
179+
180+
- name: install prefix test
181+
run: |
182+
python3 build.py --install=~/install
183+
cd libOTe_Tests/cmakeTests
184+
cmake -S . -B out/ -DSODIUM=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=~/install
185+
cmake --build out/
186+
./out/main
187+
rm -rf out/
188+
cd ../..
189+
190+
191+
- name: install test
192+
run: |
193+
python3 build.py --install --sudo
194+
cd libOTe_Tests/cmakeTests
195+
cmake -S . -B out/ -DSODIUM=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
196+
cmake --build out/
197+
./out/main
198+
rm -rf out/
199+
cd ../..
200+
201+
135202
# This workflow contains a single job called "build"
136203
build-osx:
137204
# The type of runner that the job will run on

CMakePresets.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@
1010
"cacheVariables": {
1111
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
1212
"FETCH_AUTO": true,
13-
"ENABLE_ALL_OT": true,
1413
"ENABLE_SSE": true,
1514
"ENABLE_AVX": true,
1615
"ENABLE_BOOST": false,
1716
"ENABLE_BITPOLYMUL": false,
1817
"ENABLE_CIRCUITS": true,
19-
"ENABLE_SIMPLESTOT": true,
20-
"ENABLE_MRR": true,
21-
"ENABLE_MR": true,
18+
"ENABLE_SIMPLESTOT": false,
19+
"ENABLE_SIMPLESTOT_ASM": false,
20+
"ENABLE_MR_KYBER": false,
21+
"ENABLE_MRR": false,
22+
"ENABLE_MR": false,
2223
"ENABLE_RELIC": false,
2324
"ENABLE_SODIUM": false,
2425
"ENABLE_ASAN": true,
2526
"ENABLE_MOCK_OT": true,
27+
"LIBOTE_SHARED": true,
28+
"ENABLE_PIC": true,
2629
"LIBOTE_STD_VER": "20",
2730
"CMAKE_PREFIX_PATH": "${sourceDir}/../out/install",
2831
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
@@ -72,7 +75,9 @@
7275
"VERBOSE_FETCH": true,
7376
"ENABLE_SSE": true,
7477
"ENABLE_AVX": true,
75-
"ENABLE_ASAN": true,
78+
"ENABLE_ASAN": false,
79+
"BUILD_SHARED_LIBS": false,
80+
"LIBOTE_SHARED": true,
7681
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
7782
"CMAKE_PREFIX_PATH": "${sourceDir}/../out/install/${presetName}"
7883
},

cmake/buildOptions.cmake

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if(DEFINED ENABLE_ALL_OT)
5252

5353

5454
# requires linux
55-
if(UNIX AND NOT(APPLE OR MSVC))
55+
if(UNIX AND NOT(APPLE OR MSVC) AND NOT ENABLE_PIC)
5656
set(oc_BB ${ENABLE_ALL_OT})
5757
else()
5858
set(oc_BB OFF)
@@ -180,7 +180,9 @@ message(STATUS "Option: ENABLE_KKRT = ${ENABLE_KKRT}\n\n")
180180

181181

182182
message(STATUS "other \n=======================================================")
183-
message(STATUS "Option: NO_KOS_WARNING = ${NO_KOS_WARNING}\n\n")
183+
message(STATUS "Option: NO_KOS_WARNING = ${NO_KOS_WARNING}")
184+
message(STATUS "Option: LIBOTE_SHARED = ${LIBOTE_SHARED}\n\n")
185+
184186

185187
#############################################
186188
# Config Checks #
@@ -226,5 +228,17 @@ if(ENABLE_IKNP AND NOT ENABLE_KOS)
226228
endif()
227229

228230

231+
if(LIBOTE_SHARED AND NOT ENABLE_PIC AND NOT MSVC)
232+
message(FATAL_ERROR " LIBOTE_SHARED requires ENABLE_PIC. Set ENABLE_PIC to true and recompile.")
233+
endif()
234+
235+
236+
if(ENABLE_SIMPLESTOT_ASM AND ENABLE_PIC)
237+
message(FATAL_ERROR " ENABLE_SIMPLESTOT_ASM can not be compiled with ENABLE_PIC.")
238+
endif()
239+
if(ENABLE_MR_KYBER AND ENABLE_PIC)
240+
message(FATAL_ERROR " ENABLE_MR_KYBER can not be compiled with ENABLE_PIC.")
241+
endif()
242+
229243

230244
#include(${CMAKE_CURRENT_LIST_DIR}/../cryptoTools/cmake/cryptoToolsBuildOptions.cmake)

cmake/install.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ install(FILES
6060
set(exportLibs
6161
"libOTe;libOTe_Tests;")
6262

63+
if(LIBOTE_SHARED)
64+
set(exportLibs "${exportLibs}libOTeShared;")
65+
endif()
66+
6367
if(ENABLE_MR_KYBER)
6468
set(exportLibs "${exportLibs}KyberOT;")
6569

6670
# install headers
6771
install(
68-
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../KyberOT/
72+
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../thirdparty/KyberOT/
6973
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KyberOT
7074
FILES_MATCHING PATTERN "*.h")
7175
endif()
@@ -74,7 +78,7 @@ if(ENABLE_SIMPLESTOT_ASM)
7478
set(exportLibs "${exportLibs}SimplestOT;")
7579
# install headers
7680
install(
77-
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../SimplestOT/
81+
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../thirdparty/SimplestOT/
7882
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SimplestOT
7983
FILES_MATCHING PATTERN "*.h")
8084
endif()

libOTe/CMakeLists.txt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(SRCS "${SRCS}")
77
add_library(libOTe STATIC ${SRCS} )
88

99

10+
1011
# make projects that include libOTe use this as an include folder
1112
target_include_directories(libOTe PUBLIC
1213
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..>
@@ -18,9 +19,7 @@ target_include_directories(libOTe PUBLIC
1819
target_link_libraries(libOTe cryptoTools)
1920

2021
if(MSVC)
21-
target_compile_definitions(libOTe PUBLIC _NO_DEBUG_HEAP=1)
2222
target_compile_options(libOTe PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/std:c++${LIBOTE_STD_VER}>)
23-
#target_compile_options(libOTe PRIVATE -openmp:experimental)
2423
else()
2524
target_compile_options(libOTe PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-std=c++${LIBOTE_STD_VER}>)
2625

@@ -36,14 +35,30 @@ if (ENABLE_BITPOLYMUL)
3635
endif ()
3736
if(ENABLE_SIMPLESTOT_ASM)
3837
target_link_libraries(libOTe SimplestOT)
39-
#target_compile_options(libOTe PRIVATE -fPIC -no-pie)
4038
endif()
4139

4240
if(ENABLE_MR_KYBER)
4341
target_link_libraries(libOTe KyberOT)
4442
endif()
4543

4644

45+
if(LIBOTE_SHARED)
46+
47+
add_library(libOTeShared SHARED ${SRCS} )
48+
target_link_libraries(libOTeShared libOTe)
49+
if(MSVC)
50+
target_compile_options(libOTeShared PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/std:c++${LIBOTE_STD_VER}>)
51+
else()
52+
target_compile_options(libOTeShared PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-std=c++${LIBOTE_STD_VER}>)
53+
54+
if(ENABLE_SSE)
55+
target_compile_options(libOTeShared PRIVATE -maes -msse2 -msse3 -msse4.1 -mpclmul)
56+
endif()
57+
if(ENABLE_AVX)
58+
target_compile_options(libOTeShared PRIVATE -mavx2)
59+
endif()
60+
endif()
61+
endif()
4762

4863
#############################################
4964
# Install #

libOTe/Triple/Foleage/FoleageTriple.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace osuCrypto
143143

144144
BitVector choice(baseCount.mRecvCount);
145145
choice.randomize(prng);
146-
std::vector<block> recvMsg(choice.size());
146+
AlignedUnVector<block> recvMsg(choice.size());
147147
co_await mOtExtRecver->receive(choice, recvMsg, prng, sock);
148148

149149
if (extSenderCount)
@@ -153,7 +153,7 @@ namespace osuCrypto
153153
mOtExtSender->setBaseOts(senderMsg, senderChoice);
154154
}
155155

156-
std::vector<std::array<block, 2>> sendMsg(baseCount.mSendCount);
156+
AlignedUnVector<std::array<block, 2>> sendMsg(baseCount.mSendCount);
157157
co_await mOtExtSender->send(sendMsg, prng, sock);
158158

159159
choice = BitVector(choice.data(), choice.size() - extSenderCount, extSenderCount);
@@ -206,7 +206,7 @@ namespace osuCrypto
206206
baseCount.mSendCount += extRecverCount;
207207
}
208208

209-
std::vector<std::array<block,2>> sendMsg(baseCount.mSendCount);
209+
AlignedUnVector<std::array<block,2>> sendMsg(baseCount.mSendCount);
210210
co_await mOtExtSender->send(sendMsg, prng, sock);
211211

212212
if (extRecverCount)
@@ -217,7 +217,7 @@ namespace osuCrypto
217217

218218
BitVector choice(baseCount.mRecvCount);
219219
choice.randomize(prng);
220-
std::vector<block> recvMsg(choice.size());
220+
AlignedUnVector<block> recvMsg(choice.size());
221221
co_await mOtExtRecver->receive(choice, recvMsg, prng, sock);
222222

223223
setBaseOts(span<std::array<block, 2>>(sendMsg).subspan(extRecverCount), recvMsg, choice);

libOTe/TwoChooseOne/SoftSpokenOT/SoftSpokenShOtExt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace osuCrypto
3737
MACORO_TRY{
3838
#ifdef ENABLE_SSE
3939
if ((u64)messages.data() % 32)
40-
throw std::runtime_error("SoftSpokenShOtSender: messages must point to 32 byte aligned memory. " LOCATION);
40+
throw std::runtime_error("SoftSpokenShOtSender: messages must point to 32 byte aligned memory. " + macoro::trace(co_await macoro::get_trace()).str());
4141
#endif
4242
auto numInstances = u64{};
4343
auto numChunks = u64{};

libOTe_Tests/Foleage_Tests.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,21 @@ namespace osuCrypto
247247
auto r = macoro::sync_wait(macoro::when_all_ready(
248248
oles[0].expand(ALsb, AMsb, C0Lsb, C0Msb, prng0, sock[0]),
249249
oles[1].expand(BLsb, BMsb, C1Lsb, C1Msb, prng1, sock[1])));
250-
std::get<0>(r).result();
250+
std::exception_ptr ep;
251+
try{
252+
std::get<0>(r).result();
253+
}
254+
catch (std::exception& e)
255+
{
256+
std::cout << e.what() << std::endl;
257+
ep = std::current_exception();
258+
}
259+
251260
std::get<1>(r).result();
252261

262+
if (ep)
263+
std::rethrow_exception(ep);
264+
253265
// Now we check that we got the correct OLE correlations and fail
254266
// the test otherwise.
255267
for (size_t i = 0; i < blocks; i++)

0 commit comments

Comments
 (0)