/// <summary>
 /// Generates a <code>ProofGenerationRandomData</code> instance using the internal RNG.
 /// </summary>
 /// <param name="numUndisclosed">Number of undisclosed attributes.</param>
 /// <param name="numCommitted">Number of committed attributes.</param>
 /// <param name="Zq">Field Zq</param>
 /// <param name="isDeviceProtected">True if a toke is device-protected.</param>
 /// <returns>A pregenerated set of random values.</returns>
 internal static ProofGenerationRandomData Generate(int numUndisclosed, int numCommitted, FieldZq Zq, bool isDeviceProtected)
 {
     return new ProofGenerationRandomData(
         Zq.GetRandomElement(false), 
         Zq.GetRandomElements(numUndisclosed, false), 
         isDeviceProtected ? Zq.GetRandomElement(false) : null,
         numCommitted > 0 ? Zq.GetRandomElements(numCommitted, false) : null,
         numCommitted > 0 ? Zq.GetRandomElements(numCommitted, false) : null
         );
 }
 /// <summary>
 /// Private constructor - takes and sets all fields.
 /// </summary>
 /// <param name="Gq">The group</param>
 /// <param name="gd">The device generator</param>
 /// <param name="Zq">The Field associated to the group <c>Gq</c></param>
 /// <param name="xd">The xd.</param>
 /// <param name="preGenWdPrime">The pre gen wd prime.</param>
 VirtualDevice(Group Gq, GroupElement gd, FieldZq Zq, FieldZqElement xd, FieldZqElement preGenWdPrime)
 {
     if (xd != null && !Zq.IsElement(xd))
     {
         throw new ArgumentException("xd is not a valid Zq element");
     }
     this.Gd = gd;
     this.Gq = Gq;
     this.Zq = Zq;
     this.xd = xd ?? this.Zq.GetRandomElement(true);     // assign xd a random value if null
     this.wdPrime = preGenWdPrime;
     this.hd = this.Gd.Exponentiate(this.xd);
 }
 /// <summary>
 /// Convert a base64 string to a FieldElement[] using a specific FieldZq object.
 /// </summary>
 /// <param name="encodedElements">The encoded string to convert.</param>
 /// <param name="Zq">The fieldZq object to use.</param>
 /// <returns>The converted object.</returns>
 public static FieldZqElement[] ToFieldElementArray(this String[] encodedElements, FieldZq Zq)
 {
     if (encodedElements == null) return null;
     FieldZqElement[] fieldElements = new FieldZqElement[encodedElements.Length];
     for (int i = 0; i < encodedElements.Length; i++)
     {
         fieldElements[i] = encodedElements[i].ToFieldZqElement(Zq);
     }
     return fieldElements;
 }
 /// <summary>
 /// Convert a base64 string to a FieldElement.
 /// </summary>
 /// <param name="encodedString">The encoded string to convert.</param>
 /// <param name="Zq">The FieldZq object to which the encoded element belongs.</param>
 /// <returns>The converted object.</returns>
 public static FieldZqElement ToFieldZqElement(this String encodedString, FieldZq Zq)
 {
     if (encodedString == null) return null;
     if (Zq == null) throw new ArgumentNullException("Zq");
     return Zq.GetElement(Convert.FromBase64String(encodedString));
 }
 /// <summary>
 ///  Generates a new, random, private key.
 /// </summary>
 /// <remarks>The random number generator used is the one associated
 ///  with <c>iep</c> (indirectly, via the <c>IssuerParamters</c>).
 ///  </remarks>
 public IDEscrowPrivateKey(IDEscrowParams iep)
 {
     UProveCrypto.Math.FieldZq F = iep.ip.Zq;
     x = F.GetRandomElement(true);
 }
 internal static FieldZqElement GenerateChallengeForDevice(FieldZq zq, HashFunction hash, byte[] md, byte[] mdPrime)
 {
     hash.Hash(md);
     hash.Hash(mdPrime);
     return zq.GetElementFromDigest(hash.Digest);
 }