/* * preprocessing.hpp * */ #ifndef ECDSA_PREPROCESSING_HPP_ #define ECDSA_PREPROCESSING_HPP_ #include "P256Element.h" #include "Processor/Data_Files.h" #include "Protocols/ReplicatedPrep.h" #include "Protocols/MaliciousShamirShare.h" template class T> class EcTuple { public: T a; T b; P256Element R; }; template class T> void preprocessing(vector>& tuples, int buffer_size, T& sk, SubProcessor>& proc, bool prep_mul = true) { Timer timer; timer.start(); Player& P = proc.P; auto& prep = proc.DataF; size_t start = P.sent + prep.data_sent(); auto& protocol = proc.protocol; auto& MCp = proc.MC; typedef T pShare; typedef T cShare; vector inv_ks; vector secret_Rs; for (int i = 0; i < buffer_size; i++) { pShare a, a_inv; prep.get_two(DATA_INVERSE, a, a_inv); inv_ks.push_back(a_inv); secret_Rs.push_back(a); } if (prep_mul) { protocol.init_mul(&proc); for (int i = 0; i < buffer_size; i++) protocol.prepare_mul(inv_ks[i], sk); protocol.exchange(); } else prep.buffer_triples(); vector opened_Rs; typename cShare::MAC_Check MCc(MCp.get_alphai()); MCc.POpen(opened_Rs, secret_Rs, P); MCc.Check(P); MCp.Check(P); for (int i = 0; i < buffer_size; i++) { tuples.push_back( { inv_ks[i], prep_mul ? protocol.finalize_mul() : pShare(), opened_Rs[i] }); } timer.stop(); cout << "Generated " << buffer_size << " tuples in " << timer.elapsed() << " seconds, throughput " << buffer_size / timer.elapsed() << ", " << 1e-3 * (P.sent + prep.data_sent() - start) / buffer_size << " kbytes per tuple" << endl; } template class T> void check(vector>& tuples, T sk, P256Element::Scalar alphai, Player& P) { typename T::MAC_Check MC(alphai); auto open_sk = MC.POpen(sk, P); for (auto& tuple : tuples) { auto inv_k = MC.POpen(tuple.a, P); auto k = inv_k; k.invert(); assert(open_sk * inv_k == MC.POpen(tuple.b, P)); assert(tuple.R == k); } } template<> void ReplicatedPrep>::buffer_bits() { throw not_implemented(); } template<> void ReplicatedPrep>::buffer_bits() { throw not_implemented(); } #endif /* ECDSA_PREPROCESSING_HPP_ */