Exemplo n.º 1
0
		/**
		 * Adds another <code>ECPoints.F2m</code> to <code>this</code> without
		 * checking if both points are on the same curve. Used by multiplication
		 * algorithms, because there all points are a multiple of the same point
		 * and hence the checks can be omitted.
		 * @param b The other <code>ECPoints.F2m</code> to add to
		 * <code>this</code>.
		 * @return <code>this + b</code>
		 */
		internal F2mPoint AddSimple(F2mPoint b)
		{
			if (this.IsInfinity)
				return b;

			if (b.IsInfinity)
				return this;

			F2mFieldElement x2 = (F2mFieldElement) b.X;
			F2mFieldElement y2 = (F2mFieldElement) b.Y;

			// Check if b == this or b == -this
			if (this.x.Equals(x2))
			{
				// this == b, i.e. this must be doubled
				if (this.y.Equals(y2))
					return (F2mPoint) this.Twice();

				// this = -other, i.e. the result is the point at infinity
				return (F2mPoint) this.curve.Infinity;
			}

			ECFieldElement xSum = this.x.Add(x2);

			F2mFieldElement lambda
				= (F2mFieldElement)(this.y.Add(y2)).Divide(xSum);

			F2mFieldElement x3
				= (F2mFieldElement)lambda.Square().Add(lambda).Add(xSum).Add(this.curve.A);

			F2mFieldElement y3
				= (F2mFieldElement)lambda.Multiply(this.x.Add(x3)).Add(x3).Add(this.y);

			return new F2mPoint(curve, x3, y3, withCompression);
		}
Exemplo n.º 2
0
		/**
		 * Subtracts another <code>ECPoints.F2m</code> from <code>this</code>
		 * without checking if both points are on the same curve. Used by
		 * multiplication algorithms, because there all points are a multiple
		 * of the same point and hence the checks can be omitted.
		 * @param b The other <code>ECPoints.F2m</code> to subtract from
		 * <code>this</code>.
		 * @return <code>this - b</code>
		 */
		internal F2mPoint SubtractSimple(
			F2mPoint b)
		{
			if (b.IsInfinity)
				return this;

			// Add -b
			return AddSimple((F2mPoint) b.Negate());
		}
Exemplo n.º 3
0
		/**
		 * Constructor for Pentanomial Polynomial Basis (PPB).
		 * @param m  The exponent <code>m</code> of
		 * <code>F<sub>2<sup>m</sup></sub></code>.
		 * @param k1 The integer <code>k1</code> where <code>x<sup>m</sup> +
		 * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
		 * represents the reduction polynomial <code>f(z)</code>.
		 * @param k2 The integer <code>k2</code> where <code>x<sup>m</sup> +
		 * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
		 * represents the reduction polynomial <code>f(z)</code>.
		 * @param k3 The integer <code>k3</code> where <code>x<sup>m</sup> +
		 * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
		 * represents the reduction polynomial <code>f(z)</code>.
		 * @param a The coefficient <code>a</code> in the Weierstrass equation
		 * for non-supersingular elliptic curves over
		 * <code>F<sub>2<sup>m</sup></sub></code>.
		 * @param b The coefficient <code>b</code> in the Weierstrass equation
		 * for non-supersingular elliptic curves over
		 * <code>F<sub>2<sup>m</sup></sub></code>.
		 * @param n The order of the main subgroup of the elliptic curve.
		 * @param h The cofactor of the elliptic curve, i.e.
		 * <code>#E<sub>a</sub>(F<sub>2<sup>m</sup></sub>) = h * n</code>.
		 */
		public F2mCurve(
			int			m, 
			int			k1, 
			int			k2, 
			int			k3,
			BigInteger	a, 
			BigInteger	b,
			BigInteger	n,
			BigInteger	h)
		{
			this.m = m;
			this.k1 = k1;
			this.k2 = k2;
			this.k3 = k3;
			this.n = n;
			this.h = h;
			this.infinity = new F2mPoint(this, null, null);

			if (k1 == 0)
                throw new ArgumentException("k1 must be > 0");

			if (k2 == 0)
            {
                if (k3 != 0)
                    throw new ArgumentException("k3 must be 0 if k2 == 0");
            }
            else
            {
                if (k2 <= k1)
                    throw new ArgumentException("k2 must be > k1");

				if (k3 <= k2)
                    throw new ArgumentException("k3 must be > k2");
            }

			this.a = FromBigInteger(a);
            this.b = FromBigInteger(b);
        }