/// <summary> /// Create a SubgrouGroupSerializable object from a SubgroupGroup. /// </summary> /// <param name="group">The group to serialize.</param> public SubgroupGroupSerializable(SubgroupGroup group) { if (group.P == null || group.Q == null || group.G == null) { throw new UProveSerializationException("P, Q, G cannot be null"); } this.p = group.P.ToBase64String(); this.q = group.Q.ToBase64String(); this.g = group.G.ToBase64String(); }
/// <summary> /// Create a SubgroupGroup from this serialized form. /// </summary> /// <returns>A SubgroupGroup object.</returns> public SubgroupGroup ToSubgroupGroup() { if (p == null || q == null || g == null) { throw new UProveSerializationException("p, q, g cannot be null"); } SubgroupGroup group = SubgroupGroup.CreateSubgroupGroup( p.ToByteArray(), q.ToByteArray(), g.ToByteArray(), null, null); return(group); }
public void TestSerialization() { // Create IssuerSetupParameters System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); for (int i = 0; i <= 1; i++) { for (int j = 0; j <= 1; j++) { bool useCustomGroup = (i == 0); bool useSubgroupConstruction = (j == 0); IssuerSetupParameters isp = new IssuerSetupParameters(); if (useSubgroupConstruction) { isp.GroupConstruction = GroupType.Subgroup; if (useCustomGroup) { byte[] p = HexToBytes("d21ae8d66e6c6b3ced0eb3df1a26c91bdeed013c17d849d30ec309813e4d3799f26db0d494e82ec61ea9fdc70bb5cbcaf2e5f18a836494f58e67c6d616480c37a7f2306101fc9f0f4768f9c9793c2be176b0b7c979b4065d3e835686a3f0b8420c6834cb17930386dedab2b07dd473449a48baab316286b421052475d134cd3b"); byte[] q = HexToBytes("fff80ae19daebc61f46356af0935dc0e81148eb1"); byte[] g = HexToBytes("abcec972e9a9dd8d133270cfeac26f726e567d964757630d6bd43460d0923a46aec0ace255ebf3ddd4b1c4264f53e68b361afb777a13cf0067dae364a34d55a0965a6cccf78852782923813cf8708834d91f6557d783ec75b5f37cd9185f027b042c1c72e121b1266a408be0bb7270d65917b69083633e1f3cd60624612fc8c1"); isp.Gq = SubgroupGroup.CreateSubgroupGroup( p, q, g, null, null); isp.UidH = "SHA1"; } } else { isp.GroupConstruction = GroupType.ECC; if (useCustomGroup) { continue; } } isp.UidP = encoding.GetBytes("http://issuer/uprove/issuerparams/software"); isp.E = IssuerSetupParameters.GetDefaultEValues(3); isp.S = encoding.GetBytes("application-specific specification"); // Generate IssuerKeyAndParameters IssuerKeyAndParameters ikap = isp.Generate(); // Create an IssuerParameters IssuerParameters ip = ikap.IssuerParameters; VerifySerialization(useCustomGroup, useSubgroupConstruction, ip, ikap); VerifySerialization(useCustomGroup, useSubgroupConstruction, ip, ikap.IssuerParameters); // specify the attribute values byte[][] attributes = new byte[][] { encoding.GetBytes("first attribute value"), encoding.GetBytes("second attribute value"), encoding.GetBytes("third attribute value") }; // specify the special field values byte[] tokenInformation = encoding.GetBytes("token information value"); byte[] proverInformation = encoding.GetBytes("prover information value"); // specify the number of tokens to issue int numberOfTokens = 5; // setup the issuer and generate the first issuance message IssuerProtocolParameters ipp = new IssuerProtocolParameters(ikap); ipp.Attributes = attributes; ipp.NumberOfTokens = numberOfTokens; ipp.TokenInformation = tokenInformation; Issuer issuer = ipp.CreateIssuer(); FirstIssuanceMessage firstMessage = issuer.GenerateFirstMessage(); VerifySerialization(useCustomGroup, useSubgroupConstruction, ip, firstMessage); // setup the prover and generate the second issuance message Prover prover = new Prover(ip, numberOfTokens, attributes, tokenInformation, proverInformation, null); SecondIssuanceMessage secondMessage = prover.GenerateSecondMessage(firstMessage); VerifySerialization(useCustomGroup, useSubgroupConstruction, ip, secondMessage); // generate the third issuance message ThirdIssuanceMessage thirdMessage = issuer.GenerateThirdMessage(secondMessage); VerifySerialization(useCustomGroup, useSubgroupConstruction, ip, thirdMessage); // generate the tokens UProveKeyAndToken[] upkt = prover.GenerateTokens(thirdMessage); for (int k = 0; k < upkt.Length; k++) { string json = ip.Serialize(upkt[k]); UProveKeyAndToken upkt_fromJson = ip.Deserialize <UProveKeyAndToken>(json); Assert.IsTrue(Verify(upkt[k], upkt_fromJson)); } VerifySerialization(useCustomGroup, useSubgroupConstruction, ip, upkt[0].Token); /* * token presentation */ // the indices of disclosed attributes int[] disclosed = new int[] { 2 }; // the indices of committed attributes int[] committed = new int[] { 3 }; // the returned commitment randomizers, to be used by an external proof module FieldZqElement[] tildeO; // the application-specific message that the prover will sign. Typically this is a nonce combined // with any application-specific transaction data to be signed. byte[] message = encoding.GetBytes("message"); // the application-specific verifier scope from which a scope-exclusive pseudonym will be created // (if null, then a pseudonym will not be presented) byte[] scope = encoding.GetBytes("verifier scope"); // generate the presentation proof PresentationProof proof = PresentationProof.Generate(ip, disclosed, committed, 1, scope, message, null, null, upkt[0], attributes, out tildeO); VerifySerialization(useCustomGroup, useSubgroupConstruction, ip, proof); // verify the presentation proof proof.Verify(ip, disclosed, committed, 1, scope, message, null, upkt[0].Token); } } }
public void VerifyGroupTest() { SubgroupGroup Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(2), // p StaticTestHelpers.IntToBigEndianBytes(2), // q StaticTestHelpers.IntToBigEndianBytes(0), // g null, null); try { Gq.Verify(); Assert.Fail(); } catch (InvalidUProveArtifactException) { } Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(6), // p not prime StaticTestHelpers.IntToBigEndianBytes(2), // q StaticTestHelpers.IntToBigEndianBytes(0), // g null, null); try { Gq.Verify(); Assert.Fail(); } catch (InvalidUProveArtifactException) { } Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(7), // p StaticTestHelpers.IntToBigEndianBytes(2), // q StaticTestHelpers.IntToBigEndianBytes(0), // g null, null); try { Gq.Verify(); Assert.Fail(); } catch (InvalidUProveArtifactException) { } Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(7), // p StaticTestHelpers.IntToBigEndianBytes(4), // q not prime StaticTestHelpers.IntToBigEndianBytes(0), // g null, null); try { Gq.Verify(); Assert.Fail(); } catch (InvalidUProveArtifactException) { } Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(7), // p StaticTestHelpers.IntToBigEndianBytes(5), // q doesnt divide p - 1 StaticTestHelpers.IntToBigEndianBytes(0), // g null, null); try { Gq.Verify(); Assert.Fail(); } catch (InvalidUProveArtifactException) { } Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(7), // p StaticTestHelpers.IntToBigEndianBytes(3), // q StaticTestHelpers.IntToBigEndianBytes(0), // g null, null); try { Gq.Verify(); Assert.Fail(); } catch (InvalidUProveArtifactException) { } Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(7), // p StaticTestHelpers.IntToBigEndianBytes(3), // q StaticTestHelpers.IntToBigEndianBytes(1), // g invalid value null, null); try { Gq.Verify(); Assert.Fail(); } catch (InvalidUProveArtifactException) { } Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(7), // p StaticTestHelpers.IntToBigEndianBytes(3), // q StaticTestHelpers.IntToBigEndianBytes(5), // g^q mod p != 1 null, null); try { Gq.Verify(); Assert.Fail(); } catch (InvalidUProveArtifactException) { } // Valid subgroup description Gq = SubgroupGroup.CreateSubgroupGroup( StaticTestHelpers.IntToBigEndianBytes(7), // p StaticTestHelpers.IntToBigEndianBytes(3), // q StaticTestHelpers.IntToBigEndianBytes(2), // g null, null); Gq.Verify(); }
public void TestSerializationReference() { // Create IssuerSetupParameters System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); foreach (string fileName in Directory.GetFiles("SerializationReference")) { FileStream f = File.OpenRead(fileName); BinaryFormatter bf = new BinaryFormatter(); object[] parameters = (object[])bf.Deserialize(f); f.Close(); bool useCustomGroup = (bool)parameters[0]; bool useSubgroupConstruction = (bool)parameters[1]; string typeName = (string)parameters[2]; string json = (string)parameters[3]; IssuerSetupParameters isp = new IssuerSetupParameters(); if (useSubgroupConstruction) { isp.GroupConstruction = GroupType.Subgroup; if (useCustomGroup) { byte[] p = HexToBytes("d21ae8d66e6c6b3ced0eb3df1a26c91bdeed013c17d849d30ec309813e4d3799f26db0d494e82ec61ea9fdc70bb5cbcaf2e5f18a836494f58e67c6d616480c37a7f2306101fc9f0f4768f9c9793c2be176b0b7c979b4065d3e835686a3f0b8420c6834cb17930386dedab2b07dd473449a48baab316286b421052475d134cd3b"); byte[] q = HexToBytes("fff80ae19daebc61f46356af0935dc0e81148eb1"); byte[] g = HexToBytes("abcec972e9a9dd8d133270cfeac26f726e567d964757630d6bd43460d0923a46aec0ace255ebf3ddd4b1c4264f53e68b361afb777a13cf0067dae364a34d55a0965a6cccf78852782923813cf8708834d91f6557d783ec75b5f37cd9185f027b042c1c72e121b1266a408be0bb7270d65917b69083633e1f3cd60624612fc8c1"); isp.Gq = SubgroupGroup.CreateSubgroupGroup( p, q, g, null, null); isp.UidH = "SHA1"; } } else { isp.GroupConstruction = GroupType.ECC; if (useCustomGroup) { continue; } } isp.UidP = encoding.GetBytes("http://issuer/uprove/issuerparams/software"); isp.E = IssuerSetupParameters.GetDefaultEValues(3); isp.S = encoding.GetBytes("application-specific specification"); // Generate IssuerKeyAndParameters IssuerKeyAndParameters ikap = isp.Generate(); // Create an IssuerParameters IssuerParameters ip = ikap.IssuerParameters; // check that we didn't send any null fields Assert.IsFalse(json.Contains(":null")); string roundTrip = ""; if (typeName == "UProveCrypto.IssuerParameters") { IssuerParameters obj = ip.Deserialize <IssuerParameters>(json); roundTrip = ip.Serialize <IssuerParameters>(obj); } else if (typeName == "UProveCrypto.IssuerKeyAndParameters") { IssuerKeyAndParameters obj = ip.Deserialize <IssuerKeyAndParameters>(json); roundTrip = ip.Serialize <IssuerKeyAndParameters>(obj); } else if (typeName == "UProveCrypto.FirstIssuanceMessage") { FirstIssuanceMessage obj = ip.Deserialize <FirstIssuanceMessage>(json); roundTrip = ip.Serialize <FirstIssuanceMessage>(obj); } else if (typeName == "UProveCrypto.SecondIssuanceMessage") { SecondIssuanceMessage obj = ip.Deserialize <SecondIssuanceMessage>(json); roundTrip = ip.Serialize <SecondIssuanceMessage>(obj); } else if (typeName == "UProveCrypto.ThirdIssuanceMessage") { ThirdIssuanceMessage obj = ip.Deserialize <ThirdIssuanceMessage>(json); roundTrip = ip.Serialize <ThirdIssuanceMessage>(obj); } else if (typeName == "UProveCrypto.UProveKeyAndToken") { UProveKeyAndToken obj = ip.Deserialize <UProveKeyAndToken>(json); roundTrip = ip.Serialize <UProveKeyAndToken>(obj); } else if (typeName == "UProveCrypto.UProveToken") { UProveToken obj = ip.Deserialize <UProveToken>(json); roundTrip = ip.Serialize <UProveToken>(obj); } else if (typeName == "UProveCrypto.PresentationProof") { PresentationProof obj = ip.Deserialize <PresentationProof>(json); roundTrip = ip.Serialize <PresentationProof>(obj); } else { Assert.Fail("Unrecognized type " + typeName + " in SerializationReference files"); } Assert.AreEqual(json, roundTrip); } }