@@ -63,6 +63,7 @@ pub fn crc32_iso_hdlc(crc: u32, data: &[u8]) -> u32 {
6363}
6464
6565#[ inline]
66+ #[ cfg( target_feature = "sha3" ) ]
6667#[ target_feature( enable = "neon,aes" ) ]
6768unsafe fn clmul_lo_eor3 ( a : uint64x2_t , b : uint64x2_t ) -> uint64x2_t {
6869 // Polynomial multiply low parts - convert u128 result to uint64x2_t
@@ -71,6 +72,7 @@ unsafe fn clmul_lo_eor3(a: uint64x2_t, b: uint64x2_t) -> uint64x2_t {
7172}
7273
7374#[ inline]
75+ #[ cfg( target_feature = "sha3" ) ]
7476#[ target_feature( enable = "neon,aes" ) ]
7577unsafe fn clmul_hi_eor3 ( a : uint64x2_t , b : uint64x2_t ) -> uint64x2_t {
7678 // Polynomial multiply high parts - convert u128 result to uint64x2_t
@@ -79,6 +81,7 @@ unsafe fn clmul_hi_eor3(a: uint64x2_t, b: uint64x2_t) -> uint64x2_t {
7981}
8082
8183#[ inline]
84+ #[ cfg( target_feature = "sha3" ) ]
8285#[ target_feature( enable = "neon,aes" ) ]
8386unsafe fn clmul_scalar ( a : u32 , b : u32 ) -> uint64x2_t {
8487 // Polynomial multiply scalars - convert u128 result to uint64x2_t
@@ -88,6 +91,7 @@ unsafe fn clmul_scalar(a: u32, b: u32) -> uint64x2_t {
8891
8992// x^n mod P, in log(n) time
9093#[ inline]
94+ #[ cfg( target_feature = "sha3" ) ]
9195#[ target_feature( enable = "neon,aes" ) ]
9296fn xnmodp_crc32_iscsi ( mut n : u64 ) -> u32 {
9397 let mut stack = !1u64 ;
@@ -125,13 +129,15 @@ fn xnmodp_crc32_iscsi(mut n: u64) -> u32 {
125129}
126130
127131#[ inline]
132+ #[ cfg( target_feature = "sha3" ) ]
128133#[ target_feature( enable = "neon,aes" ) ]
129134unsafe fn crc_shift_iscsi ( crc : u32 , nbytes : usize ) -> uint64x2_t {
130135 clmul_scalar ( crc, xnmodp_crc32_iscsi ( ( nbytes * 8 - 33 ) as u64 ) )
131136}
132137
133138// x^n mod P, in log(n) time
134139#[ inline]
140+ #[ cfg( target_feature = "sha3" ) ]
135141#[ target_feature( enable = "neon,aes" ) ]
136142fn xnmodp_iso_hdlc ( mut n : u64 ) -> u32 {
137143 let mut stack = !1u64 ;
@@ -169,6 +175,7 @@ fn xnmodp_iso_hdlc(mut n: u64) -> u32 {
169175}
170176
171177#[ inline]
178+ #[ cfg( target_feature = "sha3" ) ]
172179#[ target_feature( enable = "neon,aes" ) ]
173180unsafe fn crc_shift_iso_hdlc ( crc : u32 , nbytes : usize ) -> uint64x2_t {
174181 clmul_scalar ( crc, xnmodp_iso_hdlc ( ( nbytes * 8 - 33 ) as u64 ) )
@@ -179,6 +186,7 @@ unsafe fn crc_shift_iso_hdlc(crc: u32, nbytes: usize) -> uint64x2_t {
179186///
180187/// ./generate -i neon_eor3 -p crc32c -a v9s3x2e_s3
181188#[ inline]
189+ #[ cfg( target_feature = "sha3" ) ]
182190#[ target_feature( enable = "neon,aes,sha3" ) ]
183191unsafe fn crc32_iscsi_eor3_v9s3x2e_s3 ( mut crc0 : u32 , mut buf : * const u8 , mut len : usize ) -> u32 {
184192 // Align to 8-byte boundary
@@ -555,6 +563,7 @@ unsafe fn crc32_iscsi_v12e_v1(mut crc0: u32, mut buf: *const u8, mut len: usize)
555563///
556564/// ./generate -i neon_eor3 -p crc32 -a v9s3x2e_s3
557565#[ inline]
566+ #[ cfg( target_feature = "sha3" ) ]
558567#[ target_feature( enable = "neon,aes,sha3" ) ]
559568unsafe fn crc32_iso_hdlc_eor3_v9s3x2e_s3 ( mut crc0 : u32 , mut buf : * const u8 , mut len : usize ) -> u32 {
560569 // Align to 8-byte boundary
@@ -916,7 +925,6 @@ mod tests {
916925 use crate :: test:: consts:: TEST_CHECK_STRING ;
917926 use crc:: { Crc , Table } ;
918927 use rand:: { rng, Rng } ;
919- use std:: arch:: is_aarch64_feature_detected;
920928
921929 const RUST_CRC32_ISO_HDLC : Crc < u32 , Table < 16 > > =
922930 Crc :: < u32 , Table < 16 > > :: new ( & crc:: CRC_32_ISO_HDLC ) ;
@@ -985,6 +993,7 @@ mod tests {
985993 }
986994 }
987995
996+ #[ cfg( target_feature = "sha3" ) ]
988997 fn crc32_iso_hdlc_random ( len : usize ) {
989998 let mut data = vec ! [ 0u8 ; len] ;
990999 rng ( ) . fill ( & mut data[ ..] ) ;
@@ -994,13 +1003,11 @@ mod tests {
9941003 assert_eq ! ( crc32_iso_hdlc( 0xffffffff , & data) ^ 0xffffffff , checksum) ;
9951004
9961005 unsafe {
997- if is_aarch64_feature_detected ! ( "sha3" ) {
998- assert_eq ! (
999- crc32_iso_hdlc_eor3_v9s3x2e_s3( 0xffffffff , data. as_ptr( ) , data. len( ) )
1000- ^ 0xffffffff ,
1001- checksum
1002- ) ;
1003- }
1006+ assert_eq ! (
1007+ crc32_iso_hdlc_eor3_v9s3x2e_s3( 0xffffffff , data. as_ptr( ) , data. len( ) )
1008+ ^ 0xffffffff ,
1009+ checksum
1010+ ) ;
10041011
10051012 assert_eq ! (
10061013 crc32_iso_hdlc_v12e_v1( 0xffffffff , data. as_ptr( ) , data. len( ) ) ^ 0xffffffff ,
@@ -1009,6 +1016,24 @@ mod tests {
10091016 }
10101017 }
10111018
1019+ #[ cfg( not( target_feature = "sha3" ) ) ]
1020+ fn crc32_iso_hdlc_random ( len : usize ) {
1021+ let mut data = vec ! [ 0u8 ; len] ;
1022+ rng ( ) . fill ( & mut data[ ..] ) ;
1023+
1024+ let checksum = RUST_CRC32_ISO_HDLC . checksum ( & data) ;
1025+
1026+ assert_eq ! ( crc32_iso_hdlc( 0xffffffff , & data) ^ 0xffffffff , checksum) ;
1027+
1028+ unsafe {
1029+ assert_eq ! (
1030+ crc32_iso_hdlc_v12e_v1( 0xffffffff , data. as_ptr( ) , data. len( ) ) ^ 0xffffffff ,
1031+ checksum
1032+ ) ;
1033+ }
1034+ }
1035+
1036+ #[ cfg( target_feature = "sha3" ) ]
10121037 fn crc32_iscsi_random ( len : usize ) {
10131038 let mut data = vec ! [ 0u8 ; len] ;
10141039 rng ( ) . fill ( & mut data[ ..] ) ;
@@ -1018,13 +1043,28 @@ mod tests {
10181043 assert_eq ! ( crc32_iscsi( 0xffffffff , & data) ^ 0xffffffff , checksum) ;
10191044
10201045 unsafe {
1021- if is_aarch64_feature_detected ! ( "sha3" ) {
1022- assert_eq ! (
1023- crc32_iscsi_eor3_v9s3x2e_s3( 0xffffffff , data. as_ptr( ) , data. len( ) ) ^ 0xffffffff ,
1024- checksum
1025- ) ;
1026- }
1046+ assert_eq ! (
1047+ crc32_iscsi_eor3_v9s3x2e_s3( 0xffffffff , data. as_ptr( ) , data. len( ) ) ^ 0xffffffff ,
1048+ checksum
1049+ ) ;
1050+
1051+ assert_eq ! (
1052+ crc32_iscsi_v12e_v1( 0xffffffff , data. as_ptr( ) , data. len( ) ) ^ 0xffffffff ,
1053+ checksum
1054+ ) ;
1055+ }
1056+ }
1057+
1058+ #[ cfg( not( target_feature = "sha3" ) ) ]
1059+ fn crc32_iscsi_random ( len : usize ) {
1060+ let mut data = vec ! [ 0u8 ; len] ;
1061+ rng ( ) . fill ( & mut data[ ..] ) ;
1062+
1063+ let checksum = RUST_CRC32_ISCSI . checksum ( & data) ;
10271064
1065+ assert_eq ! ( crc32_iscsi( 0xffffffff , & data) ^ 0xffffffff , checksum) ;
1066+
1067+ unsafe {
10281068 assert_eq ! (
10291069 crc32_iscsi_v12e_v1( 0xffffffff , data. as_ptr( ) , data. len( ) ) ^ 0xffffffff ,
10301070 checksum
0 commit comments