embassy-crypto

Crates

git

Versions

default

Flavors

Skip to main content

P384Arith

Trait P384Arith 

Source
pub trait P384Arith {
    type Point: Copy + Send + Sync;

Show 15 methods // Required methods fn scalar_add(a: &P384Scalar, b: &P384Scalar) -> P384Scalar; fn scalar_sub(a: &P384Scalar, b: &P384Scalar) -> P384Scalar; fn scalar_mul(a: &P384Scalar, b: &P384Scalar) -> P384Scalar; fn scalar_invert(a: &P384Scalar) -> P384Scalar; fn point_identity() -> Self::Point; fn point_from_affine(p: &P384Point) -> Option<Self::Point>; fn point_from_affine_unchecked(p: &P384Point) -> Self::Point; fn point_to_affine(p: &Self::Point) -> Option<P384Point>; fn point_is_identity(p: &Self::Point) -> bool; fn point_neg(p: &Self::Point) -> Self::Point; fn point_add(p: &Self::Point, q: &Self::Point) -> Self::Point; fn point_mul(k: &P384Scalar, p: &Self::Point) -> Self::Point; fn point_mul_base(k: &P384Scalar) -> Self::Point; fn point_lincomb( a: &P384Scalar, p: &Self::Point, b: &P384Scalar, q: &Self::Point, ) -> Self::Point; fn point_lincomb_vartime( a: &P384Scalar, p: &Self::Point, b: &P384Scalar, q: &Self::Point, ) -> Self::Point;
}
Expand description

P-384 (secp384r1) scalar and point arithmetic driver.

§Contract

  • Scalars are canonical, in [0, n); results are canonical too.
  • All operations must be constant-time, except those with a _vartime suffix.

Required Associated Types§

Source

type Point: Copy + Send + Sync

Opaque storage for the implementation’s point representation.

Implementations pick whatever their arithmetic works in (projective or Jacobian coordinates, …), so a chain of operations pays for the conversion to affine coordinates once, in point_to_affine.

Required Methods§

Source

fn scalar_add(a: &P384Scalar, b: &P384Scalar) -> P384Scalar

a + b mod n.

Source

fn scalar_sub(a: &P384Scalar, b: &P384Scalar) -> P384Scalar

a - b mod n.

Source

fn scalar_mul(a: &P384Scalar, b: &P384Scalar) -> P384Scalar

a * b mod n.

Source

fn scalar_invert(a: &P384Scalar) -> P384Scalar

a^-1 mod n. a is nonzero.

Source

fn point_identity() -> Self::Point

The identity (the point at infinity).

Source

fn point_from_affine(p: &P384Point) -> Option<Self::Point>

Import an affine point, checking that it is on the curve.

Returns None if p is not on the curve.

Source

fn point_from_affine_unchecked(p: &P384Point) -> Self::Point

Import an affine point without checking that it is on the curve.

p must be a valid point on the curve. Passing an invalid point may panic, hang, or produce wrong results, including ones that compromise security.

Source

fn point_to_affine(p: &Self::Point) -> Option<P384Point>

The affine coordinates of p, or None for the identity.

Source

fn point_is_identity(p: &Self::Point) -> bool

Whether p is the identity.

Source

fn point_neg(p: &Self::Point) -> Self::Point

-p.

Source

fn point_add(p: &Self::Point, q: &Self::Point) -> Self::Point

p + q, for any p and q: equal, opposite or the identity included.

Source

fn point_mul(k: &P384Scalar, p: &Self::Point) -> Self::Point

k * p.

Source

fn point_mul_base(k: &P384Scalar) -> Self::Point

k * G for the curve’s base point G.

Source

fn point_lincomb( a: &P384Scalar, p: &Self::Point, b: &P384Scalar, q: &Self::Point, ) -> Self::Point

a * p + b * q.

Scalars may be secret. Implementations may share the doublings between the terms (Strauss’s algorithm) as long as the timing does not depend on the scalars.

Source

fn point_lincomb_vartime( a: &P384Scalar, p: &Self::Point, b: &P384Scalar, q: &Self::Point, ) -> Self::Point

a * p + b * q for public values.

What ECDSA verification needs. Implementations may use variable-time algorithms (Shamir’s trick with a signed-digit recoding, …).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§