Elliptic Curve Arithmetic

Types

BinaryECC.ECType
EC{B}

Represents a non-supersingular elliptic curve over the binary field B.

Contains fields a::B and b::B, where:

$y^2 + xy = x^3 + ax^2 + b$

source
BinaryECC.ECPointAffineType
ECPointAffine{B} <: AbstractECPoint{B}

Represents a point on an elliptic curve over the binary B. Contains fields x::B, y::B, and ec::EC{B}.

$E: y^2 + xy = x^3 + ax^2 + b$

source
BinaryECC.ECPointJacobianType
ECPointJacobian{B} <: AbstractECPoint{B}

Represents a point on an elliptic curve over the binary B. Contains fields x::B, y::B, z::B and ec::EC{B}.

$E: y^2 + xyz = x^3 + ax^2z^2 + bz^6$

Each point $(x, y)$ on the curve is represented by a set of equivalent Jacobian points, $\{(\lambda^2 x, \lambda^3 y, \lambda) : \lambda \in K^* \}$ (where $K^*$ is the binary field that the curve is based on).

source
BinaryECC.ECPointLDType
ECPointLD{B} <: AbstractECPoint{B}

Represents a point on an elliptic curve over the binary B. Contains fields x::B, y::B, z::B and ec::EC{B}.

$E: y^2 + xyz = x^3z + ax^2z^2 + bz^4$

Each (affine) point $(x, y)$ is represented by a set of Lopez-Dahab points, $\{(\lambda x, \lambda^2 y, \lambda) : \lambda \in K^* \}$ (where $K^*$ is the binary field that the curve is based on).

source

Curve Functions

Base.:==Method
==(ec1::EC{B}, ec2::EC{B}) where B

Two elliptic curves are equal if they have the same parameters a and b, and are defined over the same field.

source
Base.reprMethod
repr(ec::EC)

Returns a string representation of an elliptic curve equation, "$y^2 + xy = x^3 + ax^2 + b$".

source

Point Arithmetic

Base.:==Method
==(p1::ECPointAffine{B}, p2::ECPointAffine{B}) where B

Two points are equal iff they have the same $x$ and $y$ coordinate, and are on the same elliptic curve.

source
Base.:+Method
+(p1::ECPointAffine{B}, p2::ECPointAffine{B}) where B

Returns $p_1+p_2$.

If the points are not on the same curve, this will throw an ECMismatchException.

source
BinaryECC.doubleMethod
double(p::ECPointAffine{B})::ECPointAffine{B} where B

Returns the result of doubling the point p, using a standard method that assumes p is a random unknown point.

source
Base.:-Method
-(p::ECPointAffine{B}) where B

Returns additive inverse of the given point, $-p$.

source
Base.:-Method
-(p1::AbstractECPoint, p2::AbstractECPoint)

Returns $p_1-p_2$.

source
Base.:*Method
*(p::AbstractECPoint{B}, k) where B

Returns the result of the scalar multiplication $p \cdot k$, using a default high performance method. Commutative, so that either p * k or k * p can be written, in addition to p \cdot k or k \cdot p. k must be an integer or a PFieldElt.

source

Scalar Point Addition

BinaryECC.double_standardMethod
double_standard(p::ECPointAffine{B})::ECPointAffine{B} where B

Performs a standard version of the point doubling routine.

source
BinaryECC.double_memoMethod
double_memo(p::ECPointAffine{B})::ECPointAffine{B} where B

Performs memoised point doubling: if the point p has previously been calculated by this routine, it will be fetched from a dictionary rather than recalculated. If the point has not yet been seen, it will be doubled with the double_standard routine and stored into a dictionary.

source
BinaryECC.double_threadedMethod
double_threaded(p::ECPointAffine{B})::ECPointAffine{B} where B

Doubles the point p by spawning an additional thread to perform extra work on.

source

Scalar Point Multiplication

BinaryECC.mult_standard_rtlMethod
mult_standard_rtl(P::AbstractECPoint{B}, k::Integer) where B

Performs scalar point multiplication using a right-to-left double-and-add method.

source
BinaryECC.mult_standard_ltrMethod
mult_standard_ltr(P::AbstractECPoint{B}, k::Integer) where B

Performs scalar point multiplication using a left-to-right double-and-add method.

source
BinaryECC.mult_windowMethod
mult_window(P::AbstractECPoint{B}, k::Integer, w::Int) where B

Performs scalar point multiplication using a windowed left-to-right double-and-add method.

source
BinaryECC.mult_bnafMethod
mult_bnaf(P::AbstractECPoint{B}, k::Integer) where B

Performs scalar point multiplication using a right-to-left double-and-add method with the binary NAF of k.

source
BinaryECC.mult_memoMethod
mult_memo(P::AbstractECPoint{B}, k::Integer) where B

Performs scalar point multiplication using a right-to-left double-and-add method with the binary NAF of k. This function uses the memoised point doubling routine double_memo, and so it should only called with a known point P (i.e. one which will likely be seen again, such as a generating point).

source
BinaryECC.mult_bnaf_threadedMethod
mult_bnaf_threaded(P::AbstractECPoint{B}, k::Integer) where B

Performs scalar point multiplication using a right-to-left double-and-add method with the binary NAF of k, by spawning an extra thread where useful.

source
BinaryECC.mult_bnaf_windowMethod
mult_bnaf_window(P::AbstractECPoint{B}, k::Integer, w::Int) where B

Performs scalar point multiplication using a windowed left-to-right double-and-add method with the binary NAF of k. Performs best with a window size of 8.

source
BinaryECC.mult_wnafMethod
mult_wnaf(P::AbstractECPoint{B}, k::Integer, w::Int) where B

Performs scalar point multiplication using a left-to-right double-and-add method with the width-w NAF of k. Performs best with a width of 6.

source
BinaryECC.mult_mont_generalMethod
mult_mont_general(p::AbstractECPoint, n::Integer)

Performs $p \cdot n$ with a fixed sequence of curve and field operations. More resistant to timing attacks than the standard double and add algorithm.

source
BinaryECC.mult_mont_affineMethod
mult_mont_affine(p::ECPointAffine{B}, n::Integer) where B

Returns $p \cdot n$.

More resistant to timing attacks than the standard double and add algorithm.

Fast Multiplication on Elliptic Curves over $GF(2^m)$ without Precomputation, Algorithm 2A: Montgomery Scalar Multiplication.

source

Additive Identity

Base.iszeroMethod
iszero(p::ECPointAffine)

Returns true if $p = \mathcal{O}$, i.e it is the point at infinity.

source
Base.zeroMethod
zero(::Type{ECPointAffine{B}, ec::EC{B}) where B

Returns an object representing the point at infinity on the given curve.

source
Base.zeroMethod
zero(::Type{ECPointAffine, ec::EC{B}) where B

Returns an object representing the point at infinity on the given curve.

source
Base.iszeroMethod
iszero(p::ECPointJacobian)

Returns true if $p = \mathcal{O}$, i.e it is the point at infinity.

source
Base.zeroMethod
zero(::Type{ECPointJacobian{B}}, ec::EC{B}) where B

Returns an object representing the point at infinity on the given curve.

source
Base.zeroMethod
zero(::Type{ECPointJacobian}, ec::EC{B}) where B

Returns an object representing the point at infinity on the given curve.

source
Base.iszeroMethod
iszero(p::ECPointLD)

Returns true if $p = \mathcal{O}$, i.e it is the point at infinity.

source
Base.zeroMethod
zero(::Type{ECPointLD{B}}, ec::EC{B}) where B

Returns an object representing the point at infinity on the given curve.

source
Base.zeroMethod
zero(::Type{ECPointLD}, ec::EC{B}) where B

Returns an object representing the point at infinity on the given curve.

source

Mixed Representation Functions

Base.:+Method
+(::Type{ECPointJacobian{B}}, p1::ECPointLD{B}, p2::ECPointJacobian{B}) where B

Returns $p_1 +p_2$ in Jacobian coordinates.

source
Base.:+Method
+(::Type{ECPointJacobian{B}}, p1::ECPointJacobian{B}, p2::ECPointLD{B}) where B

Returns $p_1 +p_2$ in Jacobian coordinates.

source
Base.:+Method
+(::Type{ECPointLD{B}}, p1::ECPointLD{B}, p2::ECPointJacobian{B}) where B

Returns $p_1 +p_2$ in Lopez-Dahab coordinates.

source
Base.:+Method
+(::Type{ECPointLD{B}}, p1::ECPointJacobian{B}, p2::ECPointLD{B}) where B

Returns $p_1 +p_2$ in Lopez-Dahab coordinates.

source
Base.convertMethod
convert(::Type{ECPointAffine}, p::ECPointJacobian{B}) where B

Converts a point from Jacobian coordinates to affine coordinates.

source
Base.convertMethod
convert(::Type{ECPointAffine}, p::ECPointLD{B}) where B

Converts a point from Lopez-Dahab coordinates to affine coordinates.

source
Base.convertMethod
convert(::Type{ECPointJacobian}, p::ECPointAffine{B}) where B

Converts a point from affine coordinates to Jacobian coordinates.

source
Base.convertMethod
convert(::Type{ECPointJacobian}, p::ECPointLD{B}) where B

Converts a point from Lopez-Dahab coordinates to Jacobian coordinates.

source
Base.convertMethod
convert(::Type{ECPointLD}, p::ECPointAffine{B}) where B

Converts a point from affine coordinates to Lopez-Dahab coordinates.

source
Base.convertMethod
convert(::Type{ECPointLD}, p::ECPointJacobian{B}) where B

Converts a point from Jacobian coordinates to Lopez-Dahab coordinates.

source

Miscellaneous Point Functions

BinaryECC.ECPointAffineMethod
ECPointAffine(s::String, ec::EC{B}) where B

Convert a hex string to a point on the given elliptic curve using the procedure in SEC 2 (version 2), section 2.3.4.

source
Base.isvalidMethod
isvalid(p::ECPointAffine)

Returns true if p is a point on the elliptic curve that it is associated with.

source
Base.reprMethod
repr(p::ECPointAffine)

Returns a string representation of an elliptic curve point, i.e. "$(x, y)$".

source
Base.reprMethod
repr(p::ECPointJacobian)

Returns a string representation of an elliptic curve point, "$(x, y, z)$".

source
Base.reprMethod
repr(p::ECPointLD)

Returns a string representation of an elliptic curve point, "$(x, y, z)$".

source
BinaryECC.nafFunction
naf(k::T) where T<:Integer

Computes the binary NAF of an integer k.

source
naf(k::Integer, w::Int)

Computes the width-w NAF of integer k.

source