| 1 |
//! Stable "polyfills" for unstable `core::arch::aarch64` intrinsics which use |
| 2 |
//! `asm!` internally to allow use on stable Rust. |
| 3 |
// TODO(tarcieri): remove when these intrinsics have been stabilized |
| 4 |
|
| 5 |
use core::arch::{aarch64::uint8x16_t, asm}; |
| 6 |
|
| 7 |
/// AES single round encryption. |
| 8 |
#[inline] |
| 9 |
#[target_feature(enable = "aes")] |
| 10 |
pub(super) unsafe fn vaeseq_u8(mut data: uint8x16_t, key: uint8x16_t) -> uint8x16_t { |
| 11 |
asm!( |
| 12 |
"AESE {d:v}.16B, {k:v}.16B", |
| 13 |
d = inout(vreg) data, |
| 14 |
k = in(vreg) key, |
| 15 |
options(pure, nomem, nostack, preserves_flags) |
| 16 |
); |
| 17 |
data |
| 18 |
} |
| 19 |
|
| 20 |
/// AES single round decryption. |
| 21 |
#[inline] |
| 22 |
#[target_feature(enable = "aes")] |
| 23 |
pub(super) unsafe fn vaesdq_u8(mut data: uint8x16_t, key: uint8x16_t) -> uint8x16_t { |
| 24 |
asm!( |
| 25 |
"AESD {d:v}.16B, {k:v}.16B", |
| 26 |
d = inout(vreg) data, |
| 27 |
k = in(vreg) key, |
| 28 |
options(pure, nomem, nostack, preserves_flags) |
| 29 |
); |
| 30 |
data |
| 31 |
} |
| 32 |
|
| 33 |
/// AES mix columns. |
| 34 |
#[cfg(feature = "hazmat")] |
| 35 |
#[inline] |
| 36 |
#[target_feature(enable = "aes")] |
| 37 |
pub(super) unsafe fn vaesmcq_u8(mut data: uint8x16_t) -> uint8x16_t { |
| 38 |
asm!( |
| 39 |
"AESMC {d:v}.16B, {d:v}.16B", |
| 40 |
d = inout(vreg) data, |
| 41 |
options(pure, nomem, nostack, preserves_flags) |
| 42 |
); |
| 43 |
data |
| 44 |
} |
| 45 |
|
| 46 |
/// AES inverse mix columns. |
| 47 |
#[inline] |
| 48 |
#[target_feature(enable = "aes")] |
| 49 |
pub(super) unsafe fn vaesimcq_u8(mut data: uint8x16_t) -> uint8x16_t { |
| 50 |
asm!( |
| 51 |
"AESIMC {d:v}.16B, {d:v}.16B", |
| 52 |
d = inout(vreg) data, |
| 53 |
options(pure, nomem, nostack, preserves_flags) |
| 54 |
); |
| 55 |
data |
| 56 |
} |
| 57 |
|
| 58 |
/// AES single round encryption combined with mix columns. |
| 59 |
/// |
| 60 |
/// These two instructions are combined into a single assembly block to ensure |
| 61 |
/// that instructions fuse properly. |
| 62 |
#[inline] |
| 63 |
#[target_feature(enable = "aes")] |
| 64 |
pub(super) unsafe fn vaeseq_u8_and_vaesmcq_u8(mut data: uint8x16_t, key: uint8x16_t) -> uint8x16_t { |
| 65 |
asm!( |
| 66 |
"AESE {d:v}.16B, {k:v}.16B", |
| 67 |
"AESMC {d:v}.16B, {d:v}.16B", |
| 68 |
d = inout(vreg) data, |
| 69 |
k = in(vreg) key, |
| 70 |
options(pure, nomem, nostack, preserves_flags) |
| 71 |
); |
| 72 |
data |
| 73 |
} |
| 74 |
|
| 75 |
/// AES single round decryption combined with mix columns. |
| 76 |
/// |
| 77 |
/// These two instructions are combined into a single assembly block to ensure |
| 78 |
/// that instructions fuse properly. |
| 79 |
#[inline] |
| 80 |
#[target_feature(enable = "aes")] |
| 81 |
pub(super) unsafe fn vaesdq_u8_and_vaesimcq_u8( |
| 82 |
mut data: uint8x16_t, |
| 83 |
key: uint8x16_t, |
| 84 |
) -> uint8x16_t { |
| 85 |
asm!( |
| 86 |
"AESD {d:v}.16B, {k:v}.16B", |
| 87 |
"AESIMC {d:v}.16B, {d:v}.16B", |
| 88 |
d = inout(vreg) data, |
| 89 |
k = in(vreg) key, |
| 90 |
options(pure, nomem, nostack, preserves_flags) |
| 91 |
); |
| 92 |
data |
| 93 |
} |