sgx/signature/
body.rs

1// SPDX-License-Identifier: Apache-2.0
2
3use crate::parameters::{Attributes, Masked, MiscSelect, Parameters};
4
5impl Parameters {
6    /// Creates a signature body
7    ///
8    /// This call creates a signature `Body` using the provided parameters and
9    /// `mrenclave` value.
10    ///
11    /// Note that the `Masked` types in `Parameters` are interpreted as follows:
12    ///   * `data`: contains the features the enclave author desires
13    ///   * `mask`: contains the features the enclave author requires
14    pub fn body(&self, mrenclave: [u8; 32]) -> Body {
15        Body {
16            misc: self.misc,
17            cet_attr: Masked { data: 0, mask: 0 },
18            reserved0: [0; 2],
19            ext_fid: [0; 16],
20            attr: self.attr,
21            mrenclave,
22            reserved1: [0; 16],
23            ext_pid: self.ext_pid,
24            pid: self.pid,
25            svn: self.svn,
26        }
27    }
28}
29
30/// The enclave signature body
31///
32/// This structure encompasses the second block of fields from `SIGSTRUCT`
33/// that is included in the signature. It is split out from `Signature`
34/// in order to make it easy to hash the fields for the signature.
35#[repr(C)]
36#[derive(Copy, Clone, PartialEq, Eq)]
37pub struct Body {
38    misc: Masked<MiscSelect>,
39    cet_attr: Masked<u8>,
40    reserved0: [u8; 2],
41    ext_fid: [u8; 16],
42    attr: Masked<Attributes>,
43    mrenclave: [u8; 32],
44    reserved1: [u8; 16],
45    ext_pid: [u8; 16],
46    pid: u16,
47    svn: u16,
48}
49
50impl core::fmt::Debug for Body {
51    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52        f.debug_struct("Body")
53            .field("misc", &self.misc)
54            //.field("reserved0", &self.reserved0)
55            .field("attr", &self.attr)
56            .field("mrenclave", &self.mrenclave)
57            //.field("reserved1", &self.reserved1)
58            .field("pid", &self.pid)
59            .field("svn", &self.svn)
60            .finish()
61    }
62}
63
64impl Body {
65    /// Get the enclave measure hash
66    pub fn mrenclave(&self) -> [u8; 32] {
67        self.mrenclave
68    }
69
70    /// Get the enclave parameters
71    pub fn parameters(&self) -> Parameters {
72        Parameters {
73            pid: self.pid,
74            svn: self.svn,
75            misc: self.misc,
76            attr: self.attr,
77            ext_pid: self.ext_pid,
78            ext_fid: self.ext_fid,
79        }
80    }
81}
82
83#[cfg(test)]
84mod test {
85    use super::Body;
86    use testaso::testaso;
87
88    testaso! {
89        struct Body: 4, 128 => {
90            misc: 0,
91            cet_attr: 8,
92            reserved0: 10,
93            ext_fid: 12,
94            attr: 28,
95            mrenclave: 60,
96            reserved1: 92,
97            ext_pid: 108,
98            pid: 124,
99            svn: 126
100        }
101    }
102}