pub struct RistrettoPoint(/* private fields */);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 RistrettoPoints are exactly as fast as operations on
EdwardsPoints.
Implementations§
Source§impl RistrettoPoint
impl RistrettoPoint
Sourcepub fn compress(&self) -> CompressedRistretto
pub fn compress(&self) -> CompressedRistretto
Compress this point using the Ristretto encoding.
theorem compress_spec (self : RistrettoPoint) (h : self.IsValid) :
compress self ⦃ (result : CompressedRistretto) =>
result.IsValid ∧
math.compress_pure self.toPoint = U8x32_as_Nat result ⦄
Sourcepub fn double_and_compress_batch<'a, I>(points: I) -> Vec<CompressedRistretto>where
I: IntoIterator<Item = &'a RistrettoPoint>,
Available on crate feature alloc and non-verify only.
pub fn double_and_compress_batch<'a, I>(points: I) -> Vec<CompressedRistretto>where
I: IntoIterator<Item = &'a RistrettoPoint>,
alloc and non-verify only.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.
theorem from_uniform_bytes_spec (bytes : Array U8 64#usize) :
from_uniform_bytes bytes ⦃ (result : RistrettoPoint) =>
result.IsValid ∧
result.toPoint =
(elligator_ristretto_flavor_pure (field_from_bytes (bytes_lower bytes))).val +
(elligator_ristretto_flavor_pure (field_from_bytes (bytes_upper bytes))).val ⦄
Source§impl RistrettoPoint
impl RistrettoPoint
Sourcepub fn mul_base(scalar: &Scalar) -> Self
pub fn mul_base(scalar: &Scalar) -> Self
Fixed-base scalar multiplication by the Ristretto base point.
Uses precomputed basepoint tables when the precomputed-tables feature
is enabled, trading off increased code size for ~4x better performance.
theorem mul_base_spec (s : scalar.Scalar) (h_s_canonical : U8x32_as_Nat s.bytes < 2 ^ 255) :
mul_base s ⦃ (result : RistrettoPoint) =>
result.IsValid ∧
result.toPoint = (U8x32_as_Nat s.bytes) • _root_.Edwards.basepoint ⦄
Source§impl RistrettoPoint
impl RistrettoPoint
Sourcepub fn vartime_double_scalar_mul_basepoint(
a: &Scalar,
A: &RistrettoPoint,
b: &Scalar,
) -> RistrettoPoint
Available on non-verify only.
pub fn vartime_double_scalar_mul_basepoint( a: &Scalar, A: &RistrettoPoint, b: &Scalar, ) -> RistrettoPoint
verify only.Compute \(aA + bB\) in variable time, where \(B\) is the Ristretto basepoint.
Trait Implementations§
Source§impl<'a> Add<&'a RistrettoPoint> for &RistrettoPoint
impl<'a> Add<&'a RistrettoPoint> for &RistrettoPoint
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
+ operator.Source§fn add(self, other: &'a RistrettoPoint) -> RistrettoPoint
fn add(self, other: &'a RistrettoPoint) -> RistrettoPoint
+ operation. Read moretheorem add_spec (self other : RistrettoPoint) (h_self_valid : self.IsValid)
(h_other_valid : other.IsValid) :
add self other ⦃ (result : RistrettoPoint) =>
result.IsValid ∧
result.toPoint = self.toPoint + other.toPoint ⦄
Source§impl<'b> Add<&'b RistrettoPoint> for RistrettoPoint
impl<'b> Add<&'b RistrettoPoint> for RistrettoPoint
Source§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
Source§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 for RistrettoPoint
impl Add for RistrettoPoint
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
+ operator.Source§fn add(self, rhs: RistrettoPoint) -> RistrettoPoint
fn add(self, rhs: RistrettoPoint) -> 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 AddAssign for RistrettoPoint
impl AddAssign 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);theorem conditional_select_spec (a b : RistrettoPoint) (choice : subtle.Choice) :
conditional_select a b choice ⦃ (result : RistrettoPoint) =>
result = if choice.val = 1#u8 then b else a ⦄
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self and other if choice == 1; otherwise,
reassign both unto themselves. Read moreSource§impl ConstantTimeEq for RistrettoPoint
impl ConstantTimeEq for RistrettoPoint
Source§fn ct_eq(&self, other: &RistrettoPoint) -> Choice
fn ct_eq(&self, other: &RistrettoPoint) -> Choice
Test equality between two RistrettoPoints.
§Returns
Choice(1)if the twoRistrettoPoints are equal;Choice(0)otherwise.
theorem ct_eq_spec (self other : RistrettoPoint)
(h_self_valid : self.IsValid)
(h_other_valid : other.IsValid) :
ct_eq self other ⦃ (result : subtle.Choice) =>
result = Choice.one ↔
(Field51_as_Nat self.X * Field51_as_Nat other.Y) ≡
(Field51_as_Nat self.Y * Field51_as_Nat other.X) [MOD p] ∨
(Field51_as_Nat self.X * Field51_as_Nat other.X) ≡
(Field51_as_Nat self.Y * Field51_as_Nat other.Y) [MOD p] ⦄
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
theorem identity_spec :
identity ⦃ (result : RistrettoPoint) =>
Field51_as_Nat result.X = 0 ∧
Field51_as_Nat result.Y = 1 ∧
Field51_as_Nat result.Z = 1 ∧
Field51_as_Nat result.T = 0 ⦄
Source§impl<'a> Mul<&'a RistrettoPoint> for &Scalar
impl<'a> Mul<&'a RistrettoPoint> for &Scalar
Source§fn mul(self, point: &'a RistrettoPoint) -> RistrettoPoint
fn mul(self, point: &'a RistrettoPoint) -> RistrettoPoint
Scalar multiplication: compute self * scalar.
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
* operator.Source§impl<'b> Mul<&'b RistrettoPoint> for Scalar
impl<'b> Mul<&'b RistrettoPoint> for Scalar
Source§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> Mul<&'a Scalar> for &RistrettoPoint
impl<'a> Mul<&'a Scalar> for &RistrettoPoint
Source§fn mul(self, scalar: &'a Scalar) -> RistrettoPoint
fn mul(self, scalar: &'a Scalar) -> RistrettoPoint
Scalar multiplication: compute scalar * self.
theorem mul_spec (self : RistrettoPoint) (scalar : scalar.Scalar)
(hscalar : U8x32_as_Nat scalar.bytes < 2 ^ 255) (hself : self.IsValid) :
mul self scalar ⦃ (result : RistrettoPoint) =>
result.IsValid ∧
result.toPoint = (U8x32_as_Nat scalar.bytes) • self.toPoint ⦄
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
* operator.Source§impl<'b> Mul<&'b Scalar> for RistrettoPoint
impl<'b> Mul<&'b Scalar> for RistrettoPoint
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
* operator.Source§impl<'a> Mul<RistrettoPoint> for &'a Scalar
impl<'a> Mul<RistrettoPoint> for &'a Scalar
Source§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
Source§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
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
* operator.Source§impl Mul<Scalar> for RistrettoPoint
impl Mul<Scalar> for RistrettoPoint
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
* operator.Source§impl<'a> MulAssign<&'a Scalar> for RistrettoPoint
impl<'a> MulAssign<&'a Scalar> for RistrettoPoint
Source§fn mul_assign(&mut self, scalar: &'a Scalar)
fn mul_assign(&mut self, scalar: &'a 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
Available on crate feature alloc only.
impl MultiscalarMul for RistrettoPoint
alloc only.Source§type Point = RistrettoPoint
type Point = RistrettoPoint
RistrettoPoint.Source§fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPoint
fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPoint
Source§impl Neg for &RistrettoPoint
impl Neg for &RistrettoPoint
Source§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
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
- operator.Source§fn neg(self) -> RistrettoPoint
fn neg(self) -> RistrettoPoint
- operation. Read moreSource§impl PartialEq for RistrettoPoint
impl PartialEq 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 ==.theorem eq_spec (self other : RistrettoPoint) (h_self_valid : self.IsValid)
(h_other_valid : other.IsValid) :
eq self other ⦃ (result : Bool) =>
(result = true ↔
(Field51_as_Nat self.X * Field51_as_Nat other.Y) ≡
(Field51_as_Nat self.Y * Field51_as_Nat other.X) [MOD p] ∨
(Field51_as_Nat self.X * Field51_as_Nat other.X) ≡
(Field51_as_Nat self.Y * Field51_as_Nat other.Y) [MOD p]) ⦄
Source§impl<'a> Sub<&'a RistrettoPoint> for &RistrettoPoint
impl<'a> Sub<&'a RistrettoPoint> for &RistrettoPoint
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
- operator.Source§fn sub(self, other: &'a RistrettoPoint) -> RistrettoPoint
fn sub(self, other: &'a RistrettoPoint) -> RistrettoPoint
- operation. Read moretheorem sub_spec (self other : RistrettoPoint) (h_self_valid : self.IsValid)
(h_other_valid : other.IsValid) :
sub self other ⦃ (result : RistrettoPoint) =>
result.IsValid ∧
result.toPoint = self.toPoint - other.toPoint ⦄
Source§impl<'b> Sub<&'b RistrettoPoint> for RistrettoPoint
impl<'b> Sub<&'b RistrettoPoint> for RistrettoPoint
Source§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
Source§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 for RistrettoPoint
impl Sub for RistrettoPoint
Source§type Output = RistrettoPoint
type Output = RistrettoPoint
- operator.Source§fn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
fn sub(self, rhs: RistrettoPoint) -> 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 SubAssign for RistrettoPoint
impl SubAssign 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
Available on crate feature alloc only.
impl VartimeMultiscalarMul for RistrettoPoint
alloc only.Source§type Point = RistrettoPoint
type Point = RistrettoPoint
RistrettoPoint.Source§fn optional_multiscalar_mul<I, J>(
scalars: I,
points: J,
) -> Option<RistrettoPoint>
fn optional_multiscalar_mul<I, J>( scalars: I, points: J, ) -> Option<RistrettoPoint>
Options 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 moreSource§fn vartime_multiscalar_mul<I, J>(scalars: I, points: J) -> Self::Pointwhere
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Self::Point>,
Self::Point: Clone,
fn vartime_multiscalar_mul<I, J>(scalars: I, points: J) -> Self::Pointwhere
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Self::Point>,
Self::Point: Clone,
Source§impl Zeroize for RistrettoPoint
Available on crate feature zeroize only.
impl Zeroize for RistrettoPoint
zeroize only.