Beispiel #1
0
    def run(self):
        "Run an issuance and store the execution time of the methods executed."
        size_printed = False
        random.seed(42)

        for _ in range(self.n_repetitions):
            protocol_communication = 0      # in Bytes
            signature_size = 0              # in Bytes

            abe_param, t = perf_measure_call(AbeParam)
            self.t_abe_param_init.append(t)

            keys, t = perf_measure_call(abe_param.generate_new_key_pair)
            self.t_generate_new_key_pair.append(t)

            signer_priv, signer_pub = keys

            signer, t = perf_measure_call(AbeSigner, signer_priv, signer_pub)
            self.t_abe_signer_init.append(t)

            user, t = perf_measure_call(AbeUser, signer_pub)
            self.t_abe_user_init.append(t)

            com, t = perf_measure_call(signer.commit)
            protocol_communication += len(packb(com))
            self.t_abe_signer_commit.append(t)

            message = ''.join([random.choice(string.printable) for _ in range(100)])

            challenge, t = perf_measure_call(user.compute_blind_challenge, com, message)
            protocol_communication += len(packb(challenge))
            self.t_user_compute_blind_challenge.append(t)

            resp, t = perf_measure_call(signer.respond, challenge)
            protocol_communication += len(packb(resp))
            self.t_signer_respond.append(t)

            sig, t = perf_measure_call(user.compute_signature, resp)
            # The signature stores the message. This size is dependent on the user's input.
            signature_size = len(packb(sig)) - len(message)
            self.t_user_compute_signature.append(t)

            _, t = perf_measure_call(signer_pub.verify_signature, sig)
            self.t_signer_pub_verify_signature.append(t)
            
            if not size_printed:
                print(f"Abe's signature => size: {signature_size}, communication cost: {protocol_communication}")
                size_printed = True
Beispiel #2
0
def test_bl_pedersen_invalid():
    group = EcGroup(DEFAULT_GROUP_ID)
    g1 = group.hash_to_point(b"test_z")
    g2 = group.hash_to_point(b"test_h2")

    values = [Bn(123), Bn(456), 'hello', b"world"]
    param = BlindedPedersenParam(hs_size=len(values), Z=g1, H_2=g2)
    bcommit, bpriv = param.blind_commit(values)

    # corrupt rand
    bpriv2 = unpackb(packb(bpriv))
    bpriv2.rand.value = param.q.random()
    bproof = bcommit.prove_values(bpriv2, reveal_mask=[True, False, True, True])
    assert not bcommit.verify_proof(param, bproof)

    # corrupt rand2
    bpriv3 = unpackb(packb(bpriv))
    bpriv3.rand_2.value = param.q.random()
    bproof = bcommit.prove_values(bpriv3, reveal_mask=[True, False, True, True])
    assert not bcommit.verify_proof(param, bproof)

    # corrupt blindness
    bpriv4 = unpackb(packb(bpriv))
    bpriv4.blindness_rand.value = param.q.random()
    bproof = bcommit.prove_values(bpriv4, reveal_mask=[True, False, True, True])
    assert not bcommit.verify_proof(param, bproof)

    # corrupt revealed value
    # This leads to different zksk.statement constants between prover and
    # verifier which result in StatementMismatch exception. verify_proof checks
    # for this statement and convert it to False
    bpriv5 = unpackb(packb(bpriv))
    bpriv5.values[0].value = param.q.random()
    bproof = bcommit.prove_values(bpriv5, reveal_mask=[True, False, True, True])
    assert not bcommit.verify_proof(param, bproof)

    # corrupt hidden value
    bpriv6 = unpackb(packb(bpriv))
    bpriv6.values[1].value = param.q.random()
    bproof = bcommit.prove_values(bpriv6, reveal_mask=[True, False, True, True])
    assert not bcommit.verify_proof(param, bproof)
Beispiel #3
0
def test_pack_cls():
    @attr.s
    class CLS(object):
        a = attr.ib()
        b = attr.ib()
    add_msgpack_support(CLS, 10)

    obj = CLS(a=[3, 'asd', Bn(123)], b=EcGroup().generator())
    obj2 = CLS(a=False, b=11 * EcGroup().generator())
    d = obj.to_bytes()
    objp = CLS.from_bytes(d)
    assert obj == objp

    x = [obj, obj2]
    bt = packb(x)
    xp = unpackb(bt)
    assert x == xp
Beispiel #4
0
def test_pack_blind_sig():
    priv, pk = AbeParam().generate_new_key_pair()
    signer = AbeSigner(priv, pk)
    user = AbeUser(pk)
    message = "Hello world"
    com = signer.commit()
    challenge = user.compute_blind_challenge(com, message)
    resp = signer.respond(challenge)
    sig = user.compute_signature(resp)

    m1 = packb(com)
    m2 = packb(challenge)
    m3 = packb(resp)
    m4 = packb(sig)
    m5 = packb(priv)
    m6 = packb(pk)

    assert unpackb(m1) == com
    assert unpackb(m2) == challenge
    assert unpackb(m3) == resp
    assert unpackb(m4) == sig
    assert unpackb(m5) == priv
    assert unpackb(m6) == pk
Beispiel #5
0
def test_pack_acl():
    issuer_priv, issuer_pk = ACLParam().generate_new_key_pair()
    issuer = ACLIssuer(issuer_priv, issuer_pk)
    user = ACLUser(issuer_pk)
    attrs = [Bn(13), "Hello", "WoRlD", "Hidden"]
    message = "This isn't a test message."

    m0 = user.prove_attr_knowledge(attrs)
    m1 = issuer.commit(m0)
    m2 = user.compute_blind_challenge(m1, message)
    m3 = issuer.respond(m2)
    cred_private = user.compute_credential(m3)
    cred = cred_private.show_credential([True, True, True, False])

    m0p = packb(m0)
    m1p = packb(m1)
    m2p = packb(m2)
    m3p = packb(m3)
    cred_privatep = packb(cred_private)
    credp = packb(cred)

    
    # the original message is representing m0.nizk_proof.response as list while
    # the unpacked version represent it as a tuple
    # assert unpackb(m0p) == m0

    assert unpackb(m1p) == m1
    assert unpackb(m2p) == m2
    assert unpackb(m3p) == m3
    assert unpackb(cred_privatep) == cred_private
    assert unpackb(credp) == cred

    cred = unpackb(credp)
    assert cred.verify_credential(issuer_pk)
    assert cred.get_message() == b"This isn't a test message."
    assert cred.get_attributes() == [13, 'Hello', 'WoRlD', None]
Beispiel #6
0
    def run(self):
        "Run an issuance and store the execution time of the methods executed."
        size_printed = False
        random.seed(42)

        for _ in range(self.n_repetitions):
            protocol_communication = 0      # in Bytes
            credential_size = 0             # in Bytes
            
            acl_param, t = perf_measure_call(ACLParam)
            self.t_acl_param_init.append(t)

            keys, t = perf_measure_call(acl_param.generate_new_key_pair)
            self.t_generate_new_key_pair.append(t)

            issuer_priv, issuer_pub = keys

            issuer, t = perf_measure_call(ACLIssuer, issuer_priv, issuer_pub)
            self.t_acl_issuer_init.append(t)

            user, t = perf_measure_call(ACLUser, issuer_pub)
            self.t_acl_user_init.append(t)

            rnd_attr_num = Bn(random.randint(0, 2**32 - 1))
            rnd_attr_s = [
                ''.join([
                    random.choice(string.printable) for _ in range(10)
                ]) for _ in range(3)
            ]

            attrs = [rnd_attr_num, *rnd_attr_s]
            message = ''.join([random.choice(string.printable) for _ in range(64)])

            m0, t = perf_measure_call(user.prove_attr_knowledge, attrs)
            protocol_communication += len(packb(m0))
            self.t_prove_attr_knowledge.append(t)

            m1, t = perf_measure_call(issuer.commit, m0)
            protocol_communication += len(packb(m1))
            self.t_issuer_commit.append(t)

            m2, t = perf_measure_call(user.compute_blind_challenge, m1, message)
            protocol_communication += len(packb(m2))
            self.t_user_compute_blind_challenge.append(t)

            m3, t = perf_measure_call(issuer.respond, m2)
            protocol_communication += len(packb(m3))
            self.t_issuer_respond.append(t)

            cred_private, t = perf_measure_call(user.compute_credential, m3)
            self.t_user_compute_credential.append(t)

            cred, t = perf_measure_call(cred_private.show_credential, [True, True, True, False])
            # The credential stores the raw message and attributes. This size is dependent on the user's input. 
            credential_size = len(packb(cred)) - len(message) - len(packb(cred_private.bpriv.raw_values))
            self.t_cred_private_show_credential.append(t)

            _, t = perf_measure_call(cred.verify_credential, issuer_pub)
            self.t_cred_verify_credential.append(t)

            if not size_printed:
                print(f"ACL => priv: {len(packb(cred_private))}, credential size (showing the credential): {credential_size}, communication cost: {protocol_communication}")
                size_printed = True