Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ on:
workflow_dispatch:

jobs:
chosen-baa-portable:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Build portable Silent VOLE
run: python3 build.py --par=4 -DENABLE_SILENT_VOLE=ON -DENABLE_SILENTOT=ON -DENABLE_SOFTSPOKEN_OT=ON -DENABLE_MRR=ON -DENABLE_CIRCUITS=ON -DENABLE_SSE=OFF -DENABLE_AVX=OFF -DENABLE_AVX2=OFF -DENABLE_AVX512=OFF -DENABLE_VPCLMUL=OFF -DENABLE_VAES=OFF -DENABLE_ARM_AES=OFF -DENABLE_EDWARDS25519_ASM=OFF -DENABLE_BITPOLYMUL=OFF -DENABLE_SODIUM=OFF -DENABLE_LOGVOLE=OFF -DENABLE_SPIN=OFF -DCMAKE_BUILD_TYPE=Release
- name: Test portable arithmetic and chosen BAA
run: |
./out/build/linux/frontend/frontend_libOTe -u block_operation
./out/build/linux/frontend/frontend_libOTe -u ChosenBaa

build-ubuntu:
runs-on: ubuntu-latest
timeout-minutes: 60
Expand Down Expand Up @@ -106,7 +120,7 @@ jobs:
build-macos:
needs: build-ubuntu
if: ${{ !cancelled() }}
runs-on: macos-14
runs-on: macos-15
timeout-minutes: 60
steps:
- uses: actions/checkout@v5
Expand Down
2 changes: 1 addition & 1 deletion frontend/ExampleVole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace osuCrypto


// the LPN compression type.
MultType mulType = (MultType)cmd.getOr("multType", (int)DefaultMultType);
MultType mulType = (MultType)cmd.getOr("multType", (int)SilentVoleSender<F, G>::DefaultCode);

// regular noise or stationary noise.
SdNoiseDistribution noiseType = (SdNoiseDistribution)cmd.getOr("noise", (int)SdNoiseDistribution::Regular);
Expand Down
2 changes: 1 addition & 1 deletion frontend/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,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)DefaultMultType);
MultType multType = (MultType)cmd.getOr("m", (int)SilentVoleSender<block, block, CoeffCtxGF128>::DefaultCode);

auto noise = (SdNoiseDistribution)cmd.getOr("noise", (int)SdNoiseDistribution::Regular);
auto mal = (SilentSecType)cmd.getOr("mal", (int)SilentSecType::SemiHonest);
Expand Down
1 change: 1 addition & 0 deletions libOTe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(SRCS
Tools/LDPC/Util.cpp
Tools/LinearCode.cpp
Tools/Tools.cpp
Tools/BlkAccCode/ChosenBaaCode.cpp
Tools/TungstenCode/TungstenData.cpp
TwoChooseOne/ConfigureCode.cpp
TwoChooseOne/OTExtInterface.cpp
Expand Down
4 changes: 3 additions & 1 deletion libOTe/Dpf/RevCuckoo/BinarySolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,9 @@ namespace osuCrypto
span< MatrixView<const u8>> m{ &MM,1 };
span< MatrixView<const u8>> y{ &YY,1 };
span< MatrixView<u8>> x{ &X,1 };
return solve(m, y, x, prng, sock);
// Keep the by-value views in this coroutine frame while solve uses
// spans over them. The caller still owns the matrix data and socket.
co_await solve(m, y, x, prng, sock);
}

task<> solve(
Expand Down
58 changes: 58 additions & 0 deletions libOTe/Tools/BlkAccCode/AdditiveRs8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once
#include "ChosenBaaField.h"
#include <array>
#include <algorithm>

namespace osuCrypto::chosen_baa_detail
{
struct AdditivePoints : ChosenBaaField<block>
{
static block point(u64 i) { return block(0, i); }
};

// For evaluation points 0..7 and 8..15 the Lagrange matrix has entries
// M[i,j]=c[i XOR j]. Translate the group algebra by t_i=x_i+1; then
// t_i^2=0. A three-bit subset convolution replaces 64 field products
// with 19 (24 SIMD slots). The transform is its own inverse in char 2.
struct AdditiveRs8
{
std::array<block, 24> coefficients;
template<unsigned Bit = 0, unsigned I = 0>
static OC_FORCEINLINE void zeta(block* v)
{
if constexpr (Bit < 3)
{
if constexpr (I < 8)
{
if constexpr (!(I & (1u << Bit))) v[I] ^= v[I | (1u << Bit)];
zeta<Bit, I + 1>(v);
}
else zeta<Bit + 1, 0>(v);
}
}
void init(const block* c)
{
std::array<block, 8> v;
std::copy_n(c, 8, v.data()); zeta(v.data());
if (v[0] != OneBlock) throw std::logic_error("Additive RS row sum.");
coefficients = {v[1],v[2],v[3],v[4],v[5],v[6],v[7],ZeroBlock,
v[2],v[1],v[4],v[1],v[4],v[2],v[6],v[5],
v[4],v[3],v[2],v[1],ZeroBlock,ZeroBlock,ZeroBlock,ZeroBlock};
}
OC_FORCEINLINE void apply(const block* input, block* output) const
{
std::array<block, 8> u;
std::copy_n(input, 8, u.data()); zeta(u.data());
std::array<block, 8> a{u[0],u[0],u[0],u[0],u[0],u[0],u[0],ZeroBlock};
std::array<block, 8> b{u[1],u[2],u[1],u[4],u[2],u[4],u[1],u[2]};
std::array<block, 8> c{u[3],u[4],u[5],u[6],ZeroBlock,ZeroBlock,ZeroBlock,ZeroBlock};
ChosenBaaField<block>::mul8(a.data(), coefficients.data());
ChosenBaaField<block>::mul8(b.data(), coefficients.data() + 8);
ChosenBaaField<block>::mul8(c.data(), coefficients.data() + 16);
u[1] ^= a[0]; u[2] ^= a[1]; u[3] ^= a[2] ^ b[0] ^ b[1];
u[4] ^= a[3]; u[5] ^= a[4] ^ b[2] ^ b[3]; u[6] ^= a[5] ^ b[4] ^ b[5];
u[7] ^= a[6] ^ b[6] ^ b[7] ^ c[0] ^ c[1] ^ c[2] ^ c[3];
zeta(u.data()); std::copy(u.begin(), u.end(), output);
}
};
}
21 changes: 21 additions & 0 deletions libOTe/Tools/BlkAccCode/BinaryBAA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include "ReedMullerBaaCode.h"
#include <type_traits>

namespace osuCrypto
{
// Each bit lane is an independent binary codeword, not a field symbol.
template<typename Word>
struct BinaryBAAArithmetic
{
static_assert(std::is_same_v<Word, block> || std::is_unsigned_v<Word>);
static Word zero() { return Word{}; }
static Word one() { return Word(1); }
static OC_FORCEINLINE Word add(Word a, Word b) { return a ^ b; }
};
template<> inline block BinaryBAAArithmetic<block>::one() { return OneBlock; }

// Binary RM BAA, 10% distance tier. block stores 128 independent bit lanes.
template<typename Word = block>
using BinaryBAA = ReedMullerBaaCode<Word, BinaryBAAArithmetic<Word>>;
}
10 changes: 10 additions & 0 deletions libOTe/Tools/BlkAccCode/ChosenBAA30.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include "SmallAlphabetBaaCode.h"

namespace osuCrypto
{
// Public distance tier. The >30.524% certificate is for n=2^21 with
// ideal uniform setup, not a guarantee for every supported length/field.
template<typename F = block, typename Field = ChosenBaaField<F>>
using ChosenBAA30 = SmallAlphabetBaaCode<F, Field>;
}
109 changes: 109 additions & 0 deletions libOTe/Tools/BlkAccCode/ChosenBaaCode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "ChosenBaaVole.h"
#include "cryptoTools/Crypto/RandomOracle.h"
#include <cstring>

namespace osuCrypto
{
void chosenBaaCompress(MultType type, block seed, span<block> a, span<block> b)
{
std::unique_ptr<ChosenBaaWorkspace> workspace;
chosenBaaCompress(type, seed, workspace, a, b);
}

void chosenBaaCompress(MultType type, block seed,
std::unique_ptr<ChosenBaaWorkspace>& workspace, span<block> a, span<block> b)
{
if (!b.empty() && b.size() != a.size())
throw std::invalid_argument("Chosen BAA paired buffers differ in size.");
if (type == MultType::ChosenBAA30)
{
if (!workspace) workspace = std::make_unique<ChosenBaaWorkspace>();
workspace->code.config(a.size(), seed);
workspace->scratch.resize(a.size());
workspace->code.dualEncode(a, workspace->scratch);
if (!b.empty()) workspace->code.dualEncode(b, workspace->scratch);
}
else if (type == MultType::ChosenBaa16x8)
{
ChosenBaaCode<8> code;
code.config(a.size(), seed);
if (b.empty()) code.dualEncode(a);
else code.dualEncode2(a, b);
}
else if (type == MultType::ChosenBaa16x4)
{
ChosenBaaCode<4> code;
code.config(a.size(), seed);
if (b.empty()) code.dualEncode(a);
else code.dualEncode2(a, b);
}
else throw std::invalid_argument("Not a chosen BAA profile.");
}

void binaryBaaCompress(block seed, span<block> values, span<u8> choices)
{
if (!choices.empty() && choices.size() != values.size())
throw std::invalid_argument("BinaryBAA buffer lengths differ.");
BinaryBAA<> code;
code.config(values.size(), seed);
AlignedUnVector<block> scratch(values.size());
code.dualEncode(values, scratch);
if (!choices.empty())
{
BinaryBAA<u8> bits;
bits.config(choices.size(), seed);
AlignedUnVector<u8> bitScratch(choices.size());
bits.dualEncode(choices, bitScratch);
}
}

namespace
{
using Seed = std::array<u8, 16>;
using Commitment = std::array<u8, 32>;

OC_NOINLINE Commitment commitSeed(const Seed& seed)
{
RandomOracle hash(32);
constexpr char domain[] = "libOTe/chosen-baa/seed/v1";
hash.Update(domain, sizeof(domain));
hash.Update(seed.data(), seed.size());
Commitment result;
hash.Final(result.data());
return result;
}

OC_NOINLINE void combineSeeds(const Seed& a, const Seed& b, block& output)
{
Seed result;
for (u64 i = 0; i < result.size(); ++i)
result[i] = a[i] ^ b[i];
std::memcpy(&output, result.data(), result.size());
}
}

task<> chosenBaaSeed(bool sender, PRNG& prng, Socket& chl, block& seed)
{
// Byte arrays require no SIMD alignment in a coroutine frame. Each
// send is awaited before its storage is reused or destroyed.
Seed mine{}, theirs{};
Commitment commitment{};
prng.get(mine.data(), mine.size());
if (sender)
{
commitment = commitSeed(mine);
co_await chl.send(commitment);
co_await chl.recv(theirs);
co_await chl.send(mine);
}
else
{
co_await chl.recv(commitment);
co_await chl.send(mine);
co_await chl.recv(theirs);
if (commitSeed(theirs) != commitment)
throw std::runtime_error("Chosen BAA seed commitment mismatch.");
}
combineSeeds(mine, theirs, seed);
}
}
Loading
Loading