1- /// Keccak-f1600 on ARMv8.4-A with FEAT_SHA3.
1+ /// Keccak-p1600 on ARMv8.4-A with FEAT_SHA3.
22///
33/// See p. K12.2.2 p. 11,749 of the ARM Reference manual.
44/// Adapted from the Keccak-f1600 implementation in the XKCP/K12.
55/// see <https://github.com/XKCP/K12/blob/df6a21e6d1f34c1aa36e8d702540899c97dba5a0/lib/ARMv8Asha3/KeccakP-1600-ARMv8Asha3.S#L69>
66#[ target_feature( enable = "sha3" ) ]
7- pub unsafe fn f1600_armv8_sha3_asm ( state : & mut [ u64 ; 25 ] ) {
7+ pub unsafe fn p1600_armv8_sha3_asm ( state : & mut [ u64 ; 25 ] , round_count : usize ) {
88 core:: arch:: asm!( "
99 // Read state
1010 ld1.1d {{ v0- v3}}, [x0], #32
@@ -16,11 +16,9 @@ pub unsafe fn f1600_armv8_sha3_asm(state: &mut [u64; 25]) {
1616 ld1.1d {{v24}}, [x0]
1717 sub x0, x0, #192
1818
19- // Loop 24 rounds
2019 // NOTE: This loop actually computes two f1600 functions in
2120 // parallel, in both the lower and the upper 64-bit of the
2221 // 128-bit registers v0-v24.
23- mov x8, #24
2422 0: sub x8, x8, #1
2523
2624 // Theta Calculations
@@ -115,7 +113,8 @@ pub unsafe fn f1600_armv8_sha3_asm(state: &mut [u64; 25]) {
115113 st1.1d {{v24}}, [x0]
116114 " ,
117115 in( "x0" ) state. as_mut_ptr( ) ,
118- in( "x1" ) crate :: RC . as_ptr( ) ,
116+ in( "x1" ) crate :: RC [ 24 -round_count..] . as_ptr( ) ,
117+ in( "x8" ) round_count,
119118 clobber_abi( "C" ) ,
120119 options( nostack)
121120 ) ;
@@ -185,9 +184,9 @@ mod tests {
185184 ] ;
186185
187186 let mut state = [ 0u64 ; 25 ] ;
188- unsafe { f1600_armv8_sha3_asm ( & mut state) } ;
187+ unsafe { p1600_armv8_sha3_asm ( & mut state, 24 ) } ;
189188 assert_eq ! ( state, state_first) ;
190- unsafe { f1600_armv8_sha3_asm ( & mut state) } ;
189+ unsafe { p1600_armv8_sha3_asm ( & mut state, 24 ) } ;
191190 assert_eq ! ( state, state_second) ;
192191 }
193192}
0 commit comments