def test_suite_three_parties_double_secret_double_use():
    """
    f(a, b) = a1 * a2 + b1 * b2 + c * a2 * b1
    """
    alice_secret1 = Secret()
    alice_secret2 = Secret()
    bob_secret1 = Secret()
    bob_secret2 = Secret()
    charlie_secret = Secret()

    parties = {
        "Alice": {
            alice_secret1: 3,
            alice_secret2: 4
        },
        "Bob": {
            bob_secret1: 2,
            bob_secret2: 12
        },
        "Charlie": {
            charlie_secret: 1
        }
    }

    expr = (alice_secret1 * alice_secret2 + bob_secret1 * bob_secret2 +
            charlie_secret * alice_secret2 * bob_secret2)
    expected = (3 * 4 + 2 * 12 + 1 * 4 * 12)
    suite(parties, expr, expected)
def test_suite_three_parties_double_secret():
    """
    f(a, b) = a1 + b1 + b2 + a2 + c
    """
    alice_secret1 = Secret()
    alice_secret2 = Secret()
    bob_secret1 = Secret()
    bob_secret2 = Secret()
    charlie_secret = Secret()

    parties = {
        "Alice": {
            alice_secret1: 3,
            alice_secret2: 4
        },
        "Bob": {
            bob_secret1: 2,
            bob_secret2: 12
        },
        "Charlie": {
            charlie_secret: 1
        }
    }

    expr = (alice_secret1 + bob_secret1 + bob_secret2 + alice_secret2 +
            charlie_secret)
    expected = (3 + 4 + 12 + 2 + 1)
    suite(parties, expr, expected)
def test_suite8():
    """
    f(a, b, c, d, e) = ((a + K0) + b ∗ K1 - c) ∗ (d + e)
    """
    alice_secret = Secret()
    bob_secret = Secret()
    charlie_secret = Secret()
    david_secret = Secret()
    elusinia_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 14
        },
        "Charlie": {
            charlie_secret: 2
        },
        "David": {
            david_secret: 5
        },
        "Elusinia": {
            elusinia_secret: 7
        }
    }

    expr = (((alice_secret + Scalar(8)) +
             ((bob_secret * Scalar(9)) - charlie_secret)) *
            (david_secret + elusinia_secret))
    expected = (((3 + 8) + (14 * 9) - 2) * (5 + 7))
    suite(parties, expr, expected)
def test_suite6():
    """
    f(a, b, c, d) = a + b + c + d
    """
    alice_secret = Secret()
    bob_secret = Secret()
    charlie_secret = Secret()
    david_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 14
        },
        "Charlie": {
            charlie_secret: 2
        },
        "David": {
            david_secret: 5
        }
    }

    expr = (alice_secret + bob_secret + charlie_secret + david_secret)
    expected = 3 + 14 + 2 + 5
    suite(parties, expr, expected)
Exemple #5
0
def test_expr_construction():
    a = Secret(1)
    b = Secret(2)
    c = Secret(3)
    expr = (a + b) * c * Scalar(4) + Scalar(3)
    assert repr(
        expr
    ) == "((Secret(1) + Secret(2)) * Secret(3) * Scalar(4) + Scalar(3))"
Exemple #6
0
def test4():
    a = Secret(3)
    b = Secret(14)
    c = Secret(2)
    expr = ((a * b + b * Scalar(4)) * c - (a + Scalar(1) * b))
    assert repr(
        expr
    ) == "((Secret(3) * Secret(14) + Secret(14) * Scalar(4)) * Secret(2) - (Secret(3) + Scalar(1) * Secret(14)))"
Exemple #7
0
def test1():
    a = Secret(1)
    b = Secret(2)
    c = Secret(3)
    expr = (a + b) * c - (Scalar(4) + Scalar(3))
    assert repr(
        expr
    ) == "((Secret(1) + Secret(2)) * Secret(3) - (Scalar(4) + Scalar(3)))"
def add_scalar():
    for _ in range(repeat_experiment):
        for num_ops in ops_n:

            circuit = Scalar(0)
            parties = {}
            total = 0

            # Generate parties
            for p in range(10):
                party_secret = Secret()
                val = random.randint(0, get_mod())
                parties[str(p)] = {party_secret: val}

            for o in range(num_ops):

                val = random.randint(0, get_mod())

                if o == 0:
                    circuit = Scalar(val)
                else:
                    circuit += Scalar(val)

                total = (total + val) % get_mod()

            suite(parties, circuit, total)
def test_suite_constantes():
    """
    f(a, b) = K1 + K2
    """
    alice_secret = Secret()
    bob_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 14
        },
    }

    expr = (Scalar(2) + Scalar(1))
    expected = 3
    suite(parties, expr, expected)
def test_suite_two_parties():
    """
    f(a, b) = a + b 
    """
    alice_secret = Secret()
    bob_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 14
        },
    }

    expr = (alice_secret + bob_secret)
    expected = 3 + 14
    suite(parties, expr, expected)
def test_suite2():
    """
    f(a, b) = a - b
    """
    alice_secret = Secret()
    bob_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 14
        },
        "Bob": {
            bob_secret: 3
        },
    }

    expr = (alice_secret - bob_secret)
    expected = 14 - 3
    suite(parties, expr, expected)
def test_suite_const_mul_secret2():
    """
        f(a, b) = K * K * a
    """
    alice_secret = Secret()
    bob_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 4
        },
    }

    expr = (Scalar(3) * Scalar(3) * alice_secret)
    expected = (3 * 3 * 3)
    suite(parties, expr, expected)
def test_weight_update():
    """
    Computes a batch weight update for a perceptron with batch size = 3
    f(a, b, c) = 3 * W_t + lr * ( (a1 - a2) * a3 + (b1 - b2) * b3 + (c1 - c2) * c3 
    """

    weight = 8
    lr = 1

    alice_secret1 = Secret()
    alice_secret2 = Secret()
    alice_secret3 = Secret()
    bob_secret1 = Secret()
    bob_secret2 = Secret()
    bob_secret3 = Secret()
    charlie_secret1 = Secret()
    charlie_secret2 = Secret()
    charlie_secret3 = Secret()

    parties = {
        "Alice": {
            alice_secret1: 3,
            alice_secret2: 4,
            alice_secret3: 5
        },
        "Bob": {
            bob_secret1: 20,
            bob_secret2: 12,
            bob_secret3: 3
        },
        "Charlie": {
            charlie_secret1: 9,
            charlie_secret2: 7,
            charlie_secret3: 6
        }
    }

    expr = (Scalar(3) * Scalar(weight) + Scalar(lr) *
            ((alice_secret1 - alice_secret2) * alice_secret3 +
             (bob_secret1 - bob_secret2) * bob_secret3) +
            (charlie_secret1 - charlie_secret2) * charlie_secret3)
    expected = (3 * 8 + 1 * ((3 - 4) * 5) + (20 - 12) * 3 + (9 - 7) * 6)
    suite(parties, expr, expected)
def test_suite4():
    """
    f(a, b, c) = (a + b + c) + K
    """
    alice_secret = Secret()
    bob_secret = Secret()
    charlie_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 14
        },
        "Charlie": {
            charlie_secret: 2
        }
    }

    expr = ((alice_secret + bob_secret + charlie_secret) + Scalar(5))
    expected = (3 + 14 + 2) + 5
    suite(parties, expr, expected)
def test_suite1():
    """
    f(a, b, c) = a + b + c
    """
    alice_secret = Secret()
    bob_secret = Secret()
    charlie_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 14
        },
        "Charlie": {
            charlie_secret: 2
        }
    }

    expr = (alice_secret + bob_secret + charlie_secret)
    expected = 3 + 14 + 2
    suite(parties, expr, expected)
def test_suite_three_parties():
    """
    f(a, b) = a * b * c
    """
    alice_secret = Secret()
    bob_secret = Secret()
    charlie_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 2
        },
        "Charlie": {
            charlie_secret: 1
        }
    }

    expr = (alice_secret * bob_secret * charlie_secret)
    expected = (3 * 2 * 1)
    suite(parties, expr, expected)
def test_suite_const_mul_secret():
    """
        f(a, b) = a * K
    """
    alice_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
    }

    expr = (alice_secret * Scalar(2))
    expected = (3 * 2)
    suite(parties, expr, expected)
def test_suite5():
    """
    f(a, b, c) = (a ∗ K0 + b - c) + K1
    """
    alice_secret = Secret()
    bob_secret = Secret()
    charlie_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 14
        },
        "Charlie": {
            charlie_secret: 2
        }
    }

    expr = (((alice_secret * Scalar(5)) + bob_secret - charlie_secret) +
            Scalar(9))
    expected = ((3 * 5) + 14 - 2) + 9
    suite(parties, expr, expected)
def test_suite7():
    """
    f(a, b, c) = (a ∗ b) + (b ∗ c) + (c ∗ a)
    """
    alice_secret = Secret()
    bob_secret = Secret()
    charlie_secret = Secret()

    parties = {
        "Alice": {
            alice_secret: 3
        },
        "Bob": {
            bob_secret: 14
        },
        "Charlie": {
            charlie_secret: 2
        }
    }

    expr = ((alice_secret * bob_secret) + (bob_secret * charlie_secret) +
            (charlie_secret * alice_secret))
    expected = ((3 * 14) + (14 * 2) + (2 * 3))
    suite(parties, expr, expected)
def fixed_circuit_more_participants():
    """
    f(a, b, c, ...) = (K + a) * b
    """
    for _ in range(repeat_experiment):
        for num_part in participants_n:

            circuit = Scalar(56)
            parties = {}

            for p in range(num_part):

                party_secret = Secret()
                parties[str(p)] = {party_secret: p + 69420}

                if p == 0:
                    circuit += party_secret
                if p == 1:
                    circuit *= party_secret

            expected = (56 + 69420) * 69421
            suite(parties, circuit, expected)
def mul_secret():
    for _ in range(repeat_experiment):
        for num_ops in ops_n:

            circuit = Scalar(0)
            parties = {}
            total = 1

            # Generate parties and basic circuit
            for p in range(10):
                party_secret = Secret()
                val = random.randint(0, get_mod())
                parties[str(p)] = {party_secret: val}

            for o in range(num_ops):

                if o == 0:
                    circuit = list(parties[str(o % 10)].keys())[0]
                else:
                    circuit *= list(parties[str(o % 10)].keys())[0]

                total = (total * list(parties[str(o % 10)].values())[0]) % get_mod()

            suite(parties, circuit, total)
Exemple #22
0
def test_expr_construction():
    a = Secret(1)
    b = Secret(2)
    c = Secret(3)
    expr = (a + b) * c * Scalar(4) + Scalar(3)
Exemple #23
0
def test2():
    a = Secret(14)
    b = Secret(3)
    expr = (a - b)
    assert repr(expr) == "(Secret(14) - Secret(3))"
Exemple #24
0
def test3():
    a = Secret(3)
    b = Secret(14)
    c = Secret(2)
    expr = ((a + b + c) * Scalar(5))
    assert repr(expr) == "((Secret(3) + Secret(14) + Secret(2)) * Scalar(5))"