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.16k stars 762 forks source link

Can HElib encrypt a message without packing? #88

Closed quanhanyu closed 8 years ago

quanhanyu commented 8 years ago

I was wondering whether I can use helib without ciphertext packing techniques. For example, I want to encrypt two message m1 and m2, and compute Enc(m1+m2). According to Thomas's post, I wrote the following codes:

vector<long> v1; v1.push_back(m1); for(int i = 1 ; i < nslots; i++) { v1.push_back(0); } Ctxt ct1(publicKey); ea.encrypt(ct1, publicKey, v1);

vector<long> v2; v2.push_back(m2); for(int i = 1 ; i < nslots; i++) { v2.push_back(0); } Ctxt ct2(publicKey); ea.encrypt(ct2, publicKey, v2);

The codes above works but I was wonder whether I have another way to encrypt m1 and m2 without using packing?

ssmiler commented 8 years ago

Take a look at FHEPubKey::Encrypt method in file FHE.h. It allows to directly encrypt a polynomial. You can put your message in the zero-degree coefficient of a polynomial and encrypt it. Actually, FHEPubKey::Encrypt is the method used internally by EncryptedArray::encrypt.

JimmieLeung commented 7 years ago

I can only find one method

long Encrypt(Ctxt &ciphertxt, const ZZX& plaintxt, long ptxtSpace=0, bool highNoise=false) const;

how can I encrypt one value?

quanhanyu commented 7 years ago

Hi Jimmie, you can first encode one value into a ZZX, and then encrypt it using Encrypt( ). As ssmile said, you can put your message in the zero-degree coefficient of a ZZX polynomial.

JimmieLeung commented 7 years ago

Thank you very much and I've solved the problem.

By the way, are you a currently in Xidian University?

Yours

Jinwen Liang

2017-05-04 3:15 GMT+08:00 qhyhyl notifications@github.com:

Hi Jimmie, you can first encode one value into a ZZX, and then encrypt it using Encrypt( ). As ssmile said, you can put your message in the zero-degree coefficient of a ZZX polynomial.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/shaih/HElib/issues/88#issuecomment-299008119, or mute the thread https://github.com/notifications/unsubscribe-auth/AQbo2Jj6gAAW20UQNxYiJYoRmpdyXstnks5r2NJpgaJpZM4Iamob .

quanhanyu commented 7 years ago

@JimmieLeung you are welcome. yes, i'm a student at xidian university.