@@ -54,12 +54,22 @@ pub(crate) fn scrypt_ro_mix(b: &mut [u8], v: &mut [u8], t: &mut [u8], n: usize)
5454
5555 for chunk in v. chunks_mut ( len) {
5656 chunk. copy_from_slice ( b) ;
57+
58+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
59+ scrypt_block_mix_abcd ( chunk, b) ;
60+
61+ #[ cfg( not( any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
5762 scrypt_block_mix ( chunk, b) ;
5863 }
5964
6065 for _ in 0 ..n {
6166 let j = integerify ( b, n) ;
6267 xor ( b, & v[ j * len..( j + 1 ) * len] , t) ;
68+
69+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
70+ scrypt_block_mix_abcd ( t, b) ;
71+
72+ #[ cfg( not( any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
6373 scrypt_block_mix ( t, b) ;
6474 }
6575
@@ -113,11 +123,11 @@ fn scrypt_block_mix(input: &[u8], output: &mut [u8]) {
113123 }
114124}
115125
116- /// Execute the BlockMix operation
126+ /// Execute the BlockMix operation with pre-shuffled input.
117127/// input - the input vector. The length must be a multiple of 128.
118128/// output - the output vector. Must be the same length as input.
119129#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
120- fn scrypt_block_mix ( input : & [ u8 ] , output : & mut [ u8 ] ) {
130+ fn scrypt_block_mix_abcd ( input : & [ u8 ] , output : & mut [ u8 ] ) {
121131 #[ cfg( target_arch = "x86" ) ]
122132 use core:: arch:: x86:: * ;
123133
@@ -131,13 +141,12 @@ fn scrypt_block_mix(input: &[u8], output: &mut [u8]) {
131141 } } ;
132142 }
133143
134- let mut x = [ 0u8 ; 64 ] ;
135- x. copy_from_slice ( & input[ input. len ( ) - 64 ..] ) ;
144+ let last_block = & input[ input. len ( ) - 64 ..] ;
136145
137- let mut a = unsafe { _mm_loadu_si128 ( x . as_ptr ( ) . cast ( ) ) } ;
138- let mut b = unsafe { _mm_loadu_si128 ( x . as_ptr ( ) . add ( 16 ) . cast ( ) ) } ;
139- let mut c = unsafe { _mm_loadu_si128 ( x . as_ptr ( ) . add ( 32 ) . cast ( ) ) } ;
140- let mut d = unsafe { _mm_loadu_si128 ( x . as_ptr ( ) . add ( 48 ) . cast ( ) ) } ;
146+ let mut a = unsafe { _mm_loadu_si128 ( last_block . as_ptr ( ) . cast ( ) ) } ;
147+ let mut b = unsafe { _mm_loadu_si128 ( last_block . as_ptr ( ) . add ( 16 ) . cast ( ) ) } ;
148+ let mut c = unsafe { _mm_loadu_si128 ( last_block . as_ptr ( ) . add ( 32 ) . cast ( ) ) } ;
149+ let mut d = unsafe { _mm_loadu_si128 ( last_block . as_ptr ( ) . add ( 48 ) . cast ( ) ) } ;
141150
142151 for ( i, chunk) in input. chunks ( 64 ) . enumerate ( ) {
143152 let pos = if i % 2 == 0 {
0 commit comments