Skip to content

Commit

Permalink
try catch for protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
ladnir committed May 1, 2024
1 parent cdab2ba commit 2f10f3b
Show file tree
Hide file tree
Showing 23 changed files with 1,503 additions and 1,193 deletions.
14 changes: 12 additions & 2 deletions libOTe/Base/MasnyRindal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace osuCrypto
span<block> messages,
PRNG& prng,
Socket& chl)
{
try {
using namespace DefaultCurve;

//MC_BEGIN(task<>, &choices, messages, &prng, &chl,
Expand Down Expand Up @@ -91,10 +91,15 @@ namespace osuCrypto
}

}
catch (...)
{
chl.close();
throw;
}


task<> MasnyRindal::send(span<std::array<block, 2>> messages, PRNG& prng, Socket& chl)
{
try {
using namespace DefaultCurve;
Curve{}; // required to init relic

Expand Down Expand Up @@ -143,5 +148,10 @@ namespace osuCrypto
}
}
}
catch (...)
{
chl.close();
throw;
}
}
#endif
14 changes: 12 additions & 2 deletions libOTe/Base/MasnyRindalKyber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace osuCrypto
span<block> messages,
PRNG& prng,
Socket& chl)
{
try {
static_assert(std::is_trivial<KyberOtRecvPKs>::value, "");
static_assert(std::is_trivial<KyberOTCtxt>::value, "");

Expand Down Expand Up @@ -41,12 +41,17 @@ namespace osuCrypto
memcpy(&messages[i], ot[i].rot, sizeof(block));
}
}
catch (...)
{
chl.close();
throw;
}

task<> MasnyRindalKyber::send(
span<std::array<block, 2>> messages,
PRNG& prng,
Socket& chl)
{
try {
auto pkBuff = std::vector<KyberOtRecvPKs>{};
auto ctxts = std::vector<KyberOTCtxt>{};
auto ptxt = KyberOTPtxt{ };
Expand All @@ -72,5 +77,10 @@ namespace osuCrypto

co_await chl.send(std::move(ctxts));
}
catch (...)
{
chl.close();
throw;
}
}
#endif
14 changes: 12 additions & 2 deletions libOTe/Base/McRosRoy.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace osuCrypto
span<block> messages,
PRNG& prng,
Socket& chl)
{
try {

auto A = Point{};
auto sk = std::vector<Number>{};
Expand Down Expand Up @@ -159,13 +159,18 @@ namespace osuCrypto
}

}
catch (...)
{
chl.close();
throw;
}

template<typename DSPopf>
task<> McRosRoy<DSPopf>::send(
span<std::array<block, 2>> msg,
PRNG& prng,
Socket& chl)
{
try {

Curve{}; // init relic
auto A = Point{};
Expand Down Expand Up @@ -211,6 +216,11 @@ namespace osuCrypto
ro.Final(msg[i][1]);
}
}
catch (...)
{
chl.close();
throw;
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions libOTe/Base/McRosRoyTwist.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace osuCrypto

template<typename DSPopf>
inline task<> McRosRoyTwist<DSPopf>::receive(const BitVector& choices, span<block> messages, PRNG& prng, Socket& chl)
{
try {
auto n = choices.size();
auto sk = std::vector<Scalar25519>{};
auto curveChoice = std::vector<u8>{};
Expand Down Expand Up @@ -179,10 +179,15 @@ namespace osuCrypto
ro.Final(messages[i]);
}
}
catch (...)
{
chl.close();
throw;
}

template<typename DSPopf>
inline task<> McRosRoyTwist<DSPopf>::send(span<std::array<block, 2>> msg, PRNG& prng, Socket& chl)
{
try {

auto n = static_cast<u64>(msg.size());
auto sk = Scalar25519(prng);
Expand Down Expand Up @@ -225,6 +230,11 @@ namespace osuCrypto
ro.Final(msg[i][1]);
}
}
catch (...)
{
chl.close();
throw;
}

template<typename DSPopf>
inline typename McRosRoyTwist<DSPopf>::Monty25519 McRosRoyTwist<DSPopf>::blockToCurve(Block256 b)
Expand Down
28 changes: 24 additions & 4 deletions libOTe/Base/SimplestOT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace osuCrypto
span<block> msg,
PRNG& prng,
Socket& chl)
{
try {
using namespace DefaultCurve;
Curve{};// init relic
auto buff = std::vector<u8>{};
Expand Down Expand Up @@ -75,12 +75,17 @@ namespace osuCrypto
ro.Final(msg[i]);
}
}
catch (...)
{
chl.close();
throw;
}

task<> SimplestOT::send(
span<std::array<block, 2>> msg,
PRNG& prng,
Socket& chl)
{
try {
using namespace DefaultCurve;
Curve{}; // init relic

Expand Down Expand Up @@ -142,6 +147,11 @@ namespace osuCrypto
ro.Final(msg[i][1]);
}
}
catch (...)
{
chl.close();
throw;
}
}
#endif

Expand Down Expand Up @@ -397,7 +407,7 @@ namespace osuCrypto
span<block> msg,
PRNG& prng,
Socket& chl)
{
try {
auto rs = AlginedState<RecvState>();
auto rd = rs->recvData();
co_await chl.recv(rd);
Expand All @@ -410,12 +420,17 @@ namespace osuCrypto
rs->gen4(i, msg);
}
}
catch (...)
{
chl.close();
throw;
}

task<> AsmSimplestOT::send(
span<std::array<block, 2>> msg,
PRNG& prng,
Socket& chl)
{
try {
auto ss = AlginedState<SendState>();

auto sd = ss->init(prng);
Expand All @@ -428,5 +443,10 @@ namespace osuCrypto
ss->gen4(i, msg);
}
}
catch (...)
{
chl.close();
throw;
}
}
#endif
14 changes: 12 additions & 2 deletions libOTe/NChooseOne/Kkrt/KkrtNcoOtReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace osuCrypto


task<> KkrtNcoOtReceiver::init(u64 numOtExt, PRNG& prng, Socket& chl)
{
try {
if (hasBaseOts() == false)
co_await(genBaseOts(prng, chl));

Expand Down Expand Up @@ -140,6 +140,11 @@ namespace osuCrypto
PRNG(theirSeed).get(keys.data(), keys.size());
mMultiKeyAES.setKeys(keys);
}
catch (...)
{
chl.close();
throw;
}


u64 KkrtNcoOtReceiver::getBaseOTCount() const
Expand Down Expand Up @@ -311,7 +316,7 @@ namespace osuCrypto
}

task<> KkrtNcoOtReceiver::sendCorrection(Socket& chl, u64 sendCount)
{
try {

#ifndef NDEBUG
// make sure these OTs all contain valid correction values, aka encode has been called.
Expand All @@ -334,6 +339,11 @@ namespace osuCrypto

co_await chl.send(std::move(sub));
}
catch (...)
{
chl.close();
throw;
}

}
#endif
14 changes: 12 additions & 2 deletions libOTe/NChooseOne/Kkrt/KkrtNcoOtSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace osuCrypto

task<> KkrtNcoOtSender::init(
u64 numOTExt, PRNG& prng, Socket& chl)
{
try {



Expand Down Expand Up @@ -162,6 +162,11 @@ namespace osuCrypto
doneIdx = stopIdx;
}
}
catch (...)
{
chl.close();
throw;
}

void KkrtNcoOtSender::encode(u64 otIdx, const void* input, void* dest, u64 destSize)
{
Expand Down Expand Up @@ -258,7 +263,7 @@ namespace osuCrypto
}

task<> KkrtNcoOtSender::recvCorrection(Socket& chl, u64 recvCount)
{
try {

#ifndef NDEBUG
if (recvCount > mCorrectionVals.bounds()[0] - mCorrectionIdx)
Expand All @@ -272,5 +277,10 @@ namespace osuCrypto
mCorrectionIdx += recvCount;
co_await chl.recv(span<block>(&*dest, recvCount * mCorrectionVals.stride()));
}
catch (...)
{
chl.close();
throw;
}
}
#endif
28 changes: 24 additions & 4 deletions libOTe/NChooseOne/NcoOtExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace osuCrypto
{

task<> NcoOtExtReceiver::genBaseOts(PRNG& prng, Socket& chl)
{
try {
struct TT
{
#ifdef ENABLE_IKNP
Expand Down Expand Up @@ -59,10 +59,15 @@ namespace osuCrypto
co_await(setBaseOts(msgs, prng, chl));

}
catch (...)
{
chl.close();
throw;
}


task<> NcoOtExtSender::genBaseOts(PRNG& prng, Socket& chl)
{
try {
struct TT
{
#ifdef ENABLE_IKNP
Expand Down Expand Up @@ -108,9 +113,14 @@ namespace osuCrypto
co_await(setBaseOts(msgs, bv, chl));

}
catch (...)
{
chl.close();
throw;
}

task<> NcoOtExtSender::sendChosen(MatrixView<block> messages, PRNG& prng, Socket& chl)
{
try {
auto temp = Matrix<block>{};

if (hasBaseOts() == false)
Expand Down Expand Up @@ -143,12 +153,17 @@ namespace osuCrypto
co_await(chl.send(std::move(temp)));

}
catch (...)
{
chl.close();
throw;
}

task<> NcoOtExtReceiver::receiveChosen(
u64 numMsgsPerOT,
span<block> messages,
span<u64> choices, PRNG& prng, Socket& chl)
{
try {
auto temp = Matrix<block>{};

if (hasBaseOts() == false)
Expand Down Expand Up @@ -181,5 +196,10 @@ namespace osuCrypto
}

}
catch (...)
{
chl.close();
throw;
}
}
#endif
Loading

0 comments on commit 2f10f3b

Please sign in to comment.