/** * Normalization ensures that any projective coordinate is 1, and therefore that the x, y * coordinates reflect those of the equivalent point in an affine coordinate system. Where more * than one point is to be normalized, this method will generally be more efficient than * normalizing each point separately. An (optional) z-scaling factor can be applied; effectively * each z coordinate is scaled by this value prior to normalization (but only one * actual multiplication is needed). * * @param points * An array of points that will be updated in place with their normalized versions, * where necessary * @param off * The start of the range of points to normalize * @param len * The length of the range of points to normalize * @param iso * The (optional) z-scaling factor - can be null */ public virtual void NormalizeAll(ECPoint[] points, int off, int len, ECFieldElement iso) { CheckPoints(points, off, len); switch (this.CoordinateSystem) { case ECCurve.COORD_AFFINE: case ECCurve.COORD_LAMBDA_AFFINE: { if (iso != null) { throw new ArgumentException("not valid for affine coordinates", "iso"); } return; } } /* * Figure out which of the points actually need to be normalized */ ECFieldElement[] zs = new ECFieldElement[len]; int[] indices = new int[len]; int count = 0; for (int i = 0; i < len; ++i) { ECPoint p = points[off + i]; if (null != p && (iso != null || !p.IsNormalized())) { zs[count] = p.GetZCoord(0); indices[count++] = off + i; } } if (count == 0) { return; } ECAlgorithms.MontgomeryTrick(zs, 0, count, iso); for (int j = 0; j < count; ++j) { int index = indices[j]; points[index] = points[index].Normalize(zs[j]); } }
/** * Normalization ensures that any projective coordinate is 1, and therefore that the x, y * coordinates reflect those of the equivalent point in an affine coordinate system. Where more * than one point is to be normalized, this method will generally be more efficient than * normalizing each point separately. * * @param points * An array of points that will be updated in place with their normalized versions, * where necessary */ public virtual void NormalizeAll(ECPoint[] points) { CheckPoints(points); if (this.CoordinateSystem == ECCurve.COORD_AFFINE) { return; } /* * Figure out which of the points actually need to be normalized */ ECFieldElement[] zs = new ECFieldElement[points.Length]; int[] indices = new int[points.Length]; int count = 0; for (int i = 0; i < points.Length; ++i) { ECPoint p = points[i]; if (null != p && !p.IsNormalized()) { zs[count] = p.GetZCoord(0); indices[count++] = i; } } if (count == 0) { return; } ECAlgorithms.MontgomeryTrick(zs, 0, count); for (int j = 0; j < count; ++j) { int index = indices[j]; points[index] = points[index].Normalize(zs[j]); } }