Skip to content

Commit

Permalink
linux compile and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ladnir committed Jan 22, 2024
1 parent eeb3a24 commit 1fd141a
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 77 deletions.
18 changes: 14 additions & 4 deletions libOTe/Tools/CoeffCtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "cryptoTools/Common/BitIterator.h"
#include "cryptoTools/Common/BitVector.h"
#include <sstream>
#include <cryptoTools/Common/block.h>

namespace osuCrypto {

Expand Down Expand Up @@ -453,12 +454,21 @@ namespace osuCrypto {
};

template<typename F, typename G = F>
struct DefaultCoeffCtx : CoeffCtxInteger {
struct DefaultCoeffCtx_t {
using type = CoeffCtxInteger;
};

// GF128 vole
template<> struct DefaultCoeffCtx<block, block> : CoeffCtxGF128 {};
template<>
struct DefaultCoeffCtx_t<block, block> {
using type = CoeffCtxGF128;
};

// OT, gf2
template<> struct DefaultCoeffCtx_t<block, bool> {
using type = CoeffCtxGF2;
};

// OT
template<> struct DefaultCoeffCtx<block, bool> : CoeffCtxGF2 {};
template<typename F, typename G = F>
using DefaultCoeffCtx = typename DefaultCoeffCtx_t<F, G>::type;
}
80 changes: 49 additions & 31 deletions libOTe/Tools/ExConvCode/ExConvCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ namespace osuCrypto
Iter&& xi,
Iter&& end,
u8* matrixCoeff,
CoeffCtx& ctx,
std::integral_constant<u64, AccumulatorSize>);
CoeffCtx& ctx);

// accumulating row i. generic version
template<
Expand All @@ -183,12 +182,11 @@ namespace osuCrypto
bool rangeCheck,
typename Iter
>
OC_FORCEINLINE void accOne(
OC_FORCEINLINE void accOneGen(
Iter&& xi,
Iter&& end,
u8* matrixCoeff,
CoeffCtx& ctx,
std::integral_constant<u64, 0>);
CoeffCtx& ctx);


// accumulate x onto itself.
Expand Down Expand Up @@ -257,7 +255,7 @@ namespace osuCrypto

(void)*(e_ + mCodeSize - 1);

auto e = ctx.restrictPtr<F>(e_);
auto e = ctx.template restrictPtr<F>(e_);

if (mSystematic)
{
Expand All @@ -275,9 +273,9 @@ namespace osuCrypto
accumulate<F, CoeffCtx>(e, ctx);
setTimePoint("ExConv.encode.accumulate");

CoeffCtx::template Vec<F> w;
typename CoeffCtx::template Vec<F> w;
ctx.resize(w, mMessageSize);
auto wIter = ctx.restrictPtr<F>(w.begin());
auto wIter = ctx.template restrictPtr<F>(w.begin());

mExpander.expand<F, CoeffCtx, false>(e, wIter, ctx);
setTimePoint("ExConv.encode.expand");
Expand Down Expand Up @@ -358,14 +356,22 @@ namespace osuCrypto
assert((((b >> 7) & 1) ? *xi : ZeroBlock) == tt[7]);

// xj += bj * xi
if (rangeCheck && xj + 0 == end) return; ctx.plus(*(xj + 0), *(xj + 0), tt[0]);
if (rangeCheck && xj + 1 == end) return; ctx.plus(*(xj + 1), *(xj + 1), tt[1]);
if (rangeCheck && xj + 2 == end) return; ctx.plus(*(xj + 2), *(xj + 2), tt[2]);
if (rangeCheck && xj + 3 == end) return; ctx.plus(*(xj + 3), *(xj + 3), tt[3]);
if (rangeCheck && xj + 4 == end) return; ctx.plus(*(xj + 4), *(xj + 4), tt[4]);
if (rangeCheck && xj + 5 == end) return; ctx.plus(*(xj + 5), *(xj + 5), tt[5]);
if (rangeCheck && xj + 6 == end) return; ctx.plus(*(xj + 6), *(xj + 6), tt[6]);
if (rangeCheck && xj + 7 == end) return; ctx.plus(*(xj + 7), *(xj + 7), tt[7]);
if (rangeCheck && xj + 0 == end) return;
ctx.plus(*(xj + 0), *(xj + 0), tt[0]);
if (rangeCheck && xj + 1 == end) return;
ctx.plus(*(xj + 1), *(xj + 1), tt[1]);
if (rangeCheck && xj + 2 == end) return;
ctx.plus(*(xj + 2), *(xj + 2), tt[2]);
if (rangeCheck && xj + 3 == end) return;
ctx.plus(*(xj + 3), *(xj + 3), tt[3]);
if (rangeCheck && xj + 4 == end) return;
ctx.plus(*(xj + 4), *(xj + 4), tt[4]);
if (rangeCheck && xj + 5 == end) return;
ctx.plus(*(xj + 5), *(xj + 5), tt[5]);
if (rangeCheck && xj + 6 == end) return;
ctx.plus(*(xj + 6), *(xj + 6), tt[6]);
if (rangeCheck && xj + 7 == end) return;
ctx.plus(*(xj + 7), *(xj + 7), tt[7]);
}
else
#endif
Expand All @@ -379,14 +385,22 @@ namespace osuCrypto
auto b6 = b & 64;
auto b7 = b & 128;

if (rangeCheck && xj + 0 == end) return; if (b0) ctx.plus(*(xj + 0), *(xj + 0), *xi);
if (rangeCheck && xj + 1 == end) return; if (b1) ctx.plus(*(xj + 1), *(xj + 1), *xi);
if (rangeCheck && xj + 2 == end) return; if (b2) ctx.plus(*(xj + 2), *(xj + 2), *xi);
if (rangeCheck && xj + 3 == end) return; if (b3) ctx.plus(*(xj + 3), *(xj + 3), *xi);
if (rangeCheck && xj + 4 == end) return; if (b4) ctx.plus(*(xj + 4), *(xj + 4), *xi);
if (rangeCheck && xj + 5 == end) return; if (b5) ctx.plus(*(xj + 5), *(xj + 5), *xi);
if (rangeCheck && xj + 6 == end) return; if (b6) ctx.plus(*(xj + 6), *(xj + 6), *xi);
if (rangeCheck && xj + 7 == end) return; if (b7) ctx.plus(*(xj + 7), *(xj + 7), *xi);
if (rangeCheck && xj + 0 == end) return;
if (b0) ctx.plus(*(xj + 0), *(xj + 0), *xi);
if (rangeCheck && xj + 1 == end) return;
if (b1) ctx.plus(*(xj + 1), *(xj + 1), *xi);
if (rangeCheck && xj + 2 == end) return;
if (b2) ctx.plus(*(xj + 2), *(xj + 2), *xi);
if (rangeCheck && xj + 3 == end) return;
if (b3) ctx.plus(*(xj + 3), *(xj + 3), *xi);
if (rangeCheck && xj + 4 == end) return;
if (b4) ctx.plus(*(xj + 4), *(xj + 4), *xi);
if (rangeCheck && xj + 5 == end) return;
if (b5) ctx.plus(*(xj + 5), *(xj + 5), *xi);
if (rangeCheck && xj + 6 == end) return;
if (b6) ctx.plus(*(xj + 6), *(xj + 6), *xi);
if (rangeCheck && xj + 7 == end) return;
if (b7) ctx.plus(*(xj + 7), *(xj + 7), *xi);
}
}

Expand All @@ -398,12 +412,11 @@ namespace osuCrypto
bool rangeCheck,
typename Iter
>
OC_FORCEINLINE void ExConvCode::accOne(
OC_FORCEINLINE void ExConvCode::accOneGen(
Iter&& xi,
Iter&& end,
u8* matrixCoeff,
CoeffCtx& ctx,
std::integral_constant<u64, 0> _)
CoeffCtx& ctx)
{

// xj += xi
Expand Down Expand Up @@ -464,8 +477,7 @@ namespace osuCrypto
Iter&& xi,
Iter&& end,
u8* matrixCoeff,
CoeffCtx& ctx,
std::integral_constant<u64, AccumulatorSize>)
CoeffCtx& ctx)
{
static_assert(AccumulatorSize, "should have called the other overload");
static_assert(AccumulatorSize % 8 == 0, "must be a multiple of 8");
Expand Down Expand Up @@ -530,7 +542,10 @@ namespace osuCrypto
}

// add xi to the next positions
accOne<F, CoeffCtx, false>(xi, end, mtxCoeffIter++, ctx, std::integral_constant<u64, AccumulatorSize>{});
if constexpr(AccumulatorSize == 0)
accOneGen<F, CoeffCtx, false>(xi, end, mtxCoeffIter++, ctx);
else
accOne<F, CoeffCtx, false, AccumulatorSize>(xi, end, mtxCoeffIter++, ctx);
++xi;
}

Expand All @@ -544,7 +559,10 @@ namespace osuCrypto
}

// add xi to the next positions
accOne<F, CoeffCtx, true>(xi, end, mtxCoeffIter++, ctx, std::integral_constant<u64, AccumulatorSize>{});
if constexpr (AccumulatorSize == 0)
accOneGen<F, CoeffCtx, true>(xi, end, mtxCoeffIter++, ctx);
else
accOne<F, CoeffCtx, true, AccumulatorSize>(xi, end, mtxCoeffIter++, ctx);
++xi;
}
}
Expand Down
4 changes: 2 additions & 2 deletions libOTe/Tools/ExConvCode/Expander.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ namespace osuCrypto

detail::ExpanderModd prng(mSeed, mCodeSize);

auto rInput = ctx.restrictPtr<const F>(input);
auto rOutput = ctx.restrictPtr<F>(output);
auto rInput = ctx.template restrictPtr<const F>(input);
auto rOutput = ctx.template restrictPtr<F>(output);

auto main = mMessageSize / 8 * 8;
u64 i = 0;
Expand Down
2 changes: 1 addition & 1 deletion libOTe/Tools/Pprf/PprfUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace osuCrypto
CoeffCtx& ctx)
{

u64 elementSize = ctx.byteSize<F>();
u64 elementSize = ctx.template byteSize<F>();

// num of bytes they will take up.
u64 numBytes =
Expand Down
22 changes: 11 additions & 11 deletions libOTe/Tools/Pprf/RegularPprf.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ namespace osuCrypto
std::array<block, 8> child;

// clear the sums
std::array<CoeffCtx::template Vec<F>, 2> leafSums;
std::array<VecF, 2> leafSums;
ctx.resize(leafSums[0], 8);
ctx.resize(leafSums[1], 8);
ctx.zero(leafSums[0].begin(), leafSums[0].end());
Expand Down Expand Up @@ -368,7 +368,7 @@ namespace osuCrypto
// active child should be the correct value XOR the delta.
// This will be done by sending the sums and the sums plus
// delta and ensure that they can only decrypt the correct ones.
CoeffCtx::template Vec<F> leafOts;
VecF leafOts;
ctx.resize(leafOts, 2);
PRNG otMasker;

Expand Down Expand Up @@ -397,7 +397,7 @@ namespace osuCrypto
}

// copy m0 into the output buffer.
span<u8> buff = leafMsgs.subspan(0, 2 * ctx.byteSize<F>());
span<u8> buff = leafMsgs.subspan(0, 2 * ctx.template byteSize<F>());
leafMsgs = leafMsgs.subspan(buff.size());
ctx.serialize(leafOts.begin(), leafOts.end(), buff.begin());

Expand All @@ -411,7 +411,7 @@ namespace osuCrypto
}
else
{
CoeffCtx::template Vec<F> leafOts;
VecF leafOts;
ctx.resize(leafOts, 1);
PRNG otMasker;

Expand All @@ -421,7 +421,7 @@ namespace osuCrypto
{
// copy the sum k into the output buffer.
ctx.copy(leafOts[0], leafSums[k][j]);
span<u8> buff = leafMsgs.subspan(0, ctx.byteSize<F>());
span<u8> buff = leafMsgs.subspan(0, ctx.template byteSize<F>());
leafMsgs = leafMsgs.subspan(buff.size());
ctx.serialize(leafOts.begin(), leafOts.end(), buff.begin());

Expand Down Expand Up @@ -716,7 +716,7 @@ namespace osuCrypto
// We change the hash function for the leaf so lets update
// inactiveChildValues to use the new hash and subtract
// these from the leafSums
std::array<CoeffCtx::template Vec<F>, 2> leafSums;
std::array<VecF, 2> leafSums;
if (mDepth > 1)
{
auto theirSumsIter = theirSums.begin();
Expand Down Expand Up @@ -885,7 +885,7 @@ namespace osuCrypto
// overwrite whatever the value was. This is an optimization.
auto width = divCeil(mDomain, 1ull << (mDepth - d));

CoeffCtx::template Vec<F> temp;
VecF temp;
ctx.resize(temp, 2);
for (u64 k = 0; k < 2; ++k)
{
Expand Down Expand Up @@ -969,11 +969,11 @@ namespace osuCrypto
auto notAi = inactiveChildIdx & 1;

// offset to the first or second ot message, based on the one we want
auto offset = ctx.byteSize<F>() * 2 * notAi;
auto offset = ctx.template byteSize<F>() * 2 * notAi;


// decrypt the ot string
span<u8> buff = leafMsg.subspan(offset, ctx.byteSize<F>() * 2);
span<u8> buff = leafMsg.subspan(offset, ctx.template byteSize<F>() * 2);
leafMsg = leafMsg.subspan(buff.size() * 2);
otMasker.SetSeed(mBaseOTs[j + treeIdx][0], divCeil(buff.size(), sizeof(block)));
for (u64 i = 0; i < buff.size(); ++i)
Expand Down Expand Up @@ -1006,10 +1006,10 @@ namespace osuCrypto
auto notAi = inactiveChildIdx & 1;

// offset to the first or second ot message, based on the one we want
auto offset = ctx.byteSize<F>() * notAi;
auto offset = ctx.template byteSize<F>() * notAi;

// decrypt the ot string
span<u8> buff = leafMsg.subspan(offset, ctx.byteSize<F>());
span<u8> buff = leafMsg.subspan(offset, ctx.template byteSize<F>());
leafMsg = leafMsg.subspan(buff.size() * 2);
otMasker.SetSeed(mBaseOTs[j + treeIdx][0], divCeil(buff.size(), sizeof(block)));
for (u64 i = 0; i < buff.size(); ++i)
Expand Down
6 changes: 3 additions & 3 deletions libOTe/Vole/Noisy/NoisyVoleReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace osuCrypto {
otMsg = AlignedUnVector<std::array<block, 2>>{});

setTimePoint("NoisyVoleReceiver.ot.begin");
otMsg.resize(ctx.bitSize<F>());
otMsg.resize(ctx.template bitSize<F>());
MC_AWAIT(ot.send(otMsg, prng, chl));

setTimePoint("NoisyVoleReceiver.ot.end");
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace osuCrypto {
for (size_t j = 0; j < c.size(); ++j, ++k)
{
// msg[i,j] = otMsg[i,j,0]
ctx.fromBlock<F>(msg[k], prng.get<block>());
ctx.fromBlock(msg[k], prng.get<block>());
//ctx.zero(msg.begin() + k, msg.begin() + k + 1);
//std::cout << "m" << i << ",0 = " << ctx.str(msg[k]) << std::endl;

Expand Down Expand Up @@ -135,7 +135,7 @@ namespace osuCrypto {
}
}

buff.resize(msg.size() * ctx.byteSize<F>());
buff.resize(msg.size() * ctx.template byteSize<F>());
ctx.serialize(msg.begin(), msg.end(), buff.begin());

MC_AWAIT(chl.send(std::move(buff)));
Expand Down
8 changes: 4 additions & 4 deletions libOTe/Vole/Noisy/NoisyVoleSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
namespace osuCrypto {
template <
typename F,
typename G = F,
typename CoeffCtx = DefaultCoeffCtx<F,G>
typename G,
typename CoeffCtx
>
class NoisyVoleSender : public TimerAdapter
{
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace osuCrypto {
temp = VecF{},
xb = BitVector{});

xb = ctx.binaryDecomposition<F>(delta);
xb = ctx.binaryDecomposition(delta);

if (otMsg.size() != xb.size())
throw RTE_LOC;
Expand All @@ -93,7 +93,7 @@ namespace osuCrypto {
ctx.zero(b.begin(), b.end());

// receive the the excrypted one shares.
buffer.resize(xb.size() * b.size() * ctx.byteSize<F>());
buffer.resize(xb.size() * b.size() * ctx.template byteSize<F>());
MC_AWAIT(chl.recv(buffer));
ctx.resize(msg, xb.size() * b.size());
ctx.deserialize(buffer.begin(), buffer.end(), msg.begin());
Expand Down
Loading

0 comments on commit 1fd141a

Please sign in to comment.