Closed cgair closed 1 year ago
Is there anyone can help? I'm really in a hurry
Hi @cgair
First of all, there's a problem with the way you make a PublicKey
object.
ipcl::PublicKey newpk = ipcl::PublicKey(1, 2048);
The 1st parameter should be n
in Pailler scheme. The number 1
is not satisfying the condition. The detail info about how to make a n
is there https://github.com/intel/pailliercryptolib/blob/34f11cdf6758b8fe61a5c88331902f031567d6b6/ipcl/keygen.cpp#L92-L117
Oh I see, thanks!@justalittlenoob
What's more I'm trying to restore a CipherText from a vectorCipherText(const PublicKey& pk, const std::vector<uint32_t>& n_v);
the procedure is as following:
ipcl::KeyPair key = ipcl::generateKeypair(2048, true);
std::vector<uint32_t> x(1);
ipcl::PlainText pt_x = ipcl::PlainText(x);
ipcl::CipherText ct_x = key.pub_key.encrypt(pt_x);
std::vector<uint32_t> v = dt_add_ctx_cty.getElementVec(0);
ipcl::CipherText ct_xx = ipcl::CipherText(key.pub_key, v);
Unfortunately, it seems that I've missed something because when decrypting it I got some wrong result.
Hi @cgair
The information you provided is too little. I don't know how dt_add_ctx_cty
was calculated. If you want to calculate CT+PT, you can refer to these two examples
example 1: https://github.com/intel/pailliercryptolib/blob/34f11cdf6758b8fe61a5c88331902f031567d6b6/test/test_ops.cpp#L208
example 2: https://github.com/intel/pailliercryptolib/blob/34f11cdf6758b8fe61a5c88331902f031567d6b6/test/test_ops.cpp#L248
Well, or I should put it in this way: I try
std::vector<uint32_t> n = {13};
ipcl::PlainText pt_n1 = ipcl::PlainText(n);
ipcl::CipherText ct_n1 = key.pub_key.encrypt(pt_n1);
BigNumber ct_bg = ct_n1.getElement(0);
// get hex string
std::string s;
ct_bg.num2hex(s);
std::vector<char> chars(s.begin(), s.end());
char *c = &chars[0];
BigNumber ct_bgg2 = BigNumber(c);
std::cout << "Construct BigBumber(from hex string):" << ct_bgg2 << std::endl;
assert (ct_bg == ct_bgg2);
but the assertion failed, I was wondering what was going wrong?
@justalittlenoob BigNumber's save and load function works fine(aka I can restore a serialized BigNumber correctly), so maybe there's something wrong in this function? https://github.com/intel/pailliercryptolib/blob/34f11cdf6758b8fe61a5c88331902f031567d6b6/ipcl/bignum.cpp#L67
Hi @cgair
Thank you for the detail info.
development
branch and try it again.
std::vector<uint32_t> n = {13};
ipcl::PlainText pt_n1 = ipcl::PlainText(n);
ipcl::CipherText ct_n1 = key.pub_key.encrypt(pt_n1);
BigNumber ct_bg = ct_n1.getElement(0);
// get hex string
std::string s;
ct_bg.num2hex(s);
// std::vector<char> chars(s.begin(), s.end());
// char *c = &chars[0];
const char* c = s.c_str();
BigNumber ct_bgg2 = BigNumber(c);
ipcl::CipherText ct2(key.pub_key, ct_bgg2); ipcl::PlainText dt = key.priv_key.decrypt(ct2);
EXPECT_EQ(pt_n1.getElement(0), dt.getElement(0)); // ---> These two values are the same
@cgair I wrote a unit test of public key serialization and deserialization for your reference(https://github.com/intel/pailliercryptolib/pull/63)
@xhuan28 thanks, this really help.
@justalittlenoob thanks for your help, I'm still unclear about some conceptions of paillier cryptolib ecosystem and will try to figure it out.
I'm on branch ipcl_v2.0.0 and wanna do serialization and deserialization. I wrote somethig like this,( remove the private keyword)
but after I loads the public key and do encryption, I got:
malloc(): invalid size (unsorted)
and I got the backtrace:what did I miss?