ff: Rename PrimeField::into_repr -> PrimeField::to_repr

This commit is contained in:
Jack Grigg
2020-05-02 18:55:13 +12:00
parent 9114c367f4
commit c597db59a6
35 changed files with 106 additions and 106 deletions

View File

@@ -155,7 +155,7 @@ fn bench_fq_sqrt(c: &mut Criterion) {
});
}
fn bench_fq_into_repr(c: &mut Criterion) {
fn bench_fq_to_repr(c: &mut Criterion) {
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::from_seed([
@@ -166,10 +166,10 @@ fn bench_fq_into_repr(c: &mut Criterion) {
let v: Vec<Fq> = (0..SAMPLES).map(|_| Fq::random(&mut rng)).collect();
let mut count = 0;
c.bench_function("Fq::into_repr", |b| {
c.bench_function("Fq::to_repr", |b| {
b.iter(|| {
count = (count + 1) % SAMPLES;
v[count].into_repr()
v[count].to_repr()
})
});
}
@@ -183,7 +183,7 @@ fn bench_fq_from_repr(c: &mut Criterion) {
]);
let v: Vec<FqRepr> = (0..SAMPLES)
.map(|_| Fq::random(&mut rng).into_repr())
.map(|_| Fq::random(&mut rng).to_repr())
.collect();
let mut count = 0;
@@ -204,6 +204,6 @@ criterion_group!(
bench_fq_invert,
bench_fq_neg,
bench_fq_sqrt,
bench_fq_into_repr,
bench_fq_to_repr,
bench_fq_from_repr,
);

View File

@@ -155,7 +155,7 @@ fn bench_fr_sqrt(c: &mut Criterion) {
});
}
fn bench_fr_into_repr(c: &mut Criterion) {
fn bench_fr_to_repr(c: &mut Criterion) {
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::from_seed([
@@ -166,10 +166,10 @@ fn bench_fr_into_repr(c: &mut Criterion) {
let v: Vec<Fr> = (0..SAMPLES).map(|_| Fr::random(&mut rng)).collect();
let mut count = 0;
c.bench_function("Fr::into_repr", |b| {
c.bench_function("Fr::to_repr", |b| {
b.iter(|| {
count = (count + 1) % SAMPLES;
v[count].into_repr()
v[count].to_repr()
})
});
}
@@ -183,7 +183,7 @@ fn bench_fr_from_repr(c: &mut Criterion) {
]);
let v: Vec<FrRepr> = (0..SAMPLES)
.map(|_| Fr::random(&mut rng).into_repr())
.map(|_| Fr::random(&mut rng).to_repr())
.collect();
let mut count = 0;
@@ -204,6 +204,6 @@ criterion_group!(
bench_fr_invert,
bench_fr_neg,
bench_fr_sqrt,
bench_fr_into_repr,
bench_fr_to_repr,
bench_fr_from_repr,
);

View File

@@ -872,8 +872,8 @@ pub mod g1 {
// is at infinity.
res.0[0] |= 1 << 6;
} else {
res.0[..48].copy_from_slice(&affine.x.into_repr().0);
res.0[48..].copy_from_slice(&affine.y.into_repr().0);
res.0[..48].copy_from_slice(&affine.x.to_repr().0);
res.0[48..].copy_from_slice(&affine.y.to_repr().0);
}
res
@@ -969,7 +969,7 @@ pub mod g1 {
// is at infinity.
res.0[0] |= 1 << 6;
} else {
res.0 = affine.x.into_repr().0;
res.0 = affine.x.to_repr().0;
let negy = affine.y.neg();
@@ -1494,10 +1494,10 @@ pub mod g2 {
// is at infinity.
res.0[0] |= 1 << 6;
} else {
res.0[0..48].copy_from_slice(&affine.x.c1.into_repr().0);
res.0[48..96].copy_from_slice(&affine.x.c0.into_repr().0);
res.0[96..144].copy_from_slice(&affine.y.c1.into_repr().0);
res.0[144..192].copy_from_slice(&affine.y.c0.into_repr().0);
res.0[0..48].copy_from_slice(&affine.x.c1.to_repr().0);
res.0[48..96].copy_from_slice(&affine.x.c0.to_repr().0);
res.0[96..144].copy_from_slice(&affine.y.c1.to_repr().0);
res.0[144..192].copy_from_slice(&affine.y.c0.to_repr().0);
}
res
@@ -1608,8 +1608,8 @@ pub mod g2 {
// is at infinity.
res.0[0] |= 1 << 6;
} else {
res.0[..48].copy_from_slice(&affine.x.c1.into_repr().0);
res.0[48..].copy_from_slice(&affine.x.c0.into_repr().0);
res.0[..48].copy_from_slice(&affine.x.c1.to_repr().0);
res.0[48..].copy_from_slice(&affine.x.c0.to_repr().0);
let negy = affine.y.neg();

View File

@@ -1687,7 +1687,7 @@ fn test_fq_sqrt() {
}
#[test]
fn test_fq_from_into_repr() {
fn test_fq_from_to_repr() {
// q + 1 should not be in the field
assert!(Fq::from_repr(FqRepr([
0x1a, 0x01, 0x11, 0xea, 0x39, 0x7f, 0xe6, 0x9a, 0x4b, 0x1b, 0xa7, 0xb6, 0x43, 0x4b, 0xac,
@@ -1722,7 +1722,7 @@ fn test_fq_from_into_repr() {
0x17, 0x91, 0x4c,
]);
a_fq.mul_assign(&b_fq);
assert_eq!(a_fq.into_repr(), c);
assert_eq!(a_fq.to_repr(), c);
// Zero should be in the field.
assert!(Fq::from_repr(FqRepr([0; 48])).unwrap().is_zero());
@@ -1735,7 +1735,7 @@ fn test_fq_from_into_repr() {
for _ in 0..1000 {
// Try to turn Fq elements into representations and back again, and compare.
let a = Fq::random(&mut rng);
let a_repr = a.into_repr();
let a_repr = a.to_repr();
let b_repr = FqRepr::from(a);
assert_eq!(a_repr, b_repr);
let a_again = Fq::from_repr(a_repr).unwrap();

View File

@@ -472,7 +472,7 @@ fn test_fr_sqrt() {
}
#[test]
fn test_fr_from_into_repr() {
fn test_fr_from_to_repr() {
// r + 1 should not be in the field
assert!(Fr::from_repr(FrRepr([
0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x5b, 0xfe, 0xff, 0x02, 0xa4, 0xbd,
@@ -503,7 +503,7 @@ fn test_fr_from_into_repr() {
0x61, 0x71,
]);
a_fr.mul_assign(&b_fr);
assert_eq!(a_fr.into_repr(), c);
assert_eq!(a_fr.to_repr(), c);
// Zero should be in the field.
assert!(Fr::from_repr(FrRepr([0; 32])).unwrap().is_zero());
@@ -516,7 +516,7 @@ fn test_fr_from_into_repr() {
for _ in 0..1000 {
// Try to turn Fr elements into representations and back again, and compare.
let a = Fr::random(&mut rng);
let a_repr = a.into_repr();
let a_repr = a.to_repr();
let b_repr = FrRepr::from(a);
assert_eq!(a_repr, b_repr);
let a_again = Fr::from_repr(a_repr).unwrap();

View File

@@ -172,7 +172,7 @@ fn test_g1_uncompressed_invalid_vectors() {
}
{
let m = Fq::zero().into_repr();
let m = Fq::zero().to_repr();
let mut o = o;
o.as_mut()[..48].copy_from_slice(m.as_ref());
@@ -198,8 +198,8 @@ fn test_g1_uncompressed_invalid_vectors() {
let y = y.unwrap();
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
o.as_mut()[..48].copy_from_slice(x.into_repr().as_ref());
o.as_mut()[48..].copy_from_slice(y.into_repr().as_ref());
o.as_mut()[..48].copy_from_slice(x.to_repr().as_ref());
o.as_mut()[48..].copy_from_slice(y.to_repr().as_ref());
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
break;
@@ -310,7 +310,7 @@ fn test_g2_uncompressed_invalid_vectors() {
}
{
let m = Fq::zero().into_repr();
let m = Fq::zero().to_repr();
let mut o = o;
o.as_mut()[..48].copy_from_slice(m.as_ref());
@@ -340,10 +340,10 @@ fn test_g2_uncompressed_invalid_vectors() {
let y = y.unwrap();
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
o.as_mut()[..48].copy_from_slice(x.c1.into_repr().as_ref());
o.as_mut()[48..96].copy_from_slice(x.c0.into_repr().as_ref());
o.as_mut()[96..144].copy_from_slice(y.c1.into_repr().as_ref());
o.as_mut()[144..].copy_from_slice(y.c0.into_repr().as_ref());
o.as_mut()[..48].copy_from_slice(x.c1.to_repr().as_ref());
o.as_mut()[48..96].copy_from_slice(x.c0.to_repr().as_ref());
o.as_mut()[96..144].copy_from_slice(y.c1.to_repr().as_ref());
o.as_mut()[144..].copy_from_slice(y.c0.to_repr().as_ref());
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
break;
@@ -433,7 +433,7 @@ fn test_g1_compressed_invalid_vectors() {
if x3b.sqrt().is_some().into() {
x.add_assign(&Fq::one());
} else {
o.as_mut().copy_from_slice(x.into_repr().as_ref());
o.as_mut().copy_from_slice(x.to_repr().as_ref());
o.as_mut()[0] |= 0b1000_0000;
if let Err(GroupDecodingError::NotOnCurve) = o.into_affine() {
@@ -456,7 +456,7 @@ fn test_g1_compressed_invalid_vectors() {
if x3b.sqrt().is_some().into() {
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
o.as_mut().copy_from_slice(x.into_repr().as_ref());
o.as_mut().copy_from_slice(x.to_repr().as_ref());
o.as_mut()[0] |= 0b1000_0000;
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
@@ -565,8 +565,8 @@ fn test_g2_compressed_invalid_vectors() {
if x3b.sqrt().is_some().into() {
x.add_assign(&Fq2::one());
} else {
o.as_mut()[..48].copy_from_slice(x.c1.into_repr().as_ref());
o.as_mut()[48..].copy_from_slice(x.c0.into_repr().as_ref());
o.as_mut()[..48].copy_from_slice(x.c1.to_repr().as_ref());
o.as_mut()[48..].copy_from_slice(x.c0.to_repr().as_ref());
o.as_mut()[0] |= 0b1000_0000;
if let Err(GroupDecodingError::NotOnCurve) = o.into_affine() {
@@ -595,8 +595,8 @@ fn test_g2_compressed_invalid_vectors() {
if x3b.sqrt().is_some().into() {
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
o.as_mut()[..48].copy_from_slice(x.c1.into_repr().as_ref());
o.as_mut()[48..].copy_from_slice(x.c0.into_repr().as_ref());
o.as_mut()[..48].copy_from_slice(x.c1.to_repr().as_ref());
o.as_mut()[48..].copy_from_slice(x.c0.to_repr().as_ref());
o.as_mut()[0] |= 0b1000_0000;
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {

View File

@@ -130,7 +130,7 @@ fn random_bilinearity_tests<E: Engine>() {
let mut cd = c;
cd.mul_assign(&d);
let mut cd = cd.into_repr();
let mut cd = cd.to_repr();
<E::Fr as PrimeField>::ReprEndianness::toggle_little_endian(&mut cd);
use byteorder::ByteOrder;

View File

@@ -15,7 +15,7 @@ fn random_encoding_tests<P: PrimeField>() {
for _ in 0..1000 {
let r = P::random(&mut rng);
let v = r.into_repr();
let v = r.to_repr();
let rdecoded = P::from_repr(v).unwrap();
assert_eq!(r, rdecoded);