diff --git a/src/field.rs b/src/field.rs index 43ba5df..af5cdd6 100644 --- a/src/field.rs +++ b/src/field.rs @@ -39,6 +39,7 @@ pub trait Field: type Inner: Debug + Eq + Clone; fn inner(&self) -> &Self::Inner; + fn inner_mut(&mut self) -> &mut Self::Inner; } /// Element of an integer field modulo prime number (F_p). diff --git a/src/field/ark_ff_field.rs b/src/field/ark_ff_field.rs index 03fc032..a069e3e 100644 --- a/src/field/ark_ff_field.rs +++ b/src/field/ark_ff_field.rs @@ -401,9 +401,15 @@ impl Ring for ArkField {} impl Field for ArkField { type Inner = F; + #[inline(always)] fn inner(&self) -> &Self::Inner { &self.0 } + + #[inline(always)] + fn inner_mut(&mut self) -> &mut Self::Inner { + &mut self.0 + } } // diff --git a/src/field/ark_ff_fp.rs b/src/field/ark_ff_fp.rs index 2298b12..90136ed 100644 --- a/src/field/ark_ff_fp.rs +++ b/src/field/ark_ff_fp.rs @@ -472,9 +472,15 @@ impl, const N: usize> IntRing for Fp { impl, const N: usize> Field for Fp { type Inner = BigInt; + #[inline(always)] fn inner(&self) -> &Self::Inner { &self.0.0 } + + #[inline(always)] + fn inner_mut(&mut self) -> &mut Self::Inner { + &mut self.0.0 + } } /// ConstPrimeField is only implemented for MontConfig and MontBackend diff --git a/src/field/crypto_bigint_boxed_monty.rs b/src/field/crypto_bigint_boxed_monty.rs index c3e3e21..99b3388 100644 --- a/src/field/crypto_bigint_boxed_monty.rs +++ b/src/field/crypto_bigint_boxed_monty.rs @@ -425,6 +425,17 @@ impl Field for BoxedMontyField { fn inner(&self) -> &Self::Inner { self.0.as_montgomery() } + + #[inline(always)] + fn inner_mut(&mut self) -> &mut Self::Inner { + // TODO: address this once possible. + unimplemented!( + "For now we keep this unimplemented. \ + The method was introduced in crypto-bigint in this PR:\ + https://github.com/RustCrypto/crypto-bigint/pull/1014\ + but not yet available in the latest RC from the craits.io." + ) + } } impl PrimeField for BoxedMontyField { diff --git a/src/field/crypto_bigint_const_monty.rs b/src/field/crypto_bigint_const_monty.rs index 54142cc..a432b70 100644 --- a/src/field/crypto_bigint_const_monty.rs +++ b/src/field/crypto_bigint_const_monty.rs @@ -516,6 +516,11 @@ impl, const LIMBS: usize> Field for ConstMontyField &Self::Inner { Uint::new_ref(self.0.as_montgomery()) } + + #[inline(always)] + fn inner_mut(&mut self) -> &mut Self::Inner { + Uint::new_ref_mut(self.0.as_montgomery_mut()) + } } impl, const LIMBS: usize> ConstPrimeField for ConstMontyField { diff --git a/src/field/crypto_bigint_monty.rs b/src/field/crypto_bigint_monty.rs index f3f7da1..539953b 100644 --- a/src/field/crypto_bigint_monty.rs +++ b/src/field/crypto_bigint_monty.rs @@ -486,6 +486,11 @@ impl Field for MontyField { fn inner(&self) -> &Self::Inner { Uint::new_ref(self.0.as_montgomery()) } + + #[inline(always)] + fn inner_mut(&mut self) -> &mut Self::Inner { + Uint::new_ref_mut(self.0.as_montgomery_mut()) + } } impl PrimeField for MontyField {