@@ -14,6 +14,7 @@ pub use rand_core;
1414pub use subtle;
1515pub use zeroize;
1616
17+ mod dev;
1718mod fiat;
1819
1920/// Implements a field element type whose internal representation is in
@@ -463,120 +464,3 @@ macro_rules! field_op {
463464 }
464465 } ;
465466}
466-
467- /// Implement all tests for a type which impls the `PrimeField` trait.
468- #[ macro_export]
469- macro_rules! test_primefield {
470- ( $fe: tt, $t: expr) => {
471- $crate:: test_primefield_constants!( $fe, $t) ;
472- $crate:: test_field_identity!( $fe) ;
473- $crate:: test_field_invert!( $fe) ;
474- $crate:: test_field_sqrt!( $fe) ;
475- } ;
476- }
477-
478- /// Implement tests for constants defined by the `PrimeField` trait.
479- #[ macro_export]
480- macro_rules! test_primefield_constants {
481- ( $fe: tt, $t: expr) => {
482- #[ test]
483- fn two_inv_constant( ) {
484- use $crate:: ff:: PrimeField ;
485- assert_eq!( $fe:: from( 2u32 ) * $fe:: TWO_INV , $fe:: ONE ) ;
486- }
487-
488- #[ test]
489- fn root_of_unity_constant( ) {
490- use $crate:: ff:: PrimeField ;
491- assert!( $fe:: S < 128 ) ;
492- let two_to_s = 1u128 << $fe:: S ;
493-
494- // ROOT_OF_UNITY^{2^s} mod m == 1
495- assert_eq!(
496- $fe:: ROOT_OF_UNITY . pow_vartime( & [
497- ( two_to_s & 0xFFFFFFFFFFFFFFFF ) as u64 ,
498- ( two_to_s >> 64 ) as u64 ,
499- 0 ,
500- 0
501- ] ) ,
502- $fe:: ONE
503- ) ;
504-
505- // MULTIPLICATIVE_GENERATOR^{t} mod m == ROOT_OF_UNITY
506- assert_eq!(
507- $fe:: MULTIPLICATIVE_GENERATOR . pow_vartime( & $t) ,
508- $fe:: ROOT_OF_UNITY
509- )
510- }
511-
512- #[ test]
513- fn root_of_unity_inv_constant( ) {
514- use $crate:: ff:: PrimeField ;
515- assert_eq!( $fe:: ROOT_OF_UNITY * $fe:: ROOT_OF_UNITY_INV , $fe:: ONE ) ;
516- }
517-
518- #[ test]
519- fn delta_constant( ) {
520- use $crate:: ff:: PrimeField ;
521-
522- // DELTA^{t} mod m == 1
523- assert_eq!( $fe:: DELTA . pow_vartime( & $t) , $fe:: ONE ) ;
524- }
525- } ;
526- }
527-
528- /// Implement field element identity tests.
529- #[ macro_export]
530- macro_rules! test_field_identity {
531- ( $fe: tt) => {
532- #[ test]
533- fn zero_is_additive_identity( ) {
534- let zero = $fe:: ZERO ;
535- let one = $fe:: ONE ;
536- assert_eq!( zero. add( & zero) , zero) ;
537- assert_eq!( one. add( & zero) , one) ;
538- }
539-
540- #[ test]
541- fn one_is_multiplicative_identity( ) {
542- let one = $fe:: ONE ;
543- assert_eq!( one. multiply( & one) , one) ;
544- }
545- } ;
546- }
547-
548- /// Implement field element inversion tests.
549- #[ macro_export]
550- macro_rules! test_field_invert {
551- ( $fe: tt) => {
552- #[ test]
553- fn invert( ) {
554- let one = $fe:: ONE ;
555- assert_eq!( one. invert( ) . unwrap( ) , one) ;
556-
557- let three = one + & one + & one;
558- let inv_three = three. invert( ) . unwrap( ) ;
559- assert_eq!( three * & inv_three, one) ;
560-
561- let minus_three = -three;
562- let inv_minus_three = minus_three. invert( ) . unwrap( ) ;
563- assert_eq!( inv_minus_three, -inv_three) ;
564- assert_eq!( three * & inv_minus_three, -one) ;
565- }
566- } ;
567- }
568-
569- /// Implement field element square root tests.
570- #[ macro_export]
571- macro_rules! test_field_sqrt {
572- ( $fe: tt) => {
573- #[ test]
574- fn sqrt( ) {
575- for & n in & [ 1u64 , 4 , 9 , 16 , 25 , 36 , 49 , 64 ] {
576- let fe = $fe:: from( n) ;
577- let sqrt = fe. sqrt( ) . unwrap( ) ;
578- assert_eq!( sqrt. square( ) , fe) ;
579- }
580- }
581- } ;
582- }
0 commit comments