int pubkey::encrypt (const bvector&in, bvector&out, const bvector&errors) { if (in.size() != plain_size() ) return 2; if (errors.size() != cipher_size() ) return 2; G.mult_vecT_left (in, out); out.add (errors); return 0; }
int pubkey::encrypt (const bvector & in, bvector & out, const bvector&errors) { uint t = 1 << T; bvector p, g, r, cksum; uint i, j; /* * shortened checksum pair of G is computed blockwise accordingly to * the t-sized square dyadic blocks. */ //some checks if (!qd_sigs.width() ) return 1; if (qd_sigs.height() % t) return 1; if (in.size() != plain_size() ) return 2; if (errors.size() != cipher_size() ) return 2; uint blocks = qd_sigs.height() / t; cksum.resize (qd_sigs.height(), 0); p.resize (t); g.resize (t); r.resize (t); std::vector<int> c1, c2, c3; c1.resize (t); c2.resize (t); c3.resize (t); for (i = 0; i < qd_sigs.size(); ++i) { //plaintext block in.get_block (i * t, t, p); for (j = 0; j < blocks; ++j) { //checksum block qd_sigs[i].get_block (j * t, t, g); //block result fwht_dyadic_multiply (p, g, r, c1, c2, c3); cksum.add_offset (r, t * j); } } //compute ciphertext out = in; out.insert (out.end(), cksum.begin(), cksum.end() ); out.add (errors); return 0; }