12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include "pir.hpp"
- #include "pir_client.hpp"
- #include "pir_server.hpp"
- #include <seal/seal.h>
- #include <chrono>
- #include <memory>
- #include <random>
- #include <cstdint>
- #include <cstddef>
- using namespace std::chrono;
- using namespace std;
- using namespace seal;
- int main(int argc, char *argv[]) {
- uint64_t number_of_items = 2048;
- uint64_t size_per_item = 288; // in bytes
- uint32_t N = 8192;
- // Recommended values: (logt, d) = (12, 2) or (8, 1).
- uint32_t logt = 20;
- EncryptionParameters enc_params(scheme_type::bfv);
- // Generates all parameters
-
- cout << "Main: Generating SEAL parameters" << endl;
- gen_encryption_params(N, logt, enc_params);
-
- cout << "Main: Verifying SEAL parameters" << endl;
- verify_encryption_params(enc_params);
- cout << "Main: SEAL parameters are good" << endl;
-
- SEALContext context(enc_params, true);
- KeyGenerator keygen(context);
-
- SecretKey secret_key = keygen.secret_key();
- Encryptor encryptor(context, secret_key);
- Decryptor decryptor(context, secret_key);
- BatchEncoder encoder(context);
- logt = floor(log2(enc_params.plain_modulus().value()));
- uint32_t plain_modulus = enc_params.plain_modulus().value();
- size_t slot_count = encoder.slot_count();
- vector<uint64_t> coefficients(slot_count, 0ULL);
- for(uint32_t i = 0; i < coefficients.size(); i++){
- coefficients[i] = rand() % plain_modulus;
- }
- Plaintext pt;
- encoder.encode(coefficients, pt);
- Ciphertext ct;
- encryptor.encrypt_symmetric(pt, ct);
- std::cout << "Encrypting" << std::endl;
- EncryptionParameters params = context.first_context_data()->parms();
- std::cout << "Encoding" << std::endl;
- vector<Plaintext> encoded = decompose_to_plaintexts(params, ct);
- std::cout << "Decoding" << std::endl;
- Ciphertext decoded(context);
- compose_to_ciphertext(params, encoded, decoded);
- std::cout << "Checking" <<std::endl;
- Plaintext pt2;
- decryptor.decrypt(decoded, pt2);
- assert(pt == pt2);
- std::cout << "Worked" << std::endl;
- return 0;
- }
|