#include "Verifier.h" #include "FHE/P2Data.h" #include "Math/Z2k.hpp" #include "Math/modp.hpp" template Verifier::Verifier(Proof& proof, const FD& FieldD) : P(proof), FieldD(FieldD) { #ifdef LESS_ALLOC_MORE_MEM z.resize(proof.phim); z.allocate_slots(bigint(1) << proof.B_plain_length); t.resize(3, proof.phim); t.allocate_slots(bigint(1) << proof.B_rand_length); #endif } template bool Check_Decoding(const Plaintext& AE,bool Diag) { // // Now check decoding z[i] // if (!AE.to_type(0)) // { cout << "Fail Check 4 " << endl; // return false; // } if (Diag && !AE.is_diagonal()) { #ifdef VERBOSE cout << "Fail Check 5 " << endl; #endif return false; } return true; } template <> bool Check_Decoding(const vector& AE, bool Diag, const FFT_Data&) { if (Diag) { for (size_t i = 1; i < AE.size(); i++) if (AE[i] != 0) return false; } return true; } template <> bool Check_Decoding(const vector& AE, bool Diag, const P2Data& p2d) { if (Diag) { Plaintext_ tmp(p2d); for (size_t i = 0; i < AE.size(); i++) tmp.set_coeff(i, AE[i].get_limb(0) % 2); return tmp.is_diagonal(); } return true; } template void Verifier::Stage_2( AddableVector& c,octetStream& ciphertexts, octetStream& cleartexts, const FHE_PK& pk) { unsigned int i, V; c.unpack(ciphertexts, pk); if (c.size() != P.U) throw length_error("number of received ciphertexts incorrect"); // Now check the encryptions are correct Ciphertext d1(pk.get_params()), d2(pk.get_params()); Random_Coins rc(pk.get_params()); ciphertexts.get(V); if (V != P.V) throw length_error("number of received commitments incorrect"); cleartexts.get(V); if (V != P.V) throw length_error("number of received cleartexts incorrect"); for (i=0; i void Verifier::NIZKPoK(AddableVector& c, octetStream& ciphertexts, octetStream& cleartexts, const FHE_PK& pk) { P.set_challenge(ciphertexts); Stage_2(c,ciphertexts,cleartexts,pk); if (P.top_gear) { assert(not P.get_diagonal()); c += c; } } template class Verifier; template class Verifier;