diff --git a/CHANGELOG.md b/CHANGELOG.md index 933a8f1..81b50f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to Rust's notion of (moved to `SqrtRatio` trait). - `FieldExt::{RESCUE_ALPHA, RESCUE_INVALPHA}` - `FieldExt::from_u64` (use `From for ff::PrimeField` instead). + - `FieldExt::{from_bytes, read, to_bytes, write}` + (use `ff::PrimeField::{from_repr, to_repr}` instead). ## [0.2.1] - 2021-09-17 ### Changed diff --git a/src/arithmetic/fields.rs b/src/arithmetic/fields.rs index b2f236d..fbe0498 100644 --- a/src/arithmetic/fields.rs +++ b/src/arithmetic/fields.rs @@ -4,20 +4,16 @@ use core::mem::size_of; use static_assertions::const_assert; -use subtle::{Choice, CtOption}; +use subtle::Choice; + +#[cfg(not(feature = "std"))] +use subtle::CtOption; #[cfg(feature = "std")] use super::Group; #[cfg(feature = "std")] -use std::{ - assert, - boxed::Box, - convert::TryInto, - io::{self, Read, Write}, - marker::PhantomData, - vec::Vec, -}; +use std::{assert, boxed::Box, convert::TryInto, marker::PhantomData, vec::Vec}; const_assert!(size_of::() >= 4); @@ -85,29 +81,6 @@ pub trait FieldExt: SqrtRatio + From + Ord + Group { /// Obtains a field element congruent to the integer `v`. fn from_u128(v: u128) -> Self; - /// Converts this field element to its normalized, little endian byte - /// representation. - fn to_bytes(&self) -> [u8; 32]; - - /// Writes this element in its normalized, little endian form into a buffer. - fn write(&self, writer: &mut W) -> io::Result<()> { - let compressed = self.to_bytes(); - writer.write_all(&compressed[..]) - } - - /// Attempts to obtain a field element from its normalized, little endian - /// byte representation. - fn from_bytes(bytes: &[u8; 32]) -> CtOption; - - /// Reads a normalized, little endian represented field element from a - /// buffer. - fn read(reader: &mut R) -> io::Result { - let mut compressed = [0u8; 32]; - reader.read_exact(&mut compressed[..])?; - Option::from(Self::from_bytes(&compressed)) - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid point encoding in proof")) - } - /// Obtains a field element that is congruent to the provided little endian /// byte representation of an integer. fn from_bytes_wide(bytes: &[u8; 64]) -> Self; diff --git a/src/fields/fp.rs b/src/fields/fp.rs index 0ec5fcf..0a5ae71 100644 --- a/src/fields/fp.rs +++ b/src/fields/fp.rs @@ -627,7 +627,7 @@ impl PrimeFieldBits for Fp { type ReprBits = ReprBits; fn to_le_bits(&self) -> FieldBits { - let bytes = self.to_bytes(); + let bytes = self.to_repr(); #[cfg(not(target_pointer_width = "64"))] let limbs = [ @@ -741,14 +741,6 @@ impl FieldExt for Fp { Fp::from_raw([v as u64, (v >> 64) as u64, 0, 0]) } - fn from_bytes(bytes: &[u8; 32]) -> CtOption { - ::from_repr(*bytes) - } - - fn to_bytes(&self) -> [u8; 32] { - ::to_repr(self) - } - /// Converts a 512-bit little endian integer into /// a `Fp` by reducing by the modulus. fn from_bytes_wide(bytes: &[u8; 64]) -> Fp { diff --git a/src/fields/fq.rs b/src/fields/fq.rs index fe2045a..567b99a 100644 --- a/src/fields/fq.rs +++ b/src/fields/fq.rs @@ -627,7 +627,7 @@ impl PrimeFieldBits for Fq { type ReprBits = ReprBits; fn to_le_bits(&self) -> FieldBits { - let bytes = self.to_bytes(); + let bytes = self.to_repr(); #[cfg(not(target_pointer_width = "64"))] let limbs = [ @@ -741,14 +741,6 @@ impl FieldExt for Fq { Fq::from_raw([v as u64, (v >> 64) as u64, 0, 0]) } - fn from_bytes(bytes: &[u8; 32]) -> CtOption { - ::from_repr(*bytes) - } - - fn to_bytes(&self) -> [u8; 32] { - ::to_repr(self) - } - /// Converts a 512-bit little endian integer into /// a `Fq` by reducing by the modulus. fn from_bytes_wide(bytes: &[u8; 64]) -> Fq {