File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,11 @@ impl BoxedMontyForm {
242242 & self . montgomery_form
243243 }
244244
245+ /// Mutably access the [`BoxedMontyForm`] value in Montgomery form.
246+ pub fn as_montgomery_mut ( & mut self ) -> & mut BoxedUint {
247+ & mut self . montgomery_form
248+ }
249+
245250 /// Create a [`BoxedMontyForm`] from a value in Montgomery form.
246251 pub fn from_montgomery ( integer : BoxedUint , params : BoxedMontyParams ) -> Self {
247252 debug_assert_eq ! ( integer. bits_precision( ) , params. bits_precision( ) ) ;
@@ -375,4 +380,18 @@ mod tests {
375380 assert_eq ! ( zero. div_by_2( ) , zero) ;
376381 assert_eq ! ( one. div_by_2( ) . mul( & two) , one) ;
377382 }
383+
384+ #[ test]
385+ fn as_montgomery_mut ( ) {
386+ let modulus = Odd :: new ( BoxedUint :: from ( 9u8 ) ) . unwrap ( ) ;
387+ let params = BoxedMontyParams :: new ( modulus) ;
388+ let one = BoxedMontyForm :: one ( params. clone ( ) ) ;
389+ let two = one. add ( & one) ;
390+ let four = two. mul ( & two) ;
391+ let mut x = two. clone ( ) ;
392+
393+ * x. as_montgomery_mut ( ) = four. as_montgomery ( ) . clone ( ) ;
394+
395+ assert_eq ! ( x, four) ;
396+ }
378397}
You can’t perform that action at this time.
0 commit comments