コード例 #1
0
        /// <summary>
        /// Creates an elliptic curve characteristic 2 finite
        /// field which has 2^{@code m} elements with
        /// polynomial basis.
        /// The reduction polynomial for this field is based
        /// on {@code rp} whose i-th bit corresponds to
        /// the i-th coefficient of the reduction polynomial.<para>
        /// Note: A valid reduction polynomial is either a
        /// trinomial (X^{@code m} + X^{@code k} + 1
        /// with {@code m} &gt; {@code k} &gt;= 1) or a
        /// pentanomial (X^{@code m} + X^{@code k3}
        /// + X^{@code k2} + X^{@code k1} + 1 with
        /// {@code m} &gt; {@code k3} &gt; {@code k2}
        /// &gt; {@code k1} &gt;= 1).
        /// </para>
        /// </summary>
        /// <param name="m"> with 2^{@code m} being the number of elements. </param>
        /// <param name="rp"> the BigInteger whose i-th bit corresponds to
        /// the i-th coefficient of the reduction polynomial. </param>
        /// <exception cref="NullPointerException"> if {@code rp} is null. </exception>
        /// <exception cref="IllegalArgumentException"> if {@code m}
        /// is not positive, or {@code rp} does not represent
        /// a valid reduction polynomial. </exception>
        public ECFieldF2m(int m, System.Numerics.BigInteger rp)
        {
            // check m and rp
            this.m  = m;
            this.Rp = rp;
            if (m <= 0)
            {
                throw new IllegalArgumentException("m is not positive");
            }
            int bitCount = this.Rp.bitCount();

            if (!this.Rp.testBit(0) || !this.Rp.testBit(m) || ((bitCount != 3) && (bitCount != 5)))
            {
                throw new IllegalArgumentException("rp does not represent a valid reduction polynomial");
            }
            // convert rp into ks
            System.Numerics.BigInteger temp = this.Rp.clearBit(0).clearBit(m);
            this.Ks = new int[bitCount - 2];
            for (int i = this.Ks.Length - 1; i >= 0; i--)
            {
                int index = temp.LowestSetBit;
                this.Ks[i] = index;
                temp       = temp.clearBit(index);
            }
        }