Skip to content
47 changes: 47 additions & 0 deletions 3ec_forms/chapter4.tex
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ \subsection{Point Arithmetic in Projective Coordinates}
While projective point addition requires more individual field operations than affine point addition, in the context of finite fields, a single modular inversion can cost as much as a hundred multiplications.
Eliminating the inversion therefore results in a substantial overall speedup.

\subsection{Converting Projective to Affine Coordinates in Rust}

After a sequence of projective point operations is complete, a single inversion, which was deferred throughout, converts the result back to affine coordinates:

\begin{listing}[H]
\caption{\texttt{From} trait implementation to convert a projective point to affine coordinates}
\begin{minted}{rust}
impl<F: Field, C: EllipticCurve<F>> From<ProjectiveEllipticCurvePoint<F, C>>
for AffineEllipticCurvePoint<F, C>
{
fn from(proj_pt: ProjectiveEllipticCurvePoint<F, C>) -> Self {
if let Some(z_inv) = proj_pt.z().multiplicative_inverse() {
Self::finite(&z_inv * proj_pt.x(), z_inv * proj_pt.y())
} else {
Self::point_at_infinity()
}
}
}
\end{minted}
\end{listing}

\section{Jacobian Coordinates}

Jacobian coordinates are another form that eliminates division from point arithmetic.
Expand Down Expand Up @@ -136,4 +157,30 @@ \subsection{Point Arithmetic in Jacobian Coordinates}
While both projective and Jacobian coordinates avoid costly inversions, the weighted mapping of Jacobian coordinates allows for even faster point doubling formulas.
This can improve efficiency of scalar multiplication, which relies heavily on point doubling.

\subsection{Converting Jacobian to Affine Coordinates in Rust}

After a sequence of point operations is complete, the resulting Jacobian point can be converted back to affine coordinates, requiring division by $Z^2$ and $Z^3$.
Since $Z^{-2}$ and $Z^{-3}$ can be derived from $Z^{-1}$ by multiplication, the library performs only one expensive inversion.
If $Z = 0$, no inverse exists, which identifies the point as the point at infinity $\mathcal{O}$:
\nopagebreak
\begin{listing}[H]
\caption{\texttt{From} trait implementation to convert a Jacobian point to affine coordinates}
\begin{minted}{rust}
impl<F: Field, C: EllipticCurve<F>> From<JacobianEllipticCurvePoint<F, C>>
for AffineEllipticCurvePoint<F, C>
{
fn from(jacobian_pt: JacobianEllipticCurvePoint<F, C>) -> Self {
if let Some(z_inv) = jacobian_pt.z().multiplicative_inverse() {
let zz_inv = &z_inv * &z_inv;
let zzz_inv = z_inv * &zz_inv;

Self::finite(zz_inv * jacobian_pt.x(), zzz_inv * jacobian_pt.y())
} else {
Self::point_at_infinity()
}
}
}
\end{minted}
\end{listing}

\end{document}