@@ -61,6 +61,8 @@ mod fiat;
6161/// - `Mul`
6262/// - `MulAssign`
6363/// - `Neg`
64+ /// - `Shr`
65+ /// - `ShrAssign`
6466#[ macro_export]
6567macro_rules! field_element_type {
6668 (
@@ -201,6 +203,22 @@ macro_rules! field_element_type {
201203
202204 res
203205 }
206+
207+ /// Right shifts the [`
208+ #[ doc = stringify!( $fe) ]
209+ /// `].
210+ pub const fn shr( & self , shift: u32 ) -> Self {
211+ Self ( self . 0 . wrapping_shr( shift) )
212+ }
213+
214+ /// Right shifts the [`
215+ #[ doc = stringify!( $fe) ]
216+ /// `].
217+ ///
218+ /// Note: not constant-time with respect to the `shift` parameter.
219+ pub const fn shr_vartime( & self , shift: u32 ) -> Self {
220+ Self ( self . 0 . wrapping_shr_vartime( shift) )
221+ }
204222 }
205223
206224 impl $crate:: ff:: Field for $fe {
@@ -293,6 +311,31 @@ macro_rules! field_element_type {
293311 }
294312 }
295313
314+ impl :: core:: ops:: Shr <u32 > for $fe {
315+ type Output = Self ;
316+
317+ #[ inline]
318+ fn shr( self , rhs: u32 ) -> Self {
319+ Self :: shr( & self , rhs)
320+ }
321+ }
322+
323+ impl :: core:: ops:: Shr <u32 > for & $fe {
324+ type Output = Self ;
325+
326+ #[ inline]
327+ fn shr( self , rhs: u32 ) -> Self {
328+ Self :: shr( self , rhs)
329+ }
330+ }
331+
332+ impl :: core:: ops:: ShrAssign <u32 > for $fe {
333+ #[ inline]
334+ fn shr_assign( & mut self , rhs: u32 ) {
335+ * self = Self :: shr( self , rhs)
336+ }
337+ }
338+
296339 impl Default for $fe {
297340 fn default ( ) -> Self {
298341 Self :: ZERO
0 commit comments