mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-01-31 07:42:15 +00:00
Some (easy) cleanups as suggested from @ebfull.
Thanks!
This commit is contained in:
parent
2ac2d1213d
commit
9846ad2d17
@ -158,7 +158,7 @@ impl Field for Fq2 {
|
|||||||
impl SqrtField for Fq2 {
|
impl SqrtField for Fq2 {
|
||||||
|
|
||||||
fn legendre(&self) -> ::LegendreSymbol {
|
fn legendre(&self) -> ::LegendreSymbol {
|
||||||
Fq2::norm(&self).legendre()
|
self.norm().legendre()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sqrt(&self) -> Option<Self> {
|
fn sqrt(&self) -> Option<Self> {
|
||||||
@ -578,7 +578,7 @@ fn bench_fq2_sqrt(b: &mut ::test::Bencher) {
|
|||||||
#[test]
|
#[test]
|
||||||
fn fq2_field_tests() {
|
fn fq2_field_tests() {
|
||||||
use ::PrimeField;
|
use ::PrimeField;
|
||||||
|
|
||||||
::tests::field::random_field_tests::<Fq2>();
|
::tests::field::random_field_tests::<Fq2>();
|
||||||
::tests::field::random_sqrt_tests::<Fq2>();
|
::tests::field::random_sqrt_tests::<Fq2>();
|
||||||
::tests::field::random_frobenius_tests::<Fq2, _>(super::fq::Fq::char(), 13);
|
::tests::field::random_frobenius_tests::<Fq2, _>(super::fq::Fq::char(), 13);
|
||||||
|
@ -554,6 +554,7 @@ impl Fr {
|
|||||||
impl SqrtField for Fr {
|
impl SqrtField for Fr {
|
||||||
|
|
||||||
fn legendre(&self) -> ::LegendreSymbol {
|
fn legendre(&self) -> ::LegendreSymbol {
|
||||||
|
// s = self^((r - 1) // 2)
|
||||||
let s = self.pow([0x7fffffff80000000, 0xa9ded2017fff2dff, 0x199cec0404d0ec02, 0x39f6d3a994cebea4]);
|
let s = self.pow([0x7fffffff80000000, 0xa9ded2017fff2dff, 0x199cec0404d0ec02, 0x39f6d3a994cebea4]);
|
||||||
if s == Self::zero() { Zero }
|
if s == Self::zero() { Zero }
|
||||||
else if s == Self::one() { QuadraticResidue }
|
else if s == Self::one() { QuadraticResidue }
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use rand::{Rng, SeedableRng, XorShiftRng};
|
use rand::{Rng, SeedableRng, XorShiftRng};
|
||||||
use ::{SqrtField, Field, PrimeField};
|
use ::{SqrtField, Field, PrimeField, LegendreSymbol};
|
||||||
|
|
||||||
pub fn random_frobenius_tests<F: Field, C: AsRef<[u64]>>(characteristic: C, maxpower: usize) {
|
pub fn random_frobenius_tests<F: Field, C: AsRef<[u64]>>(characteristic: C, maxpower: usize) {
|
||||||
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
|
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
|
||||||
@ -26,6 +26,7 @@ pub fn random_sqrt_tests<F: SqrtField>() {
|
|||||||
let a = F::rand(&mut rng);
|
let a = F::rand(&mut rng);
|
||||||
let mut b = a;
|
let mut b = a;
|
||||||
b.square();
|
b.square();
|
||||||
|
assert_eq!(b.legendre(), LegendreSymbol::QuadraticResidue);
|
||||||
|
|
||||||
let b = b.sqrt().unwrap();
|
let b = b.sqrt().unwrap();
|
||||||
let mut negb = b;
|
let mut negb = b;
|
||||||
@ -38,6 +39,8 @@ pub fn random_sqrt_tests<F: SqrtField>() {
|
|||||||
for _ in 0..10000 {
|
for _ in 0..10000 {
|
||||||
let mut b = c;
|
let mut b = c;
|
||||||
b.square();
|
b.square();
|
||||||
|
assert_eq!(b.legendre(), LegendreSymbol::QuadraticResidue);
|
||||||
|
|
||||||
b = b.sqrt().unwrap();
|
b = b.sqrt().unwrap();
|
||||||
|
|
||||||
if b != c {
|
if b != c {
|
||||||
|
Loading…
Reference in New Issue
Block a user