예제 #1
0
        public void SMProverParametersConstructorTest()
        {
            // Test1: compute commitment automatically
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            prover.setProverParameters(ValidDaysOfTheWeek[1], ValidDaysOfTheWeek);
            AssertCorrectProverParameters(prover,
                                          _cryptoParameters,
                                          prover.OpenCommitment, // computed open commitment automatically, so check committed value later
                                          ValidDaysOfTheWeek);
            Assert.AreEqual(ValidDaysOfTheWeek[1], prover.OpenCommitment.CommittedValue, "wrong committed value.");

            // Test 2: use explicit commitment
            prover = new ProverSetMembershipParameters(_cryptoParameters);
            PedersenCommitment ped = new PedersenCommitment(ValidDaysOfTheWeek[4], _cryptoParameters);

            prover.setProverParameters(ped, ValidDaysOfTheWeek);
            AssertCorrectProverParameters(
                prover,
                _cryptoParameters,
                ped,
                ValidDaysOfTheWeek);

            // Test 3: use constructor to set explicit commitment
            prover = new ProverSetMembershipParameters(ped, ValidDaysOfTheWeek, _cryptoParameters);
            prover.setProverParameters(ped, ValidDaysOfTheWeek);
            AssertCorrectProverParameters(
                prover,
                _cryptoParameters,
                ped,
                ValidDaysOfTheWeek);
        }
        public void CSChangeGroupTest()
        {
            CryptoParameters crypto1 = StaticHelperClass.ParameterArray[4];
            ProverSetMembershipParameters prover1 = new ProverSetMembershipParameters(crypto1);

            FieldZqElement[] memberSet1 = crypto1.FieldZq.GetRandomElements(10, true);
            prover1.setProverParameters(memberSet1[0], memberSet1);
            SetMembershipProof proof1 = new SetMembershipProof(prover1);

            string             serialized1 = CryptoSerializer.Serialize <SetMembershipProof>(proof1);
            SetMembershipProof output1     = CryptoSerializer.Deserialize <SetMembershipProof>(serialized1);

            Assert.IsTrue(output1.Verify(prover1), "output1");

            CryptoParameters crypto2 = StaticHelperClass.ParameterArray[3];
            ProverSetMembershipParameters prover2 = new ProverSetMembershipParameters(crypto2);

            FieldZqElement[] memberSet2 = crypto2.FieldZq.GetRandomElements(10, true);
            prover2.setProverParameters(memberSet2[0], memberSet2);
            SetMembershipProof proof2 = new SetMembershipProof(prover2);

            string             serialized2 = CryptoSerializer.Serialize <SetMembershipProof>(proof2);
            SetMembershipProof output2     = CryptoSerializer.Deserialize <SetMembershipProof>(serialized2);

            Assert.IsTrue(output2.Verify(prover2), "output2");
        }
예제 #3
0
        public void SMSerializationTest()
        {
            for (int paramIndex = 0; paramIndex < StaticHelperClass.ParameterArray.Length; ++paramIndex)
            {
                // choose parameters
                CryptoParameters crypto    = StaticHelperClass.ParameterArray[paramIndex];
                FieldZqElement[] memberSet = crypto.FieldZq.GetRandomElements(10, true);

                // create a set membership proof
                ProverSetMembershipParameters prover = new ProverSetMembershipParameters(crypto);
                prover.setProverParameters(memberSet[3], memberSet);
                SetMembershipProof originalProof = new SetMembershipProof(prover);

                // serialize the proof
                IssuerParameters ip = new IssuerParameters();
                string           serializedProof = ip.Serialize <SetMembershipProof>(originalProof);

                // deserialize the proof
                SetMembershipProof deserializedProof = ip.Deserialize <SetMembershipProof>(serializedProof);

                // make sure it verifies
                Assert.IsTrue(deserializedProof.Verify(prover), "deserialized proof does not verify.");

                // serialize the proof again
                string serializedProof2 = ip.Serialize <SetMembershipProof>(deserializedProof);

                // make sure the two serialized proofs are equal
                Assert.AreEqual(serializedProof, serializedProof2, "inconsistent proof serialization.");
            }
        }
예제 #4
0
        public void SMBadConstructorTest()
        {
            ProverSetMembershipParameters badProver = new ProverSetMembershipParameters(_cryptoParameters);

            StaticHelperClass.AssertThrowsException(
                new StaticHelperClass.TryBodyDelegate(() => { SetMembershipProof proof = new SetMembershipProof(badProver); }),
                typeof(Exception),
                "Constructor SetMembershipProof called with bad prover parameters.");
        }
예제 #5
0
        public void SMGetOpenCommitmentTest()
        {
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            Assert.IsNull(prover.OpenCommitment);

            prover.setProverParameters(ValidDaysOfTheWeek[2], ValidDaysOfTheWeek);
            Assert.IsNotNull(prover.OpenCommitment);
            Assert.AreEqual(ValidDaysOfTheWeek[2], prover.OpenCommitment.CommittedValue);
        }
예제 #6
0
        public void SMIndexOfMemberSetE2ETest()
        {
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            for (int day = 0; day < ValidDaysOfTheWeek.Length; ++day)
            {
                prover.setProverParameters(ValidDaysOfTheWeek[day], ValidDaysOfTheWeek);
                SetMembershipProof proof = new SetMembershipProof(prover);
                Assert.IsTrue(proof.Verify(prover), "proof should verify.");
            }
        }
예제 #7
0
        public void SMIsCommittedValueInSetTest()
        {
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            Assert.IsFalse(prover.IsCommittedValueInSet, "witness set to null so should return false.");

            prover.setProverParameters(prover.FieldZq.One, ValidDaysOfTheWeek);
            Assert.IsFalse(prover.IsCommittedValueInSet, "FieldZq.One is not in MemberSet.");

            prover.setProverParameters(ValidDaysOfTheWeek[4], ValidDaysOfTheWeek);
            Assert.IsTrue(prover.IsCommittedValueInSet, "Committed value is in the set.");
        }
예제 #8
0
        public void SMGetVerifierParametersTest()
        {
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            prover.setProverParameters(ValidDaysOfTheWeek[1], ValidDaysOfTheWeek);
            Assert.IsTrue(prover.Verify(), "prover parameters should be valid.");

            VerifierSetMembershipParameters verifier = prover.GetVerifierParameters();

            AssertCorrectVerifierParameters(verifier, _cryptoParameters, prover.ClosedCommitment, ValidDaysOfTheWeek);
            Assert.IsNull(verifier.Witnesses, "witnesses should be null.");
        }
예제 #9
0
        public void SMBadSetMembershipProofTest()
        {
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            prover.setProverParameters(ValidDaysOfTheWeek[3], ValidDaysOfTheWeek);
            SetMembershipProof proof = new SetMembershipProof(prover);

            // verification fail because verifier parameters don't verify
            VerifierSetMembershipParameters verifier = new VerifierSetMembershipParameters(_cryptoParameters);

            Assert.IsFalse(proof.Verify(verifier), "proof should fail since verifier parameters fail.");

            // verification fail because verifier uses wrong length memberset
            FieldZqElement[] badMemberSet = new FieldZqElement[ValidDaysOfTheWeek.Length + 1];
            for (int i = 0; i < ValidDaysOfTheWeek.Length; ++i)
            {
                badMemberSet[i] = ValidDaysOfTheWeek[i];
            }
            badMemberSet[badMemberSet.Length - 1] = _cryptoParameters.FieldZq.One;
            verifier.setVerifierParameters(prover.ClosedCommitment, badMemberSet);
            Assert.IsFalse(proof.Verify(verifier), "should fail because memberset too long.");

            // verification should fail because memberset too short
            badMemberSet = new FieldZqElement[ValidDaysOfTheWeek.Length - 1];
            for (int i = 0; i < badMemberSet.Length; ++i)
            {
                badMemberSet[i] = ValidDaysOfTheWeek[i];
            }
            verifier.setVerifierParameters(prover.ClosedCommitment, badMemberSet);
            Assert.IsFalse(proof.Verify(verifier), "should fail because memberset too long.");

            // verification should fail because closed commitment is wrong
            verifier.setVerifierParameters(prover.G, prover.MemberSet);
            Assert.IsFalse(proof.Verify(verifier), "should fail because closed commitment is wrong.");

            // verification fail because generators are wrong
            GroupElement [] badGenerators = new GroupElement[2] {
                _cryptoParameters.H, _cryptoParameters.G
            };
            CryptoParameters badcrypto = new CryptoParameters(_cryptoParameters.Group, badGenerators, _cryptoParameters.HashFunctionName);

            verifier = new VerifierSetMembershipParameters(badcrypto);
            verifier.setVerifierParameters(prover.ClosedCommitment, prover.MemberSet);
            Assert.IsFalse(proof.Verify(verifier), "should fail because crypto parameters use wrong generators.");

            // verification fail because hash function is wrong
            badcrypto = new CryptoParameters(_cryptoParameters.Group, _cryptoParameters.Generators, "SHA-512");
            verifier  = new VerifierSetMembershipParameters(badcrypto);
            verifier.setVerifierParameters(prover.ClosedCommitment, prover.MemberSet);
            Assert.IsFalse(proof.Verify(verifier), "should fail because hash function is wrong.");
        }
예제 #10
0
        public void SMProverParamSerializationTest()
        {
            // prover test
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            prover.setProverParameters(ValidDaysOfTheWeek[3], ValidDaysOfTheWeek);

            string jsonString = CryptoSerializer.Serialize <ProverSetMembershipParameters>(prover);
            ProverSetMembershipParameters deserializedProver = CryptoSerializer.Deserialize <ProverSetMembershipParameters>(jsonString);

            Assert.AreEqual(prover.Group.GroupName, deserializedProver.Group.GroupName);
            StaticHelperClass.AssertArraysAreEqual(prover.MemberSet, deserializedProver.MemberSet, "MemberSet");
            StaticHelperClass.AssertArraysAreEqual(prover.PublicValues, deserializedProver.PublicValues, "PublicValues");
            StaticHelperClass.AssertArraysAreEqual <DLRepOfGroupElement>(prover.Witnesses, deserializedProver.Witnesses, "Witnesses");
        }
예제 #11
0
        public void SMEndToEndTest()
        {
            // generate prover and verifier parameters
            ProverSetMembershipParameters proverParams = GeneratePSMParameters(0, 10);

            Assert.IsTrue(proverParams.Verify());
            VerifierSetMembershipParameters verifierParams = new VerifierSetMembershipParameters(proverParams.ClosedCommitment, proverParams.MemberSet, proverParams);

            Assert.IsTrue(verifierParams.Verify());

            //  create the proof and verify it.
            SetMembershipProof proof = new SetMembershipProof(proverParams);

            Assert.IsTrue(proof.Verify(verifierParams));
            Assert.IsTrue(proof.Verify(proverParams));
        }
예제 #12
0
        public static void AssertCorrectProverParameters(
            ProverSetMembershipParameters prover,
            CryptoParameters expectedCryptoParameters,
            PedersenCommitment expectedOpenCommitment,
            FieldZqElement [] expectedMemberSet
            )
        {
            // check crypto parameters and everything associated with verifer
            AssertCorrectVerifierParameters(prover, expectedCryptoParameters, expectedOpenCommitment.Value, expectedMemberSet);

            // now check witness
            Assert.AreEqual(expectedOpenCommitment, prover.OpenCommitment, "wrong open commitment.");
            Assert.AreEqual(expectedCryptoParameters.G, prover.OpenCommitment.G, "G value does not match expected crypto parameters.");
            Assert.AreEqual(expectedOpenCommitment.G, prover.OpenCommitment.G, "G value does not match expected Open commitment.");
            Assert.AreEqual(expectedCryptoParameters.H, prover.OpenCommitment.H, "H value does not match expected crypto parameters.");
            Assert.AreEqual(expectedOpenCommitment.H, prover.OpenCommitment.H, "H value does not match expected Open commitment.");
        }
예제 #13
0
        public void SMBadParametersTest()
        {
            // committed value not in memberset
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            prover.setProverParameters(_cryptoParameters.FieldZq.One, ValidDaysOfTheWeek);
            Assert.IsFalse(prover.Verify(), "Verify should fail since committed value not in memberset.");

            // open commitment uses wrong base
            PedersenCommitment ped = new PedersenCommitment(_cryptoParameters.H, _cryptoParameters.G, ValidDaysOfTheWeek[0], ValidDaysOfTheWeek[2], _cryptoParameters.Group);

            prover.setProverParameters(ped, ValidDaysOfTheWeek);
            Assert.IsFalse(prover.Verify(), "Verify should fail since commitment uses wrong bases.");

            // null memberset
            prover.setProverParameters(ValidDaysOfTheWeek[0], null);
            Assert.IsFalse(prover.Verify(), "Verify should fail since memberset is null.");
        }
        public void CSGenericBadSerializationTest()
        {
            StaticHelperClass.AssertThrowsException(
                () => { CryptoSerializer.Deserialize <SetMembershipProof>("bad jsonString"); },
                typeof(SerializationException),
                "deserialization");

            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(crypto);

            FieldZqElement [] memberSet = crypto.FieldZq.GetRandomElements(10, true);
            prover.setProverParameters(memberSet[0], memberSet);
            SetMembershipProof proof         = new SetMembershipProof(prover);
            PrivateObject      proofAccessor = new PrivateObject(proof);

            proofAccessor.SetProperty("c", null);

            StaticHelperClass.AssertThrowsException(
                () => { CryptoSerializer.Serialize <SetMembershipProof>(proof); },
                typeof(SerializationException),
                "serialization");
        }
예제 #15
0
        public void SMIndexOfCommittedValueTest()
        {
            // place index in set
            ProverSetMembershipParameters prover = new ProverSetMembershipParameters(_cryptoParameters);

            prover.setProverParameters(ValidDaysOfTheWeek[4], ValidDaysOfTheWeek);
            Assert.AreEqual(4, prover.IndexOfCommittedValueInSet, "computed wrong index of committed value.");

            // now index is not in set
            FieldZqElement badday = _cryptoParameters.FieldZq.One;

            prover.setProverParameters(badday, ValidDaysOfTheWeek);
            StaticHelperClass.AssertThrowsException(
                new StaticHelperClass.TryBodyDelegate(() => { int index = prover.IndexOfCommittedValueInSet; }),
                typeof(Exception),
                "Witness not in memberset.");

            // prover parameters not set yet
            prover = new ProverSetMembershipParameters(_cryptoParameters);
            StaticHelperClass.AssertThrowsException(
                new StaticHelperClass.TryBodyDelegate(() => { int index = prover.IndexOfCommittedValueInSet; }),
                typeof(Exception),
                "witness set to null.");
        }