diff --git a/ff_derive/src/lib.rs b/ff_derive/src/lib.rs index 53bc6ea..198d89e 100644 --- a/ff_derive/src/lib.rs +++ b/ff_derive/src/lib.rs @@ -1189,7 +1189,7 @@ fn prime_field_impl( impl ::ff::PrimeField for #name { type Repr = #repr; - fn from_repr(r: #repr) -> ::ff::derive::subtle::CtOption<#name> { + fn from_repr(r: &#repr) -> ::ff::derive::subtle::CtOption<#name> { #from_repr_impl // Try to subtract the modulus @@ -1207,7 +1207,7 @@ fn prime_field_impl( ::ff::derive::subtle::CtOption::new(r * &R2, is_some) } - fn from_repr_vartime(r: #repr) -> Option<#name> { + fn from_repr_vartime(r: &#repr) -> Option<#name> { #from_repr_impl if r.is_valid() { diff --git a/src/lib.rs b/src/lib.rs index 4ffb982..8fca835 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -280,7 +280,7 @@ pub trait PrimeField: Field + From { /// /// The byte representation is interpreted with the same endianness as elements /// returned by [`PrimeField::to_repr`]. - fn from_repr(repr: Self::Repr) -> CtOption; + fn from_repr(repr: &Self::Repr) -> CtOption; /// Attempts to convert a byte representation of a field element into an element of /// this prime field, failing if the input is not canonical (is not smaller than the @@ -293,7 +293,7 @@ pub trait PrimeField: Field + From { /// /// This method provides **no** constant-time guarantees. Implementors of the /// `PrimeField` trait **may** optimise this method using non-constant-time logic. - fn from_repr_vartime(repr: Self::Repr) -> Option { + fn from_repr_vartime(repr: &Self::Repr) -> Option { Self::from_repr(repr).into() }