@@ -63,6 +63,7 @@ pub fn crc32_iso_hdlc(crc: u32, data: &[u8]) -> u32 {
63
63
}
64
64
65
65
#[ inline]
66
+ #[ cfg( target_feature = "sha3" ) ]
66
67
#[ target_feature( enable = "neon,aes" ) ]
67
68
unsafe fn clmul_lo_eor3 ( a : uint64x2_t , b : uint64x2_t ) -> uint64x2_t {
68
69
// 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 {
71
72
}
72
73
73
74
#[ inline]
75
+ #[ cfg( target_feature = "sha3" ) ]
74
76
#[ target_feature( enable = "neon,aes" ) ]
75
77
unsafe fn clmul_hi_eor3 ( a : uint64x2_t , b : uint64x2_t ) -> uint64x2_t {
76
78
// 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 {
79
81
}
80
82
81
83
#[ inline]
84
+ #[ cfg( target_feature = "sha3" ) ]
82
85
#[ target_feature( enable = "neon,aes" ) ]
83
86
unsafe fn clmul_scalar ( a : u32 , b : u32 ) -> uint64x2_t {
84
87
// Polynomial multiply scalars - convert u128 result to uint64x2_t
@@ -88,6 +91,7 @@ unsafe fn clmul_scalar(a: u32, b: u32) -> uint64x2_t {
88
91
89
92
// x^n mod P, in log(n) time
90
93
#[ inline]
94
+ #[ cfg( target_feature = "sha3" ) ]
91
95
#[ target_feature( enable = "neon,aes" ) ]
92
96
fn xnmodp_crc32_iscsi ( mut n : u64 ) -> u32 {
93
97
let mut stack = !1u64 ;
@@ -125,13 +129,15 @@ fn xnmodp_crc32_iscsi(mut n: u64) -> u32 {
125
129
}
126
130
127
131
#[ inline]
132
+ #[ cfg( target_feature = "sha3" ) ]
128
133
#[ target_feature( enable = "neon,aes" ) ]
129
134
unsafe fn crc_shift_iscsi ( crc : u32 , nbytes : usize ) -> uint64x2_t {
130
135
clmul_scalar ( crc, xnmodp_crc32_iscsi ( ( nbytes * 8 - 33 ) as u64 ) )
131
136
}
132
137
133
138
// x^n mod P, in log(n) time
134
139
#[ inline]
140
+ #[ cfg( target_feature = "sha3" ) ]
135
141
#[ target_feature( enable = "neon,aes" ) ]
136
142
fn xnmodp_iso_hdlc ( mut n : u64 ) -> u32 {
137
143
let mut stack = !1u64 ;
@@ -169,6 +175,7 @@ fn xnmodp_iso_hdlc(mut n: u64) -> u32 {
169
175
}
170
176
171
177
#[ inline]
178
+ #[ cfg( target_feature = "sha3" ) ]
172
179
#[ target_feature( enable = "neon,aes" ) ]
173
180
unsafe fn crc_shift_iso_hdlc ( crc : u32 , nbytes : usize ) -> uint64x2_t {
174
181
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 {
179
186
///
180
187
/// ./generate -i neon_eor3 -p crc32c -a v9s3x2e_s3
181
188
#[ inline]
189
+ #[ cfg( target_feature = "sha3" ) ]
182
190
#[ target_feature( enable = "neon,aes,sha3" ) ]
183
191
unsafe fn crc32_iscsi_eor3_v9s3x2e_s3 ( mut crc0 : u32 , mut buf : * const u8 , mut len : usize ) -> u32 {
184
192
// 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)
555
563
///
556
564
/// ./generate -i neon_eor3 -p crc32 -a v9s3x2e_s3
557
565
#[ inline]
566
+ #[ cfg( target_feature = "sha3" ) ]
558
567
#[ target_feature( enable = "neon,aes,sha3" ) ]
559
568
unsafe fn crc32_iso_hdlc_eor3_v9s3x2e_s3 ( mut crc0 : u32 , mut buf : * const u8 , mut len : usize ) -> u32 {
560
569
// Align to 8-byte boundary
@@ -916,7 +925,6 @@ mod tests {
916
925
use crate :: test:: consts:: TEST_CHECK_STRING ;
917
926
use crc:: { Crc , Table } ;
918
927
use rand:: { rng, Rng } ;
919
- use std:: arch:: is_aarch64_feature_detected;
920
928
921
929
const RUST_CRC32_ISO_HDLC : Crc < u32 , Table < 16 > > =
922
930
Crc :: < u32 , Table < 16 > > :: new ( & crc:: CRC_32_ISO_HDLC ) ;
@@ -985,6 +993,7 @@ mod tests {
985
993
}
986
994
}
987
995
996
+ #[ cfg( target_feature = "sha3" ) ]
988
997
fn crc32_iso_hdlc_random ( len : usize ) {
989
998
let mut data = vec ! [ 0u8 ; len] ;
990
999
rng ( ) . fill ( & mut data[ ..] ) ;
@@ -994,13 +1003,11 @@ mod tests {
994
1003
assert_eq ! ( crc32_iso_hdlc( 0xffffffff , & data) ^ 0xffffffff , checksum) ;
995
1004
996
1005
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
+ ) ;
1004
1011
1005
1012
assert_eq ! (
1006
1013
crc32_iso_hdlc_v12e_v1( 0xffffffff , data. as_ptr( ) , data. len( ) ) ^ 0xffffffff ,
@@ -1009,6 +1016,24 @@ mod tests {
1009
1016
}
1010
1017
}
1011
1018
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" ) ]
1012
1037
fn crc32_iscsi_random ( len : usize ) {
1013
1038
let mut data = vec ! [ 0u8 ; len] ;
1014
1039
rng ( ) . fill ( & mut data[ ..] ) ;
@@ -1018,13 +1043,28 @@ mod tests {
1018
1043
assert_eq ! ( crc32_iscsi( 0xffffffff , & data) ^ 0xffffffff , checksum) ;
1019
1044
1020
1045
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) ;
1027
1064
1065
+ assert_eq ! ( crc32_iscsi( 0xffffffff , & data) ^ 0xffffffff , checksum) ;
1066
+
1067
+ unsafe {
1028
1068
assert_eq ! (
1029
1069
crc32_iscsi_v12e_v1( 0xffffffff , data. as_ptr( ) , data. len( ) ) ^ 0xffffffff ,
1030
1070
checksum
0 commit comments