Skip to content

Commit

Permalink
cpp 20 update
Browse files Browse the repository at this point in the history
  • Loading branch information
ladnir committed Apr 29, 2024
1 parent 24fab35 commit aabf944
Show file tree
Hide file tree
Showing 39 changed files with 4,514 additions and 5,313 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ if(DEFINED LIBOTE_CPP_VER)
unset(LIBOTE_CPP_VER CACHE )
endif()
if(NOT DEFINED LIBOTE_STD_VER)
set(LIBOTE_STD_VER 17)
set(LIBOTE_STD_VER 20)
endif()
if(NOT LIBOTE_STD_VER EQUAL 20 AND
NOT LIBOTE_STD_VER EQUAL 17)
message(FATAL_ERROR "Unknown c++ version. LIBOTE_STD_VER=${LIBOTE_STD_VER}")
if (NOT LIBOTE_STD_VER EQUAL 23 AND
NOT LIBOTE_STD_VER EQUAL 20)
message(FATAL_ERROR "unsupported c++ version (requires 20,23). LIBOTE_STD_VER=${LIBOTE_STD_VER}")
endif()
set(CRYPTO_TOOLS_STD_VER ${LIBOTE_STD_VER})
if(NOT DEFINED ENABLE_COPROTO)
set(ENABLE_COPROTO true)
endif()
if(NOT ENABLE_COPROTO)
message("warning: setting ENABLE_BOOST as true")
message("warning: setting ENABLE_COPROTO as true")
set(ENABLE_COPROTO true)
endif()

Expand Down
10 changes: 5 additions & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"ENABLE_ALL_OT": true,
"ENABLE_SSE": true,
"ENABLE_AVX": true,
"ENABLE_BOOST": true,
"ENABLE_BOOST": false,
"ENABLE_BITPOLYMUL": false,
"ENABLE_CIRCUITS": true,
"ENABLE_SIMPLESTOT": true,
"ENABLE_MRR": true,
"ENABLE_MR": true,
"ENABLE_SIMPLESTOT": true,
"ENABLE_RELIC": true,
"LIBOTE_STD_VER": "17",
"LIBOTE_STD_VER": "20",
"CMAKE_PREFIX_PATH": "${sourceDir}/../out/install",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
},
Expand Down Expand Up @@ -51,7 +51,7 @@
"ENABLE_INSECURE_SILVER": false,
"ENABLE_PPRF": true,
"ENABLE_SILENT_VOLE": true,
"LIBOTE_STD_VER": "17",
"LIBOTE_STD_VER": "20",
"ENABLE_ALL_OT": true,
"ENABLE_KKRT": "ON",
"ENABLE_IKNP": "ON",
Expand All @@ -60,7 +60,7 @@
"ENABLE_GMP": false,
"ENABLE_RELIC": false,
"ENABLE_SODIUM": true,
"ENABLE_BOOST": false,
"ENABLE_BOOST": true,
"ENABLE_BITPOLYMUL": true,
"FETCH_AUTO": "ON",
"ENABLE_CIRCUITS": true,
Expand Down Expand Up @@ -91,7 +91,7 @@
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"LIBOTE_STD_VER": "17",
"LIBOTE_STD_VER": "20",
"ENABLE_GMP": false,
"ENABLE_ALL_OT": true,
"ENABLE_RELIC": false,
Expand Down
41 changes: 17 additions & 24 deletions frontend/ExampleNChooseOne.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,18 @@ namespace osuCrypto
// create a lambda function that performs the computation of a single receiver thread.
auto recvRoutine = [&]() -> task<>
{
MC_BEGIN(task<>, &,
i = u64{}, min = u64{},
recvMsgs = std::vector<block>{},
choices = std::vector<u64>{}
);
auto i = u64{}, min = u64{};
auto recvMsgs = std::vector<block>{};
auto choices = std::vector<u64>{};

recver.configure(maliciousSecure, statSecParam, inputBitCount);
//MC_AWAIT(sync(chl, Role::Receiver));

if (randomOT)
{
// once configure(...) and setBaseOts(...) are called,
// we can compute many batches of OTs. First we need to tell
// the instance how many OTs we want in this batch. This is done here.
MC_AWAIT(recver.init(numOTs, prng, chl));
co_await (recver.init(numOTs, prng, chl));

// now we can iterate over the OTs and actually retrieve the desired
// messages. However, for efficiency we will do this in steps where
Expand Down Expand Up @@ -104,13 +101,13 @@ namespace osuCrypto
// allows the sender to also compute the OT mMessages. Since we just
// encoded "min" OT mMessages, we will tell the class to send the
// next min "correction" values.
MC_AWAIT(recver.sendCorrection(chl, min));
co_await (recver.sendCorrection(chl, min));
}

// once all numOTs have been encoded and had their correction values sent
// we must call check. This allows to sender to make sure we did not cheat.
// For semi-honest protocols, this can and will be skipped.
MC_AWAIT(recver.check(chl, prng.get()));
co_await (recver.check(chl, prng.get()));
}
else
{
Expand All @@ -122,28 +119,25 @@ namespace osuCrypto
choices[i] = prng.get<u8>();

// the messages that were learned are written to recvMsgs.
MC_AWAIT(recver.receiveChosen(numChosenMsgs, recvMsgs, choices, prng, chl));
co_await (recver.receiveChosen(numChosenMsgs, recvMsgs, choices, prng, chl));
}

MC_AWAIT(chl.flush());
MC_END();
co_await (chl.flush());
};

// create a lambda function that performs the computation of a single sender thread.
auto sendRoutine = [&]()
auto sendRoutine = [&]() -> macoro::task<>
{
MC_BEGIN(task<>, &,
sendMessages = Matrix<block>{},
i = u64{}, min = u64{}
);
auto sendMessages = Matrix<block>{};
auto i = u64{}, min = u64{};

sender.configure(maliciousSecure, statSecParam, inputBitCount);
//MC_AWAIT(sync(chl, Role::Sender));
//co_await (sync(chl, Role::Sender));

if (randomOT)
{
// Same explanation as above.
MC_AWAIT(sender.init(numOTs, prng, chl));
co_await (sender.init(numOTs, prng, chl));

// Same explanation as above.
for (i = 0; i < numOTs; )
Expand All @@ -158,7 +152,7 @@ namespace osuCrypto
// Note that the step size must match what the receiver used.
// If this is unknown you can use recvCorrection(chl) -> u64
// which will tell you how many were sent.
MC_AWAIT(sender.recvCorrection(chl, min));
co_await (sender.recvCorrection(chl, min));

// we now encode any OT message with index less that i + min.
for (u64 j = 0; j < min; ++j, ++i)
Expand All @@ -185,7 +179,7 @@ namespace osuCrypto

// This call is required to make sure the receiver did not cheat.
// All corrections must be received before this is called.
MC_AWAIT(sender.check(chl, ZeroBlock));
co_await (sender.check(chl, ZeroBlock));
}
else
{
Expand All @@ -194,12 +188,11 @@ namespace osuCrypto
prng.get(sendMessages.data(), sendMessages.size());

// perform the OTs with the given messages.
MC_AWAIT(sender.sendChosen(sendMessages, prng, chl));
co_await (sender.sendChosen(sendMessages, prng, chl));

}

MC_AWAIT(chl.flush());
MC_END();
co_await (chl.flush());
};


Expand Down
2 changes: 1 addition & 1 deletion frontend/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace osuCrypto
u64 n = cmd.getOr("n", 1ull << cmd.getOr("nn", 14));

PRNG prng0(ZeroBlock), prng1(ZeroBlock);
block delta = prng0.get();
//block delta = prng0.get();

auto sock = coproto::LocalAsyncSocket::makePair();

Expand Down
33 changes: 15 additions & 18 deletions frontend/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,27 @@ namespace osuCrypto

task<> sync(Socket& chl, Role role)
{
MC_BEGIN(task<>,&chl, role,
dummy = u8{},
timer = std::unique_ptr<Timer>{new Timer},
start = Timer::timeUnit{},
mid = Timer::timeUnit{},
end = Timer::timeUnit{},
ms = u64{},
rrt = std::chrono::system_clock::duration{}
);
auto dummy = u8{};
auto timer = std::unique_ptr<Timer>{ new Timer };
auto start = Timer::timeUnit{};
auto mid = Timer::timeUnit{};
//auto end = Timer::timeUnit{};
auto ms = u64{};
auto rrt = std::chrono::system_clock::duration{};

if (role == Role::Receiver)
{

MC_AWAIT(chl.recv(dummy));
co_await(chl.recv(dummy));

start = timer->setTimePoint("");

MC_AWAIT(chl.send(dummy));
MC_AWAIT(chl.recv(dummy));
co_await(chl.send(dummy));
co_await(chl.recv(dummy));

mid = timer->setTimePoint("");

MC_AWAIT(chl.send(std::move(dummy)));
co_await(chl.send(std::move(dummy)));

rrt = mid - start;
ms = std::chrono::duration_cast<std::chrono::milliseconds>(rrt).count();
Expand All @@ -187,13 +185,12 @@ namespace osuCrypto
}
else
{
MC_AWAIT(chl.send(dummy));
MC_AWAIT(chl.recv(dummy));
MC_AWAIT(chl.send(dummy));
MC_AWAIT(chl.recv(dummy));
co_await(chl.send(dummy));
co_await(chl.recv(dummy));
co_await(chl.send(dummy));
co_await(chl.recv(dummy));
}

MC_END();
}


Expand Down
Loading

0 comments on commit aabf944

Please sign in to comment.