public void DivideTest() { ParameterSet parameters = ECParameterSets.ParamSet_EC_P256_V1; for (int i = 0; i < 10; ++i) { FieldZqElement a = parameters.Group.FieldZq.GetRandomElement(false); FieldZqElement b = parameters.Group.FieldZq.GetRandomElement(true); FieldZqElement c = a.Divide(b); Assert.AreEqual <FieldZqElement>(a * b.Invert(), c, "a.divide(b)."); FieldZqElement d = a / b; Assert.AreEqual <FieldZqElement>(c, d, "a / b"); } FieldZq Zq = FieldZq.CreateFieldZq(new byte[] { 0x05 }); Assert.AreEqual <FieldZqElement>(Zq.GetElement(4), Zq.GetElement(2) / Zq.GetElement(3), "2/3 = 4"); Assert.AreEqual <FieldZqElement>(Zq.GetElement(4), Zq.GetElement(1) / Zq.GetElement(4), "1/4 = 4"); Assert.AreEqual <FieldZqElement>(Zq.GetElement(1), Zq.GetElement(2) / Zq.GetElement(2), "2/3 = 1"); }
/// <summary> /// Constructs a new <code>Prover</code> instance. /// </summary> /// <param name="ip">The Issuer parameters.</param> /// <param name="numberOfTokens">Number of tokens to issue.</param> /// <param name="gamma">The gamma value encoding the token attributes. If <c>beta0</c> is non-null, then this value is blinded with <c>beta0</c>.</param> /// <param name="TI">The token information field value.</param> /// <param name="PI">The Prover information field value.</param> /// <param name="preGeneratedRandomData">Optional pregenerated ProverRandomData instance.</param> /// <param name="isDeviceProtected">True if the token is to be device-protected, false otherwise.</param> /// <param name="batchValidationSecurityLevel">The security level of the batch token signature validation. Given a security level <code>l</code>, /// the probability for the Prover to accept an invalid token is <code>2^-l</code>. If set to 0, than /// regular validation is used. A value of 20 is recommended.</param> /// <param name="beta0">Non-null if the input <c>gamma</c> value is blinded (collaborative issuance, i.e., the input <c>gamma</c> is blinded with beta0). /// This parameter defaults to null if ommitted. </param> internal Prover(IssuerParameters ip, int numberOfTokens, GroupElement gamma, byte[] TI, byte[] PI, ProverRandomData preGeneratedRandomData, bool isDeviceProtected, ushort batchValidationSecurityLevel, FieldZqElement beta0 = null) { if (ip == null) { throw new ArgumentNullException("ip"); } this.ip = ip; if (numberOfTokens <= 0) { throw new ArgumentException("numberOfTokens must be greater than 0"); } this.numberOfTokens = numberOfTokens; this.TI = TI; this.PI = PI; if (preGeneratedRandomData != null && (preGeneratedRandomData.Alpha.Length != numberOfTokens || preGeneratedRandomData.Beta1.Length != numberOfTokens || preGeneratedRandomData.Beta2.Length != numberOfTokens)) { throw new ArgumentException("invalid preGeneratedRandomData"); } this.isDeviceProtected = isDeviceProtected; this.batchValidationSecurityLevel = batchValidationSecurityLevel; this.gamma = gamma; if (beta0 != null) // inputs are blinded; collab issuance { this.beta0Inverse = beta0.Invert(); } else // no collab issuance { this.beta0Inverse = ip.Zq.One; } Precompute(gamma, preGeneratedRandomData); }