@@ -20,8 +20,6 @@ use generic_array::typenum::{U1, U11, U2, U20};
20
20
use generic_array:: GenericArray ;
21
21
use rand_core:: { CryptoRng , RngCore } ;
22
22
use subtle:: ConstantTimeEq ;
23
- #[ cfg( feature = "serde" ) ]
24
- use :: { core:: ops:: Add , generic_array:: typenum:: Sum , generic_array:: ArrayLength } ;
25
23
26
24
use crate :: errors:: InternalError ;
27
25
use crate :: group:: Group ;
@@ -58,110 +56,137 @@ enum Mode {
58
56
#[ derive( DeriveWhere ) ]
59
57
#[ derive_where( Clone , Zeroize ( drop) ) ]
60
58
#[ derive_where( Debug , Eq , Hash , Ord , PartialEq , PartialOrd ; G :: Scalar ) ]
59
+ #[ cfg_attr(
60
+ feature = "serde" ,
61
+ derive( serde:: Deserialize , serde:: Serialize ) ,
62
+ serde( bound(
63
+ deserialize = "G::Scalar: serde::Deserialize<'de>" ,
64
+ serialize = "G::Scalar: serde::Serialize"
65
+ ) )
66
+ ) ]
61
67
pub struct NonVerifiableClient < G : Group , H : BlockInput + Digest > {
62
68
pub ( crate ) blind : G :: Scalar ,
63
69
#[ derive_where( skip( Zeroize ) ) ]
64
70
pub ( crate ) hash : PhantomData < H > ,
65
71
}
66
72
67
- impl_serialize_and_deserialize_for ! ( NonVerifiableClient ) ;
68
-
69
73
/// A client which engages with a [VerifiableServer] in verifiable mode, meaning
70
74
/// that the OPRF outputs can be checked against a server public key.
71
75
#[ derive( DeriveWhere ) ]
72
76
#[ derive_where( Clone , Zeroize ( drop) ) ]
73
77
#[ derive_where( Debug , Eq , Hash , Ord , PartialEq , PartialOrd ; G , G :: Scalar ) ]
78
+ #[ cfg_attr(
79
+ feature = "serde" ,
80
+ derive( serde:: Deserialize , serde:: Serialize ) ,
81
+ serde( bound(
82
+ deserialize = "G::Scalar: serde::Deserialize<'de>, G: serde::Deserialize<'de>" ,
83
+ serialize = "G::Scalar: serde::Serialize, G: serde::Serialize"
84
+ ) )
85
+ ) ]
74
86
pub struct VerifiableClient < G : Group , H : BlockInput + Digest > {
75
87
pub ( crate ) blind : G :: Scalar ,
76
88
pub ( crate ) blinded_element : G ,
77
89
#[ derive_where( skip( Zeroize ) ) ]
78
90
pub ( crate ) hash : PhantomData < H > ,
79
91
}
80
92
81
- impl_serialize_and_deserialize_for ! (
82
- VerifiableClient
83
- where
84
- G :: ScalarLen : Add <G :: ElemLen >,
85
- Sum <G :: ScalarLen , G :: ElemLen >: ArrayLength <u8 >,
86
- ) ;
87
-
88
93
/// A server which engages with a [NonVerifiableClient] in base mode, meaning
89
94
/// that the OPRF outputs are not verifiable.
90
95
#[ derive( DeriveWhere ) ]
91
96
#[ derive_where( Clone , Zeroize ( drop) ) ]
92
97
#[ derive_where( Debug , Eq , Hash , Ord , PartialEq , PartialOrd ; G :: Scalar ) ]
98
+ #[ cfg_attr(
99
+ feature = "serde" ,
100
+ derive( serde:: Deserialize , serde:: Serialize ) ,
101
+ serde( bound(
102
+ deserialize = "G::Scalar: serde::Deserialize<'de>" ,
103
+ serialize = "G::Scalar: serde::Serialize"
104
+ ) )
105
+ ) ]
93
106
pub struct NonVerifiableServer < G : Group , H : BlockInput + Digest > {
94
107
pub ( crate ) sk : G :: Scalar ,
95
108
#[ derive_where( skip( Zeroize ) ) ]
96
109
pub ( crate ) hash : PhantomData < H > ,
97
110
}
98
111
99
- impl_serialize_and_deserialize_for ! ( NonVerifiableServer ) ;
100
-
101
112
/// A server which engages with a [VerifiableClient] in verifiable mode, meaning
102
113
/// that the OPRF outputs can be checked against a server public key.
103
114
#[ derive( DeriveWhere ) ]
104
115
#[ derive_where( Clone , Zeroize ( drop) ) ]
105
116
#[ derive_where( Debug , Eq , Hash , Ord , PartialEq , PartialOrd ; G , G :: Scalar ) ]
117
+ #[ cfg_attr(
118
+ feature = "serde" ,
119
+ derive( serde:: Deserialize , serde:: Serialize ) ,
120
+ serde( bound(
121
+ deserialize = "G::Scalar: serde::Deserialize<'de>, G: serde::Deserialize<'de>" ,
122
+ serialize = "G::Scalar: serde::Serialize, G: serde::Serialize"
123
+ ) )
124
+ ) ]
106
125
pub struct VerifiableServer < G : Group , H : BlockInput + Digest > {
107
126
pub ( crate ) sk : G :: Scalar ,
108
127
pub ( crate ) pk : G ,
109
128
#[ derive_where( skip( Zeroize ) ) ]
110
129
pub ( crate ) hash : PhantomData < H > ,
111
130
}
112
131
113
- impl_serialize_and_deserialize_for ! (
114
- VerifiableServer
115
- where
116
- G :: ScalarLen : Add <G :: ElemLen >,
117
- Sum <G :: ScalarLen , G :: ElemLen >: ArrayLength <u8 >,
118
- ) ;
119
-
120
132
/// A proof produced by a [VerifiableServer] that the OPRF output matches
121
133
/// against a server public key.
122
134
#[ derive( DeriveWhere ) ]
123
135
#[ derive_where( Clone , Zeroize ( drop) ) ]
124
136
#[ derive_where( Debug , Eq , Hash , Ord , PartialEq , PartialOrd ; G :: Scalar ) ]
137
+ #[ cfg_attr(
138
+ feature = "serde" ,
139
+ derive( serde:: Deserialize , serde:: Serialize ) ,
140
+ serde( bound(
141
+ deserialize = "G::Scalar: serde::Deserialize<'de>" ,
142
+ serialize = "G::Scalar: serde::Serialize"
143
+ ) )
144
+ ) ]
125
145
pub struct Proof < G : Group , H : BlockInput + Digest > {
126
146
pub ( crate ) c_scalar : G :: Scalar ,
127
147
pub ( crate ) s_scalar : G :: Scalar ,
128
148
#[ derive_where( skip( Zeroize ) ) ]
129
149
pub ( crate ) hash : PhantomData < H > ,
130
150
}
131
151
132
- impl_serialize_and_deserialize_for ! (
133
- Proof
134
- where
135
- G :: ScalarLen : Add <G :: ScalarLen >,
136
- Sum <G :: ScalarLen , G :: ScalarLen >: ArrayLength <u8 >,
137
- ) ;
138
-
139
152
/// The first client message sent from a client (either verifiable or not) to a
140
153
/// server (either verifiable or not).
141
154
#[ derive( DeriveWhere ) ]
142
155
#[ derive_where( Clone , Zeroize ( drop) ) ]
143
156
#[ derive_where( Debug , Eq , Hash , Ord , PartialEq , PartialOrd ; G ) ]
157
+ #[ cfg_attr(
158
+ feature = "serde" ,
159
+ derive( serde:: Deserialize , serde:: Serialize ) ,
160
+ serde( bound(
161
+ deserialize = "G: serde::Deserialize<'de>" ,
162
+ serialize = "G: serde::Serialize"
163
+ ) )
164
+ ) ]
144
165
pub struct BlindedElement < G : Group , H : BlockInput + Digest > {
145
166
pub ( crate ) value : G ,
146
167
#[ derive_where( skip( Zeroize ) ) ]
147
168
pub ( crate ) hash : PhantomData < H > ,
148
169
}
149
170
150
- impl_serialize_and_deserialize_for ! ( BlindedElement ) ;
151
-
152
171
/// The server's response to the [BlindedElement] message from a client (either
153
172
/// verifiable or not) to a server (either verifiable or not).
154
173
#[ derive( DeriveWhere ) ]
155
174
#[ derive_where( Clone , Zeroize ( drop) ) ]
156
175
#[ derive_where( Debug , Eq , Hash , Ord , PartialEq , PartialOrd ; G ) ]
176
+ #[ cfg_attr(
177
+ feature = "serde" ,
178
+ derive( serde:: Deserialize , serde:: Serialize ) ,
179
+ serde( bound(
180
+ deserialize = "G: serde::Deserialize<'de>" ,
181
+ serialize = "G: serde::Serialize"
182
+ ) )
183
+ ) ]
157
184
pub struct EvaluationElement < G : Group , H : BlockInput + Digest > {
158
185
pub ( crate ) value : G ,
159
186
#[ derive_where( skip( Zeroize ) ) ]
160
187
pub ( crate ) hash : PhantomData < H > ,
161
188
}
162
189
163
- impl_serialize_and_deserialize_for ! ( EvaluationElement ) ;
164
-
165
190
/////////////////////////
166
191
// API Implementations //
167
192
// =================== //
0 commit comments