【问题标题】:Microsoft SEAL : Subtraction of two PolyCRT composed ciphertext results in overflowMicrosoft SEAL:减去两个 PolyCRT 组成的密文导致溢出
【发布时间】:2020-06-17 18:13:21
【问题描述】:

假设我有两个数组 x = [1,2,3,4,5]xMean = [3,3,3,3,3]。我使用 PolyCRTBuilder(xCiphertext 和 xMeanCiphertext)组成并加密了这两个数组。如果我减去两个密文( xCiphertext MINUS xMeanCiphertext ),我应该得到 xResult = [-2, -1, 0, 1, 2] 但在同态减法之后我得到 xResultDecrypted = [40959, 40960, 0 ,1, 2] 。我可以将溢出结果与普通模数集相关联,但是否有解决此问题的方法。代码如下:

int main()  {

    EncryptionParameters parms;
    parms.set_poly_modulus("1x^4096 + 1");
    parms.set_coeff_modulus(coeff_modulus_128(4096));
    parms.set_plain_modulus(40961);

    SEALContext context(parms);

    KeyGenerator keygen(context);
    auto public_key = keygen.public_key();
    auto secret_key = keygen.secret_key();

    Encryptor encryptor(context, public_key);
    Evaluator evaluator(context);
    Decryptor decryptor(context, secret_key);

    PolyCRTBuilder crtbuilder(context);

    int slot_count = crtbuilder.slot_count();
    int row_size = slot_count / 2;

    vector<uint64_t> x_pod_matrix(slot_count, 0);
    x_pod_matrix[0] = 1;
    x_pod_matrix[1] = 2;
    x_pod_matrix[2] = 3;
    x_pod_matrix[3] = 4;
    x_pod_matrix[4] = 5;

    Plaintext x_plain_matrix;
    crtbuilder.compose(x_pod_matrix, x_plain_matrix);

    Ciphertext x_encrypted_matrix;

    encryptor.encrypt(x_plain_matrix, x_encrypted_matrix);

    vector<uint64_t> x_mean_pod_matrix(slot_count, 0);
    x_mean_pod_matrix[0] = 3;
    x_mean_pod_matrix[1] = 3;
    x_mean_pod_matrix[2] = 3;
    x_mean_pod_matrix[3] = 3;
    x_mean_pod_matrix[4] = 3;

    Plaintext x_mean_plain_matrix;
    crtbuilder.compose(x_mean_pod_matrix, x_mean_plain_matrix);

    Ciphertext x_mean_encrypted_matrix;

    encryptor.encrypt(x_mean_plain_matrix, x_mean_encrypted_matrix);

    evaluator.sub_plain(x_encrypted_matrix, x_mean_encrypted_matrix);

    // Decrypt x_encrypted_matrix
    Plaintext x_plain_result;

    decryptor.decrypt(x_encrypted_matrix, x_plain_result);

    vector<uint64_t> pod_result;

    crtbuilder.decompose(x_plain_result, pod_result);

    for(int i = 0; i < 5; i++)  {

        std::cout << pod_result[i] << '\n';

    }

    /*
    Expected output:
    -2
    -1
     0
     1
     2  
    */

    /*
     Actual output:
     40959
     40960
     0
     1
     2
    */


  return 0;

}

evaluator.negate() 不会帮助解决我的问题。

【问题讨论】:

    标签: seal


    【解决方案1】:

    因此,您得到的结果是正确的,因为明文仅以 plain_modulus 为模定义。 PolyCRTBuilder::decompose 的重载采用 std::int64_t 的向量,并会自动执行您希望看到的转换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      相关资源
      最近更新 更多