Skip to content

Commit

Permalink
minor improvements and correction to exconv parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ladnir committed Apr 1, 2024
1 parent 17b1f9b commit 5b3a08e
Show file tree
Hide file tree
Showing 15 changed files with 1,729 additions and 153 deletions.
216 changes: 176 additions & 40 deletions frontend/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "libOTe/Vole/Silent/SilentVoleReceiver.h"
#include "libOTe/Tools/CoeffCtx.h"
#include "libOTe/Tools/TungstenCode/TungstenCode.h"
#include "libOTe/Tools/ExConvCodeOld/ExConvCodeOld.h"

namespace osuCrypto
{
Expand Down Expand Up @@ -157,7 +158,7 @@ namespace osuCrypto
timer.setTimePoint("_____________________");
for (u64 i = 0; i < trials; ++i)
{
if(gf128)
if (gf128)
code.dualEncode<block, CoeffCtxGF128>(x.begin(), {});
else
code.dualEncode<block, CoeffCtxGF2>(x.begin(), {});
Expand All @@ -172,6 +173,143 @@ namespace osuCrypto
std::cout << verbose << std::endl;
}

inline void ExConvCodeOldBench(CLP& cmd)
{
#ifdef LIBOTE_ENABLE_OLD_EXCONV

u64 trials = cmd.getOr("t", 10);

// the message length of the code.
// The noise vector will have size n=2*k.
// the user can use
// -k X
// to state that exactly X rows should be used or
// -kk X
// to state that 2^X rows should be used.
u64 k = cmd.getOr("k", 1ull << cmd.getOr("kk", 10));

u64 n = cmd.getOr<u64>("n", k * cmd.getOr("R", 2.0));

// the weight of the code
u64 w = cmd.getOr("w", 7);

// size for the accumulator (# random transitions)
u64 a = cmd.getOr("a", roundUpTo(log2ceil(n), 8));

bool gf128 = cmd.isSet("gf128");

// verbose flag.
bool v = cmd.isSet("v");
bool sys = cmd.isSet("sys");

ExConvCodeOld code;
code.config(k, n, w, a, sys);

if (v)
{
std::cout << "n: " << code.mCodeSize << std::endl;
std::cout << "k: " << code.mMessageSize << std::endl;
//std::cout << "w: " << code.mExpanderWeight << std::endl;
}

std::vector<block> x(code.mCodeSize), y(code.mMessageSize * !sys);
Timer timer, verbose;

if (v)
code.setTimer(verbose);

timer.setTimePoint("_____________________");
for (u64 i = 0; i < trials; ++i)
{
code.dualEncode<block>(x);

timer.setTimePoint("encode");
}

if (cmd.isSet("quiet") == false)
{
std::cout << "EC " << std::endl;
std::cout << timer << std::endl;
}
if (v)
std::cout << verbose << std::endl;
#else
std::cout << "LIBOTE_ENABLE_OLD_EXCONV = false" << std::endl;
#endif
}


inline void PprfBench(CLP& cmd)
{

#ifdef ENABLE_SILENTOT

try
{
using Ctx = CoeffCtxGF2;
RegularPprfReceiver<block, block, Ctx> recver;
RegularPprfSender<block, block, Ctx> sender;

u64 trials = cmd.getOr("t", 10);

u64 w = cmd.getOr("w", 32);
u64 n = cmd.getOr("n", 1ull << cmd.getOr("nn", 14));

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

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

Timer rTimer;
auto s = rTimer.setTimePoint("start");
auto ctx = Ctx{};
auto vals = Ctx::Vec<block>(w);
auto out0 = Ctx::Vec<block>(n / w * w);
auto out1 = Ctx::Vec<block>(n / w * w);



for (u64 t = 0; t < trials; ++t)
{
sender.configure(n / w, w);
recver.configure(n / w, w);

std::vector<std::array<block, 2>> baseSend(sender.baseOtCount());
std::vector<block> baseRecv(sender.baseOtCount());
BitVector baseChoice(sender.baseOtCount());
sender.setBase(baseSend);
recver.setBase(baseRecv);
recver.setChoiceBits(baseChoice);

auto p0 = sender.expand(sock[0], vals, prng0.get(), out0, PprfOutputFormat::Interleaved, true, 1, ctx);
auto p1 = recver.expand(sock[1], out1, PprfOutputFormat::Interleaved, true, 1, ctx);

rTimer.setTimePoint("r start");
coproto::sync_wait(macoro::when_all_ready(
std::move(p0), std::move(p1)));
rTimer.setTimePoint("r done");

}
auto e = rTimer.setTimePoint("end");

auto time = std::chrono::duration_cast<std::chrono::milliseconds>(e - s).count();
auto avgTime = time / double(trials);
auto timePer512 = avgTime / n * 512;
std::cout << "OT n:" << n << ", " <<
avgTime << "ms/batch, " << timePer512 << "ms/512ot" << std::endl;

std::cout << rTimer << std::endl;

std::cout << sock[0].bytesReceived() / trials << " " << sock[1].bytesReceived() / trials << " bytes per " << std::endl;
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
}
#else
std::cout << "ENABLE_SILENTOT = false" << std::endl;
#endif
}

inline void TungstenCodeBench(CLP& cmd)
{
Expand Down Expand Up @@ -201,21 +339,23 @@ namespace osuCrypto
std::cout << "k: " << code.mMessageSize << std::endl;
}

std::vector<block> x(code.mCodeSize);
AlignedUnVector<block> x(code.mCodeSize);
Timer timer, verbose;


timer.setTimePoint("_____________________");
for (u64 i = 0; i < trials; ++i)
{
code.dualEncode<block, CoeffCtxGF128>(x.data(), {});
code.dualEncode<block, CoeffCtxGF2>(x.data(), {});

timer.setTimePoint("encode");
}

std::cout << "tungsten " << std::endl;
std::cout << timer << std::endl;

if (cmd.isSet("quiet") == false)
{
std::cout << "tungsten " << std::endl;
std::cout << timer << std::endl;
}
if (v)
std::cout << verbose << std::endl;
}
Expand Down Expand Up @@ -301,7 +441,7 @@ namespace osuCrypto
u64 trials = cmd.getOr("t", 10);

u64 n = cmd.getOr("n", 1ull << cmd.getOr("nn", 20));
MultType multType = (MultType)cmd.getOr("m", (int)MultType::ExAcc7);
MultType multType = (MultType)cmd.getOr("m", (int)MultType::ExConv7x24);
std::cout << multType << std::endl;

recver.mMultType = multType;
Expand All @@ -314,51 +454,47 @@ namespace osuCrypto

Timer sTimer;
Timer rTimer;
recver.setTimer(rTimer);
sender.setTimer(rTimer);
sTimer.setTimePoint("start");
rTimer.setTimePoint("start");

auto t0 = std::thread([&] {
for (u64 t = 0; t < trials; ++t)
{
auto p0 = sender.silentSendInplace(delta, n, prng0, sock[0]);

char c;

coproto::sync_wait(sock[0].send(std::move(c)));
coproto::sync_wait(sock[0].recv(c));
sTimer.setTimePoint("__");
coproto::sync_wait(sock[0].send(std::move(c)));
coproto::sync_wait(sock[0].recv(c));
sTimer.setTimePoint("s start");
coproto::sync_wait(p0);
sTimer.setTimePoint("s done");
}
});

auto s = sTimer.setTimePoint("start");

for (u64 t = 0; t < trials; ++t)
{
auto p1 = recver.silentReceiveInplace(n, prng1, sock[1]);
char c;
coproto::sync_wait(sock[1].send(std::move(c)));
coproto::sync_wait(sock[1].recv(c));
sender.configure(n);
recver.configure(n);

rTimer.setTimePoint("__");
coproto::sync_wait(sock[1].send(std::move(c)));
coproto::sync_wait(sock[1].recv(c));
auto choice = recver.sampleBaseChoiceBits(prng0);
std::vector<std::array<block, 2>> sendBase(sender.silentBaseOtCount());
std::vector<block> recvBase(recver.silentBaseOtCount());
sender.setSilentBaseOts(sendBase);
recver.setSilentBaseOts(recvBase);

auto p0 = sender.silentSendInplace(delta, n, prng0, sock[0]);
auto p1 = recver.silentReceiveInplace(n, prng1, sock[1], ChoiceBitPacking::True);

rTimer.setTimePoint("r start");
coproto::sync_wait(p1);
coproto::sync_wait(macoro::when_all_ready(
std::move(p0), std::move(p1)));
rTimer.setTimePoint("r done");

}
auto e = rTimer.setTimePoint("end");

if (cmd.isSet("quiet") == false)
{

t0.join();
std::cout << sTimer << std::endl;
std::cout << rTimer << std::endl;
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(e - s).count();
auto avgTime = time / double(trials);
auto timePer512 = avgTime / n * 512;
std::cout << "OT n:" << n << ", " <<
avgTime << "ms/batch, " << timePer512 << "ms/512ot" << std::endl;

std::cout << sock[0].bytesReceived() / trials << " " << sock[1].bytesReceived() / trials << " bytes per " << std::endl;
std::cout << sTimer << std::endl;
std::cout << rTimer << std::endl;

std::cout << sock[0].bytesReceived() / trials << " " << sock[1].bytesReceived() / trials << " bytes per " << std::endl;
}
}
catch (std::exception& e)
{
Expand Down
4 changes: 4 additions & 0 deletions frontend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@ int main(int argc, char** argv)
QCCodeBench(cmd);
else if (cmd.isSet("silent"))
SilentOtBench(cmd);
else if (cmd.isSet("pprf"))
PprfBench(cmd);
else if (cmd.isSet("vole2"))
VoleBench2(cmd);
else if (cmd.isSet("ea"))
EACodeBench(cmd);
else if (cmd.isSet("ec"))
ExConvCodeBench(cmd);
else if (cmd.isSet("ecold"))
ExConvCodeOldBench(cmd);
else if (cmd.isSet("tungsten"))
TungstenCodeBench(cmd);

Expand Down
3 changes: 2 additions & 1 deletion libOTe/Tools/CoeffCtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ namespace osuCrypto {
static_assert(std::is_trivially_copyable<F1>::value, "memcpy is used so must be trivially_copyable.");
static_assert(std::is_same_v<F1, F2>, "src and destication types are not the same.");

std::copy(begin, end, dstBegin);
memcpy((F2* __restrict) & *dstBegin, (F1 * __restrict) &*begin, std::distance(begin, end) * sizeof(F1));
//std::copy(begin, end, dstBegin);
}

// deserialize [begin,...,end) into [dstBegin, ...)
Expand Down
20 changes: 20 additions & 0 deletions libOTe/Tools/ExConvCodeOld/ExConvCodeInstantiations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#define EXCONVCODE_INSTANTIATIONS
#include "ExConvCodeOld.cpp"
#ifdef LIBOTE_ENABLE_OLD_EXCONV

namespace osuCrypto
{

template void ExConvCodeOld::dualEncode<block>(span<block> e);
template void ExConvCodeOld::dualEncode<u8>(span<u8> e);
template void ExConvCodeOld::dualEncode<block>(span<block> e, span<block> w);
template void ExConvCodeOld::dualEncode<u8>(span<u8> e, span<u8> w);
template void ExConvCodeOld::dualEncode2<block, u8>(span<block>, span<u8> e);
template void ExConvCodeOld::dualEncode2<block, block>(span<block>, span<block> e);

template void ExConvCodeOld::accumulate<block, u8>(span<block>, span<u8> e);
template void ExConvCodeOld::accumulate<block, block>(span<block>, span<block> e);
}

#endif
Loading

0 comments on commit 5b3a08e

Please sign in to comment.