Ejemplo n.º 1
0
def test_keygenerator_relinkeys(ctx):
    poly_modulus_degree = helper_poly_modulus_degree(ctx)

    index = 4
    assert sealapi.RelinKeys.get_index(index) == index - 2

    keygen = sealapi.KeyGenerator(ctx)
    relin_keys = keygen.relin_keys_local()

    assert relin_keys.has_key(2) is True

    pubkey = relin_keys.key(2)[0]
    assert pubkey.data().poly_modulus_degree() == poly_modulus_degree

    assert relin_keys.size() > 0
    assert len(relin_keys.data()) == relin_keys.size()
    assert relin_keys.data(0)[0].data().poly_modulus_degree() == helper_poly_modulus_degree(ctx)
    assert len(relin_keys.parms_id()) == 4

    tmp = NamedTemporaryFile()
    serial = keygen.relin_keys()
    serial.save(tmp.name)
    assert Path(tmp.name).stat().st_size > 0

    tmp = NamedTemporaryFile()
    keygen.relin_keys_local().save(tmp.name)
    save_test = sealapi.RelinKeys()
    assert save_test.has_key(2) is False
    save_test.load(ctx, tmp.name)
    assert save_test.has_key(2) is True
Ejemplo n.º 2
0
def test_keygenerator_relinkeys(ctx):
    poly_modulus_degree = helper_poly_modulus_degree(ctx)

    index = 4
    assert sealapi.RelinKeys.get_index(index) == index - 2

    keygen = sealapi.KeyGenerator(ctx)
    relin_keys = sealapi.RelinKeys()
    keygen.create_relin_keys(relin_keys)

    assert relin_keys.has_key(2) is True

    pubkey = relin_keys.key(2)[0]
    assert pubkey.data().poly_modulus_degree() == poly_modulus_degree

    assert relin_keys.size() > 0
    assert len(relin_keys.data()) == relin_keys.size()
    assert relin_keys.data(
        0)[0].data().poly_modulus_degree() == helper_poly_modulus_degree(ctx)
    assert len(relin_keys.parms_id()) == 4

    def save_load(path):
        rk = sealapi.RelinKeys()
        keygen.create_relin_keys(rk)
        rk.save(path)
        assert Path(path).stat().st_size > 0

    tmp_file(save_load)
Ejemplo n.º 3
0
def test_valcheck(check):
    ctx = helper_context_bfv(8192)
    other_ctx = helper_context_ckks(8192)
    invalid_ctx = helper_context_invalid()

    ciphertext = sealapi.Ciphertext(ctx)

    assert check(ciphertext, ctx) is True
    assert check(ciphertext, other_ctx) is False
    assert check(ciphertext, invalid_ctx) is False

    assert sealapi.is_buffer_valid(ciphertext) is True

    plaintext = sealapi.Plaintext()

    assert check(plaintext, ctx) is True
    assert check(plaintext, other_ctx) is True
    assert check(plaintext, invalid_ctx) is False

    keygen = sealapi.KeyGenerator(ctx)

    pk = sealapi.PublicKey()
    keygen.create_public_key(pk)

    rk = sealapi.RelinKeys()
    keygen.create_relin_keys(rk)

    gk = sealapi.GaloisKeys()
    keygen.create_galois_keys(gk)

    for key in [pk, keygen.secret_key(), gk, rk]:
        assert check(key, ctx) is True
        assert check(key, other_ctx) is False
        assert check(key, invalid_ctx) is False
        assert sealapi.is_buffer_valid(key) is True
Ejemplo n.º 4
0
def helper_generate_evaluator(ctx):
    evaluator = sealapi.Evaluator(ctx)

    keygen = sealapi.KeyGenerator(ctx)
    public_key = sealapi.PublicKey()
    keygen.create_public_key(public_key)
    secret_key = keygen.secret_key()
    relin_keys = sealapi.RelinKeys()
    keygen.create_relin_keys(relin_keys)

    decryptor = sealapi.Decryptor(ctx, secret_key)
    encryptor = sealapi.Encryptor(ctx, public_key, secret_key)

    return evaluator, encryptor, decryptor, relin_keys
Ejemplo n.º 5
0
 def save_load(path):
     rk = sealapi.RelinKeys()
     keygen.create_relin_keys(rk)
     rk.save(path)
     assert Path(path).stat().st_size > 0