Beispiel #1
0
def test_encryptionparams_scheme_specific():
    testcase = sealapi.EncryptionParameters(sealapi.SCHEME_TYPE.NONE)
    with pytest.raises(BaseException):
        testcase.set_poly_modulus_degree(10)

    testcase.set_poly_modulus_degree(0)
    assert testcase.poly_modulus_degree() == 0
    testcase.set_coeff_modulus([])

    testcase = sealapi.EncryptionParameters(sealapi.SCHEME_TYPE.BFV)
    testcase.set_plain_modulus(sealapi.Modulus(1023))
    assert testcase.plain_modulus().value() == 1023

    testcase.set_random_generator(sealapi.BlakePRNGFactory())
    generator = testcase.random_generator().create()
    assert generator.generate() != generator.generate()
Beispiel #2
0
    header.compr_mode = sealapi.COMPR_MODE_TYPE.DEFLATE

    tmp = NamedTemporaryFile()
    sealapi.Serialization.SaveHeader(header, tmp.name)
    save_test = sealapi.Serialization.SEALHeader()
    sealapi.Serialization.LoadHeader(tmp.name, save_test, True)
    assert save_test.compr_mode == sealapi.COMPR_MODE_TYPE.DEFLATE
    sealapi.Serialization.LoadHeader(tmp.name, save_test, False)
    assert save_test.compr_mode == sealapi.COMPR_MODE_TYPE.DEFLATE


@pytest.mark.parametrize(
    "factory",
    [
        sealapi.BlakePRNGFactory.DefaultFactory(),
        sealapi.BlakePRNGFactory(),
        sealapi.BlakePRNGFactory([sealapi.random_uint64() for i in range(8)]),
    ],
)
def test_randomgen(factory):
    assert sealapi.random_uint64() != sealapi.random_uint64()

    for generator in [
        factory.create(),
        factory.create([sealapi.random_uint64() for i in range(8)]),
    ]:
        assert generator.generate() != generator.generate()

        adapter = sealapi.RandomToStandardAdapter(generator)
        assert adapter() != adapter()