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 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 CSFieldZqElementArrayTest() { FieldZqElement[] input = StaticHelperClass.GenerateRandomExponents(10, paramIndex); string[] output = CryptoSerializer.SerializeFieldZqElementArray(input, "blah"); Assert.AreEqual(input.Length, output.Length, "serialized array length different."); FieldZqElement[] deserialized = CryptoSerializer.DeserializeFieldZqElementArray(output, "blah", crypto.Group); StaticHelperClass.AssertArraysAreEqual(input, deserialized, "deserialized"); }
public static void AssertProofParametersAreEqual(ProofParameters A, ProofParameters B, string msg) { Assert.AreEqual(A.ProverParameters, B.ProverParameters, msg + " Prover parameters"); Assert.AreEqual(A.GetType(), B.GetType(), msg + " different classes"); Assert.AreEqual(A.Group.GroupName, B.Group.GroupName, msg + " Groups"); Assert.AreEqual(A.Group.Q, B.Group.Q, msg + " Q"); StaticHelperClass.AssertArraysAreEqual(A.Generators, B.Generators, msg + " Generators"); StaticHelperClass.AssertArraysAreEqual <GroupElement>(A.PublicValues, B.PublicValues, msg + " Public values"); StaticHelperClass.AssertArraysAreEqual <DLRepOfGroupElement>(A.Witnesses, B.Witnesses, msg + " Witnesses"); }
public void CSGroupElementArrayTest2() { GroupElement[] input = StaticHelperClass.GenerateRandomBases(10, paramIndex); string[] serialized = CryptoSerializer.SerializeGroupElementArray(input, 3, 4, "blah"); Assert.AreEqual(4, serialized.Length, "serialized array length"); GroupElement[] output = CryptoSerializer.DeserializeGroupElementArray(serialized, 3, 10, "output", crypto.Group); GroupElement [] expectedOutput = new GroupElement[10] { null, null, null, input[3], input[4], input[5], input[6], null, null, null }; StaticHelperClass.AssertArraysAreEqual(expectedOutput, output, "output"); GroupElement[] output2 = CryptoSerializer.DeserializeGroupElementArray(serialized, 0, 10, "output2", crypto.Group); GroupElement[] expectedOutput2 = new GroupElement[10] { input[3], input[4], input[5], input[6], null, null, null, null, null, null }; StaticHelperClass.AssertArraysAreEqual(expectedOutput2, output2, "output2"); GroupElement[] output3 = CryptoSerializer.DeserializeGroupElementArray(serialized, 6, 10, "output3", crypto.Group); GroupElement[] expectedOutput3 = new GroupElement[10] { null, null, null, null, null, null, input[3], input[4], input[5], input[6] }; StaticHelperClass.AssertArraysAreEqual(expectedOutput3, output3, "output3"); }
public void BDVerifierSerializationTest() { VerifierBitDecompositionParameters verifier = new VerifierBitDecompositionParameters( _parameters[0].G, _parameters[0].Generators, _parameters[0]); string jsonString = CryptoSerializer.Serialize <VerifierBitDecompositionParameters>(verifier); VerifierBitDecompositionParameters deserializedVerifier = CryptoSerializer.Deserialize <VerifierBitDecompositionParameters>(jsonString); Assert.AreEqual(verifier.Group.GroupName, deserializedVerifier.Group.GroupName); StaticHelperClass.AssertArraysAreEqual(verifier.PublicValues, deserializedVerifier.PublicValues, "PublicValues"); StaticHelperClass.AssertArraysAreEqual <DLRepOfGroupElement>(verifier.Witnesses, deserializedVerifier.Witnesses, "Witnesses"); }
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 BDProverSerializationTest() { FieldZqElement bigNum = _parameters[0].FieldZq.GetElement(2056); PedersenCommitment bigNumCommit = new PedersenCommitment(bigNum, _parameters[0]); int decompositionLength = 15; ProverBitDecompositionParameters prover = new ProverBitDecompositionParameters( bigNumCommit, decompositionLength, _parameters[0]); string jsonString = CryptoSerializer.Serialize <ProverBitDecompositionParameters>(prover); ProverBitDecompositionParameters deserializedProver = CryptoSerializer.Deserialize <ProverBitDecompositionParameters>(jsonString); Assert.AreEqual(prover.Group.GroupName, deserializedProver.Group.GroupName); StaticHelperClass.AssertArraysAreEqual(prover.PublicValues, deserializedProver.PublicValues, "PublicValues"); StaticHelperClass.AssertArraysAreEqual <DLRepOfGroupElement>(prover.Witnesses, deserializedProver.Witnesses, "Witnesses"); }
public void EQMapHashTest2() { int length = 20; // 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) ); } byte[] hash1 = map.Hash(DefaultHashFunction); byte[] hash2 = map.Hash(DefaultHashFunction); StaticHelperClass.AssertArraysAreEqual <byte>(hash1, hash2, "same map hash."); // create parallel map in different order EqualityMap map2 = new EqualityMap(); for (int i = 0; i < length; ++i) { map2.Add( new PrettyName("chi", i), new DoubleIndex(length + i, 0) ); } for (int i = 0; i < length; ++i) { map2.Add( new PrettyName("chi", i), new DoubleIndex(i, 0) ); } byte[] hash3 = map2.Hash(DefaultHashFunction); byte[] hash4 = map2.Hash(DefaultHashFunction); StaticHelperClass.AssertArraysAreEqual <byte>(hash3, hash4, "map2 hash."); StaticHelperClass.AssertArraysAreEqual <byte>(hash1, hash3, "hash1 vs hash 3."); }
public void EQMapHashTest() { EqualityMap map1 = new EqualityMap(); map1.Add(new PrettyName("alpha", 0), new DoubleIndex(0, 0)); map1.Add(new PrettyName("alpha", 2), new DoubleIndex(1, 1)); byte[] hash1 = map1.Hash(CryptoParameters.DefaultHashFunctionName); byte[] hash2 = map1.Hash(CryptoParameters.DefaultHashFunctionName); StaticHelperClass.AssertArraysAreEqual <byte>(hash1, hash2, "hash1 vs hash2 of same map."); EqualityMap map2 = new EqualityMap(); map2.Add(new PrettyName("alpha", 2), new DoubleIndex(1, 1)); map2.Add(new PrettyName("alpha", 0), new DoubleIndex(0, 0)); byte[] hash3 = map2.Hash(CryptoParameters.DefaultHashFunctionName); byte[] hash4 = map2.Hash(CryptoParameters.DefaultHashFunctionName); StaticHelperClass.AssertArraysAreEqual <byte>(hash3, hash4, "hash3 vs hash4 of same map."); StaticHelperClass.AssertArraysAreEqual <byte>(hash1, hash3, "hash1 vs hash3."); }
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"); }
public void EQMapSerializationTest() { int length = 20; // 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) ); } string jsonString = CryptoSerializer.Serialize <EqualityMap>(map); EqualityMap deserializedMap = CryptoSerializer.Deserialize <EqualityMap>(jsonString); byte[] hash1 = map.Hash(DefaultHashFunction); byte[] hash2 = deserializedMap.Hash(DefaultHashFunction); StaticHelperClass.AssertArraysAreEqual(hash1, hash2, "hash of deserialized map."); }
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)"); }