Example #1
0
        /// <summary>
        /// Verifies that e is an element of the group.
        /// </summary>
        /// <param name="e">The element to test.</param>
        /// <exception cref="InvalidUProveArtifactException">
        /// Thrown if i is not in the group.</exception>
        public override void ValidateGroupElement(GroupElement e)
        {
            SubgroupGroupElementBCImpl sge = e as SubgroupGroupElementBCImpl;

            if (sge == null)
            {
                throw new InvalidUProveArtifactException(
                          "Invalid group element (wrong construction)");
            }

            // verify that 1 < g < p
            if (sge.i <= BCBigInt.One || sge.i >= pValue)
            {
                throw new InvalidUProveArtifactException(
                          "Invalid group element (out of range)");
            }

            // verify that g^q mod p = 1
            BCBigInt modpow = sge.i.ModPow(qValue, pValue);

            if (sge.i.ModPow(qValue, pValue) != BCBigInt.One)
            {
                throw new InvalidUProveArtifactException(
                          "Invalid group element (i^Q mod P != 1)");
            }
        }
        public override bool Equals(Object o)
        {
            if (o == null)
            {
                return(false);
            }

            SubgroupGroupElementBCImpl e = o as SubgroupGroupElementBCImpl;

            if (e == null)
            {
                return(false);
            }

            return(this.i == e.i && this.p == e.p);
        }