コード例 #1
0
        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);
        }
コード例 #2
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)
                    );
            }
        }
コード例 #3
0
        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");
            }
        }
コード例 #4
0
        public void CSClosedDLRepArrayTest()
        {
            int arrayLength = 10;

            DLRepOfGroupElement[]        openInput = StaticHelperClass.GenerateRandomDLRepOfGroupElementArray(10, 7, this.paramIndex);
            ClosedDLRepOfGroupElement [] input     = new ClosedDLRepOfGroupElement[arrayLength];
            for (int i = 0; i < input.Length; ++i)
            {
                GroupElement[] bases = StaticHelperClass.GenerateRandomBases(10, this.paramIndex);
                GroupElement   value = bases[0];
                input[i] = new ClosedDLRepOfGroupElement(bases, value, crypto.Group);
            }

            string[] serialized = CryptoSerializer.Serialize(input, false);
            ClosedDLRepOfGroupElement[] output = CryptoSerializer.Deserialize <ClosedDLRepOfGroupElement>(serialized, crypto.Group);
            StaticHelperClass.AssertArraysAreEqual(input, output, "no group");


            string[] serialized2 = CryptoSerializer.Serialize(input, true);
            ClosedDLRepOfGroupElement[] output2 = CryptoSerializer.Deserialize <ClosedDLRepOfGroupElement>(serialized, crypto.Group);
            StaticHelperClass.AssertArraysAreEqual(input, output2, "group");
        }
コード例 #5
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)");
        }