]> git.proxmox.com Git - rustc.git/blame - src/libstd/sys/sgx/ext/arch.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / libstd / 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
ba9703b0 34 llvm_asm!(
0731742a
XL
35 "enclu"
36 : "={eax}"(error)
37 : "{eax}"(ENCLU_EGETKEY),
38 "{rbx}"(request),
39 "{rcx}"(out.as_mut_ptr())
40 : "flags"
41 );
42
43 match error {
532ac7d7 44 0 => Ok(out.assume_init()),
0731742a
XL
45 err => Err(err),
46 }
47 }
48}
49
50/// Call the `EREPORT` instruction.
51///
52/// This creates a cryptographic report describing the contents of the current
53/// enclave. The report may be verified by the enclave described in
54/// `targetinfo`.
55#[unstable(feature = "sgx_platform", issue = "56975")]
56pub fn ereport(
57 targetinfo: &Align512<[u8; 512]>,
58 reportdata: &Align128<[u8; 64]>,
59) -> Align512<[u8; 432]> {
60 unsafe {
532ac7d7 61 let mut report = MaybeUninit::uninit();
0731742a 62
ba9703b0 63 llvm_asm!(
0731742a
XL
64 "enclu"
65 : /* no output registers */
66 : "{eax}"(ENCLU_EREPORT),
67 "{rbx}"(targetinfo),
68 "{rcx}"(reportdata),
69 "{rdx}"(report.as_mut_ptr())
70 );
71
532ac7d7 72 report.assume_init()
0731742a
XL
73 }
74}