homenc / HElib

HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
https://homenc.github.io/HElib
Other
3.11k stars 760 forks source link

Send PublicKey to a server #410

Closed juy13 closed 3 years ago

juy13 commented 3 years ago

Hi, I want to share a PK with my server. However, if I use send/recv from standart library, I can't build key on server (it was a segmentation fall). On client: char *buffer = static_cast<char*>(static_cast<void*>(&public_key)); connect(sock, (struct sockaddr *)&addr, sizeof(addr)); send(sock, buffer, sizeof(public_key), 0); On server: bytes_read = recvfrom(sock, buf, 1024, 0, NULL, NULL); if(bytes_read > 0) { helib::PubKey *public_key = (static_cast<helib::PubKey *>(static_cast<void*>(buf))); break; }

In addition I tried void writePubKeyBinary(std::ostream& str, const PubKey& pk); void readPubKeyBinary(std::istream& str, PubKey& pk);

but it didn't help, because I need initialize PK previously, but I can't do it due to the fall against Can you help me, please?

faberga commented 3 years ago

Hi @juy13,

Check the utilities we have in https://github.com/homenc/HElib/tree/master/utils The "create context" util show how to create a context, PK and SK, serializes those to a file; The "encrypt" utils show how you can load the PK for encryption; The "decrypt" shows how to load the SK for decryption.

juy13 commented 3 years ago

Thank you! It works now