Esempio n. 1
0
def test_dlrep_non_interactive_1(group):
    g, h = make_generators(2, group)
    expr = Secret(value=3) * g + Secret(value=4) * h
    p = DLRep(expr.eval(), expr)
    tr = p.prove()
    prover = p.get_prover()
    assert p.verify(tr)
Esempio n. 2
0
    def commit(self, messages, zkp=True):
        """
        Construct the product of messages and optionaly a Pedersen commitment and its proof.

        Args:
            messages: Messages (attributes) to commit to
            zkp (bool): Whether to construct a Pedersen commitment and proof the knowledge of the
                messages for this commitment.

        Returns:
            :py:class:`UserCommitmentMessage`: user's packed commitment.
        """
        lhs = self.pk.generators[0].group.wsum(
            messages, self.pk.generators[2 : len(messages) + 2]
        )
        com_nizk_proof = None
        if zkp:
            self.s1 = self.pk.generators[0].group.order().random()
            lhs = self.s1 * self.pk.generators[1] + lhs

            # TODO: Extract into a separate ExtendedProofStmt.
            secret_vars = [Secret() for _ in range(len(messages) + 1)]
            secrets = [self.s1] + messages
            rhs = wsum_secrets(secret_vars, self.pk.generators[1 : len(messages) + 2])
            com_stmt = DLRep(lhs, rhs)
            com_nizk_proof = com_stmt.prove(
                {s: v for s, v in zip(secret_vars, secrets)}
            )

        return UserCommitmentMessage(com_message=lhs, com_nizk_proof=com_nizk_proof)
Esempio n. 3
0
def test_dlrep_non_interactive_with_message(group):
    g, h = make_generators(2, group)

    expr = Secret(value=3) * g + Secret(value=4) * h
    p = DLRep(expr.eval(), expr)
    tr = p.prove(message="mymessage")

    assert DLRep(expr.eval(), expr).verify(tr, message="mymessage")
Esempio n. 4
0
def test_dlrep_bad_hash(group):
    g, h = make_generators(2, group=group)
    x, y = Secret(), Secret()
    secret_dict = {x: 2, y: 3}
    p1 = DLRep(2 * g + 3 * h, x * g + y * h)
    p2 = DLRep(2 * g + 3 * h, y * h + x * g)
    tr = p1.prove(secret_dict)
    assert p1.verify(tr)

    with pytest.raises(StatementMismatch):
        p2.verify(tr)
Esempio n. 5
0
def test_dlrep_wrong_response_non_interactive(group):
    g, h = make_generators(2, group=group)
    x, y = Secret(value=3), Secret(value=4)
    expr = x * g + y * h

    p = DLRep(expr.eval(), expr)
    tr = p.prove(message="mymessage")

    # Turn one of the responses random
    tr.responses[1] = group.order().random()

    assert not p.verify(tr, message="mymessage")
Esempio n. 6
0
def test_dlrep_non_interactive_2(group):
    (g, ) = make_generators(1, group)
    x = Secret()
    p = DLRep(4 * g, x * g)
    tr = p.prove({x: 4})
    assert p.verify(tr)