-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds "polyfills" for the unstable ARMv8 AES intrinsics using the `asm!` macro which was stabilized in Rust 1.59. However note we also need `target_feature` stabilizations for `aes` and `neon` which occurred in Rust 1.61. Based on benchmarks this has no effect on performance, although it was necessary to place AESE/AESMC and AESD/AESIMC into a single `asm!` block in order to ensure that instructions fuse properly, as they did when using the proper intrinsics.
- Loading branch information
Showing
8 changed files
with
133 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//! Stable "polyfills" for unstable `core::arch::aarch64` intrinsics which use | ||
//! `asm!` internally to allow use on stable Rust. | ||
// TODO(tarcieri): remove when these intrinsics have been stabilized | ||
|
||
use core::arch::{aarch64::uint8x16_t, asm}; | ||
|
||
/// AES single round encryption. | ||
#[inline] | ||
#[target_feature(enable = "aes")] | ||
pub(super) unsafe fn vaeseq_u8(mut data: uint8x16_t, key: uint8x16_t) -> uint8x16_t { | ||
asm!( | ||
"AESE {d:v}.16B, {k:v}.16B", | ||
d = inout(vreg) data, | ||
k = in(vreg) key, | ||
options(pure, nomem, nostack, preserves_flags) | ||
); | ||
data | ||
} | ||
|
||
/// AES single round decryption. | ||
#[inline] | ||
#[target_feature(enable = "aes")] | ||
pub(super) unsafe fn vaesdq_u8(mut data: uint8x16_t, key: uint8x16_t) -> uint8x16_t { | ||
asm!( | ||
"AESD {d:v}.16B, {k:v}.16B", | ||
d = inout(vreg) data, | ||
k = in(vreg) key, | ||
options(pure, nomem, nostack, preserves_flags) | ||
); | ||
data | ||
} | ||
|
||
/// AES mix columns. | ||
#[cfg(feature = "hazmat")] | ||
#[inline] | ||
#[target_feature(enable = "aes")] | ||
pub(super) unsafe fn vaesmcq_u8(mut data: uint8x16_t) -> uint8x16_t { | ||
asm!( | ||
"AESMC {d:v}.16B, {d:v}.16B", | ||
d = inout(vreg) data, | ||
options(pure, nomem, nostack, preserves_flags) | ||
); | ||
data | ||
} | ||
|
||
/// AES inverse mix columns. | ||
#[inline] | ||
#[target_feature(enable = "aes")] | ||
pub(super) unsafe fn vaesimcq_u8(mut data: uint8x16_t) -> uint8x16_t { | ||
asm!( | ||
"AESIMC {d:v}.16B, {d:v}.16B", | ||
d = inout(vreg) data, | ||
options(pure, nomem, nostack, preserves_flags) | ||
); | ||
data | ||
} | ||
|
||
/// AES single round encryption combined with mix columns. | ||
/// | ||
/// These two instructions are combined into a single assembly block to ensure | ||
/// that instructions fuse properly. | ||
#[inline] | ||
#[target_feature(enable = "aes")] | ||
pub(super) unsafe fn vaeseq_u8_and_vaesmcq_u8(mut data: uint8x16_t, key: uint8x16_t) -> uint8x16_t { | ||
asm!( | ||
"AESE {d:v}.16B, {k:v}.16B", | ||
"AESMC {d:v}.16B, {d:v}.16B", | ||
d = inout(vreg) data, | ||
k = in(vreg) key, | ||
options(pure, nomem, nostack, preserves_flags) | ||
); | ||
data | ||
} | ||
|
||
/// AES single round decryption combined with mix columns. | ||
/// | ||
/// These two instructions are combined into a single assembly block to ensure | ||
/// that instructions fuse properly. | ||
#[inline] | ||
#[target_feature(enable = "aes")] | ||
pub(super) unsafe fn vaesdq_u8_and_vaesimcq_u8( | ||
mut data: uint8x16_t, | ||
key: uint8x16_t, | ||
) -> uint8x16_t { | ||
asm!( | ||
"AESD {d:v}.16B, {k:v}.16B", | ||
"AESIMC {d:v}.16B, {d:v}.16B", | ||
d = inout(vreg) data, | ||
k = in(vreg) key, | ||
options(pure, nomem, nostack, preserves_flags) | ||
); | ||
data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters