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."); }
public void SMVerifierParamSerializationTest() { // prover test VerifierSetMembershipParameters verifier = new VerifierSetMembershipParameters(_cryptoParameters.G, ValidDaysOfTheWeek, _cryptoParameters); string jsonString = CryptoSerializer.Serialize <VerifierSetMembershipParameters>(verifier); VerifierSetMembershipParameters deserializedVerifier = CryptoSerializer.Deserialize <ProverSetMembershipParameters>(jsonString); Assert.AreEqual(verifier.Group.GroupName, deserializedVerifier.Group.GroupName); StaticHelperClass.AssertArraysAreEqual(verifier.MemberSet, deserializedVerifier.MemberSet, "MemberSet"); StaticHelperClass.AssertArraysAreEqual(verifier.PublicValues, deserializedVerifier.PublicValues, "PublicValues"); StaticHelperClass.AssertArraysAreEqual <DLRepOfGroupElement>(verifier.Witnesses, deserializedVerifier.Witnesses, "Witnesses"); }
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."); }
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)); }
public static void AssertCorrectVerifierParameters( VerifierSetMembershipParameters verifier, CryptoParameters expectedCryptoParameters, GroupElement expectedClosedCommitment, FieldZqElement[] expectedMemberSet) { StaticHelperClass.AssertCorrectCryptoParameters(expectedCryptoParameters, verifier); Assert.AreEqual(expectedClosedCommitment, verifier.ClosedCommitment, "wrong closed commitment"); if (expectedMemberSet == null) { Assert.IsNull(verifier.MemberSet, "Memberset should be null."); } else { Assert.AreEqual(expectedMemberSet.Length, verifier.MemberSet.Length, "wrong memberset length."); for (int i = 0; i < expectedMemberSet.Length; ++i) { Assert.AreEqual(expectedMemberSet[i], verifier.MemberSet[i], "wrong element in memberset."); } } }