private static UProveKeyAndToken[] IssueUProveTokens(IssuerKeyAndParameters ikap, IssuerParameters ip, byte[][] attributes, int numOfTokens, byte[] ti = null, byte[] pi = null) { WriteLine("Issuing " + numOfTokens + " tokens"); // setup the issuer and generate the first issuance message IssuerProtocolParameters ipp = new IssuerProtocolParameters(ikap); ipp.Attributes = attributes; ipp.NumberOfTokens = numOfTokens; ipp.TokenInformation = ti; Issuer issuer = ipp.CreateIssuer(); string firstMessage = ip.Serialize<FirstIssuanceMessage>(issuer.GenerateFirstMessage()); // setup the prover and generate the second issuance message ProverProtocolParameters ppp = new ProverProtocolParameters(ip); ppp.Attributes = attributes; ppp.NumberOfTokens = numOfTokens; ppp.TokenInformation = ti; ppp.ProverInformation = pi; Prover prover = ppp.CreateProver(); string secondMessage = ip.Serialize<SecondIssuanceMessage>(prover.GenerateSecondMessage(ip.Deserialize<FirstIssuanceMessage>(firstMessage))); // generate the third issuance message string thirdMessage = ip.Serialize<ThirdIssuanceMessage>(issuer.GenerateThirdMessage(ip.Deserialize<SecondIssuanceMessage>(secondMessage))); // generate the tokens return prover.GenerateTokens(ip.Deserialize<ThirdIssuanceMessage>(thirdMessage)); }
/// <summary> /// Constructs a new <code>Issuer</code> instance. /// </summary> /// <param name="ikap">The Issuer key and parameters.</param> /// <param name="numberOfTokens">Number of tokens to issue.</param> /// <param name="gamma">The gamma value encoding the token attributes.</param> /// <param name="preGeneratedW">Optional pregenerated <code>numberOfTokens</code> random Zq elements.</param> internal Issuer(IssuerKeyAndParameters ikap, int numberOfTokens, GroupElement gamma, FieldZqElement[] preGeneratedW) { if (ikap == null || ikap.PrivateKey == null || ikap.IssuerParameters == null) { throw new ArgumentNullException("ikap is malformed or null"); } this.ikap = ikap; if (numberOfTokens <= 0) { throw new ArgumentException("numberOfTokens must be greater than 0"); } this.numberOfTokens = numberOfTokens; if (gamma == null) { throw new ArgumentNullException("gamma is null"); } if (preGeneratedW != null && preGeneratedW.Length != numberOfTokens) { throw new ArgumentException("invalid preGeneratedW array length"); } Precompute(gamma, preGeneratedW); }
public static void GenerateTestIssuanceParameters(string uidp, string spec, int numberOfAttributes, bool useRecommendedParameters, int numberOfTokens, out IssuerKeyAndParameters ikap, out IssuerProtocolParameters ipp, out ProverProtocolParameters ppp) { IssuerSetupParameters isp = new IssuerSetupParameters(); isp.UidP = (uidp == null ? null : encoding.GetBytes(uidp)); isp.E = IssuerSetupParameters.GetDefaultEValues(numberOfAttributes); isp.UseRecommendedParameterSet = useRecommendedParameters; isp.S = (spec == null ? null : encoding.GetBytes(spec)); ikap = isp.Generate(); IssuerParameters ip = ikap.IssuerParameters; // Issuance byte[][] attributes = new byte[numberOfAttributes][]; for (int i = 0; i < numberOfAttributes; i++) { attributes[i] = encoding.GetBytes("attribute value " + (i + 1)); } byte[] tokenInformation = encoding.GetBytes("token information field"); byte[] proverInformation = encoding.GetBytes("prover information field"); ipp = new IssuerProtocolParameters(ikap); ipp.Attributes = attributes; ipp.NumberOfTokens = numberOfTokens; ipp.TokenInformation = tokenInformation; ppp = new ProverProtocolParameters(ip); ppp.Attributes = attributes; ppp.NumberOfTokens = numberOfTokens; ppp.TokenInformation = tokenInformation; ppp.ProverInformation = proverInformation; }
/// <summary> /// Constructs a new <code>Issuer</code> instance ready to complete the issuance. /// </summary> /// <param name="ikap">The issuer key and parameters.</param> /// <param name="pfms">State of another <code>Issuer</code> instance after the first message was generated.</param> public Issuer(IssuerKeyAndParameters ikap, PostFirstMessageState pfms) { this.ikap = ikap; this.w = pfms.W; this.numberOfTokens = w.Length; state = State.First; }
/// <summary> /// Constructs new issuance protocol parameters for the Issuer. /// </summary> /// <param name="ikap">The Issuer key and parameters.</param> public IssuerProtocolParameters(IssuerKeyAndParameters ikap) { if (ikap == null || ikap.PrivateKey == null || ikap.IssuerParameters == null) { throw new ArgumentNullException("IssuerKeyAndParameters is malformed or null"); } IssuerKeyAndParameters = ikap; }
/// <summary> /// Constructs new issuance protocol parameters for the Issuer. /// </summary> /// <param name="ikap">The Issuer key and parameters.</param> public IssuerProtocolParameters(IssuerKeyAndParameters ikap) { if (ikap == null || ikap.PrivateKey == null || ikap.IssuerParameters == null) { throw new ArgumentNullException("IssuerKeyAndParameters is malformed or null"); } IssuerKeyAndParameters = ikap; }
private void RunProtocol(IssuerKeyAndParameters ikap, IssuerParameters ip) { ip.Verify(); // sanity check // Issuance int numberOfAttribs = ip.G.Length - 2; // minus g_0 and g_t byte[][] attributes = new byte[numberOfAttribs][]; for (int i = 0; i < numberOfAttribs; i++) { attributes[i] = new byte[] { (byte)i }; } byte[] tokenInformation = new byte[] { 0x01 }; byte[] proverInformation = new byte[] { 0x01 }; int numberOfTokens = 1; IssuerProtocolParameters ipp = new IssuerProtocolParameters(ikap); ipp.Attributes = attributes; ipp.NumberOfTokens = numberOfTokens; ipp.TokenInformation = tokenInformation; Issuer issuer = ipp.CreateIssuer(); FirstIssuanceMessage msg1 = issuer.GenerateFirstMessage(); ProverProtocolParameters ppp = new ProverProtocolParameters(ip); ppp.NumberOfTokens = numberOfTokens; ppp.Attributes = attributes; ppp.TokenInformation = tokenInformation; ppp.ProverInformation = proverInformation; Prover prover = ppp.CreateProver(); SecondIssuanceMessage msg2 = prover.GenerateSecondMessage(msg1); ThirdIssuanceMessage msg3 = issuer.GenerateThirdMessage(msg2); // issue token UProveKeyAndToken[] upkt = prover.GenerateTokens(msg3); // Presentation int[] disclosed = new int[] { 1 }; byte[] message = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // generate the presentation proof PresentationProof proof = PresentationProof.Generate(new ProverPresentationProtocolParameters(ip, disclosed, message, upkt[0], attributes)); // verify the presentation proof proof.Verify(new VerifierPresentationProtocolParameters(ip, disclosed, message, upkt[0].Token)); }
public void completeUProveProtocolTest() { byte[] attributeEncoding = new byte[] { 0x0, 0x1 }; IssuerSetupParameters isp = this.getIssuerSetupParameters(attributeEncoding, "foobar"); // generate the serializable IssuerKeyAndParameters IssuerKeyAndParameters ikap = null; Assert.DoesNotThrow(delegate { ikap = isp.Generate(true); }); Assert.DoesNotThrow(delegate { ikap.IssuerParameters.Verify(); }); byte[] issuerPrivateKey = new byte[] { 187, 133, 215, 21, 39, 178, 240, 67, 170, 4, 148, 139, 213, 36, 164, 114, 146, 228, 243, 140, 61, 76, 174, 136, 137, 65, 238, 59, 7, 198, 34, 129 }; int numberOfTokens = 10; string[] attributesString = new string[] { "foo", "bar" }; int numberOfAttributes = attributesString.Length; byte[][] attributes = new byte[numberOfAttributes][]; for (int i = 0; i < numberOfAttributes; i++) { attributes[i] = encoding.GetBytes(attributesString[i]); } BigInteger bi = new BigInteger(1, issuerPrivateKey); IssuerKeyAndParameters ikapFristMessage = new IssuerKeyAndParameters(bi, ikap.IssuerParameters); GroupElement hdG = ikap.IssuerParameters.Gq.CreateGroupElement(defines.hd); Issuer issuer = new Issuer(ikapFristMessage, numberOfTokens, attributes, null, hdG); FirstIssuanceMessage fi = issuer.GenerateFirstMessage(); byte[] attributes2nd = (byte[])attributes.Clone(); byte[] tokenInformation = new byte[] { }; byte[] proverInformation = new byte[] { }; Prover prover = new Prover(ip, numberOfTokens, attributes, tokenInformation, proverInformation, sessionDB[sessionID].deviceManager.GetDevice()); /* * issue steps. creds. * setupIssuerParams. * * setIssuerPrivateKey. {byte[32]} : * * getFirstMessage - [0] "42595520544300663591556673075677003532579993719172074290116620403700505383419" string * * getSecondMessage - with outputfrom getFristMessage. * * getThirdMessage - with output from getSecondMessage. * * generateTokens - with output from getThirdMessage * * proveToken - commitedIndices 0x00000001 , * messageParms "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\n<abc:Message xmlns:abc=\"http://abc4trust.eu/wp2/abcschemav1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://abc4trust.eu/wp2/abcschemav1.0 ../../../../../../../../../abc4trust-xml/src/main/resources/xsd/schema.xsd\">\n<abc:Nonce>r9MQ57udpiWRwA==</abc:Nonce>\n</abc:Message>\n" * Token, * - tokenPrivateKeyParam {byte[0x00000020]} byte[] [0x00000000] 0x37 byte [0x00000001] 0xaa byte [0x00000002] 0xb6 byte [0x00000003] 0xa9 byte [0x00000004] 0xd5 byte [0x00000005] 0x56 byte [0x00000006] 0xd8 byte [0x00000007] 0x21 byte [0x00000008] 0x77 byte [0x00000009] 0xe1 byte [0x0000000a] 0x7b byte [0x0000000b] 0x5a byte [0x0000000c] 0xf3 byte [0x0000000d] 0xad byte [0x0000000e] 0xf7 byte [0x0000000f] 0x83 byte [0x00000010] 0x3c byte [0x00000011] 0x2d byte [0x00000012] 0xcf byte [0x00000013] 0xdd byte [0x00000014] 0x8a byte [0x00000015] 0xbf byte [0x00000016] 0x62 byte [0x00000017] 0xae byte [0x00000018] 0xeb byte [0x00000019] 0x44 byte [0x0000001a] 0x59 byte [0x0000001b] 0x6f byte [0x0000001c] 0x1b byte [0x0000001d] 0x09 byte [0x0000001e] 0x6d byte [0x0000001f] 0xf0 byte * * verifyTokenProof - proff from proveToken, otherwise same values. * * * * */ }
public Issuer(IssuerKeyAndParameters ikap, int numberOfTokens, byte[][] A, byte[] TI, GroupElement hd, FieldZqElement[] preGeneratedW) : this(ikap, numberOfTokens, ProtocolHelper.ComputeIssuanceInput(ikap.IssuerParameters, A, TI, hd), preGeneratedW) { }
public Issuer(IssuerKeyAndParameters ikap, int numberOfTokens, byte[][] A, byte[] TI, GroupElement hd) : this(ikap, numberOfTokens, ProtocolHelper.ComputeIssuanceInput(ikap.IssuerParameters, A, TI, hd), null) { }
// issuerPrivateKey must be set using setIssuerPrivateKey() before calling this method public FirstIssuanceMessageComposite getFirstMessage(string[] attributesParam, IssuerParametersComposite ipc, int numberOfTokensParam, string sessionID, byte[] hd) { /* * token issuance - generate first message */ cOut.write("Issuing U-Prove tokens - generate first message, issuer side"); VerifySessionId(sessionID); try { // specify the attribute values agreed to by the Issuer and Prover int numberOfAttributes = attributesParam.Length; byte[][] attributes = new byte[numberOfAttributes][]; for (int i = 0; i < numberOfAttributes; i++) { attributes[i] = encoding.GetBytes(attributesParam[i]); } IssuerParameters ip = ConvertUtils.convertIssuerParametersComposite(ipc, sessionDB[sessionID]); byte[] issuerPrivateKey = sessionDB[sessionID].privateKey; if (issuerPrivateKey == null) { cOut.write("Issuer side, issuerPrivateKey is null. Did you forget to add the issuer private key for the given sessionKey?"); return null; } BigInteger bi = new BigInteger(1, issuerPrivateKey); IssuerKeyAndParameters ikap = new IssuerKeyAndParameters(bi, ip); // setup the issuer and generate the first issuance message GroupElement hdG = ip.Gq.CreateGroupElement(hd); Issuer issuer = new Issuer(ikap, numberOfTokensParam, attributes, null, hdG); // Store the issuer in issuersDictionary using the sessionKey as key sessionDB[sessionID].issuer = issuer; FirstIssuanceMessage fi = issuer.GenerateFirstMessage(); // Convert FirstIssuanceMessage members to serializable FirstIssuanceMessageComposite FirstIssuanceMessageComposite fic = ConvertUtils.convertFirstIssuanceMessage(fi); // Add the sessionKey to FirstIssuanceMessageComposite fic.SessionKey = sessionID; return fic; } catch (Exception e) { cOut.write(e.ToString()); DebugUtils.DebugPrint(e.StackTrace.ToString()); } return null; }
/// <summary> /// Constructs a new <code>Issuer</code> instance. /// </summary> /// <param name="ikap">The Issuer key and parameters.</param> /// <param name="numberOfTokens">Number of tokens to issue.</param> /// <param name="gamma">The gamma value encoding the token attributes.</param> /// <param name="preGeneratedW">Optional pregenerated <code>numberOfTokens</code> random Zq elements.</param> internal Issuer(IssuerKeyAndParameters ikap, int numberOfTokens, GroupElement gamma, FieldZqElement[] preGeneratedW) { if (ikap == null || ikap.PrivateKey == null || ikap.IssuerParameters == null) { throw new ArgumentNullException("ikap is malformed or null"); } this.ikap = ikap; if (numberOfTokens <= 0) { throw new ArgumentException("numberOfTokens must be greater than 0"); } this.numberOfTokens = numberOfTokens; if (gamma == null) { throw new ArgumentNullException("gamma is null"); } if (preGeneratedW != null && preGeneratedW.Length != numberOfTokens) { throw new ArgumentException("invalid preGeneratedW array length"); } Precompute(gamma, preGeneratedW); }
/// <summary> /// Constructs a new <code>Issuer</code> instance ready to complete the issuance. /// </summary> /// <param name="ikap">The issuer key and parameters.</param> /// <param name="pfms">State of another <code>Issuer</code> instance after the first message was generated.</param> public Issuer(IssuerKeyAndParameters ikap, PostFirstMessageState pfms) { this.ikap = ikap; this.w = pfms.W; this.numberOfTokens = w.Length; state = State.First; }
public Issuer(IssuerKeyAndParameters ikap, int numberOfTokens, byte[][] A, byte[] TI, GroupElement hd, FieldZqElement[] preGeneratedW) : this(ikap, numberOfTokens, ProtocolHelper.ComputeIssuanceInput(ikap.IssuerParameters, A, TI, hd), preGeneratedW) { }
public Issuer(IssuerKeyAndParameters ikap, int numberOfTokens, byte[][] A, byte[] TI, GroupElement hd) : this(ikap, numberOfTokens, ProtocolHelper.ComputeIssuanceInput(ikap.IssuerParameters, A, TI, hd), null) { }