コード例 #1
0
def test_add_inplace(context, vec1, vec2):
    first_vec = ts.bfv_naive_vector(context, vec1)
    second_vec = ts.bfv_naive_vector(context, vec2)
    first_vec += second_vec
    expected = [v1 + v2 for v1, v2 in zip(vec1, vec2)]

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == expected, "Addition of vectors is incorrect."
    assert second_vec.decrypt() == vec2, "Something went wrong in memory."
コード例 #2
0
def test_sub_inplace(context):
    first_vec = ts.bfv_naive_vector(context, [1, 2, 3, 4])
    second_vec = ts.bfv_naive_vector(context, [4, 3, 2, 1])
    first_vec -= second_vec

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == [-3, -1, 1,
                                3], "Substraction of vectors is incorrect."
    assert second_vec.decrypt() == [4, 3, 2,
                                    1], "Something went wrong in memory."
コード例 #3
0
def test_add_inplace(context):
    first_vec = ts.bfv_naive_vector(context, [1, 2, 3, 4])
    second_vec = ts.bfv_naive_vector(context, [4, 3, 2, 1])
    first_vec += second_vec

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == [5, 5, 5,
                                5], "Addition of vectors is incorrect."
    assert second_vec.decrypt() == [4, 3, 2,
                                    1], "Something went wrong in memory."
コード例 #4
0
def test_mul_inplace(context):
    first_vec = ts.bfv_naive_vector(context, [66, 73, 81, 90])
    second_vec = ts.bfv_naive_vector(context, [2, 3, 4, 5])
    first_vec *= second_vec

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == [132, 219, 324,
                                450], "Multiplication of vectors is incorrect."
    assert second_vec.decrypt() == [2, 3, 4,
                                    5], "Something went wrong in memory."
コード例 #5
0
def test_mul(context, vec1, vec2):
    first_vec = ts.bfv_naive_vector(context, vec1)
    second_vec = ts.bfv_naive_vector(context, vec2)
    result = first_vec * second_vec
    expected = [v1 * v2 for v1, v2 in zip(vec1, vec2)]

    # Decryption
    decrypted_result = result.decrypt()
    assert decrypted_result == expected, "Multiplication of vectors is incorrect."
    assert first_vec.decrypt() == vec1, "Something went wrong in memory."
    assert second_vec.decrypt() == vec2, "Something went wrong in memory."
コード例 #6
0
def test_bfv_naive_encryption_decryption(plain_vec):
    context = ts.context(ts.SCHEME_TYPE.BFV, 4096, 1024)

    bfv_vec = ts.bfv_naive_vector(context, plain_vec)
    decrypted_vec = bfv_vec.decrypt()

    assert decrypted_vec == plain_vec, "Decryption of vector is incorrect."
コード例 #7
0
def test_mul_plain_zero(context):
    pt = [0]
    ct = ts.bfv_naive_vector(context, [1])

    with pytest.raises(RuntimeError) as e:
        # bfv_naive_vector can't be multiplied with zero value
        result = ct * pt
    assert str(e.value) == "result ciphertext is transparent"
コード例 #8
0
def test_add__plain_inplace(context):
    first_vec = ts.bfv_naive_vector(context, [1, 2, 3, 4])
    second_vec = [4, 3, 2, 1]
    first_vec += second_vec

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == [5, 5, 5,
                                5], "Addition of vectors is incorrect."
コード例 #9
0
def test_mul_plain_inplace(context):
    first_vec = ts.bfv_naive_vector(context, [66, 73, 81, 90])
    second_vec = [2, 3, 4, 5]
    first_vec *= second_vec

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == [132, 219, 324,
                                450], "Multiplication of vectors is incorrect."
コード例 #10
0
def test_sub_plain_inplace(context):
    first_vec = ts.bfv_naive_vector(context, [1, 2, 3, 4])
    second_vec = [4, 3, 2, 1]
    first_vec -= second_vec

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == [-3, -1, 1,
                                3], "Substraction of vectors is incorrect."
コード例 #11
0
def test_mul_plain_inplace(context, vec1, vec2):
    first_vec = ts.bfv_naive_vector(context, vec1)
    second_vec = vec2
    first_vec *= second_vec
    expected = [v1 * v2 for v1, v2 in zip(vec1, vec2)]

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == expected, "Multiplication of vectors is incorrect."
コード例 #12
0
def test_sub_plain_inplace(context, vec1, vec2):
    first_vec = ts.bfv_naive_vector(context, vec1)
    second_vec = vec2
    first_vec -= second_vec
    expected = [v1 - v2 for v1, v2 in zip(vec1, vec2)]

    # Decryption
    decrypted_result = first_vec.decrypt()
    assert decrypted_result == expected, "Substraction of vectors is incorrect."
コード例 #13
0
def test_bfv_naive_secretkey_decryption(plain_vec):
    context = ts.context(ts.SCHEME_TYPE.BFV, 4096, 1024)

    bfv_vec = ts.bfv_naive_vector(context, plain_vec)
    secret_key = context.secret_key()
    context.make_context_public()
    decrypted_vec = bfv_vec.decrypt(secret_key)

    assert decrypted_vec == plain_vec, "Decryption of vector is incorrect."
コード例 #14
0
def test_sub_plain(context, vec1, vec2):
    first_vec = ts.bfv_naive_vector(context, vec1)
    second_vec = vec2
    result = first_vec - second_vec
    expected = [v1 - v2 for v1, v2 in zip(vec1, vec2)]

    # Decryption
    decrypted_result = result.decrypt()
    assert decrypted_result == expected, "Substraction of vectors is incorrect."
    assert first_vec.decrypt() == vec1, "Something went wrong in memory."
コード例 #15
0
ファイル: test_perf.py プロジェクト: dhuynh95/TenSEAL
def bfv_naive_test():
    ctx = ts.context(ts.SCHEME_TYPE.BFV, 4096, 1024)
    l, r = gen_values(200)
    return ts.bfv_naive_vector(ctx, l), ts.bfv_naive_vector(ctx, r)
コード例 #16
0
def test_size(context):
    for size in range(10):
        vec = ts.bfv_naive_vector(context, [1] * size)
        assert vec.size() == size, "Size of encrypted vector is incorrect."