Change various into_bytes to to_bytes.

This commit is contained in:
Sean Bowe 2019-05-31 19:47:56 -06:00
parent 02b05eb075
commit 160cb42398
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
5 changed files with 30 additions and 30 deletions

View File

@ -15,7 +15,7 @@ pub struct Fq(pub(crate) [u64; 4]);
impl fmt::Debug for Fq {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let tmp = self.into_bytes();
let tmp = self.to_bytes();
write!(f, "0x")?;
for &b in tmp.iter().rev() {
write!(f, "{:02x}", b)?;
@ -228,7 +228,7 @@ impl Fq {
/// Converts an element of `Fq` into a byte representation in
/// little-endian byte order.
pub fn into_bytes(&self) -> [u8; 32] {
pub fn to_bytes(&self) -> [u8; 32] {
// Turn into canonical form by computing
// (a.R) / R = a
let tmp = Fq::montgomery_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);
@ -604,7 +604,7 @@ impl Fq {
impl<'a> From<&'a Fq> for [u8; 32] {
fn from(value: &'a Fq) -> [u8; 32] {
value.into_bytes()
value.to_bytes()
}
}
@ -651,9 +651,9 @@ fn test_equality() {
}
#[test]
fn test_into_bytes() {
fn test_to_bytes() {
assert_eq!(
Fq::zero().into_bytes(),
Fq::zero().to_bytes(),
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0
@ -661,7 +661,7 @@ fn test_into_bytes() {
);
assert_eq!(
Fq::one().into_bytes(),
Fq::one().to_bytes(),
[
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0
@ -669,7 +669,7 @@ fn test_into_bytes() {
);
assert_eq!(
R2.into_bytes(),
R2.to_bytes(),
[
254, 255, 255, 255, 1, 0, 0, 0, 2, 72, 3, 0, 250, 183, 132, 88, 245, 79, 188, 236, 239,
79, 140, 153, 111, 5, 197, 172, 89, 177, 36, 24
@ -677,7 +677,7 @@ fn test_into_bytes() {
);
assert_eq!(
(-&Fq::one()).into_bytes(),
(-&Fq::one()).to_bytes(),
[
0, 0, 0, 0, 255, 255, 255, 255, 254, 91, 254, 255, 2, 164, 189, 83, 5, 216, 161, 9, 8,
216, 57, 51, 72, 125, 157, 41, 83, 167, 237, 115
@ -914,7 +914,7 @@ fn test_multiplication() {
let mut tmp2 = Fq::zero();
for b in cur
.into_bytes()
.to_bytes()
.iter()
.rev()
.flat_map(|byte| (0..8).rev().map(move |i| ((byte >> i) & 1u8) == 1u8))
@ -943,7 +943,7 @@ fn test_squaring() {
let mut tmp2 = Fq::zero();
for b in cur
.into_bytes()
.to_bytes()
.iter()
.rev()
.flat_map(|byte| (0..8).rev().map(move |i| ((byte >> i) & 1u8) == 1u8))

View File

@ -15,7 +15,7 @@ pub struct Fr(pub(crate) [u64; 4]);
impl fmt::Debug for Fr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let tmp = self.into_bytes();
let tmp = self.to_bytes();
write!(f, "0x")?;
for &b in tmp.iter().rev() {
write!(f, "{:02x}", b)?;
@ -217,7 +217,7 @@ impl Fr {
/// Converts an element of `Fr` into a byte representation in
/// little-endian byte order.
pub fn into_bytes(&self) -> [u8; 32] {
pub fn to_bytes(&self) -> [u8; 32] {
// Turn into canonical form by computing
// (a.R) / R = a
let tmp = Fr::montgomery_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);
@ -557,7 +557,7 @@ impl Fr {
impl<'a> From<&'a Fr> for [u8; 32] {
fn from(value: &'a Fr) -> [u8; 32] {
value.into_bytes()
value.to_bytes()
}
}
@ -604,9 +604,9 @@ fn test_equality() {
}
#[test]
fn test_into_bytes() {
fn test_to_bytes() {
assert_eq!(
Fr::zero().into_bytes(),
Fr::zero().to_bytes(),
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0
@ -614,7 +614,7 @@ fn test_into_bytes() {
);
assert_eq!(
Fr::one().into_bytes(),
Fr::one().to_bytes(),
[
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0
@ -622,7 +622,7 @@ fn test_into_bytes() {
);
assert_eq!(
R2.into_bytes(),
R2.to_bytes(),
[
217, 7, 150, 185, 179, 11, 248, 37, 80, 231, 182, 102, 47, 214, 21, 243, 244, 20, 136,
235, 238, 20, 37, 147, 198, 85, 145, 71, 111, 252, 166, 9
@ -630,7 +630,7 @@ fn test_into_bytes() {
);
assert_eq!(
(-&Fr::one()).into_bytes(),
(-&Fr::one()).to_bytes(),
[
182, 44, 247, 214, 94, 14, 151, 208, 130, 16, 200, 204, 147, 32, 104, 166, 0, 59, 52,
1, 1, 59, 103, 6, 169, 175, 51, 101, 234, 180, 125, 14
@ -869,7 +869,7 @@ fn test_multiplication() {
let mut tmp2 = Fr::zero();
for b in cur
.into_bytes()
.to_bytes()
.iter()
.rev()
.flat_map(|byte| (0..8).rev().map(move |i| ((byte >> i) & 1u8) == 1u8))
@ -898,7 +898,7 @@ fn test_squaring() {
let mut tmp2 = Fr::zero();
for b in cur
.into_bytes()
.to_bytes()
.iter()
.rev()
.flat_map(|byte| (0..8).rev().map(move |i| ((byte >> i) & 1u8) == 1u8))

View File

@ -256,7 +256,7 @@ impl<'a, 'b> Mul<&'b Fr> for &'a AffineNielsPoint {
type Output = ExtendedPoint;
fn mul(self, other: &'b Fr) -> ExtendedPoint {
self.multiply(&other.into_bytes())
self.multiply(&other.to_bytes())
}
}
@ -340,7 +340,7 @@ impl<'a, 'b> Mul<&'b Fr> for &'a ExtendedNielsPoint {
type Output = ExtendedPoint;
fn mul(self, other: &'b Fr) -> ExtendedPoint {
self.multiply(&other.into_bytes())
self.multiply(&other.to_bytes())
}
}
@ -398,9 +398,9 @@ impl AffinePoint {
}
/// Converts this element into its byte representation.
pub fn into_bytes(&self) -> [u8; 32] {
let mut tmp = self.v.into_bytes();
let u = self.u.into_bytes();
pub fn to_bytes(&self) -> [u8; 32] {
let mut tmp = self.v.to_bytes();
let u = self.u.to_bytes();
// Encode the sign of the u-coordinate in the most
// significant bit.
@ -438,7 +438,7 @@ impl AffinePoint {
.sqrt()
.and_then(|u| {
// Fix the sign of `u` if necessary
let flip_sign = Choice::from((u.into_bytes()[0] ^ sign) & 1);
let flip_sign = Choice::from((u.to_bytes()[0] ^ sign) & 1);
let u_negated = -u;
let final_u = Fq::conditional_select(&u, &u_negated, flip_sign);
@ -659,7 +659,7 @@ impl<'a, 'b> Mul<&'b Fr> for &'a ExtendedPoint {
type Output = ExtendedPoint;
fn mul(self, other: &'b Fr) -> ExtendedPoint {
self.multiply(&other.into_bytes())
self.multiply(&other.to_bytes())
}
}
@ -1315,7 +1315,7 @@ fn test_serialization_consistency() {
for expected_serialized in v {
assert!(p.is_on_curve_vartime());
let affine = AffinePoint::from(p);
let serialized = affine.into_bytes();
let serialized = affine.to_bytes();
let deserialized = AffinePoint::from_bytes(serialized).unwrap();
assert_eq!(affine, deserialized);
assert_eq!(expected_serialized, serialized);

View File

@ -8,7 +8,7 @@ fn test_to_and_from_bytes() {
let mut rng = new_rng();
for _ in 0..NUM_BLACK_BOX_CHECKS {
let a = Fq::new_random(&mut rng);
assert_eq!(a, Fq::from_bytes(&Fq::into_bytes(&a)).unwrap());
assert_eq!(a, Fq::from_bytes(&Fq::to_bytes(&a)).unwrap());
}
}

View File

@ -8,7 +8,7 @@ fn test_to_and_from_bytes() {
let mut rng = new_rng();
for _ in 0..NUM_BLACK_BOX_CHECKS {
let a = Fr::new_random(&mut rng);
assert_eq!(a, Fr::from_bytes(&Fr::into_bytes(&a)).unwrap());
assert_eq!(a, Fr::from_bytes(&Fr::to_bytes(&a)).unwrap());
}
}