Ejemplo n.º 1
0
def testGetHash():
    input = [
        'b1134a647eb818069c089e7694f63e6d',
        '57fbf9dc8c8e6acde33de98c6d747b28c',
        '77fbf9dc8c8e6acde33de98c6d747b28c'
    ]
    mathInput = [int(i, 16) for i in input]
    h1 = get_hash(*mathInput)
    h2 = get_hash(*reversed(sorted(mathInput)))

    assert h1 == h2
Ejemplo n.º 2
0
    def verifyProof(cls, credDefPks, proof, nonce, encodedAttrs, revealedAttrs):
        """
        Verify the proof
        :param encodedAttrs: The encoded attributes dictionary
        :param revealedAttrs: The revealed attributes list
        :param nonce: The nonce used to have a commit
        :return: A boolean with the verification status for the proof
        """

        import logging
        Aprime, c, Tvect = getProofParams(proof, credDefPks, encodedAttrs,
                                          revealedAttrs)
        logging.debug("Proof Verification 1: proof, "
                      "credDefPks, encodedAttrs, revealedAttrs: {} {} {} {}".
                      format(proof, credDefPks, encodedAttrs, revealedAttrs))
        # Calculate the `cvect` value based on proof.
        # This value is mathematically proven to be equal to `c`
        # if proof is created correctly from credentials. Refer 2.8 in document
        logging.debug("Proof Verification 2: Aprime, Tvect, nonce: {} {} {}".
                      format(Aprime, Tvect, nonce))

        cvect = cmod.integer(get_hash(*get_values_of_dicts(Aprime, Tvect,
                                                           {NONCE: nonce})))
        logging.debug("Proof Verification 3: c, cvect: {} {}".
                      format(c, cvect))

        return c == cvect
Ejemplo n.º 3
0
    def verifyPredicateProof(proof: PredicateProof, credDefPks, nonce,
                             attrs: Dict[str, Dict[str, T]],
                             revealedAttrs: Sequence[str],
                             predicate: Dict[str, Sequence[str]]):
        """
        Verify the proof for Predicate implementation
        :param proof: The proof which is a combination of sub-proof for
        credential and proof, C
        :param nonce: The nonce used
        :param attrs: The encoded attributes
        :param revealedAttrs: The list of revealed attributes
        :param predicate: The predicate to be validated
        :return:
        """

        Tau = []
        subProofC, subProofPredicate, C, CList = proof

        # Get all the random and prime numbers for verifying the proof
        c, evect, mvect, vvect, Aprime = subProofC
        alphavect, rvect, uvect = subProofPredicate

        Aprime, c, Tvect = getProofParams(subProofC, credDefPks, attrs,
                                          revealedAttrs)

        Tau.extend(get_values_of_dicts(Tvect))

        for key, val in predicate.items():
            p = credDefPks[key]
            Tval = C[key][TVAL]

            # Iterate over the predicates for a given credential(issuer)
            for k, value in val.items():

                Tdeltavect1 = (Tval[DELTA] * (p.Z ** value))
                Tdeltavect2 = (p.Z ** mvect[k]) * (p.S ** rvect[DELTA])
                Tdeltavect = (Tdeltavect1 ** (-1 * c)) * Tdeltavect2 % p.N

                Tuproduct = 1 % p.N
                for i in range(0, ITERATIONS):
                    Tvalvect1 = (Tval[str(i)] ** (-1 * c))
                    Tvalvect2 = (p.Z ** uvect[str(i)])
                    Tvalvect3 = (p.S ** rvect[str(i)])
                    Tau.append(Tvalvect1 * Tvalvect2 * Tvalvect3 % p.N)
                    Tuproduct *= Tval[str(i)] ** uvect[str(i)]

                Tau.append(Tdeltavect)

                Qvect1 = (Tval[DELTA] ** (-1 * c))
                Qvect = Qvect1 * Tuproduct * (p.S ** alphavect) % p.N
                Tau.append(Qvect)

        tauAndC = reduce(lambda x, y: x + y, [Tau, CList])
        cvect = cmod.integer(get_hash(nonce, *tauAndC))

        return c == cvect
Ejemplo n.º 4
0
        def appendToProofCompWithPredicateData(proofComponent, predicate):
            for key, val in predicate.items():
                x = self.credDefPks[key]
                # Iterate over the predicates for a given credential(issuer)
                for k, value in val.items():

                    delta = proofComponent.flatAttrs[k] - value
                    if delta < 0:
                        raise ValueError("Predicate is not satisfied")

                    proofComponent.u = fourSquares(delta)

                    for i in range(0, ITERATIONS):
                        proofComponent.r[str(i)] = cmod.integer(
                            cmod.randomBits(LARGE_VPRIME))
                    proofComponent.r[DELTA] = cmod.integer(
                        cmod.randomBits(LARGE_VPRIME))

                    Tval = {}
                    for i in range(0, ITERATIONS):
                        Tval[str(i)] = (x.Z**proofComponent.u[i]) * (
                            x.S**proofComponent.r[str(i)]) % x.N
                        proofComponent.utilde[str(i)] = cmod.integer(
                            cmod.randomBits(LARGE_UTILDE))
                        proofComponent.rtilde[str(i)] = cmod.integer(
                            cmod.randomBits(LARGE_RTILDE))
                    Tval[DELTA] = (x.Z**delta) * (
                        x.S**proofComponent.r[DELTA]) % x.N
                    proofComponent.rtilde[DELTA] = cmod.integer(
                        cmod.randomBits(LARGE_RTILDE))

                    proofComponent.CList.extend(get_values_of_dicts(Tval))
                    updateDict(proofComponent.C, key, TVAL, Tval)

                    for i in range(0, ITERATIONS):
                        proofComponent.TauList.append(
                            (x.Z**proofComponent.utilde[str(i)]) *
                            (x.S**proofComponent.rtilde[str(i)]) % x.N)
                    proofComponent.TauList.append(
                        (x.Z**proofComponent.tildeValues.mtilde[k]) *
                        (x.S**proofComponent.rtilde[DELTA]) % x.N)

                    proofComponent.alphatilde = cmod.integer(
                        cmod.randomBits(LARGE_ALPHATILDE))

                    Q = 1 % x.N
                    for i in range(0, ITERATIONS):
                        Q *= Tval[str(i)]**proofComponent.utilde[str(i)]
                    Q *= x.S**proofComponent.alphatilde % x.N
                    proofComponent.TauList.append(Q)

            proofComponent.c = cmod.integer(
                get_hash(
                    nonce,
                    *reduce(lambda x, y: x + y,
                            [proofComponent.TauList, proofComponent.CList])))
Ejemplo n.º 5
0
        def initProofComponent(issuerPks, creds, encodedAttrs, revealedAttrs,
                               nonce):
            proofComponent = ProofComponent()
            proofComponent.flatAttrs, proofComponent.unrevealedAttrs = \
                getUnrevealedAttrs(
                    encodedAttrs, revealedAttrs)
            proofComponent.tildeValues, proofComponent.primeValues, \
            proofComponent.T = findSecretValues(
                encodedAttrs,
                proofComponent.unrevealedAttrs, creds,
                issuerPks)

            # Calculate the `c` value as the hash result of Aprime, T and nonce.
            # This value will be used to verify the proof against the credential

            proofComponent.c = cmod.integer(get_hash(
                *get_values_of_dicts(proofComponent.primeValues.Aprime,
                                     proofComponent.T, {NONCE: nonce})))
            return proofComponent