Ejemplo n.º 1
0
        public void EQEndToEndTest1()
        {
            // create two pedersen commitments to 1
            DLRepOfGroupElement[] dlarray = new DLRepOfGroupElement[2]
            {
                new PedersenCommitment(_parameters.FieldZq.One, _parameters),
                new PedersenCommitment(_parameters.FieldZq.One, _parameters)
            };
            PrettyName  alpha = new PrettyName("alpha", 0);
            DoubleIndex d1    = new DoubleIndex(0, 0); // dlarray[0].BaseAtIndex(0)
            DoubleIndex d2    = new DoubleIndex(1, 0); // dlarray[1].BaseAtIndex(0)
            EqualityMap map   = new EqualityMap();

            map.Add(alpha, d1);
            map.Add(alpha, d2);

            int index;

            Assert.IsTrue(map.TryRetrieveIntIndex(d1, out index));
            Assert.AreEqual(0, index);
            Assert.IsTrue(map.TryRetrieveIntIndex(d2, out index));
            Assert.AreEqual(0, index);


            ProverEqualityParameters peParameters = new ProverEqualityParameters(
                dlarray,
                map,
                _parameters);
            EqualityProof proof = new EqualityProof(peParameters);

            Assert.IsTrue(proof.Verify(peParameters));
        }
        public void EqualsTest()
        {
            int replen1 = 12;
            int replen2 = 11;

            for (int paramIndex = 0; paramIndex < _parameters.Length; ++paramIndex)
            {
                FieldZqElement[]    exponents1 = _parameters[paramIndex].FieldZq.GetRandomElements(replen1, true);
                FieldZqElement[]    exponents2 = _parameters[paramIndex].FieldZq.GetRandomElements(replen2, true);
                DLRepOfGroupElement dl1        = new DLRepOfGroupElement(exponents1, _parameters[paramIndex]);
                DLRepOfGroupElement dl2        = new DLRepOfGroupElement(exponents1, _parameters[paramIndex]);
                DLRepOfGroupElement dl3        = new DLRepOfGroupElement(exponents2, _parameters[paramIndex]);

                Assert.IsTrue(dl1.Equals(dl1), "dl1 should equal itself");
                Assert.IsTrue(dl1.Equals(dl2), "dl1 should equal dl2");
                Assert.IsTrue(dl2.Equals(dl1), "dl2 should equal dl1");
                Assert.IsFalse(dl2.Equals(dl3), "dl2 should not equal dl3");
                Assert.IsFalse(dl3.Equals(dl2), "dl3 should not equal dl2");
                Assert.IsFalse(dl3.Equals(exponents1[0]), "wrong class input!");

                DLRepOfGroupElement nulldl = new DLRepOfGroupElement();
                Assert.IsFalse(dl1.Equals(nulldl), "not equal to nulldl");
                Assert.IsFalse(nulldl.Equals(dl1), "nulldl not equal to dl1");
                Assert.IsTrue(nulldl.Equals(nulldl), "nulldl equal to itself");

                GroupElement[] bases = new GroupElement[replen1];
                for (int i = 0; i < bases.Length; ++i)
                {
                    bases[i] = _parameters[paramIndex].Group.Identity;
                }
                DLRepOfGroupElement dl4 = new DLRepOfGroupElement(bases, exponents1, _parameters[paramIndex].Group);
                Assert.IsFalse(dl1.Equals(dl4), "dl1 and dl4 different due to bases");
                Assert.IsFalse(dl4.Equals(dl1), "dl4 and dl1 different due to bases");
            }
        }
Ejemplo n.º 3
0
        public void PPSerializationTest()
        {
            int             paramIndex = 4;
            ProofParameters original   = new ProofParameters(StaticHelperClass.ParameterArray[paramIndex]);

            DLRepOfGroupElement [] witnesses = new DLRepOfGroupElement[10];
            GroupElement[]         bases     = new GroupElement[5] {
                original.Generators[0],
                original.Generators[1],
                original.Generators[2],
                original.Generators[3],
                original.Generators[4]
            };
            for (int i = 0; i < 10; ++i)
            {
                FieldZqElement[] exponents = StaticHelperClass.GenerateRandomExponents(5, paramIndex);
                witnesses[i] = new DLRepOfGroupElement(bases, exponents, original.Group);
            }
            original.setProverParameters(witnesses);

            string          serializedParams = CryptoSerializer.Serialize <ProofParameters>(original);
            ProofParameters deserialized     = CryptoSerializer.Deserialize <ProofParameters>(serializedParams);

            Assert.AreEqual(original.ProverParameters, deserialized.ProverParameters, "ProverParameters field improperly deserialized");
            StaticHelperClass.AssertArraysAreEqual(original.Generators, deserialized.Generators, "Generators.");
            StaticHelperClass.AssertArraysAreEqual(original.PublicValues, deserialized.PublicValues, "Public Values.");
            StaticHelperClass.AssertArraysAreEqual(original.Witnesses, deserialized.Witnesses, "Witnesses");
            Assert.AreEqual(original.Group.G, deserialized.Group.G, "Group.group.g");
        }
        public void DLGetHashCodeTest()
        {
            FieldZqElement[]    exponents = StaticHelperClass.GenerateRandomExponents(8, 1);
            DLRepOfGroupElement dl        = new DLRepOfGroupElement(exponents, _parameters[1]);

            Assert.AreEqual(dl.BaseAtIndex(0).GetHashCode(), dl.GetHashCode());
        }
        public void NullConstructorTest()
        {
            DLRepOfGroupElement dl = new DLRepOfGroupElement();

            Assert.AreEqual(0, dl.RepresentationLength, "dl.representation length should be 0");
            Assert.IsNull(dl.Value, "Value is null");
        }
        public void CSDLRepArrayTestWithGroup()
        {
            DLRepOfGroupElement[] input          = StaticHelperClass.GenerateRandomDLRepOfGroupElementArray(10, 7, this.paramIndex);
            FieldZqElement[][]    inputExponents = new FieldZqElement[10][];
            for (int dlIndex = 0; dlIndex < 10; ++dlIndex)
            {
                inputExponents[dlIndex] = new FieldZqElement[7];
                for (int exponentIndex = 0; exponentIndex < 7; ++exponentIndex)
                {
                    inputExponents[dlIndex][exponentIndex] = input[dlIndex].ExponentAtIndex(exponentIndex);
                }
            }


            string[] serializedTT          = CryptoSerializer.Serialize(input, true, true);
            DLRepOfGroupElement[] outputTT = CryptoSerializer.Deserialize <DLRepOfGroupElement>(serializedTT, null, null);
            StaticHelperClass.AssertArraysAreEqual(input, outputTT, "outputTT");

            string[]              serializedNT = CryptoSerializer.Serialize(input, true, false);
            GroupElement[]        newBases     = StaticHelperClass.GenerateRandomBases(input[0].RepresentationLength, this.paramIndex);
            DLRepOfGroupElement[] outputNT     = CryptoSerializer.Deserialize <DLRepOfGroupElement>(serializedNT, null, newBases);
            Assert.AreEqual(input.Length, outputNT.Length, "outputNT.Length");
            for (int i = 0; i < outputNT.Length; ++i)
            {
                DLRepOfGroupElement expected = new DLRepOfGroupElement(newBases, inputExponents[i], this.crypto.Group);
                expected.Value = input[i].Value;
                Assert.AreEqual(expected, outputNT[i], "outputNT " + i);
            }

            FieldZqElement[] commitments = StaticHelperClass.GenerateRandomExponents(10, this.paramIndex);
            FieldZqElement[] openings    = StaticHelperClass.GenerateRandomExponents(10, this.paramIndex);
            input = PedersenCommitment.GetCommitments(this.crypto, commitments, openings);
        }
 public static DLRepOfGroupElement[] GenerateRandomDLRepOfGroupElementArray(int arrayLength, int representationLength, int paramIndex)
 {
     DLRepOfGroupElement[] output = new DLRepOfGroupElement[arrayLength];
     for (int i = 0; i < arrayLength; ++i)
     {
         output[i] = GenerateRandomDLRepOfGroupElement(representationLength, paramIndex);
     }
     return(output);
 }
        public void DLRepEqualsWrongExponentTest()
        {
            GroupElement[]   bases     = StaticHelperClass.GenerateRandomBases(8, 0);
            FieldZqElement[] exponents = StaticHelperClass.GenerateRandomExponents(8, 0);

            DLRepOfGroupElement dl = new DLRepOfGroupElement(bases, exponents, _parameters[0].Group);

            exponents[7] = exponents[2];
            DLRepOfGroupElement badDL = new DLRepOfGroupElement(bases, exponents, _parameters[0].Group);

            Assert.IsFalse(dl.Equals(badDL), "should fail due to bad exponent.");
            Assert.IsFalse(badDL.Equals(dl), "should fail due to bad exponent.");
        }
        public void TryStrictMultiplyWithExponentsTest()
        {
            bool success;

            DLRepOfGroupElement [] dlArray;
            FieldZqElement []      exponents;
            DLRepOfGroupElement    product;

            for (int paramIndex = 0; paramIndex < _parameters.Length; ++paramIndex)
            {
                dlArray = new DLRepOfGroupElement[128];
                GroupElement expectedProduct = _parameters[paramIndex].Group.Identity;
                for (int i = 0; i < dlArray.Length; ++i)
                {
                    exponents        = StaticHelperClass.GenerateRandomExponents(5, paramIndex);
                    dlArray[i]       = new DLRepOfGroupElement(exponents, _parameters[paramIndex]);
                    expectedProduct *= dlArray[i].Value;
                }

                DLRepOfGroupElement actualProduct;
                success = DLRepOfGroupElement.TryStrictMultiply(dlArray, out actualProduct);
                Assert.IsTrue(success, "TryStrictMultiply should have succeeded.");
                Assert.IsNotNull(actualProduct, "actualProduct should be set to a value.");
                Assert.IsTrue(actualProduct.AreBasesEqual(dlArray[0]), "Bases should be the same.");
                Assert.AreEqual(expectedProduct, actualProduct.Value, "Value computed incorrectly.");
            }

            // fail on null/ empty input
            DLRepOfGroupElement dl;

            success = DLRepOfGroupElement.TryStrictMultiply(null, out dl);
            Assert.IsFalse(success);

            DLRepOfGroupElement[] emptyArray = new DLRepOfGroupElement[0];
            success = DLRepOfGroupElement.TryStrictMultiply(emptyArray, out dl);
            Assert.IsFalse(success);

            // fail because bases are different
            dlArray = new DLRepOfGroupElement[5];
            GroupElement [] bases = StaticHelperClass.GenerateRandomBases(8, 5);
            for (int dlIndex = 0; dlIndex < dlArray.Length - 1; ++dlIndex)
            {
                exponents        = StaticHelperClass.GenerateRandomExponents(8, 5);
                dlArray[dlIndex] = new DLRepOfGroupElement(bases, exponents, _parameters[5].Group);
            }
            GroupElement [] badBases = StaticHelperClass.GenerateRandomBases(8, 5);
            exponents = StaticHelperClass.GenerateRandomExponents(8, 5);
            dlArray[dlArray.Length - 1] = new DLRepOfGroupElement(badBases, exponents, _parameters[5].Group);
            success = DLRepOfGroupElement.TryStrictMultiply(dlArray, out product);
            Assert.IsFalse(success, "should fail since one of the elements in dlArray has different bases.");
        }
Ejemplo n.º 10
0
        public void EQBadVerifierParametersTest()
        {
            int length     = 20;
            int fullLength = length * 2;

            DLRepOfGroupElement[] openEquations    = StaticHelperClass.GenerateRandomDLRepOfGroupElementArray(length, 5, _paramIndex);
            DLRepOfGroupElement[] allOpenEquations = new DLRepOfGroupElement[fullLength];
            for (int i = 0; i < openEquations.Length; ++i)
            {
                allOpenEquations[i]          = openEquations[i];
                allOpenEquations[i + length] = openEquations[i];
            }

            // create equality map
            EqualityMap map = new EqualityMap();

            for (int i = 0; i < length; ++i)
            {
                map.Add(
                    new PrettyName("chi", i),
                    new DoubleIndex(i, 0)
                    );

                map.Add(
                    new PrettyName("chi", i),
                    new DoubleIndex(length + i, 0)
                    );
                map.Add(
                    new PrettyName("delta", i),
                    new DoubleIndex(i, 19)
                    );
                map.Add(
                    new PrettyName("delta", i),
                    new DoubleIndex(length + i, 19)
                    );

                map.Add(
                    new PrettyName("beta", i),
                    new DoubleIndex(i, 5)
                    );
                map.Add(
                    new PrettyName("beta", i),
                    new DoubleIndex(length + i, 5)
                    );
            }
        }
        public void BaseAndExponentAtIndexTest()
        {
            int replen = 25;

            for (int paramIndex = 0; paramIndex < _parameters.Length; ++paramIndex)
            {
                GroupElement []     bases     = StaticHelperClass.GenerateRandomBases(replen, paramIndex);
                FieldZqElement []   exponents = StaticHelperClass.GenerateRandomExponents(replen, paramIndex);
                DLRepOfGroupElement dl        = new DLRepOfGroupElement(bases, exponents, _parameters[paramIndex].Group);

                Assert.AreEqual(replen, dl.RepresentationLength, "incorrect representation length");
                for (int i = 0; i < replen; ++i)
                {
                    Assert.AreEqual(bases[i], dl.BaseAtIndex(i), "wrong base");
                    Assert.AreEqual(exponents[i], dl.ExponentAtIndex(i), "wrong exponent");
                }
            }
        }
        public void OpenClosedPairTest()
        {
            GroupElement[]   bases     = StaticHelperClass.GenerateRandomBases(4, 0);
            GroupElement[]   goodBases = StaticHelperClass.GenerateRandomBases(4, 0);
            FieldZqElement[] exponents = StaticHelperClass.GenerateRandomExponents(4, 0);

            DLRepOfGroupElement       dl             = new DLRepOfGroupElement(goodBases, exponents, _parameters[0].Group);
            IStatement                expectedClosed = dl.GetStatement();
            ClosedDLRepOfGroupElement badClosed      = new ClosedDLRepOfGroupElement(bases, dl.Value, dl.Group);

            Assert.IsTrue(DLRepOfGroupElement.IsValidOpenClosedPair(dl, expectedClosed), "should be valid.");
            Assert.IsFalse(DLRepOfGroupElement.IsValidOpenClosedPair(dl, badClosed), "bad pair due to wrong bases.");

            badClosed = new ClosedDLRepOfGroupElement(goodBases, bases[0], _parameters[0].Group);
            Assert.IsFalse(DLRepOfGroupElement.IsValidOpenClosedPair(dl, badClosed), "bad pair due to wrong value.");


            Assert.IsFalse(DLRepOfGroupElement.IsValidOpenClosedPair(null, null), "should fail on null input.");
        }
        public void CSDLRepTest()
        {
            DLRepOfGroupElement[] input = StaticHelperClass.GenerateRandomDLRepOfGroupElementArray(10, 7, this.paramIndex);
            for (int i = 0; i < input.Length; ++i)
            {
                Group             group     = input[i].Group;
                GroupElement []   bases     = new GroupElement[input[i].RepresentationLength];
                FieldZqElement [] exponents = new FieldZqElement[input[i].RepresentationLength];
                for (int j = 0; j < input[i].RepresentationLength; ++j)
                {
                    bases[j]     = input[i].BaseAtIndex(j);
                    exponents[j] = input[i].ExponentAtIndex(j);
                }
                DLRepOfGroupElement expected = new DLRepOfGroupElement(bases, exponents, group);
                expected.Value = input[i].Value;

                input[i].IsGroupSerializable  = false;
                input[i].AreBasesSerializable = false;
                string serializedNN          = CryptoSerializer.Serialize <DLRepOfGroupElement>(input[i]);
                DLRepOfGroupElement outputNN = CryptoSerializer.Deserialize <DLRepOfGroupElement>(serializedNN, group, bases);
                Assert.AreEqual(input[i], outputNN, "outputNN");


                input[i].IsGroupSerializable  = false;
                input[i].AreBasesSerializable = true;
                string serializedNB          = CryptoSerializer.Serialize <DLRepOfGroupElement>(input[i]);
                DLRepOfGroupElement outputNB = CryptoSerializer.Deserialize <DLRepOfGroupElement>(serializedNB, group);
                Assert.AreEqual(input[i], outputNB, "outputNB");


                input[i].IsGroupSerializable  = true;
                input[i].AreBasesSerializable = false;
                string serializedAN          = CryptoSerializer.Serialize <DLRepOfGroupElement>(input[i]);
                DLRepOfGroupElement outputAN = CryptoSerializer.Deserialize <DLRepOfGroupElement>(serializedAN, null, bases);
                Assert.AreEqual(expected, outputAN, "outputAN");

                input[i].IsGroupSerializable  = true;
                input[i].AreBasesSerializable = true;
                string serializedAB          = CryptoSerializer.Serialize <DLRepOfGroupElement>(input[i]);
                DLRepOfGroupElement outputAB = CryptoSerializer.Deserialize <DLRepOfGroupElement>(serializedAB, null, null);
                Assert.AreEqual(input[i], outputAB, "outputAB");
            }
        }
        public void DLtoPedConstructorTest()
        {
            for (int paramIndex = 0; paramIndex < _parameters.Length; ++paramIndex)
            {
                GroupElement[]      bases     = StaticHelperClass.GenerateRandomBases(2, paramIndex);
                FieldZqElement[]    exponents = StaticHelperClass.GenerateRandomExponents(2, paramIndex);
                DLRepOfGroupElement dl        = new DLRepOfGroupElement(bases, exponents, _parameters[paramIndex].Group);
                PedersenCommitment  ped       = new PedersenCommitment(dl);

                Assert.IsTrue(ped.Validate(), "ped should be a valid pedersen commitment.");
                Assert.AreEqual(bases[0], ped.G, "Wrong G value.");
                Assert.AreEqual(bases[1], ped.H, "Wrong H value.");
                Assert.AreEqual(exponents[0], ped.CommittedValue, "wrong committed value.");
                Assert.AreEqual(exponents[1], ped.Opening, "wrong opening.");

                GroupElement expectedValue = _parameters[paramIndex].Group.MultiExponentiate(bases, exponents);
                Assert.AreEqual(expectedValue, ped.Value, "wrong value.");
            }
        }
        public void DLRepToPedBadConstructorTest()
        {
            int paramIndex = 5;

            GroupElement[]     bases     = null;
            FieldZqElement[]   exponents = null;
            Group              group     = _parameters[paramIndex].Group;
            PedersenCommitment ped;


            // wrong length bases & exponent arrays
            bool threwException = false;

            bases     = StaticHelperClass.GenerateRandomBases(1, paramIndex);
            exponents = StaticHelperClass.GenerateRandomExponents(1, paramIndex);
            DLRepOfGroupElement dl = new DLRepOfGroupElement(bases, exponents, group);

            try
            {
                ped = new PedersenCommitment(dl);
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.IsTrue(threwException, "should throw exception when dl representation length is 1.");

            // wrong length bases & exponent arrays
            threwException = false;
            bases          = StaticHelperClass.GenerateRandomBases(3, paramIndex);
            exponents      = StaticHelperClass.GenerateRandomExponents(3, paramIndex);
            dl             = new DLRepOfGroupElement(bases, exponents, group);
            try
            {
                ped = new PedersenCommitment(dl);
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.IsTrue(threwException, "should throw exception when bases and exponents are arrays of length 3.");
        }
        public void ComputeValueTest()
        {
            for (int paramIndex = 0; paramIndex < _parameters.Length; ++paramIndex)
            {
                int replen = 10;
                FieldZqElement[] exponents = StaticHelperClass.GenerateRandomExponents(replen, paramIndex);
                GroupElement[]   bases     = StaticHelperClass.GenerateRandomBases(replen, paramIndex);

                DLRepOfGroupElement actualDL      = new DLRepOfGroupElement(bases, exponents, _parameters[paramIndex].Group);
                GroupElement        expectedValue = _parameters[paramIndex].Group.MultiExponentiate(bases, exponents);

                Assert.AreEqual(expectedValue, actualDL.Value, "different values");
                Assert.AreEqual(exponents.Length, actualDL.RepresentationLength, "different number of bases");
                for (int baseIndex = 0; baseIndex < actualDL.RepresentationLength; ++baseIndex)
                {
                    Assert.AreEqual(bases[baseIndex], actualDL.BaseAtIndex(baseIndex), "different base");
                    Assert.AreEqual(exponents[baseIndex], actualDL.ExponentAtIndex(baseIndex), "different exponent");
                }
            }
        }
        public void ComputeValueWithParametersTest()
        {
            for (int paramIndex = 0; paramIndex < _parameters.Length; ++paramIndex)
            {
                int              replen    = 14;
                GroupElement[]   bases     = GetGenerators(_parameters[paramIndex], replen);
                FieldZqElement[] exponents = StaticHelperClass.GenerateRandomExponents(replen, paramIndex);

                DLRepOfGroupElement actualDL   = new DLRepOfGroupElement(exponents, _parameters[paramIndex]);
                DLRepOfGroupElement expectedDL = new DLRepOfGroupElement(bases, exponents, _parameters[paramIndex].Group);

                //compare expectedDL and actualDL
                Assert.IsNotNull(actualDL, "actualDl null");
                Assert.IsNotNull(expectedDL, "expectedDL null");
                Assert.AreEqual(expectedDL.Value, actualDL.Value, "different values");
                Assert.AreEqual(expectedDL.RepresentationLength, actualDL.RepresentationLength, "different number of bases");

                Assert.AreEqual(expectedDL, actualDL, "ComputeValue created different objects");
            }
        }
        public void BaseConstructorTest()
        {
            for (int paramIndex = 0; paramIndex < _parameters.Length; ++paramIndex)
            {
                int replen = 10;
                FieldZqElement[]    exponents = StaticHelperClass.GenerateRandomExponents(replen, paramIndex);
                GroupElement[]      bases     = StaticHelperClass.GenerateRandomBases(replen, paramIndex);
                DLRepOfGroupElement dl        = new DLRepOfGroupElement(bases, exponents, _parameters[paramIndex].Group);

                // check bases and exponents got copied correctly, and value was computed correctly
                GroupElement expectedValue = _parameters[paramIndex].Group.Identity;
                for (int baseIndex = 0; baseIndex < bases.Length; ++baseIndex)
                {
                    Assert.AreEqual(bases[baseIndex], dl.BaseAtIndex(baseIndex), "Wrong base");
                    Assert.AreEqual(exponents[baseIndex], dl.ExponentAtIndex(baseIndex), "wrong exponent");
                    expectedValue = expectedValue * bases[baseIndex].Exponentiate(exponents[baseIndex]);
                }
                Assert.AreEqual(expectedValue, dl.Value, "Incorrect Value");
            }
        }
Ejemplo n.º 19
0
        public void EQSerializationTest()
        {
            int length     = 20;
            int fullLength = length * 2;

            DLRepOfGroupElement [] openEquations    = StaticHelperClass.GenerateRandomDLRepOfGroupElementArray(length, 5, _paramIndex);
            DLRepOfGroupElement [] allOpenEquations = new DLRepOfGroupElement[fullLength];
            for (int i = 0; i < openEquations.Length; ++i)
            {
                allOpenEquations[i]          = openEquations[i];
                allOpenEquations[i + length] = openEquations[i];
            }

            // create equality map
            EqualityMap map = new EqualityMap();

            for (int i = 0; i < length; ++i)
            {
                map.Add(
                    new PrettyName("chi", i),
                    new DoubleIndex(i, 0)
                    );

                map.Add(
                    new PrettyName("chi", i),
                    new DoubleIndex(length + i, 0)
                    );
                map.Add(
                    new PrettyName("delta", i),
                    new DoubleIndex(i, 4)
                    );
                map.Add(
                    new PrettyName("delta", i),
                    new DoubleIndex(length + i, 4)
                    );

                map.Add(
                    new PrettyName("beta", i),
                    new DoubleIndex(i, 2)
                    );
                map.Add(
                    new PrettyName("beta", i),
                    new DoubleIndex(length + i, 2)
                    );
            }

            // create proverParameters
            ProverEqualityParameters prover = new ProverEqualityParameters(allOpenEquations, map, _crypto);
            string jsonProver = CryptoSerializer.Serialize <ProverEqualityParameters>(prover);
            ProverEqualityParameters deserializedProver = CryptoSerializer.Deserialize <ProverEqualityParameters>(jsonProver);

            StaticHelperClass.AssertArraysAreEqual(prover.Statements, deserializedProver.Statements, "Prover closedDLEquations");
            StaticHelperClass.AssertArraysAreEqual(prover.Witnesses, deserializedProver.Witnesses, "Prover Witnesses");
            StaticHelperClass.AssertArraysAreEqual(prover.HashDigest, deserializedProver.HashDigest, "equality map hash.");
            StaticHelperClass.AssertArraysAreEqual(prover.Generators, deserializedProver.Generators, "prover Generators");
            for (int i = 0; i < prover.Statements.Length; ++i)
            {
                Assert.IsTrue(prover.Statements[i].AreBasesEqual(deserializedProver.Statements[i]), "unequal bases for equation " + i);
            }
            Assert.IsTrue(deserializedProver.Verify(), "deserializedProver.Verify()");

            // create proof
            EqualityProof proof = new EqualityProof(prover);

            Assert.IsTrue(proof.Verify(prover), "Proof.Verify(prover)");
            Assert.IsTrue(proof.Verify(deserializedProver), "proof.Verify(deserializedProver)");
            string jsonProof = CryptoSerializer.Serialize <EqualityProof>(proof);
            // TODO: switch to using ip-based de-serialization; need to harmonize with U-Prove SDK code
            IssuerParameters ip = new IssuerParameters();

            ip.Gq = prover.Group;
            EqualityProof deserializedProof = ip.Deserialize <EqualityProof>(jsonProof); // CryptoSerializer.Deserialize<EqualityProof>(jsonProof);

            Assert.IsTrue(deserializedProof.Verify(prover), "deserializedProof.Verify(prover)");
            Assert.IsTrue(deserializedProof.Verify(deserializedProver), "deserializedProof.Verify(deserializedProver)");

            // create verifier
            IStatement[] closedEquations = new ClosedDLRepOfGroupElement[allOpenEquations.Length];
            for (int i = 0; i < allOpenEquations.Length; ++i)
            {
                closedEquations[i] = allOpenEquations[i].GetStatement();
            }
            VerifierEqualityParameters verifier = new VerifierEqualityParameters(closedEquations, map, _crypto);

            Assert.IsTrue(proof.Verify(verifier), "Proof.Verify(verifier)");
            Assert.IsTrue(deserializedProof.Verify(verifier), "proof.Verify(verifier)");
            string jsonVerifier = CryptoSerializer.Serialize <VerifierEqualityParameters>(verifier);
            VerifierEqualityParameters deserializedVerifier = CryptoSerializer.Deserialize <VerifierEqualityParameters>(jsonVerifier);

            Assert.IsTrue(deserializedVerifier.Verify(), "deserializedVerifier.Verify()");
            Assert.IsTrue(deserializedProof.Verify(deserializedVerifier), "deserializedProof.Verify(deserializedVerifier)");

            // create proof from deserialized prover
            EqualityProof newProof = new EqualityProof(deserializedProver);

            Assert.IsTrue(newProof.Verify(deserializedProver), "newProof.verify(deserializedProver)");
            Assert.IsTrue(newProof.Verify(verifier), "newProof.Verify(verifier)");
        }
        public void ComputeValueBadInputTest()
        {
            GroupElement[]    bases     = StaticHelperClass.GenerateRandomBases(8, 1);
            FieldZqElement [] exponents = StaticHelperClass.GenerateRandomExponents(9, 1);

            bool threwException = false;

            try
            {
                DLRepOfGroupElement dl = new DLRepOfGroupElement(bases, exponents, _parameters[1].Group);
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.IsTrue(threwException, "should throw exception when given 8 bases and 9 exponents.");


            exponents = StaticHelperClass.GenerateRandomExponents(8, 1);

            threwException = false;
            try
            {
                DLRepOfGroupElement dl = new DLRepOfGroupElement(null, exponents, _parameters[1].Group);
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.IsTrue(threwException, "should throw exception on null bases");

            threwException = false;
            try
            {
                DLRepOfGroupElement dl = new DLRepOfGroupElement(bases, null, _parameters[1].Group);
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.IsTrue(threwException, "should throw exception on null exponents");

            threwException = false;
            try
            {
                DLRepOfGroupElement dl = new DLRepOfGroupElement(bases, exponents, null);
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.IsTrue(threwException, "should throw exception on null group");

            threwException = false;
            try
            {
                DLRepOfGroupElement dl = new DLRepOfGroupElement(bases, exponents, _parameters[4].Group);
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.IsTrue(threwException, "should throw exception on wrong Group");

            threwException = false;
            bases          = new GroupElement[0];
            exponents      = new FieldZqElement[0];
            try
            {
                DLRepOfGroupElement dl = new DLRepOfGroupElement(bases, exponents, _parameters[4].Group);
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.IsTrue(threwException, "should throw exception on zero length bases and exponents arrays");
        }