]> git.proxmox.com Git - rustc.git/blame - library/std/src/sys/sgx/ext/arch.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / library / std / src / sys / sgx / ext / arch.rs
CommitLineData
0731742a
XL
1//! SGX-specific access to architectural features.
2//!
3//! The functionality in this module is further documented in the Intel
4//! Software Developer's Manual, Volume 3, Chapter 40.
5#![unstable(feature = "sgx_platform", issue = "56975")]
6
532ac7d7 7use crate::mem::MaybeUninit;
0731742a
XL
8
9/// Wrapper struct to force 16-byte alignment.
10#[repr(align(16))]
11#[unstable(feature = "sgx_platform", issue = "56975")]
12pub struct Align16<T>(pub T);
13
14/// Wrapper struct to force 128-byte alignment.
15#[repr(align(128))]
16#[unstable(feature = "sgx_platform", issue = "56975")]
17pub struct Align128<T>(pub T);
18
19/// Wrapper struct to force 512-byte alignment.
20#[repr(align(512))]
21#[unstable(feature = "sgx_platform", issue = "56975")]
22pub struct Align512<T>(pub T);
23
24const ENCLU_EREPORT: u32 = 0;
25const ENCLU_EGETKEY: u32 = 1;
26
27/// Call the `EGETKEY` instruction to obtain a 128-bit secret key.
28#[unstable(feature = "sgx_platform", issue = "56975")]
29pub fn egetkey(request: &Align512<[u8; 512]>) -> Result<Align16<[u8; 16]>, u32> {
30 unsafe {
532ac7d7 31 let mut out = MaybeUninit::uninit();
0731742a
XL
32 let error;
33
1b1a35ee
XL
34 asm!(
35 "enclu",
36 inlateout("eax") ENCLU_EGETKEY => error,
37 in("rbx") request,
38 in("rcx") out.as_mut_ptr(),
cdc7bbd5 39 options(nostack),
0731742a
XL
40 );
41
42 match error {
532ac7d7 43 0 => Ok(out.assume_init()),
0731742a
XL
44 err => Err(err),
45 }
46 }
47}
48
49/// Call the `EREPORT` instruction.
50///
51/// This creates a cryptographic report describing the contents of the current
52/// enclave. The report may be verified by the enclave described in
53/// `targetinfo`.
54#[unstable(feature = "sgx_platform", issue = "56975")]
55pub fn ereport(
56 targetinfo: &Align512<[u8; 512]>,
57 reportdata: &Align128<[u8; 64]>,
58) -> Align512<[u8; 432]> {
59 unsafe {
532ac7d7 60 let mut report = MaybeUninit::uninit();
0731742a 61
1b1a35ee
XL
62 asm!(
63 "enclu",
64 in("eax") ENCLU_EREPORT,
65 in("rbx") targetinfo,
66 in("rcx") reportdata,
67 in("rdx") report.as_mut_ptr(),
cdc7bbd5 68 options(preserves_flags, nostack),
0731742a
XL
69 );
70
532ac7d7 71 report.assume_init()
0731742a
XL
72 }
73}