I tried using threshold encryption CKKS in my project and recovering keys using the Shamir mechanism.
kp1 = cc->KeyGen();
auto kp1smap = cc->ShareKeys(kp1.secretKey, N, THRESH, 1, “shamir”);
kp2 = cc->MultipartyKeyGen(kp1.publicKey);
auto kp2smap = cc->ShareKeys(kp2.secretKey, N, THRESH, 2, “shamir”);
kp3 = cc->MultipartyKeyGen(kp2.publicKey);
auto kp3smap = cc->ShareKeys(kp3.secretKey, N, THRESH, 3, “shamir”);
kp4 = cc->MultipartyKeyGen(kp3.publicKey);
auto kp4smap = cc->ShareKeys(kp4.secretKey, N, THRESH, 4, “shamir”);
kp5 = cc->MultipartyKeyGen(kp4.publicKey);
auto kp5smap = cc->ShareKeys(kp5.secretKey, N, THRESH, 5, “shamir”);
When I recovered kp1
and performed decryption, there were no issues.
PrivateKey kp1_recovered_sk = std::make_shared<PrivateKeyImpl>(cc);
cc->RecoverSharedKey(kp1_recovered_sk, kp1smap, N, THRESH, “shamir”);
auto ciphertextPartial1 = cc->MultipartyDecryptLead({ciphertextAdd12345}, kp1_recovered_sk);
However, when I tried to recover kp1
and kp2
simultaneously and perform decryption, I encountered an error, and the result was nan
.
PrivateKey kp1_recovered_sk = std::make_shared<PrivateKeyImpl>(cc);
cc->RecoverSharedKey(kp1_recovered_sk, kp1smap, N, THRESH, “shamir”);
auto ciphertextPartial1 = cc->MultipartyDecryptLead({ciphertextAdd12345}, kp1_recovered_sk);
PrivateKey kp2_recovered_sk = std::make_shared<PrivateKeyImpl>(cc);
cc->RecoverSharedKey(kp2_recovered_sk, kp2smap, N, THRESH, “shamir”);
auto ciphertextPartial2 = cc->MultipartyDecryptLead({ciphertextAdd12345}, kp2_recovered_sk);
Is there an error in my usage?
The initial problem I encountered was ‘The decryption failed because the approximation error is too high. Check the parameters.’ So, I tried adjusting the parameters by setting parameters.SetMultiplicativeDepth(32)
, parameters.SetScalingModSize(50)
, and parameters.SetBatchSize(32768)
. After these adjustments, the error disappeared, but the result was nan
.
My N is set to 5, and THRESH is set to 3.