Skip to content

Update to PrimeField::from_repr() changes #1869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ members = [

[patch.crates-io]
digest = { path = "digest" }
ff = { git = "https://github.com/zkcrypto/ff.git", rev = "8e139e2fb25ab61a5d362394af0a34b10c03d59b" }
signature = { path = "signature" }
8 changes: 4 additions & 4 deletions elliptic-curve/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Field for Scalar {

loop {
rng.try_fill_bytes(&mut bytes)?;
if let Some(scalar) = Self::from_repr(bytes).into() {
if let Some(scalar) = Self::from_repr(&bytes).into() {
return Ok(scalar);
}
}
Expand Down Expand Up @@ -149,8 +149,8 @@ impl PrimeField for Scalar {
const ROOT_OF_UNITY_INV: Self = Self::ZERO; // BOGUS!
const DELTA: Self = Self::ZERO; // BOGUS!

fn from_repr(bytes: FieldBytes) -> CtOption<Self> {
ScalarPrimitive::from_bytes(&bytes).map(Self)
fn from_repr(bytes: &FieldBytes) -> CtOption<Self> {
ScalarPrimitive::from_bytes(bytes).map(Self)
}

fn to_repr(&self) -> FieldBytes {
Expand Down Expand Up @@ -898,7 +898,7 @@ mod tests {
#[test]
fn round_trip() {
let bytes = hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721");
let scalar = Scalar::from_repr(bytes.into()).unwrap();
let scalar = Scalar::from_repr(&bytes.into()).unwrap();
assert_eq!(&bytes, scalar.to_repr().as_slice());
}
}
2 changes: 1 addition & 1 deletion elliptic-curve/src/point/non_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ mod tests {
#[test]
fn mul_by_generator() {
let scalar = NonZeroScalar::from_repr(
hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721").into(),
&hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721").into(),
)
.unwrap();
let point = NonIdentity::<ProjectivePoint>::mul_by_generator(&scalar);
Expand Down
6 changes: 3 additions & 3 deletions elliptic-curve/src/scalar/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ where
}

/// Decode a [`NonZeroScalar`] from a big endian-serialized field element.
pub fn from_repr(repr: FieldBytes<C>) -> CtOption<Self> {
pub fn from_repr(repr: &FieldBytes<C>) -> CtOption<Self> {
Scalar::<C>::from_repr(repr).and_then(Self::new)
}

Expand Down Expand Up @@ -419,7 +419,7 @@ where
let mut bytes = FieldBytes::<C>::default();

if base16ct::mixed::decode(hex, &mut bytes)?.len() == bytes.len() {
Self::from_repr(bytes).into_option().ok_or(Error)
Self::from_repr(&bytes).into_option().ok_or(Error)
} else {
Err(Error)
}
Expand Down Expand Up @@ -465,7 +465,7 @@ mod tests {
#[test]
fn round_trip() {
let bytes = hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721");
let scalar = NonZeroScalar::from_repr(bytes.into()).unwrap();
let scalar = NonZeroScalar::from_repr(&bytes.into()).unwrap();
assert_eq!(&bytes, scalar.to_repr().as_slice());
}

Expand Down