From d238ca6fd4b45d944c1fd3407aaec5833f6fbfa8 Mon Sep 17 00:00:00 2001 From: Marcel Keller Date: Thu, 16 Nov 2023 15:51:29 +1100 Subject: [PATCH] Avoid unnecessary setup execution. --- Protocols/MalRepRingPrep.h | 11 +++++++++++ Protocols/MalRepRingPrep.hpp | 31 +++++++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Protocols/MalRepRingPrep.h b/Protocols/MalRepRingPrep.h index 58e2313e..7034be3a 100644 --- a/Protocols/MalRepRingPrep.h +++ b/Protocols/MalRepRingPrep.h @@ -7,6 +7,7 @@ #define PROTOCOLS_MALREPRINGPREP_H_ #include "Protocols/ReplicatedPrep.h" +#include "Protocols/MaliciousRepPrep.h" /** * Generate random triples with malicious security modulo a power two, @@ -15,6 +16,9 @@ template class MalRepRingPrep : public virtual BufferPrep { + DataPositions dummy_pos; + MaliciousRepPrep prep; + public: MalRepRingPrep(SubProcessor* proc, DataPositions& usage); @@ -37,8 +41,15 @@ public: template class RingOnlyBitsFromSquaresPrep : public virtual BufferPrep { + typedef typename T::SquareToBitShare BitShare; + DataPositions dummy_pos; + typename BitShare::SquarePrep prep; + SubProcessor* bit_proc; + typename BitShare::MAC_Check* bit_MC; + public: RingOnlyBitsFromSquaresPrep(SubProcessor* proc, DataPositions& usage); + ~RingOnlyBitsFromSquaresPrep(); void buffer_bits(); }; diff --git a/Protocols/MalRepRingPrep.hpp b/Protocols/MalRepRingPrep.hpp index 45a29837..0217d3bc 100644 --- a/Protocols/MalRepRingPrep.hpp +++ b/Protocols/MalRepRingPrep.hpp @@ -16,14 +16,14 @@ template MalRepRingPrep::MalRepRingPrep(SubProcessor*, DataPositions& usage) : - BufferPrep(usage) + BufferPrep(usage), prep(dummy_pos) { } template RingOnlyBitsFromSquaresPrep::RingOnlyBitsFromSquaresPrep(SubProcessor*, DataPositions& usage) : - BufferPrep(usage) + BufferPrep(usage), prep(0, dummy_pos), bit_proc(0), bit_MC(0) { } @@ -47,6 +47,15 @@ MalRepRingPrepWithBits::MalRepRingPrepWithBits(SubProcessor* proc, { } +template +RingOnlyBitsFromSquaresPrep::~RingOnlyBitsFromSquaresPrep() +{ + if (bit_proc) + delete bit_proc; + if (bit_MC) + delete bit_MC; +} + template void MalRepRingPrep::buffer_triples() { @@ -59,9 +68,6 @@ void MalRepRingPrep::buffer_triples() template void MalRepRingPrep::buffer_squares() { - typedef typename T::prep_type prep_type; - DataPositions _; - MaliciousRepPrep prep(_); assert(this->proc != 0); prep.init_honest(this->proc->P); prep.buffer_size = BaseMachine::batch_size(DATA_SQUARE, @@ -75,9 +81,6 @@ void MalRepRingPrep::buffer_squares() template void MalRepRingPrep::simple_buffer_triples() { - typedef typename T::prep_type prep_type; - DataPositions _; - MaliciousRepPrep prep(_); assert(this->proc != 0); prep.init_honest(this->proc->P); prep.buffer_size = this->buffer_size; @@ -230,12 +233,12 @@ void RingOnlyBitsFromSquaresPrep::buffer_bits() { auto proc = this->proc; assert(proc != 0); - typedef typename T::SquareToBitShare BitShare; - typename BitShare::MAC_Check MC; - DataPositions usage; - typename BitShare::SquarePrep prep(0, usage); - SubProcessor bit_proc(MC, prep, proc->P); - prep.set_proc(&bit_proc); + if (bit_proc == 0) + { + bit_MC = new typename BitShare::MAC_Check; + bit_proc = new SubProcessor(*bit_MC, prep, proc->P); + prep.set_proc(bit_proc); + } bits_from_square_in_ring(this->bits, this->buffer_size, &prep); }