def test_fv_relin_exceptions(val1, val2): ctx = Context(EncryptionParams(128, CoeffModulus().create(128, [40, 40]), 64)) keygenerator = KeyGenerator(ctx) keys = keygenerator.keygen() relin_key = keygenerator.get_relin_keys() encoder = IntegerEncoder(ctx) encryptor = Encryptor(ctx, keys[1]) # keys[1] = public_key evaluator = Evaluator(ctx) op1 = encryptor.encrypt(encoder.encode(val1)) op2 = encryptor.encrypt(encoder.encode(val2)) temp_prod = evaluator.mul(op1, op2) with pytest.raises(Warning): evaluator.relin(op1, relin_key) # Ciphertext size 2 with pytest.raises(Exception): evaluator.relin(evaluator.mul(temp_prod, val1), relin_key) # Ciphertext size 4
def test_fv_mul_plain_plain(int1, int2): ctx = Context(EncryptionParams(64, CoeffModulus().create(64, [30, 30]), 64)) encoder = IntegerEncoder(ctx) evaluator = Evaluator(ctx) op1 = encoder.encode(int1) op2 = encoder.encode(int2) assert (int1 * int2 == encoder.decode(evaluator._mul_plain_plain(op1, op2)) == encoder.decode(evaluator.mul(op1, op2)) == encoder.decode( evaluator._mul_plain_plain(op2, op1)))
def test_fv_mul_cipher_plain(int1, int2): ctx = Context(EncryptionParams(64, CoeffModulus().create(64, [30, 30]), 64)) keys = KeyGenerator(ctx).keygen() encoder = IntegerEncoder(ctx) encryptor = Encryptor(ctx, keys[1]) # keys[1] = public_key decryptor = Decryptor(ctx, keys[0]) # keys[0] = secret_key evaluator = Evaluator(ctx) op1 = encryptor.encrypt(encoder.encode(int1)) op2 = encoder.encode(int2) assert (int1 * int2 == encoder.decode( decryptor.decrypt(evaluator._mul_cipher_plain(op1, op2))) == encoder.decode(decryptor.decrypt(evaluator.mul(op1, op2))) == encoder.decode(decryptor.decrypt(evaluator.mul(op2, op1))))
def test_fv_relin(val1, val2): ctx = Context(EncryptionParams(128, CoeffModulus().create(128, [40, 40]), 64)) keygenerator = KeyGenerator(ctx) keys = keygenerator.keygen() relin_key = keygenerator.get_relin_keys() encoder = IntegerEncoder(ctx) encryptor = Encryptor(ctx, keys[1]) # keys[1] = public_key decryptor = Decryptor(ctx, keys[0]) # keys[0] = secret_key evaluator = Evaluator(ctx) op1 = encryptor.encrypt(encoder.encode(val1)) op2 = encryptor.encrypt(encoder.encode(val2)) temp_prod = evaluator.mul(op1, op2) relin_prod = evaluator.relin(temp_prod, relin_key) assert len(temp_prod.data) - 1 == len(relin_prod.data) assert val1 * val2 == encoder.decode(decryptor.decrypt(relin_prod))