Struct curve25519_dalek::ristretto::RistrettoPoint
source · pub struct RistrettoPoint(_);
Expand description
A RistrettoPoint
represents a point in the Ristretto group for
Curve25519. Ristretto, a variant of Decaf, constructs a
prime-order group as a quotient group of a subgroup of (the
Edwards form of) Curve25519.
Internally, a RistrettoPoint
is implemented as a wrapper type
around EdwardsPoint
, with custom equality, compression, and
decompression routines to account for the quotient. This means that
operations on RistrettoPoint
s are exactly as fast as operations on
EdwardsPoint
s.
Implementations§
source§impl RistrettoPoint
impl RistrettoPoint
sourcepub fn compress(&self) -> CompressedRistretto
pub fn compress(&self) -> CompressedRistretto
Compress this point using the Ristretto encoding.
sourcepub fn double_and_compress_batch<'a, I>(points: I) -> Vec<CompressedRistretto>where
I: IntoIterator<Item = &'a RistrettoPoint>,
pub fn double_and_compress_batch<'a, I>(points: I) -> Vec<CompressedRistretto>where I: IntoIterator<Item = &'a RistrettoPoint>,
Double-and-compress a batch of points. The Ristretto encoding is not batchable, since it requires an inverse square root.
However, given input points \( P_1, \ldots, P_n, \) it is possible to compute the encodings of their doubles \( \mathrm{enc}( [2]P_1), \ldots, \mathrm{enc}( [2]P_n ) \) in a batch.
use rand_core::OsRng;
let mut rng = OsRng;
let points: Vec<RistrettoPoint> =
(0..32).map(|_| RistrettoPoint::random(&mut rng)).collect();
let compressed = RistrettoPoint::double_and_compress_batch(&points);
for (P, P2_compressed) in points.iter().zip(compressed.iter()) {
assert_eq!(*P2_compressed, (P + P).compress());
}
sourcepub fn from_uniform_bytes(bytes: &[u8; 64]) -> RistrettoPoint
pub fn from_uniform_bytes(bytes: &[u8; 64]) -> RistrettoPoint
Construct a RistrettoPoint
from 64 bytes of data.
If the input bytes are uniformly distributed, the resulting point will be uniformly distributed over the group, and its discrete log with respect to other points should be unknown.
Implementation
This function splits the input array into two 32-byte halves, takes the low 255 bits of each half mod p, applies the Ristretto-flavored Elligator map to each, and adds the results.
source§impl RistrettoPoint
impl RistrettoPoint
sourcepub fn vartime_double_scalar_mul_basepoint(
a: &Scalar,
A: &RistrettoPoint,
b: &Scalar
) -> RistrettoPoint
pub fn vartime_double_scalar_mul_basepoint( a: &Scalar, A: &RistrettoPoint, b: &Scalar ) -> RistrettoPoint
Compute \(aA + bB\) in variable time, where \(B\) is the Ristretto basepoint.
Trait Implementations§
source§impl<'a, 'b> Add<&'b RistrettoPoint> for &'a RistrettoPoint
impl<'a, 'b> Add<&'b RistrettoPoint> for &'a RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
+
operator.source§fn add(self, other: &'b RistrettoPoint) -> RistrettoPoint
fn add(self, other: &'b RistrettoPoint) -> RistrettoPoint
+
operation. Read moresource§impl<'b> Add<&'b RistrettoPoint> for RistrettoPoint
impl<'b> Add<&'b RistrettoPoint> for RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
+
operator.source§fn add(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
fn add(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
+
operation. Read moresource§impl<'a> Add<RistrettoPoint> for &'a RistrettoPoint
impl<'a> Add<RistrettoPoint> for &'a RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
+
operator.source§fn add(self, rhs: RistrettoPoint) -> RistrettoPoint
fn add(self, rhs: RistrettoPoint) -> RistrettoPoint
+
operation. Read moresource§impl Add<RistrettoPoint> for RistrettoPoint
impl Add<RistrettoPoint> for RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
+
operator.source§fn add(self, rhs: RistrettoPoint) -> RistrettoPoint
fn add(self, rhs: RistrettoPoint) -> RistrettoPoint
+
operation. Read moresource§impl<'b> AddAssign<&'b RistrettoPoint> for RistrettoPoint
impl<'b> AddAssign<&'b RistrettoPoint> for RistrettoPoint
source§fn add_assign(&mut self, _rhs: &RistrettoPoint)
fn add_assign(&mut self, _rhs: &RistrettoPoint)
+=
operation. Read moresource§impl AddAssign<RistrettoPoint> for RistrettoPoint
impl AddAssign<RistrettoPoint> for RistrettoPoint
source§fn add_assign(&mut self, rhs: RistrettoPoint)
fn add_assign(&mut self, rhs: RistrettoPoint)
+=
operation. Read moresource§impl Clone for RistrettoPoint
impl Clone for RistrettoPoint
source§fn clone(&self) -> RistrettoPoint
fn clone(&self) -> RistrettoPoint
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl ConditionallySelectable for RistrettoPoint
impl ConditionallySelectable for RistrettoPoint
source§fn conditional_select(
a: &RistrettoPoint,
b: &RistrettoPoint,
choice: Choice
) -> RistrettoPoint
fn conditional_select( a: &RistrettoPoint, b: &RistrettoPoint, choice: Choice ) -> RistrettoPoint
Conditionally select between self
and other
.
Example
use subtle::ConditionallySelectable;
use subtle::Choice;
let A = RistrettoPoint::identity();
let B = constants::RISTRETTO_BASEPOINT_POINT;
let mut P = A;
P = RistrettoPoint::conditional_select(&A, &B, Choice::from(0));
assert_eq!(P, A);
P = RistrettoPoint::conditional_select(&A, &B, Choice::from(1));
assert_eq!(P, B);
source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
source§impl ConstantTimeEq for RistrettoPoint
impl ConstantTimeEq for RistrettoPoint
source§impl Debug for RistrettoPoint
impl Debug for RistrettoPoint
source§impl Default for RistrettoPoint
impl Default for RistrettoPoint
source§fn default() -> RistrettoPoint
fn default() -> RistrettoPoint
source§impl Identity for RistrettoPoint
impl Identity for RistrettoPoint
source§fn identity() -> RistrettoPoint
fn identity() -> RistrettoPoint
source§impl<'a, 'b> Mul<&'b RistrettoPoint> for &'a Scalar
impl<'a, 'b> Mul<&'b RistrettoPoint> for &'a Scalar
source§fn mul(self, point: &'b RistrettoPoint) -> RistrettoPoint
fn mul(self, point: &'b RistrettoPoint) -> RistrettoPoint
Scalar multiplication: compute self * scalar
.
§type Output = RistrettoPoint
type Output = RistrettoPoint
*
operator.source§impl<'b> Mul<&'b RistrettoPoint> for Scalar
impl<'b> Mul<&'b RistrettoPoint> for Scalar
§type Output = RistrettoPoint
type Output = RistrettoPoint
*
operator.source§fn mul(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
fn mul(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
*
operation. Read moresource§impl<'a, 'b> Mul<&'b Scalar> for &'a RistrettoPoint
impl<'a, 'b> Mul<&'b Scalar> for &'a RistrettoPoint
source§fn mul(self, scalar: &'b Scalar) -> RistrettoPoint
fn mul(self, scalar: &'b Scalar) -> RistrettoPoint
Scalar multiplication: compute scalar * self
.
§type Output = RistrettoPoint
type Output = RistrettoPoint
*
operator.source§impl<'b> Mul<&'b Scalar> for RistrettoPoint
impl<'b> Mul<&'b Scalar> for RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
*
operator.source§impl<'a> Mul<RistrettoPoint> for &'a Scalar
impl<'a> Mul<RistrettoPoint> for &'a Scalar
§type Output = RistrettoPoint
type Output = RistrettoPoint
*
operator.source§fn mul(self, rhs: RistrettoPoint) -> RistrettoPoint
fn mul(self, rhs: RistrettoPoint) -> RistrettoPoint
*
operation. Read moresource§impl Mul<RistrettoPoint> for Scalar
impl Mul<RistrettoPoint> for Scalar
§type Output = RistrettoPoint
type Output = RistrettoPoint
*
operator.source§fn mul(self, rhs: RistrettoPoint) -> RistrettoPoint
fn mul(self, rhs: RistrettoPoint) -> RistrettoPoint
*
operation. Read moresource§impl<'a> Mul<Scalar> for &'a RistrettoPoint
impl<'a> Mul<Scalar> for &'a RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
*
operator.source§impl Mul<Scalar> for RistrettoPoint
impl Mul<Scalar> for RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
*
operator.source§impl<'b> MulAssign<&'b Scalar> for RistrettoPoint
impl<'b> MulAssign<&'b Scalar> for RistrettoPoint
source§fn mul_assign(&mut self, scalar: &'b Scalar)
fn mul_assign(&mut self, scalar: &'b Scalar)
*=
operation. Read moresource§impl MulAssign<Scalar> for RistrettoPoint
impl MulAssign<Scalar> for RistrettoPoint
source§fn mul_assign(&mut self, rhs: Scalar)
fn mul_assign(&mut self, rhs: Scalar)
*=
operation. Read moresource§impl MultiscalarMul for RistrettoPoint
impl MultiscalarMul for RistrettoPoint
§type Point = RistrettoPoint
type Point = RistrettoPoint
RistrettoPoint
.source§fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPointwhere
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<RistrettoPoint>,
fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPointwhere I: IntoIterator, I::Item: Borrow<Scalar>, J: IntoIterator, J::Item: Borrow<RistrettoPoint>,
source§impl<'a> Neg for &'a RistrettoPoint
impl<'a> Neg for &'a RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
-
operator.source§fn neg(self) -> RistrettoPoint
fn neg(self) -> RistrettoPoint
-
operation. Read moresource§impl Neg for RistrettoPoint
impl Neg for RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
-
operator.source§fn neg(self) -> RistrettoPoint
fn neg(self) -> RistrettoPoint
-
operation. Read moresource§impl PartialEq<RistrettoPoint> for RistrettoPoint
impl PartialEq<RistrettoPoint> for RistrettoPoint
source§fn eq(&self, other: &RistrettoPoint) -> bool
fn eq(&self, other: &RistrettoPoint) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a, 'b> Sub<&'b RistrettoPoint> for &'a RistrettoPoint
impl<'a, 'b> Sub<&'b RistrettoPoint> for &'a RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
-
operator.source§fn sub(self, other: &'b RistrettoPoint) -> RistrettoPoint
fn sub(self, other: &'b RistrettoPoint) -> RistrettoPoint
-
operation. Read moresource§impl<'b> Sub<&'b RistrettoPoint> for RistrettoPoint
impl<'b> Sub<&'b RistrettoPoint> for RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
-
operator.source§fn sub(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
fn sub(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
-
operation. Read moresource§impl<'a> Sub<RistrettoPoint> for &'a RistrettoPoint
impl<'a> Sub<RistrettoPoint> for &'a RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
-
operator.source§fn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
fn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
-
operation. Read moresource§impl Sub<RistrettoPoint> for RistrettoPoint
impl Sub<RistrettoPoint> for RistrettoPoint
§type Output = RistrettoPoint
type Output = RistrettoPoint
-
operator.source§fn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
fn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
-
operation. Read moresource§impl<'b> SubAssign<&'b RistrettoPoint> for RistrettoPoint
impl<'b> SubAssign<&'b RistrettoPoint> for RistrettoPoint
source§fn sub_assign(&mut self, _rhs: &RistrettoPoint)
fn sub_assign(&mut self, _rhs: &RistrettoPoint)
-=
operation. Read moresource§impl SubAssign<RistrettoPoint> for RistrettoPoint
impl SubAssign<RistrettoPoint> for RistrettoPoint
source§fn sub_assign(&mut self, rhs: RistrettoPoint)
fn sub_assign(&mut self, rhs: RistrettoPoint)
-=
operation. Read moresource§impl<T> Sum<T> for RistrettoPointwhere
T: Borrow<RistrettoPoint>,
impl<T> Sum<T> for RistrettoPointwhere T: Borrow<RistrettoPoint>,
source§impl VartimeMultiscalarMul for RistrettoPoint
impl VartimeMultiscalarMul for RistrettoPoint
§type Point = RistrettoPoint
type Point = RistrettoPoint
RistrettoPoint
.source§fn optional_multiscalar_mul<I, J>(
scalars: I,
points: J
) -> Option<RistrettoPoint>where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator<Item = Option<RistrettoPoint>>,
fn optional_multiscalar_mul<I, J>( scalars: I, points: J ) -> Option<RistrettoPoint>where I: IntoIterator, I::Item: Borrow<Scalar>, J: IntoIterator<Item = Option<RistrettoPoint>>,
Option
s of points, compute either Some(Q)
, where
$$
Q = c_1 P_1 + \cdots + c_n P_n,
$$
if all points were Some(P_i)
, or else return None
. Read more