microsoft / SealPIR

Example implementation of the SealPIR protocol
MIT License
139 stars 54 forks source link

Reuse Enc_Parameters and PIR_Parameters #33

Open cnquang opened 1 year ago

cnquang commented 1 year ago

How can we store and reuse Enc_Parameters and PIR_Parameters? Because if we execute another time, the Enc_Parameters and PIR_Parameters will change. And we cannot decode previous replies anymore.

sga001 commented 1 year ago

You can write code to do just that. Store the parameters. Did you encounter a problem with that?

cnquang commented 1 year ago

Below is my code to store and read pir_params. I successful save the pir_params.bin file, but when I read the pir_params.bin file in another time. It is show an error: Segmentation fault (core dumped) when I run this line: print_pir_params(pir_params);

void save_pir_parameters(const PirParams &pir_params, const string &filename) { try { ofstream file(filename, std::ios::binary); if (file.is_open()) { // Serialize the PirParams structure to the file file.write(reinterpret_cast<const char*>(&pir_params), sizeof(PirParams)); file.close(); cout << "PirParams saved to " << filename << endl; } else { cerr << "Error: Unable to open file for writing." << endl; } } catch (const exception &e) { cerr << "Exception: " << e.what() << endl; } }

PirParams load_pir_parameters(const string &filename) { PirParams pir_params;

try {
    ifstream file(filename, std::ios::binary);
    if (file.is_open()) {
        // Deserialize the PirParams structure from the file
        file.read(reinterpret_cast<char*>(&pir_params), sizeof(PirParams));
        file.close();
        cout << "PirParams loaded from " << filename << endl;
    } else {
        cerr << "Error: Unable to open file for reading." << endl;
    }
} catch (const exception &e) {
    cerr << "Exception: " << e.what() << endl;
}

return pir_params;

}