11use crate :: {
2- bytes:: { FromBytes , ToBytes } ,
3- fields:: { BitIteratorBE , BitIteratorLE } ,
4- UniformRand ,
2+ bytes:: { FromBytes , ToBytes } , fields:: { BitIteratorBE , BitIteratorLE } , UniformRand
53} ;
64use ark_serialize:: { CanonicalDeserialize , CanonicalSerialize , SerializationError } ;
75use ark_std:: rand:: {
@@ -31,14 +29,17 @@ pub fn signed_mod_reduction(n: u64, modulus: u64) -> i64 {
3129 }
3230}
3331
34- bigint_impl ! ( BigInteger64 , 1 ) ;
35- bigint_impl ! ( BigInteger128 , 2 ) ;
36- bigint_impl ! ( BigInteger256 , 4 ) ;
37- bigint_impl ! ( BigInteger320 , 5 ) ;
38- bigint_impl ! ( BigInteger384 , 6 ) ;
39- bigint_impl ! ( BigInteger448 , 7 ) ;
40- bigint_impl ! ( BigInteger768 , 12 ) ;
41- bigint_impl ! ( BigInteger832 , 13 ) ;
32+ pub mod native_bigint {
33+ use super :: * ;
34+ bigint_impl ! ( BigInteger256 , 4 ) ;
35+ }
36+ pub mod webnode;
37+
38+ #[ cfg( not( any( target_family = "wasm" , feature = "32x9" ) ) ) ]
39+ pub use native_bigint:: * ;
40+
41+ #[ cfg( any( target_family = "wasm" , feature = "32x9" ) ) ]
42+ pub use webnode:: * ;
4243
4344#[ cfg( test) ]
4445mod tests;
@@ -63,15 +64,16 @@ pub trait BigInteger:
6364 + ' static
6465 + UniformRand
6566 + Zeroize
66- + AsMut < [ u64 ] >
67- + AsRef < [ u64 ] >
6867 + From < u64 >
6968 + TryFrom < BigUint >
7069 + Into < BigUint >
7170{
7271 /// Number of limbs.
7372 const NUM_LIMBS : usize ;
7473
74+ fn to_64x4 ( & self ) -> [ u64 ; 4 ] ;
75+ fn from_64x4 ( value : [ u64 ; 4 ] ) -> Self ;
76+
7577 /// Add another representation to this one, returning the carry bit.
7678 fn add_nocarry ( & mut self , other : & Self ) -> bool ;
7779
@@ -119,13 +121,13 @@ pub trait BigInteger:
119121 /// Returns the bit representation in a big endian boolean array,
120122 /// with leading zeroes.
121123 fn to_bits_be ( & self ) -> Vec < bool > {
122- BitIteratorBE :: new ( self ) . collect :: < Vec < _ > > ( )
124+ BitIteratorBE :: new ( self . to_64x4 ( ) ) . collect :: < Vec < _ > > ( )
123125 }
124126
125127 /// Returns the bit representation in a little endian boolean array,
126128 /// with trailing zeroes.
127129 fn to_bits_le ( & self ) -> Vec < bool > {
128- BitIteratorLE :: new ( self ) . collect :: < Vec < _ > > ( )
130+ BitIteratorLE :: new ( self . to_64x4 ( ) ) . collect :: < Vec < _ > > ( )
129131 }
130132
131133 /// Returns the byte representation in a big endian byte array,
@@ -143,11 +145,12 @@ pub trait BigInteger:
143145 if w >= 2 && w < 64 {
144146 let mut res = vec ! [ ] ;
145147 let mut e = * self ;
148+ let e64 = self . to_64x4 ( ) ;
146149
147150 while !e. is_zero ( ) {
148151 let z: i64 ;
149152 if e. is_odd ( ) {
150- z = signed_mod_reduction ( e . as_ref ( ) [ 0 ] , 1 << w) ;
153+ z = signed_mod_reduction ( e64 . as_ref ( ) [ 0 ] , 1 << w) ;
151154 if z >= 0 {
152155 e. sub_noborrow ( & Self :: from ( z as u64 ) ) ;
153156 } else {
0 commit comments