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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ Dependencies can be managed by cmake/build.py or installed via an external tool.


**[SPIN](https://github.com/ladnir/spin_codes) (Silent OT encoder):**
`ENABLE_SPIN` defaults on with Silent OT or Silent VOLE. Install SPIN 0.2 or
use `FETCH_SPIN=ON` / `FETCH_AUTO`. Requires CMake 3.20+ and x86-64 with AVX2;
set `ENABLE_SPIN=OFF` to omit it. See the [usage guide](libOTe/Tools/Spin/README.md).
`ENABLE_SPIN` defaults on with Silent OT or Silent VOLE. Install SPIN 0.4.2 or
use `FETCH_SPIN=ON` / `FETCH_AUTO`. Requires CMake 3.20+ and a little-endian
CPU; SPIN selects x86-64, AArch64 (NEON) or portable kernels at runtime.
Set `ENABLE_SPIN=OFF` to omit it. See the [usage guide](libOTe/Tools/Spin/README.md).

**Enabling/Disabling [Relic](https://github.com/relic-toolkit/relic) (for base OTs):**
The library can be built with Relic as
Expand Down
2 changes: 1 addition & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/buildOptions.cmake")
find_package(cryptoTools REQUIRED HINTS "${CMAKE_CURRENT_LIST_DIR}/.." ${CMAKE_CURRENT_LIST_DIR})
if(@ENABLE_SPIN@)
include(CMakeFindDependencyMacro)
find_dependency(spin 0.2 CONFIG)
find_dependency(spin 0.4.2 CONFIG)
endif()


Expand Down
2 changes: 1 addition & 1 deletion cmake/libOTeDepHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ macro(FIND_SPIN)
else()
unset(SPIN_DP)
endif()
find_package(spin 0.2 CONFIG ${SPIN_DP} ${ARGN})
find_package(spin 0.4.2 CONFIG ${SPIN_DP} ${ARGN})
endmacro()

if(ENABLE_SPIN AND NOT TARGET spin::spin)
Expand Down
7 changes: 3 additions & 4 deletions frontend/SpinCompressionBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int spinCompressionBenchmark(CLP& cmd) {try {
SilentOtExtSender s;
// Hold stationary geometry fixed even when the encoder uses full setup.
s.configure(k,2,1,SilentSecType::SemiHonest,SdNoiseDistribution::Stationary,MultType::Spin);
s.mSpin=std::make_unique<SpinOtState>(k,s.mCodeSeed,false,noise);
s.mSpin.emplace(k,s.mCodeSeed,noise);
s.mB.resize(s.mNoiseVecSize);
s.mDelta=block(345,679);
StationaryPprfSender<block,CoeffCtxGF2> leaves;
Expand All @@ -59,7 +59,7 @@ int spinCompressionBenchmark(CLP& cmd) {try {
}
if(context!="bare") std::fill(s.mB.begin()+active,s.mB.end(),ZeroBlock);
auto b=Clock::now();
prepareSpin(s.mSpin,k,s.mCodeSeed,false,noise);
SpinCode::prepare(s.mSpin,k,s.mCodeSeed,noise);
auto c=Clock::now();
s.mSpin->transpose(s.mB);
auto d=Clock::now();
Expand Down Expand Up @@ -94,8 +94,7 @@ int spinCompressionBenchmark(CLP& cmd) {try {
if(messages[i][0]!=s.mB[i] || messages[i][1]!=s.mB[i])
throw std::runtime_error("output-store check failed");
std::cout<<std::setprecision(9)<<"{\"family\":\""<<family<<"\",\"context\":\""<<context
<<"\",\"K\":"<<k<<",\"setup_bytes\":"<<s.mSpin->code.code().setup_bytes()
<<",\"workspace_bytes\":"<<s.mSpin->blocks.bytes()
<<"\",\"K\":"<<k<<",\"setup_bytes\":"<<s.mSpin->encoder().setup_bytes()
<<",\"stimulus_ms\":"<<median(0)<<",\"prepare_ms\":"<<median(1)
<<",\"encode_ms\":"<<median(2)<<",\"post_ms\":"<<median(3)
<<",\"checksum\":"<<(s.mB[0].get<u64>(0)^(output?messages[0][0].get<u64>(0):0))<<",\"samples\":[";
Expand Down
24 changes: 14 additions & 10 deletions frontend/SpinOtBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "coproto/Socket/BufferingSocket.h"
#include "macoro/when_all.h"
#include "macoro/sync_wait.h"
#include "cryptoTools/Crypto/RandomOracle.h"
#include <algorithm>
#include <chrono>
#include <iomanip>
Expand Down Expand Up @@ -75,8 +76,8 @@ int spinOtBenchmark(CLP& cmd) {try {
const auto noise=regular?SdNoiseDistribution::Regular:SdNoiseDistribution::Stationary;
s.configure(k,2,1,SilentSecType::SemiHonest,noise,MultType::Spin);
r.configure(k,2,1,SilentSecType::SemiHonest,noise,MultType::Spin);
s.mSpin=std::make_unique<SpinOtState>(k,s.mCodeSeed,false,s.mNoiseDist);
r.mSpin=std::make_unique<SpinOtState>(k,r.mCodeSeed,true,r.mNoiseDist);
s.mSpin.emplace(k,s.mCodeSeed,s.mNoiseDist);
r.mSpin.emplace(k,r.mCodeSeed,r.mNoiseDist);
s.mB.reserve(s.mNoiseVecSize);r.mA.reserve(r.mNoiseVecSize);
std::vector<std::array<block,2>> sent(k);std::vector<block> received(k);BitVector choices(k);
// Untimed initial correctness check. Stationary mode also caches tree seeds;
Expand All @@ -90,14 +91,19 @@ int spinOtBenchmark(CLP& cmd) {try {
auto* sg=regular?nullptr:dynamic_cast<StationaryPprfSender<block,CoeffCtxGF2>*>(&s.gen());
auto* rg=regular?nullptr:dynamic_cast<StationaryPprfReceiver<block,CoeffCtxGF2>*>(&r.gen());
require(regular || (sg && rg && sg->mExpanded && rg->mExpanded));
require(s.mSpin->code.code().setup_options().mode==
require(s.mSpin->encoder().setup_options().mode==
(regular?spin::SetupMode::Full:spin::SetupMode::BankedHeuristic));
s.hash(sent,ChoiceBitPacking::True,streaming);r.hash(choices,received,ChoiceBitPacking::True);
for(u64 i=0;i<k;++i) require(received[i]==sent[i][choices[i]]);
if(cmd.isSet("check")) {std::cout<<"SPIN hashed OT correctness: passed\n";return 0;}
if(cmd.isSet("check")) {
// Fixed seeds: the digest identifies the exact sender and receiver outputs,
// so two builds can be compared bit for bit.
RandomOracle ro(sizeof(block));
ro.Update(sent.data(),sent.size());ro.Update(received.data(),received.size());
block digest;ro.Final(digest);
std::cout<<"SPIN hashed OT correctness: passed, output digest "<<digest<<"\n";return 0;}
const auto* ss=sg?sg->mShare.data():nullptr;const auto* rs=rg?rg->mShare.data():nullptr;
const auto* sw=s.mSpin.get();const auto* rw=r.mSpin.get();
const auto fixedDescriptor=s.mSpin->code.descriptor();
const auto fixedDescriptor=s.mSpin->encoder().descriptor();
std::cout<<"{\"geometry\":true,\"K\":"<<k<<",\"N\":"<<s.mNoiseVecSize
<<",\"noise\":\""<<(regular?"regular":"stationary")<<"\""
<<",\"partitions\":"<<s.mNumPartitions<<",\"tree_size\":"<<s.mSizePer
Expand Down Expand Up @@ -142,8 +148,7 @@ int spinOtBenchmark(CLP& cmd) {try {
auto wire=sendSocket.getOutbound();require(bool(wire));
if(!paired) {
require(s.mCodeSeed==(regular?seed:mAesFixedKey.hashBlock(seed)));
require(sw==s.mSpin.get());
if(regular) require(s.mSpin->code.descriptor()==fixedDescriptor);
if(regular) require(s.mSpin->encoder().descriptor()==fixedDescriptor);
else require(sg->mExpandCounter==counter+1 && ss==sg->mShare.data());
if(round>=5)sender.push_back(a);
continue;
Expand All @@ -157,8 +162,7 @@ int spinOtBenchmark(CLP& cmd) {try {
Sample b{stage(rt,"recver.expand.start","recver.expand.pprf"),
stage(rt,"recver.expand.pprf","recver.expand.dualEncode"),ms(encoded,end),ms(begin,end)};
require(s.mCodeSeed==r.mCodeSeed && s.mCodeSeed==(regular?seed:mAesFixedKey.hashBlock(seed)));
require(sw==s.mSpin.get() && rw==r.mSpin.get());
if(regular) require(s.mSpin->code.descriptor()==fixedDescriptor && r.mSpin->code.descriptor()==fixedDescriptor);
if(regular) require(s.mSpin->encoder().descriptor()==fixedDescriptor && r.mSpin->encoder().descriptor()==fixedDescriptor);
else {
require(sg->mExpandCounter==counter+1 && rg->mExpandCounter==sg->mExpandCounter);
require(ss==sg->mShare.data() && rs==rg->mShare.data());
Expand Down
1 change: 0 additions & 1 deletion libOTe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ target_include_directories(libOTe PUBLIC

target_link_libraries(libOTe cryptoTools)
if(ENABLE_SPIN)
target_sources(libOTe PRIVATE Tools/Spin/SpinOt.cpp)
target_link_libraries(libOTe spin::spin)
endif()

Expand Down
Loading
Loading