@@ -9,11 +9,12 @@ extern crate alloc;
99// Re-export ff to make version-matching easier.
1010pub use ff;
1111
12+ use core:: convert:: Infallible ;
1213use core:: fmt;
1314use core:: iter:: Sum ;
1415use core:: ops:: { Add , AddAssign , Mul , MulAssign , Neg , Sub , SubAssign } ;
1516use ff:: PrimeField ;
16- use rand_core:: RngCore ;
17+ use rand_core:: { RngCore , TryRngCore } ;
1718use subtle:: { Choice , CtOption } ;
1819
1920pub mod cofactor;
@@ -76,7 +77,22 @@ pub trait Group:
7677 /// this group.
7778 ///
7879 /// This function is non-deterministic, and samples from the user-provided RNG.
79- fn random ( rng : impl RngCore ) -> Self ;
80+ fn random < R : RngCore + ?Sized > ( rng : & mut R ) -> Self {
81+ Self :: try_from_rng ( rng)
82+ . map_err ( |e : Infallible | e)
83+ . expect ( "Infallible failed" )
84+
85+ // NOTE: once MSRV gets to 1.82 remove the map_err/expect and use
86+ // let Ok(out) = Self::try_from_rng(rng);
87+ // out
88+ // See: https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#omitting-empty-types-in-pattern-matching
89+ }
90+
91+ /// Returns an element chosen uniformly at random from the non-identity elements of
92+ /// this group.
93+ ///
94+ /// This function is non-deterministic, and samples from the user-provided RNG.
95+ fn try_from_rng < R : TryRngCore + ?Sized > ( rng : & mut R ) -> Result < Self , R :: Error > ;
8096
8197 /// Returns the additive identity, also known as the "neutral element".
8298 fn identity ( ) -> Self ;
@@ -90,6 +106,12 @@ pub trait Group:
90106 /// Doubles this element.
91107 #[ must_use]
92108 fn double ( & self ) -> Self ;
109+
110+ /// Multiply by the generator of the prime-order subgroup.
111+ #[ must_use]
112+ fn mul_by_generator ( scalar : & Self :: Scalar ) -> Self {
113+ Self :: generator ( ) * scalar
114+ }
93115}
94116
95117/// Efficient representation of an elliptic curve point guaranteed.
0 commit comments