public void PedCommitmentIndexTest() { int[] commited = new int[3] { 1, 3, 7 }; int commitmentIndex = ClosedPedersenCommitment.GetCommitmentIndex(commited, 1); int expectedCommitmentIndex = 0; Assert.AreEqual(expectedCommitmentIndex, commitmentIndex, "wrong attribute index."); commitmentIndex = ClosedPedersenCommitment.GetCommitmentIndex(commited, 3); expectedCommitmentIndex = 1; Assert.AreEqual(expectedCommitmentIndex, commitmentIndex, "wrong attribute index."); commitmentIndex = ClosedPedersenCommitment.GetCommitmentIndex(commited, 7); expectedCommitmentIndex = 2; Assert.AreEqual(expectedCommitmentIndex, commitmentIndex, "wrong attribute index."); bool threwException = false; try { commitmentIndex = ClosedPedersenCommitment.GetCommitmentIndex(commited, 2); } catch (Exception) { threwException = true; } Assert.IsTrue(threwException, "ClosedPedersenCommitment.GetCommitmentIndex should have thrown exception on input 1"); }
public void GetAttributeIndexTest() { int[] commited = new int[5] { 4, 5, 5, 3, 12 }; for (int commitmentIndex = 0; commitmentIndex < commited.Length; ++commitmentIndex) { Assert.AreEqual(commited[commitmentIndex] - 1, ClosedPedersenCommitment.GetAttributeIndex(commited, commitmentIndex), "Could not get correct attribute index."); } }
public void Get_G_H_Tests() { for (int i = 0; i < _parameters.Length; ++i) { GroupElement[] bases = StaticHelperClass.GenerateRandomBases(2, i); GroupElement value = _parameters[i].Generators[0]; ClosedPedersenCommitment ped = new ClosedPedersenCommitment(bases, value, _parameters[i].Group); Assert.AreEqual(bases[0], ped.G, "Failed to get G."); Assert.AreEqual(bases[1], ped.H, "Failed to get H."); Assert.IsTrue(ped.Validate()); } }
public void ClosedDLRepToClosedPedTest() { GroupElement[] bases = StaticHelperClass.GenerateRandomBases(2, 3); GroupElement value = StaticHelperClass.GenerateRandomValue(3); ClosedDLRepOfGroupElement udl = new ClosedDLRepOfGroupElement(bases, value, _parameters[3].Group); ClosedPedersenCommitment closedPed = new ClosedPedersenCommitment(udl); Assert.AreEqual(2, closedPed.RepresentationLength, "representation length should be 2"); Assert.AreEqual(bases[0], closedPed.G, "G value should be bases[0]"); Assert.AreEqual(bases[1], closedPed.H, "H value incorrect."); Assert.AreEqual(value, closedPed.Value, "value incorrect."); Assert.IsTrue(closedPed.Validate(), "should be valid closed pederson commitment."); }
public void ClosedPedConstructorTests() { GroupElement[] badbases = StaticHelperClass.GenerateRandomBases(3, 0); GroupElement value = badbases[2]; ClosedDLRepOfGroupElement baddl = new ClosedDLRepOfGroupElement(badbases, value, _parameters[0].Group); bool threwException = false; try { ClosedPedersenCommitment ped = new ClosedPedersenCommitment(badbases, value, _parameters[0].Group); } catch (Exception) { threwException = true; } Assert.IsTrue(threwException, "ClosedPedersenCommitment constructor should throw Exception when length of bases is not 2"); threwException = false; try { ClosedPedersenCommitment ped = new ClosedPedersenCommitment(baddl); } catch (Exception) { threwException = true; } badbases = StaticHelperClass.GenerateRandomBases(1, 0); baddl = new ClosedDLRepOfGroupElement(badbases, value, _parameters[0].Group); threwException = false; try { ClosedPedersenCommitment ped = new ClosedPedersenCommitment(badbases, value, _parameters[0].Group); } catch (Exception) { threwException = true; } Assert.IsTrue(threwException, "ClosedPedersenCommitment constructor should throw Exception when length of bases is 1."); threwException = false; try { ClosedPedersenCommitment ped = new ClosedPedersenCommitment(baddl); } catch (Exception) { threwException = true; } Assert.IsTrue(threwException, "ClosedPedersenCommitment constructor should throw Exception when length of bases is 1."); }
public void PresentationProofConstructorTest() { // generate array of commitments using PresentationProof CommitmentPrivateValues cpv; Assert.IsNotNull(_proverParams, "prover params null"); PresentationProof proof = PresentationProof.Generate(_proverParams, out cpv); Assert.IsNotNull(proof.Commitments, "proof failed to generate commitments"); Assert.IsNotNull(cpv, "failed to output cpv"); Assert.IsNotNull(cpv.TildeO, "cpv.TildeO is null"); CommitmentValues [] expectedCommitmentValues = proof.Commitments; // generate array of commitments using Pedersen Commitment constructor PedersenCommitment [] proverCommitments = PedersenCommitment.ArrayOfPedersenCommitments(_proverParams, proof, cpv); // compare values GroupElement expectedG = _proverParams.IP.Gq.G; GroupElement expectedH = _proverParams.IP.G[1]; for (int commitIndex = 0; commitIndex < expectedCommitmentValues.Length; ++commitIndex) { int attributeIndex = _proverParams.Committed[commitIndex] - 1; FieldZqElement expectedCommittedValue = ProtocolHelper.ComputeXi(_proverParams.IP, attributeIndex, _proverParams.Attributes[attributeIndex]); Assert.AreEqual(expectedCommittedValue, proverCommitments[commitIndex].CommittedValue, "wrong committed value"); Assert.AreEqual(cpv.TildeO[commitIndex], proverCommitments[commitIndex].Opening, "opening does not match tildeO"); Assert.AreEqual(expectedG, proverCommitments[commitIndex].G, "base g wrong"); Assert.AreEqual(expectedH, proverCommitments[commitIndex].H, "base h wrong"); Assert.AreEqual(expectedCommitmentValues[commitIndex].TildeC, proverCommitments[commitIndex].Value, "wrong value"); } // generate array of closed pedersen commitments ClosedPedersenCommitment[] verifierCommitments = ClosedPedersenCommitment.ArrayOfClosedPedersenCommitments(_verifierParams.IP, proof); // compare bases and values to actualCommitments Assert.IsTrue(ClosedPedersenCommitment.AreBasesEqual(verifierCommitments), "all closed commitments should have same bases."); Assert.IsTrue(verifierCommitments[0].AreBasesEqual(proverCommitments[0]), "all closed commitments should have same bases as open commitments"); Assert.AreEqual(proverCommitments.Length, verifierCommitments.Length, "should be as many open and closed commitments"); for (int i = 0; i < verifierCommitments.Length; ++i) { Assert.AreEqual(verifierCommitments[i].Value, proverCommitments[i].Value, "open and closed commitments should be equal."); } }
public void InequalityTokenIntegration2Test() { // 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); CommitmentPrivateValues cpv; PresentationProof proof = PresentationProof.Generate(prover, out cpv); // computing target constant - "Student" byte[] targetAttribute = _encoding.GetBytes("Student"); int targetAttributeIndex = 3 - 1; // We will compare "Student" to the third token attribute. FieldZqElement targetValue = ProtocolHelper.ComputeXi(prover.IP, targetAttributeIndex, targetAttribute); // this is what "Student" would be encoded as if it was the third token attribute // Create PedersenCommitments // The prover and verifier have a map Committed that contains the relationship between // token attributes and CommitmentPrivateValues. int commitmentIndex = ClosedPedersenCommitment.GetCommitmentIndex(prover.Committed, 3); // attribute 3 from prover1 PedersenCommitment ped = new PedersenCommitment(prover, proof, cpv, commitmentIndex); Assert.AreNotEqual(targetValue, ped.CommittedValue, "Committed value is not Student."); // Check that "Teaching Assistant" is the commited value of the pedesen commitment. FieldZqElement expectedCommittedValue = ProtocolHelper.ComputeXi(prover.IP, targetAttributeIndex, _encoding.GetBytes("Teaching Assistant")); Assert.AreEqual(expectedCommittedValue, ped.CommittedValue, "Committed value is Teaching Assistant."); // Create InequalityProof CryptoParameters crypto = new CryptoParameters(prover.IP); // Can use prover2.IP ProverInequalityProofParameters inequalityProver = new ProverInequalityProofParameters(ped, targetValue, crypto); // compares committed values in ped1 and ped2 InequalityProof ineQproof = new InequalityProof(inequalityProver); // Verify InequalityProof commitmentIndex = ClosedPedersenCommitment.GetCommitmentIndex(verifier.Committed, 3); // attribute 3 from prover ClosedPedersenCommitment closedPed = new ClosedPedersenCommitment(verifier.IP, proof, commitmentIndex); VerifierInequalityProofParameters inequalityVerifier = new VerifierInequalityProofParameters(closedPed.Value, targetValue, crypto); Assert.IsTrue(ineQproof.Verify(inequalityVerifier)); // test U-Prove wrapper InequalityProof ineQProof2 = InequalityProof.GenerateUProveInequalityProof( new EQProofUProveProverData(prover, cpv, proof, 3), targetAttribute); InequalityProof.VerifyUProveEqualityProof( new EQProofUProveVerifierData(verifier, proof, 3), targetAttribute, ineQProof2); }
public void InequalityTokenIntegrationTest() { // Both tokens will hash attributes // but example also works if hashAttributes=false bool hashAttributes = true; // Setting up IssuerParameters for token1 byte[] uidP1 = new byte[] { 1, 1, 2, 3, 5, 8 }; byte[] tokenInformation1 = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; byte[][] attributes1 = 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") }; // Setting up IssuerParameters for token2 byte[] tokenInformation2 = new byte[] { 12, 13, 14, 15, 0, 10 }; byte[] uidP2 = new byte[] { 3, 1, 4, 1, 5 }; byte[][] attributes2 = new byte[][] { _encoding.GetBytes("Student"), // this is the attribute we'll compare _encoding.GetBytes("Attribute 2"), _encoding.GetBytes("Attribute 3"), _encoding.GetBytes("Attribute 4") }; // generate tokens ProverPresentationProtocolParameters prover1, prover2; VerifierPresentationProtocolParameters verifier1, verifier2; StaticHelperClass.GetUProveParameters(hashAttributes, out prover1, out verifier1, tokenInformation1, attributes1, null, uidP1); StaticHelperClass.GetUProveParameters(hashAttributes, out prover2, out verifier2, tokenInformation2, attributes2, null, uidP2); CommitmentPrivateValues cpv1, cpv2; PresentationProof proof1 = PresentationProof.Generate(prover1, out cpv1); PresentationProof proof2 = PresentationProof.Generate(prover2, out cpv2); // Create PedersenCommitments // The prover and verifier have a map Committed that contains the relationship between // token attributes and CommitmentPrivateValues. int commitmentIndex1 = ClosedPedersenCommitment.GetCommitmentIndex(prover1.Committed, 3); // attribute 3 from prover1 PedersenCommitment ped1 = new PedersenCommitment(prover1, proof1, cpv1, commitmentIndex1); int commitmentIndex2 = ClosedPedersenCommitment.GetCommitmentIndex(prover2.Committed, 1); // attribute 1 from prover2 PedersenCommitment ped2 = new PedersenCommitment(prover2, proof2, cpv2, commitmentIndex2); // Create InequalityProof CryptoParameters crypto = new CryptoParameters(prover1.IP); // Can use prover2.IP ProverInequalityProofParameters inequalityProver = new ProverInequalityProofParameters(ped1, ped2, crypto); // compares committed values in ped1 and ped2 InequalityProof ineQProof = new InequalityProof(inequalityProver); // Verify InequalityProof commitmentIndex1 = ClosedPedersenCommitment.GetCommitmentIndex(verifier1.Committed, 3); // attribute 3 from prover1 commitmentIndex2 = ClosedPedersenCommitment.GetCommitmentIndex(verifier2.Committed, 1); // attribute 1 from prover2 ClosedPedersenCommitment closedPed1 = new ClosedPedersenCommitment(verifier1.IP, proof1, commitmentIndex1); ClosedPedersenCommitment closedPed2 = new ClosedPedersenCommitment(verifier2.IP, proof2, commitmentIndex2); VerifierInequalityProofParameters inequalityVerifier = new VerifierInequalityProofParameters(closedPed1.Value, closedPed2.Value, crypto); Assert.IsTrue(ineQProof.Verify(inequalityVerifier)); // test U-Prove wrapper InequalityProof ineQProof2 = InequalityProof.GenerateUProveInequalityProof( new EQProofUProveProverData(prover1, cpv1, proof1, 3), new EQProofUProveProverData(prover2, cpv2, proof2, 1)); InequalityProof.VerifyUProveEqualityProof( new EQProofUProveVerifierData(verifier1, proof1, 3), new EQProofUProveVerifierData(verifier2, proof2, 1), ineQProof2); }