@@ -59,13 +59,28 @@ pub trait Mac: OutputSizeUser + Sized {
59
59
/// Check if tag/code value is correct for the processed input.
60
60
fn verify ( self , tag : & Output < Self > ) -> Result < ( ) , MacError > ;
61
61
62
+ /// Check if tag/code value is correct for the processed input and reset
63
+ /// [`Mac`] instance.
64
+ fn verify_reset ( & mut self , tag : & Output < Self > ) -> Result < ( ) , MacError >
65
+ where
66
+ Self : FixedOutputReset ;
67
+
62
68
/// Check truncated tag correctness using all bytes
63
69
/// of calculated tag.
64
70
///
65
71
/// Returns `Error` if `tag` is not valid or not equal in length
66
72
/// to MAC's output.
67
73
fn verify_slice ( self , tag : & [ u8 ] ) -> Result < ( ) , MacError > ;
68
74
75
+ /// Check truncated tag correctness using all bytes
76
+ /// of calculated tag and reset [`Mac`] instance.
77
+ ///
78
+ /// Returns `Error` if `tag` is not valid or not equal in length
79
+ /// to MAC's output.
80
+ fn verify_slice_reset ( & mut self , tag : & [ u8 ] ) -> Result < ( ) , MacError >
81
+ where
82
+ Self : FixedOutputReset ;
83
+
69
84
/// Check truncated tag correctness using left side bytes
70
85
/// (i.e. `tag[..n]`) of calculated tag.
71
86
///
@@ -137,6 +152,18 @@ impl<T: Update + FixedOutput + MacMarker> Mac for T {
137
152
}
138
153
}
139
154
155
+ #[ inline]
156
+ fn verify_reset ( & mut self , tag : & Output < Self > ) -> Result < ( ) , MacError >
157
+ where
158
+ Self : FixedOutputReset ,
159
+ {
160
+ if self . finalize_reset ( ) == tag. into ( ) {
161
+ Ok ( ( ) )
162
+ } else {
163
+ Err ( MacError )
164
+ }
165
+ }
166
+
140
167
#[ inline]
141
168
fn verify_slice ( self , tag : & [ u8 ] ) -> Result < ( ) , MacError > {
142
169
let n = tag. len ( ) ;
@@ -151,6 +178,23 @@ impl<T: Update + FixedOutput + MacMarker> Mac for T {
151
178
}
152
179
}
153
180
181
+ #[ inline]
182
+ fn verify_slice_reset ( & mut self , tag : & [ u8 ] ) -> Result < ( ) , MacError >
183
+ where
184
+ Self : FixedOutputReset ,
185
+ {
186
+ let n = tag. len ( ) ;
187
+ if n != Self :: OutputSize :: USIZE {
188
+ return Err ( MacError ) ;
189
+ }
190
+ let choice = self . finalize_fixed_reset ( ) . ct_eq ( tag) ;
191
+ if choice. into ( ) {
192
+ Ok ( ( ) )
193
+ } else {
194
+ Err ( MacError )
195
+ }
196
+ }
197
+
154
198
fn verify_truncated_left ( self , tag : & [ u8 ] ) -> Result < ( ) , MacError > {
155
199
let n = tag. len ( ) ;
156
200
if n == 0 || n > Self :: OutputSize :: USIZE {
0 commit comments