@@ -28,7 +28,7 @@ impl<T, Rhs, Output> GroupOpsOwned<Rhs, Output> for T where T: for<'r> GroupOps<
28
28
pub trait ScalarMulOwned < Rhs , Output = Self > : for < ' r > ScalarMul < & ' r Rhs , Output > { }
29
29
impl < T , Rhs , Output > ScalarMulOwned < Rhs , Output > for T where T : for < ' r > ScalarMul < & ' r Rhs , Output > { }
30
30
31
- /// A trait that defines extensions to the Group trait
31
+ /// A trait that defines the core discrete logarithm group functionality
32
32
pub trait DlogGroup :
33
33
Group
34
34
+ Serialize
@@ -51,6 +51,27 @@ pub trait DlogGroup:
51
51
+ CurveAffine
52
52
+ SerdeObject ;
53
53
54
+ /// Produce a vector of group elements using a static label
55
+ fn from_label ( label : & ' static [ u8 ] , n : usize ) -> Vec < Self :: AffineGroupElement > ;
56
+
57
+ /// Produces a preprocessed element
58
+ fn affine ( & self ) -> Self :: AffineGroupElement ;
59
+
60
+ /// Returns a group element from a preprocessed group element
61
+ fn group ( p : & Self :: AffineGroupElement ) -> Self ;
62
+
63
+ /// Returns an element that is the additive identity of the group
64
+ fn zero ( ) -> Self ;
65
+
66
+ /// Returns the generator of the group
67
+ fn gen ( ) -> Self ;
68
+
69
+ /// Returns the affine coordinates (x, y, infinity) for the point
70
+ fn to_coordinates ( & self ) -> ( <Self as Group >:: Base , <Self as Group >:: Base , bool ) ;
71
+ }
72
+
73
+ /// Extension trait for DlogGroup that provides multi-scalar multiplication operations
74
+ pub trait DlogGroupExt : DlogGroup {
54
75
/// A method to compute a multiexponentation
55
76
fn vartime_multiscalar_mul ( scalars : & [ Self :: Scalar ] , bases : & [ Self :: AffineGroupElement ] ) -> Self ;
56
77
@@ -81,29 +102,11 @@ pub trait DlogGroup:
81
102
. map ( |scalar| Self :: vartime_multiscalar_mul_small ( scalar, & bases[ ..scalar. len ( ) ] ) )
82
103
. collect :: < Vec < _ > > ( )
83
104
}
84
-
85
- /// Produce a vector of group elements using a static label
86
- fn from_label ( label : & ' static [ u8 ] , n : usize ) -> Vec < Self :: AffineGroupElement > ;
87
-
88
- /// Produces a preprocessed element
89
- fn affine ( & self ) -> Self :: AffineGroupElement ;
90
-
91
- /// Returns a group element from a preprocessed group element
92
- fn group ( p : & Self :: AffineGroupElement ) -> Self ;
93
-
94
- /// Returns an element that is the additive identity of the group
95
- fn zero ( ) -> Self ;
96
-
97
- /// Returns the generator of the group
98
- fn gen ( ) -> Self ;
99
-
100
- /// Returns the affine coordinates (x, y, infinity) for the point
101
- fn to_coordinates ( & self ) -> ( <Self as Group >:: Base , <Self as Group >:: Base , bool ) ;
102
105
}
103
106
104
107
/// A trait that defines extensions to the DlogGroup trait, to be implemented for
105
108
/// elliptic curve groups that are pairing friendly
106
- pub trait PairingGroup : DlogGroup {
109
+ pub trait PairingGroup : DlogGroupExt {
107
110
/// A type representing the second group
108
111
type G2 : DlogGroup < Scalar = Self :: Scalar , Base = Self :: Base > ;
109
112
@@ -141,20 +144,6 @@ macro_rules! impl_traits {
141
144
impl DlogGroup for $name:: Point {
142
145
type AffineGroupElement = $name:: Affine ;
143
146
144
- fn vartime_multiscalar_mul(
145
- scalars: & [ Self :: Scalar ] ,
146
- bases: & [ Self :: AffineGroupElement ] ,
147
- ) -> Self {
148
- msm( scalars, bases)
149
- }
150
-
151
- fn vartime_multiscalar_mul_small<T : Integer + Into <u64 > + Copy + Sync + ToPrimitive >(
152
- scalars: & [ T ] ,
153
- bases: & [ Self :: AffineGroupElement ] ,
154
- ) -> Self {
155
- msm_small( scalars, bases)
156
- }
157
-
158
147
fn affine( & self ) -> Self :: AffineGroupElement {
159
148
self . to_affine( )
160
149
}
@@ -229,6 +218,22 @@ macro_rules! impl_traits {
229
218
}
230
219
}
231
220
221
+ impl DlogGroupExt for $name:: Point {
222
+ fn vartime_multiscalar_mul(
223
+ scalars: & [ Self :: Scalar ] ,
224
+ bases: & [ Self :: AffineGroupElement ] ,
225
+ ) -> Self {
226
+ msm( scalars, bases)
227
+ }
228
+
229
+ fn vartime_multiscalar_mul_small<T : Integer + Into <u64 > + Copy + Sync + ToPrimitive >(
230
+ scalars: & [ T ] ,
231
+ bases: & [ Self :: AffineGroupElement ] ,
232
+ ) -> Self {
233
+ msm_small( scalars, bases)
234
+ }
235
+ }
236
+
232
237
impl PrimeFieldExt for $name:: Scalar {
233
238
fn from_uniform( bytes: & [ u8 ] ) -> Self {
234
239
let bytes_arr: [ u8 ; 64 ] = bytes. try_into( ) . unwrap( ) ;
0 commit comments