1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#![cfg(target_feature = "aes")]

use super::*;

/// "Perform one round of AES decryption flow on `a` using the `round_key`."
/// ```
/// # use safe_arch::*;
/// // TODO
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "aes")))]
pub fn aes_decrypt_m128i(a: m128i, round_key: m128i) -> m128i {
  m128i(unsafe { _mm_aesdec_si128(a.0, round_key.0) })
}

/// "Perform the last round of AES decryption flow on `a` using the
/// `round_key`."
/// ```
/// # use safe_arch::*;
/// // TODO
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "aes")))]
pub fn aes_decrypt_last_m128i(a: m128i, round_key: m128i) -> m128i {
  m128i(unsafe { _mm_aesdeclast_si128(a.0, round_key.0) })
}

/// "Perform one round of AES encryption flow on `a` using the `round_key`."
/// ```
/// # use safe_arch::*;
/// // TODO
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "aes")))]
pub fn aes_encrypt_m128i(a: m128i, round_key: m128i) -> m128i {
  m128i(unsafe { _mm_aesenc_si128(a.0, round_key.0) })
}

/// "Perform the last round of AES encryption flow on `a` using the
/// `round_key`."
/// ```
/// # use safe_arch::*;
/// // TODO
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "aes")))]
pub fn aes_encrypt_last_m128i(a: m128i, round_key: m128i) -> m128i {
  m128i(unsafe { _mm_aesenclast_si128(a.0, round_key.0) })
}

/// "Perform the InvMixColumns transform on `a`."
/// ```
/// # use safe_arch::*;
/// // TODO
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "aes")))]
pub fn aes_inv_mix_columns_m128i(a: m128i) -> m128i {
  m128i(unsafe { _mm_aesimc_si128(a.0) })
}

/// ?
/// ```
/// # use safe_arch::*;
/// // TODO
/// ```
#[macro_export]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "aes")))]
macro_rules! aes_key_gen_assist_m128i {
  ($a:expr, $imm:expr) => {{
    let a: $crate::m128i = $a;
    const IMM: ::core::primitive::i32 =
      ($imm & 0b1111_1111) as ::core::primitive::i32;
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_mm_aeskeygenassist_si128;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_mm_aeskeygenassist_si128;
    $crate::m128i(unsafe { _mm_aeskeygenassist_si128(a.0, IMM) })
  }};
}