我希望有人能帮助我理解我在使用 Palisades 时遇到的错误。我只想使用 BGV 密文的前 329 个插槽,其余部分归零(在某些时候包含一些“垃圾”,我不想在旋转时重新输入前 329 个插槽)。所以我创建了一个名为掩码的明文,我在前 329 个插槽中填充了 1,然后在密文上相乘以将这些插槽之外的所有内容归零。生成错误的完整代码在这里:
#include <fstream>
#include <iostream>
#include <iterator>
#include <random>
#include "palisade.h"
using namespace std;
using namespace lbcrypto;
Plaintext mask;
CryptoContext<DCRTPoly> cryptoContext;
Ciphertext<DCRTPoly> RotateLeft(Ciphertext<DCRTPoly> ct, int r, int ll){
/* Rotates the ciphertext ct of length ll with r positions to the right. */
Ciphertext<DCRTPoly> res, shiftR, shiftL;
shiftL=cryptoContext->EvalAtIndex(ct, r);
shiftR=cryptoContext->EvalAtIndex(ct, r-ll);
res=cryptoContext->EvalAdd(shiftR, shiftL);
res=cryptoContext->EvalMult(res,mask);
return res;
}
int main(){
usint plaintextModulus = 65537;
float sigma = 3.2;
SecurityLevel securityLevel = HEStd_128_classic;
uint32_t depth = 6;
////////////////////////////////////////////////////////////
// Parameter generation
////////////////////////////////////////////////////////////
cryptoContext = CryptoContextFactory<DCRTPoly>::genCryptoContextBGVrns(
depth,
plaintextModulus,
securityLevel,
sigma,
2,
OPTIMIZED,
BV,
0,
0,
0,
0,
0,
0,
AUTO);
// enable features that you wish to use
cryptoContext->Enable(ENCRYPTION);
cryptoContext->Enable(SHE);
cryptoContext->Enable(LEVELEDSHE);
LPKeyPair<DCRTPoly> keyPair;
// Perform Key Generation Operation
keyPair = cryptoContext->KeyGen();
if (!keyPair.good()) {
std::cout << "Key generation failed!" << std::endl;
exit(1);
}
//Keys for multiplication
cryptoContext->EvalMultKeysGen(keyPair.secretKey);
//Keys for rotations
cryptoContext->EvalAtIndexKeyGen(keyPair.secretKey,{1,2,3,-326,-327,-328});
vector<int64_t> vecMask;
for(int i=0; i<329; ++i)
vecMask.push_back(1);
mask = cryptoContext->MakePackedPlaintext(vecMask);
std::vector<int64_t> vectorOfBits1;
for(int64_t i=0; i<329; ++i)
vectorOfBits1.push_back((i/2)%2);
Plaintext p1 = cryptoContext->MakePackedPlaintext(vectorOfBits1);
Ciphertext<DCRTPoly> c1=cryptoContext->Encrypt(keyPair.publicKey, p1);
Ciphertext<DCRTPoly> r1=RotateLeft(c1,1,329);
Ciphertext<DCRTPoly> r2=RotateLeft(c1,2,329);
Ciphertext<DCRTPoly> chi_res=cryptoContext->EvalMult(r1,r2);
chi_res=cryptoContext->EvalAdd(chi_res,c1);
}
这会导致错误
塔架尺寸不匹配;无法添加
如果屏蔽被注释掉,一切正常,除了 c1 将包含我想要删除的垃圾。我应该如何正确地进行掩蔽?