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
sourceimpl 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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
where
I: IntoIterator<Item = &'a RistrettoPoint>,
pub fn double_and_compress_batch<'a, I>(points: I) -> Vec<CompressedRistretto>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
where
I: IntoIterator<Item = &'a RistrettoPoint>,
A: Allocator,
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.
extern crate rand_core;
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 random<R: RngCore + CryptoRng>(rng: &mut R) -> Self
pub fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self
Return a RistrettoPoint
chosen uniformly at random using a user-provided RNG.
Inputs
rng
: any RNG which implements theRngCore + CryptoRng
interface.
Returns
A random element of the Ristretto group.
Implementation
Uses the Ristretto-flavoured Elligator 2 map, so that the discrete log of the output point with respect to any other point should be unknown. The map is applied twice and the results are added, to ensure a uniform distribution.
sourcepub fn hash_from_bytes<D>(input: &[u8]) -> RistrettoPoint where
D: Digest<OutputSize = U64> + Default,
pub fn hash_from_bytes<D>(input: &[u8]) -> RistrettoPoint where
D: Digest<OutputSize = U64> + Default,
Hash a slice of bytes into a RistrettoPoint
.
Takes a type parameter D
, which is any Digest
producing 64
bytes of output.
Convenience wrapper around from_hash
.
Implementation
Uses the Ristretto-flavoured Elligator 2 map, so that the discrete log of the output point with respect to any other point should be unknown. The map is applied twice and the results are added, to ensure a uniform distribution.
Example
extern crate sha2;
use sha2::Sha512;
let msg = "To really appreciate architecture, you may even need to commit a murder";
let P = RistrettoPoint::hash_from_bytes::<Sha512>(msg.as_bytes());
sourcepub fn from_hash<D>(hash: D) -> RistrettoPoint where
D: Digest<OutputSize = U64> + Default,
pub fn from_hash<D>(hash: D) -> RistrettoPoint where
D: Digest<OutputSize = U64> + Default,
Construct a RistrettoPoint
from an existing Digest
instance.
Use this instead of hash_from_bytes
if it is more convenient
to stream data into the Digest
than to pass a single byte
slice.
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.
sourceimpl 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
sourceimpl<'a, 'b> Add<&'b RistrettoPoint> for &'a RistrettoPoint
impl<'a, 'b> Add<&'b RistrettoPoint> for &'a RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the +
operator.
sourcefn add(self, other: &'b RistrettoPoint) -> RistrettoPoint
fn add(self, other: &'b RistrettoPoint) -> RistrettoPoint
Performs the +
operation. Read more
sourceimpl<'b> Add<&'b RistrettoPoint> for RistrettoPoint
impl<'b> Add<&'b RistrettoPoint> for RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the +
operator.
sourcefn add(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
fn add(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
Performs the +
operation. Read more
sourceimpl<'a> Add<RistrettoPoint> for &'a RistrettoPoint
impl<'a> Add<RistrettoPoint> for &'a RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the +
operator.
sourcefn add(self, rhs: RistrettoPoint) -> RistrettoPoint
fn add(self, rhs: RistrettoPoint) -> RistrettoPoint
Performs the +
operation. Read more
sourceimpl Add<RistrettoPoint> for RistrettoPoint
impl Add<RistrettoPoint> for RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the +
operator.
sourcefn add(self, rhs: RistrettoPoint) -> RistrettoPoint
fn add(self, rhs: RistrettoPoint) -> RistrettoPoint
Performs the +
operation. Read more
sourceimpl<'b> AddAssign<&'b RistrettoPoint> for RistrettoPoint
impl<'b> AddAssign<&'b RistrettoPoint> for RistrettoPoint
sourcefn add_assign(&mut self, _rhs: &RistrettoPoint)
fn add_assign(&mut self, _rhs: &RistrettoPoint)
Performs the +=
operation. Read more
sourceimpl AddAssign<RistrettoPoint> for RistrettoPoint
impl AddAssign<RistrettoPoint> for RistrettoPoint
sourcefn add_assign(&mut self, rhs: RistrettoPoint)
fn add_assign(&mut self, rhs: RistrettoPoint)
Performs the +=
operation. Read more
sourceimpl Clone for RistrettoPoint
impl Clone for RistrettoPoint
sourcefn clone(&self) -> RistrettoPoint
fn clone(&self) -> RistrettoPoint
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl ConditionallySelectable for RistrettoPoint
impl ConditionallySelectable for RistrettoPoint
sourcefn 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);
sourcefn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Conditionally assign other
to self
, according to choice
. Read more
sourceimpl ConstantTimeEq for RistrettoPoint
impl ConstantTimeEq for RistrettoPoint
sourcefn ct_eq(&self, other: &RistrettoPoint) -> Choice
fn ct_eq(&self, other: &RistrettoPoint) -> Choice
Test equality between two RistrettoPoint
s.
Returns
Choice(1)
if the twoRistrettoPoint
s are equal;Choice(0)
otherwise.
sourceimpl Debug for RistrettoPoint
impl Debug for RistrettoPoint
sourceimpl Default for RistrettoPoint
impl Default for RistrettoPoint
sourcefn default() -> RistrettoPoint
fn default() -> RistrettoPoint
Returns the “default value” for a type. Read more
sourceimpl Identity for RistrettoPoint
impl Identity for RistrettoPoint
sourcefn identity() -> RistrettoPoint
fn identity() -> RistrettoPoint
Returns the identity element of the curve. Can be used as a constructor. Read more
sourceimpl<'a, 'b> Mul<&'b RistrettoPoint> for &'a Scalar
impl<'a, 'b> Mul<&'b RistrettoPoint> for &'a Scalar
sourcefn mul(self, point: &'b RistrettoPoint) -> RistrettoPoint
fn mul(self, point: &'b RistrettoPoint) -> RistrettoPoint
Scalar multiplication: compute self * scalar
.
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the *
operator.
sourceimpl<'b> Mul<&'b RistrettoPoint> for Scalar
impl<'b> Mul<&'b RistrettoPoint> for Scalar
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the *
operator.
sourcefn mul(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
fn mul(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
Performs the *
operation. Read more
sourceimpl<'a, 'b> Mul<&'b Scalar> for &'a RistrettoPoint
impl<'a, 'b> Mul<&'b Scalar> for &'a RistrettoPoint
sourcefn mul(self, scalar: &'b Scalar) -> RistrettoPoint
fn mul(self, scalar: &'b Scalar) -> RistrettoPoint
Scalar multiplication: compute scalar * self
.
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the *
operator.
sourceimpl<'b> Mul<&'b Scalar> for RistrettoPoint
impl<'b> Mul<&'b Scalar> for RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the *
operator.
sourcefn mul(self, rhs: &'b Scalar) -> RistrettoPoint
fn mul(self, rhs: &'b Scalar) -> RistrettoPoint
Performs the *
operation. Read more
sourceimpl<'a> Mul<RistrettoPoint> for &'a Scalar
impl<'a> Mul<RistrettoPoint> for &'a Scalar
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the *
operator.
sourcefn mul(self, rhs: RistrettoPoint) -> RistrettoPoint
fn mul(self, rhs: RistrettoPoint) -> RistrettoPoint
Performs the *
operation. Read more
sourceimpl Mul<RistrettoPoint> for Scalar
impl Mul<RistrettoPoint> for Scalar
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the *
operator.
sourcefn mul(self, rhs: RistrettoPoint) -> RistrettoPoint
fn mul(self, rhs: RistrettoPoint) -> RistrettoPoint
Performs the *
operation. Read more
sourceimpl<'a> Mul<Scalar> for &'a RistrettoPoint
impl<'a> Mul<Scalar> for &'a RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the *
operator.
sourcefn mul(self, rhs: Scalar) -> RistrettoPoint
fn mul(self, rhs: Scalar) -> RistrettoPoint
Performs the *
operation. Read more
sourceimpl Mul<Scalar> for RistrettoPoint
impl Mul<Scalar> for RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the *
operator.
sourcefn mul(self, rhs: Scalar) -> RistrettoPoint
fn mul(self, rhs: Scalar) -> RistrettoPoint
Performs the *
operation. Read more
sourceimpl<'b> MulAssign<&'b Scalar> for RistrettoPoint
impl<'b> MulAssign<&'b Scalar> for RistrettoPoint
sourcefn mul_assign(&mut self, scalar: &'b Scalar)
fn mul_assign(&mut self, scalar: &'b Scalar)
Performs the *=
operation. Read more
sourceimpl MulAssign<Scalar> for RistrettoPoint
impl MulAssign<Scalar> for RistrettoPoint
sourcefn mul_assign(&mut self, rhs: Scalar)
fn mul_assign(&mut self, rhs: Scalar)
Performs the *=
operation. Read more
sourceimpl MultiscalarMul for RistrettoPoint
impl MultiscalarMul for RistrettoPoint
type Point = RistrettoPoint
type Point = RistrettoPoint
The type of point being multiplied, e.g., RistrettoPoint
.
sourcefn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPoint where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<RistrettoPoint>,
fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPoint where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<RistrettoPoint>,
Given an iterator of (possibly secret) scalars and an iterator of public points, compute $$ Q = c_1 P_1 + \cdots + c_n P_n. $$ Read more
sourceimpl<'a> Neg for &'a RistrettoPoint
impl<'a> Neg for &'a RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the -
operator.
sourcefn neg(self) -> RistrettoPoint
fn neg(self) -> RistrettoPoint
Performs the unary -
operation. Read more
sourceimpl Neg for RistrettoPoint
impl Neg for RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the -
operator.
sourcefn neg(self) -> RistrettoPoint
fn neg(self) -> RistrettoPoint
Performs the unary -
operation. Read more
sourceimpl PartialEq<RistrettoPoint> for RistrettoPoint
impl PartialEq<RistrettoPoint> for RistrettoPoint
sourceimpl<'a, 'b> Sub<&'b RistrettoPoint> for &'a RistrettoPoint
impl<'a, 'b> Sub<&'b RistrettoPoint> for &'a RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the -
operator.
sourcefn sub(self, other: &'b RistrettoPoint) -> RistrettoPoint
fn sub(self, other: &'b RistrettoPoint) -> RistrettoPoint
Performs the -
operation. Read more
sourceimpl<'b> Sub<&'b RistrettoPoint> for RistrettoPoint
impl<'b> Sub<&'b RistrettoPoint> for RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the -
operator.
sourcefn sub(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
fn sub(self, rhs: &'b RistrettoPoint) -> RistrettoPoint
Performs the -
operation. Read more
sourceimpl<'a> Sub<RistrettoPoint> for &'a RistrettoPoint
impl<'a> Sub<RistrettoPoint> for &'a RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the -
operator.
sourcefn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
fn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
Performs the -
operation. Read more
sourceimpl Sub<RistrettoPoint> for RistrettoPoint
impl Sub<RistrettoPoint> for RistrettoPoint
type Output = RistrettoPoint
type Output = RistrettoPoint
The resulting type after applying the -
operator.
sourcefn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
fn sub(self, rhs: RistrettoPoint) -> RistrettoPoint
Performs the -
operation. Read more
sourceimpl<'b> SubAssign<&'b RistrettoPoint> for RistrettoPoint
impl<'b> SubAssign<&'b RistrettoPoint> for RistrettoPoint
sourcefn sub_assign(&mut self, _rhs: &RistrettoPoint)
fn sub_assign(&mut self, _rhs: &RistrettoPoint)
Performs the -=
operation. Read more
sourceimpl SubAssign<RistrettoPoint> for RistrettoPoint
impl SubAssign<RistrettoPoint> for RistrettoPoint
sourcefn sub_assign(&mut self, rhs: RistrettoPoint)
fn sub_assign(&mut self, rhs: RistrettoPoint)
Performs the -=
operation. Read more
sourceimpl<T> Sum<T> for RistrettoPoint where
T: Borrow<RistrettoPoint>,
impl<T> Sum<T> for RistrettoPoint where
T: Borrow<RistrettoPoint>,
sourceimpl VartimeMultiscalarMul for RistrettoPoint
impl VartimeMultiscalarMul for RistrettoPoint
type Point = RistrettoPoint
type Point = RistrettoPoint
The type of point being multiplied, e.g., RistrettoPoint
.
sourcefn 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>>,
Given an iterator of public scalars and an iterator of
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
sourcefn vartime_multiscalar_mul<I, J>(scalars: I, points: J) -> Self::Point where
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::Point where
I: IntoIterator,
I::Item: Borrow<Scalar>,
J: IntoIterator,
J::Item: Borrow<Self::Point>,
Self::Point: Clone,
Given an iterator of public scalars and an iterator of public points, compute $$ Q = c_1 P_1 + \cdots + c_n P_n, $$ using variable-time operations. Read more
sourceimpl Zeroize for RistrettoPoint
impl Zeroize for RistrettoPoint
impl Copy for RistrettoPoint
impl Eq for RistrettoPoint
Auto Trait Implementations
impl RefUnwindSafe for RistrettoPoint
impl Send for RistrettoPoint
impl Sync for RistrettoPoint
impl Unpin for RistrettoPoint
impl UnwindSafe for RistrettoPoint
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ConditionallyNegatable for T where
T: ConditionallySelectable,
&'a T: for<'a> Neg,
<&'a T as Neg>::Output == T,
impl<T> ConditionallyNegatable for T where
T: ConditionallySelectable,
&'a T: for<'a> Neg,
<&'a T as Neg>::Output == T,
sourcepub fn conditional_negate(&mut self, choice: Choice)
pub fn conditional_negate(&mut self, choice: Choice)
Negate self
if choice == Choice(1)
; otherwise, leave it
unchanged. Read more
sourceimpl<T> IsIdentity for T where
T: ConstantTimeEq + Identity,
impl<T> IsIdentity for T where
T: ConstantTimeEq + Identity,
sourcefn is_identity(&self) -> bool
fn is_identity(&self) -> bool
Return true if this element is the identity element of the curve.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more