Skip to content

Commit 196b90f

Browse files
committed
Remove crypto feature. Add AES/SHA2 features to all arm/aarch64 platforms.
1 parent 391fbff commit 196b90f

File tree

6 files changed

+23
-35
lines changed

6 files changed

+23
-35
lines changed

crates/std_detect/src/detect/arch/aarch64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ features! {
1919
/// * `"fp16"` - FEAT_FP16
2020
/// * `"sve"` - FEAT_SVE
2121
/// * `"crc"` - FEAT_CRC
22-
/// * `"crypto"` - Cryptographic Extension (AES + PMULL + SHA1 + SHA2-256)
2322
/// * `"lse"` - FEAT_LSE
2423
/// * `"lse2"` - FEAT_LSE2
2524
/// * `"rdm"` - FEAT_RDM
@@ -50,6 +49,7 @@ features! {
5049
/// * `"mte"` - FEAT_MTE
5150
/// * `"jsconv"` - FEAT_JSCVT
5251
/// * `"fcma"` - FEAT_FCMA
52+
/// * `"aes"` - FEAT_AES
5353
/// * `"sha2"` - FEAT_SHA1 & FEAT_SHA256
5454
/// * `"sha3"` - FEAT_SHA512 & FEAT_SHA3
5555
/// * `"sm4"` - FEAT_SM3 & FEAT_SM4
@@ -77,8 +77,6 @@ features! {
7777
/// FEAT_SVE (Scalable Vector Extension)
7878
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] crc: "crc";
7979
/// FEAT_CRC32 (Cyclic Redundancy Check)
80-
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] crypto: "crypto";
81-
/// Cryptographic Extension (AES + PMULL + SHA1 + SHA2-256)
8280
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] lse: "lse";
8381
/// FEAT_LSE (Large System Extension - atomics)
8482
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] lse2: "lse2";
@@ -139,6 +137,8 @@ features! {
139137
/// FEAT_JSCVT (JavaScript float conversion instructions)
140138
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] fcma: "fcma";
141139
/// FEAT_FCMA (float complex number operations)
140+
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] aes: "aes";
141+
/// FEAT_AES (AES instructions)
142142
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] sha2: "sha2";
143143
/// FEAT_SHA1 & FEAT_SHA256 (SHA1 & SHA2-256 instructions)
144144
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] sha3: "sha3";

crates/std_detect/src/detect/arch/arm.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ features! {
1616
/// Polynomial Multiply
1717
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] crc: "crc";
1818
/// CRC32 (Cyclic Redundancy Check)
19-
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] crypto: "crypto";
20-
/// Crypto: AES + PMULL + SHA1 + SHA2
19+
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] aes: "aes";
20+
/// FEAT_AES (AES instructions)
21+
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] sha2: "sha2";
22+
/// FEAT_SHA1 & FEAT_SHA256 (SHA1 & SHA2-256 instructions)
2123
}

crates/std_detect/src/detect/os/aarch64.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
4141
);
4242
}
4343

44-
let aes = bits_shift(aa64isar0, 7, 4) >= 1;
45-
let pmull = bits_shift(aa64isar0, 7, 4) >= 2;
46-
let sha1 = bits_shift(aa64isar0, 11, 8) >= 1;
47-
let sha2 = bits_shift(aa64isar0, 15, 12) >= 1;
48-
enable_feature(Feature::pmull, pmull);
49-
// Crypto is specified as AES + PMULL + SHA1 + SHA2 per LLVM/hosts.cpp
50-
enable_feature(Feature::crypto, aes && pmull && sha1 && sha2);
44+
enable_feature(Feature::pmull, bits_shift(aa64isar0, 7, 4) >= 2);
5145
enable_feature(Feature::tme, bits_shift(aa64isar0, 27, 24) == 1);
5246
enable_feature(Feature::lse, bits_shift(aa64isar0, 23, 20) >= 1);
5347
enable_feature(Feature::crc, bits_shift(aa64isar0, 19, 16) >= 1);
@@ -72,6 +66,10 @@ pub(crate) fn detect_features() -> cache::Initializer {
7266
// supported, it also requires half-float support:
7367
enable_feature(Feature::asimd, fp && asimd && (!fphp | asimdhp));
7468
// SIMD extensions require SIMD support:
69+
enable_feature(Feature::aes, asimd && bits_shift(aa64isar0, 7, 4) >= 1);
70+
let sha1 = bits_shift(aa64isar0, 11, 8) >= 1;
71+
let sha2 = bits_shift(aa64isar0, 15, 12) >= 1;
72+
enable_feature(Feature::sha2, asimd && sha1 && sha2);
7573
enable_feature(Feature::rdm, asimd && bits_shift(aa64isar0, 31, 28) >= 1);
7674
enable_feature(
7775
Feature::dotprod,

crates/std_detect/src/detect/os/linux/aarch64.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ impl AtHwcap {
261261
enable_feature(Feature::f64mm, self.svef64mm && self.sve && asimd);
262262

263263
// Cryptographic extensions require ASIMD
264+
enable_feature(Feature::aes, self.aes && asimd);
264265
enable_feature(Feature::sha2, self.sha1 && self.sha2 && asimd);
265266
// SHA512/SHA3 require SHA1 & SHA256
266267
enable_feature(Feature::sha3, self.sha512 && self.sha3 && self.sha1 && self.sha2 && asimd);
@@ -274,12 +275,6 @@ impl AtHwcap {
274275
enable_feature(Feature::sve2_sm4, self.svesm4 && sve2 && self.sm3 && self.sm4);
275276
enable_feature(Feature::sve2_sha3, self.svesha3 && sve2 && self.sha512 && self.sha3 && self.sha1 && self.sha2);
276277
enable_feature(Feature::sve2_bitperm, self.svebitperm && self.sve2);
277-
278-
// Crypto is specified as AES + PMULL + SHA1 + SHA2 per LLVM/hosts.cpp
279-
enable_feature(
280-
Feature::crypto,
281-
self.aes && self.pmull && self.sha1 && self.sha2,
282-
);
283278
}
284279
value
285280
}

crates/std_detect/src/detect/os/linux/arm.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ pub(crate) fn detect_features() -> cache::Initializer {
2020
enable_feature(&mut value, Feature::neon, bit::test(auxv.hwcap, 12));
2121
enable_feature(&mut value, Feature::pmull, bit::test(auxv.hwcap2, 1));
2222
enable_feature(&mut value, Feature::crc, bit::test(auxv.hwcap2, 4));
23-
enable_feature(
24-
&mut value,
25-
Feature::crypto,
26-
bit::test(auxv.hwcap2, 0)
27-
&& bit::test(auxv.hwcap2, 1)
28-
&& bit::test(auxv.hwcap2, 2)
29-
&& bit::test(auxv.hwcap2, 3),
30-
);
23+
enable_feature(&mut value, Feature::aes, bit::test(auxv.hwcap2, 0));
24+
// SHA2 requires SHA1 & SHA2 features
25+
enable_feature(&mut value, Feature::sha2, bit::test(auxv.hwcap2, 2) && bit::test(auxv.hwcap2, 3));
3126
return value;
3227
}
3328

@@ -40,14 +35,8 @@ pub(crate) fn detect_features() -> cache::Initializer {
4035
);
4136
enable_feature(&mut value, Feature::pmull, c.field("Features").has("pmull"));
4237
enable_feature(&mut value, Feature::crc, c.field("Features").has("crc32"));
43-
enable_feature(
44-
&mut value,
45-
Feature::crypto,
46-
c.field("Features").has("aes")
47-
&& c.field("Features").has("pmull")
48-
&& c.field("Features").has("sha1")
49-
&& c.field("Features").has("sha2"),
50-
);
38+
enable_feature(&mut value, Feature::aes, c.field("Features").has("aes"));
39+
enable_feature(&mut value, Feature::sha2, c.field("Features").has("sha1") && c.field("Features").has("sha2"));
5140
return value;
5241
}
5342
value

crates/std_detect/src/detect/os/windows/aarch64.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ pub(crate) fn detect_features() -> cache::Initializer {
4242
// PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE means aes, sha1, sha2 and
4343
// pmull support
4444
enable_feature(
45-
Feature::crypto,
45+
Feature::aes,
4646
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != FALSE,
4747
);
4848
enable_feature(
4949
Feature::pmull,
5050
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != FALSE,
5151
);
52+
enable_feature(
53+
Feature::sha2,
54+
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != FALSE,
55+
);
5256
}
5357
}
5458
value

0 commit comments

Comments
 (0)