Skip to content

Commit

Permalink
Added unit test for multiply_plain_inplace when plain is a monomial.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei Dai authored and kimlaine committed Apr 30, 2020
1 parent 71ff582 commit 6688c19
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Version 3.5.0

### Hotfix - 4/30/2020

- Fixed a critical bug [(Issue 166)](https://github.com/microsoft/SEAL/issues/166) in `Evaluator::multiply_plain_inplace`. Thanks s0l0ist!

### Hotfix - 4/29/2020

- Switched to using Microsoft GSL v3.0.1 and fixed minor GSL related issues in `CMakeLists.txt`.
Expand Down
70 changes: 70 additions & 0 deletions native/tests/seal/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,76 @@ namespace sealtest
ASSERT_EQ(static_cast<uint64_t>(0x5B05B058), encoder.decode_uint64(plain));
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());
}
{
EncryptionParameters parms(scheme_type::BFV);
Modulus plain_modulus(PlainModulus::Batching(64, 20));
parms.set_poly_modulus_degree(64);
parms.set_plain_modulus(plain_modulus);
parms.set_coeff_modulus(CoeffModulus::Create(64, { 30, 30, 30 }));

auto context = SEALContext::Create(parms, false, sec_level_type::none);
KeyGenerator keygen(context);

BatchEncoder batch_encoder(context);
Encryptor encryptor(context, keygen.public_key());
Evaluator evaluator(context);
Decryptor decryptor(context, keygen.secret_key());

Ciphertext encrypted;
Plaintext plain;
vector<int64_t> result;

batch_encoder.encode(vector<int64_t>(batch_encoder.slot_count(), 7), plain);
encryptor.encrypt(plain, encrypted);
evaluator.multiply_plain_inplace(encrypted, plain);
decryptor.decrypt(encrypted, plain);
batch_encoder.decode(plain, result);
ASSERT_TRUE(vector<int64_t>(batch_encoder.slot_count(), 49) == result);
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());

batch_encoder.encode(vector<int64_t>(batch_encoder.slot_count(), -7), plain);
encryptor.encrypt(plain, encrypted);
evaluator.multiply_plain_inplace(encrypted, plain);
decryptor.decrypt(encrypted, plain);
batch_encoder.decode(plain, result);
ASSERT_TRUE(vector<int64_t>(batch_encoder.slot_count(), 49) == result);
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());
}
{
EncryptionParameters parms(scheme_type::BFV);
Modulus plain_modulus(PlainModulus::Batching(64, 40));
parms.set_poly_modulus_degree(64);
parms.set_plain_modulus(plain_modulus);
parms.set_coeff_modulus(CoeffModulus::Create(64, { 30, 30, 30 }));

auto context = SEALContext::Create(parms, false, sec_level_type::none);
KeyGenerator keygen(context);

BatchEncoder batch_encoder(context);
Encryptor encryptor(context, keygen.public_key());
Evaluator evaluator(context);
Decryptor decryptor(context, keygen.secret_key());

Ciphertext encrypted;
Plaintext plain;
vector<int64_t> result;

batch_encoder.encode(vector<int64_t>(batch_encoder.slot_count(), 7), plain);
encryptor.encrypt(plain, encrypted);
evaluator.multiply_plain_inplace(encrypted, plain);
decryptor.decrypt(encrypted, plain);
batch_encoder.decode(plain, result);
ASSERT_TRUE(vector<int64_t>(batch_encoder.slot_count(), 49) == result);
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());

batch_encoder.encode(vector<int64_t>(batch_encoder.slot_count(), -7), plain);
encryptor.encrypt(plain, encrypted);
evaluator.multiply_plain_inplace(encrypted, plain);
decryptor.decrypt(encrypted, plain);
batch_encoder.decode(plain, result);
ASSERT_TRUE(vector<int64_t>(batch_encoder.slot_count(), 49) == result);
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());
}
}

TEST(EvaluatorTest, BFVEncryptMultiplyDecrypt)
Expand Down

0 comments on commit 6688c19

Please sign in to comment.