@@ -4,14 +4,15 @@ use alloc::string::String;
44use core:: convert:: TryFrom ;
55use core:: ops:: { Add , Mul , Neg } ;
66use derive_more:: { From , Into } ;
7+ use elliptic_curve:: ops:: MulByGenerator ;
78use k256:: elliptic_curve:: group:: prime:: PrimeCurveAffine ;
89use k256:: elliptic_curve:: sec1:: ToEncodedPoint ;
910use k256:: { ProjectivePoint , PublicKey , Scalar } ;
1011use sigma_ser:: vlq_encode:: { ReadSigmaVlqExt , WriteSigmaVlqExt } ;
1112use sigma_ser:: { ScorexParsingError , ScorexSerializable , ScorexSerializeResult } ;
1213
1314/// Elliptic curve point
14- #[ derive( PartialEq , Clone , Default , From , Into ) ]
15+ #[ derive( PartialEq , Clone , Copy , Default , From , Into ) ]
1516#[ cfg_attr(
1617 feature = "json" ,
1718 derive( serde:: Serialize , serde:: Deserialize ) ,
@@ -104,7 +105,7 @@ pub fn is_identity(ge: &EcPoint) -> bool {
104105
105106/// Calculates the inverse of the given group element
106107pub fn inverse ( ec : & EcPoint ) -> EcPoint {
107- -ec . clone ( )
108+ -* ec
108109}
109110
110111/// Raises the base GroupElement to the exponent. The result is another GroupElement.
@@ -113,10 +114,15 @@ pub fn exponentiate(base: &EcPoint, exponent: &Scalar) -> EcPoint {
113114 // we treat EC as a multiplicative group, therefore, exponentiate point is multiply.
114115 EcPoint ( base. 0 * exponent)
115116 } else {
116- base. clone ( )
117+ * base
117118 }
118119}
119120
121+ /// Raise the generator g to the exponent. This is faster than exponentiate(&generator(), exponent)
122+ pub fn exponentiate_gen ( exponent : & Scalar ) -> EcPoint {
123+ ProjectivePoint :: mul_by_generator ( exponent) . into ( )
124+ }
125+
120126impl ScorexSerializable for EcPoint {
121127 fn scorex_serialize < W : WriteSigmaVlqExt > ( & self , w : & mut W ) -> ScorexSerializeResult {
122128 let caff = self . 0 . to_affine ( ) ;
0 commit comments