IBM / fhe-toolkit-linux

IBM Fully Homomorphic Encryption Toolkit For Linux. This toolkit is a Linux based Docker container that demonstrates computing on encrypted data without decrypting it! The toolkit ships with two demos including a fully encrypted Machine Learning inference with a Neural Network and a Privacy-Preserving key-value search.
MIT License
1.44k stars 158 forks source link

How can I separate the small size public key for encryption only and secret key for decryption only from the public evaluation keys and save them separately? #126

Closed yangjundy closed 3 years ago

yangjundy commented 3 years ago

I have just started to try to use the toolkit. I am very impressed that it is very easy to bring up and well maintained.

I have been using a different library which can save the small size public key for data encryption and secret key for decryption of FHE computing results, while other large size public keys for evaluation/computation such as relinarazation key and rotation Galios key can be saved as separated files, and that makes it is very easy to manage and distribute the keys. In general, that works well.

When I tried to use the toolkit's simple ML APIs with HelibCkksContext, I noticed that it creates similar size contexts with or without the secret key. Those contexts are very large size (over 7G bytes for instances) and the size make the APIs not very practical in manage and distribute the keys.

Could you let me know how can I save the keys to different files, and still can do the public evaluation with the encrypted data or is there finer control APIs please? Thanks.

github-actions[bot] commented 3 years ago

Thank you very much for helping us to improve the quality of our software. The FHE Toolkit develiopment team want to sincerely thank you for submitting your first issue and joining our technical community! We will get started on your issue immediately.

aehud commented 3 years ago

You are correct. Current API only allows storing the context with or without the secret key. The secret key is very small, so there's no noticeable difference. Note also that it's also possible to store just the secret key.

You are also right that allowing to store just different parts of the public key for different purposes is a useful feature. We added it to our task list and hope to have it ready in the near future.

yangjundy commented 3 years ago

Many thanks for the consideration.  It is great that the secret key can be saved in the place of the context with secret key, so that the size is very small and no duplication.  Trying to save the secret key to file with HelibCkksContext.saveSecretKeyToFile(), I noticed it reported the context has not the member function. Would I need to include another class? 

On Thursday, March 25, 2021, 4:49 pm, aehud @.***> wrote:

You are correct. Current API only allows storing the context with or without the secret key. The secret key is very small, so there's no noticeable difference. Note also that it's also possible to store just the secret key.

You are also right that allowing to store just different parts of the public key for different purposes is a useful feature. We added it to our task list and hope to have it ready in the near future.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

aehud commented 3 years ago

Strange, it should work. You can see an example of using this method here: https://github.com/IBM/fhe-toolkit-linux/blob/master/samples/mlhelib_tutorial/tut_3_io.cpp#L68

yangjundy commented 3 years ago

You are right. But when I tried to the line to examples\credit_card_fraud\credit_card_fraud.cpp as the follow, the compiling error is seen: cout << "Clearing " << outDir << endl; FileUtils::createCleanDir(outDir); cout << "Saving client side context to " << clientContext << endl; bool withSecretKey = true;

he.saveToFile(clientContext, withSecretKey); // save client context

cout << "Saving client side private key to " << clientSecretKey << endl;
he.saveSecretKeyToFile(clientSecretKey);
dowem commented 3 years ago

Hi @yangjundy, If I understand you correctly, you are saying you get a compile error when you try to add the last three lines shown in your output above. Can you show us what the actual compiler error on that output was when you tried to call he.saveSecrtetKeyToFile(clientSecretKey)?

yangjundy commented 3 years ago

Hi @dowem, Yes, that is right. The compiling output is as follows: error: 'class HelibCkksContext' has no member named saveSecretKeyToFile' 109 | he.saveSecretKeyToFile(clientSecretKey);

I can see there is difference with the 'context' definitions: The compiler error is from the definition 'HelibCkksContext he;'

The compiler is happy with https://github.com/IBM/fhe-toolkit-linux/blob/master/samples/mlhelib_tutorial/tut_3_io.cpp#L68, the 'context' is defined as: shared_ptr hePtr = HelibContext::create(HELIB_CKKS_8192);

aehud commented 3 years ago

@yangjundy Do you have the latest version? Because this sample is now named CKKS_credit_card_fraud.cpp and the code looks a bit different. Your code should work too, but only if you have the latest version. Please try with the latest version and let us know if you still see a problem.

yangjundy commented 3 years ago

@aehud Thanks for the information. You are right, with the latest version, the code works. Checking the sizes of the saved secrete key file and the client 'context with secret key' file, I noticed that the two files are the same size (security level 97 generates 2.3Gb size files). I expect the secret key file size smaller than 1MB. I tested with the follow changes: bool withSecretKey = true; hePtr->saveToFile(clientContext, withSecretKey); // save client context hePtr->saveSecretKeyToFile(clientSecretKey); // Change add to save the secret key

aehud commented 3 years ago

@yangjundy This is indeed a bug in our API. Thanks for pointing it out. We'll fix it in a few days and update.

dowem commented 3 years ago

Hi Gents, I think we should close this issue as we sorted the original one. We can open a new issue to track the API fix @aehud will be working on! We can track that separate API fix here: https://github.com/IBM/fhe-toolkit-linux/issues/135

yangjundy commented 3 years ago

That’s brilliant. Many thanks.

On Friday, April 2, 2021, 3:12 pm, Eli M. Dow @.***> wrote:

Hi Gents, I think we should close this issue as we sorted the original one. We can open a new issue to track the API fix @aehud will be working on! We can track that separate API fix here: #135

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.