Exemplo n.º 1
0
        public void EQTokenAndDLTest()
        {
            // In this example, the token hashes the attribute
            // but example also works if hashAttributes=false
            bool hashAttributes = true;

            // Setting up attributes for token
            byte[][] attributes = new byte[][]
            {
                _encoding.GetBytes("Attribute 1"),
                _encoding.GetBytes("Attribute 2"),
                _encoding.GetBytes("Teaching Assistant"), // this is the attribute we'll compare
                _encoding.GetBytes("Attribute 4")
            };

            // generate token
            ProverPresentationProtocolParameters   prover;
            VerifierPresentationProtocolParameters verifier;

            StaticHelperClass.GetUProveParameters(hashAttributes, out prover, out verifier, null, attributes);
            OpenUProveToken token = new OpenUProveToken(prover);

            Assert.IsTrue(token.Validate(null), "validate token.");


            // generate pedersen commitment to Teaching Assistant
            PedersenCommitment ped = new PedersenCommitment(prover.IP, 3, _encoding.GetBytes("Teaching Assistant"));

            // Verify they are equal
            Assert.AreEqual(token.AttributeXI(3), ped.CommittedValue, "Token and PedersenCommitment different.");

            // Create a proof that the 3rd attribute in token is equal to the committed value in ped.
            ProverEqualityParameters eqProver = new ProverEqualityParameters(
                token, // token
                3,     // 3rd attribute is the 3rd exponent
                ped,   // pedersen commitment
                0,     // committed value is the 0th exponent
                new CryptoParameters(prover.IP));
            EqualityProof proof = new EqualityProof(eqProver);

            // Verify proof
            ClosedUProveToken closedToken = new ClosedUProveToken(verifier);

            Assert.IsTrue(closedToken.AreBasesEqual(token), "token bases.");
            IStatement closedPed = ped.GetStatement();

            Assert.IsTrue(closedPed.AreBasesEqual(ped), "token bases.");
            VerifierEqualityParameters eqVerifier = new VerifierEqualityParameters(
                closedToken, // verifier token information
                3,           // 3rd attribute is the 3nd exponent
                closedPed,   // verifier information about ped
                0,           // committed value is the 0th exponent
                new CryptoParameters(prover.IP));

            Assert.IsTrue(proof.Verify(eqVerifier));
        }
        public void TokenConstructorTest()
        {
            // generate prover parameters using recommended parameters.
            ProverPresentationProtocolParameters   proverParams;
            VerifierPresentationProtocolParameters verifierParams;

            StaticHelperClass.GetUProveParameters(false, out proverParams, out verifierParams);

            // create token
            OpenUProveToken token = new OpenUProveToken(proverParams);

            // get expected public key
            Assert.AreEqual(proverParams.KeyAndToken.Token.H, token.PublicKey, "check public key");
            Assert.IsTrue(token.Validate(null), "validate token.");
        }
        public void TokenSerializationTest()
        {
            // generate prover parameters using recommended parameters.
            ProverPresentationProtocolParameters   proverParams;
            VerifierPresentationProtocolParameters verifierParams;

            StaticHelperClass.GetUProveParameters(false, out proverParams, out verifierParams);

            // create token
            OpenUProveToken token = new OpenUProveToken(proverParams);

            // Serialize token
            string          serialized = CryptoSerializer.Serialize <OpenUProveToken>(token);
            OpenUProveToken newToken   = CryptoSerializer.Deserialize <OpenUProveToken>(serialized, null, token.G);

            Assert.AreEqual(token, newToken, "token");
        }