Skip to content

Commit 06c83ba

Browse files
committed
improve docs
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent d2e2ea5 commit 06c83ba

File tree

5 files changed

+43
-39
lines changed

5 files changed

+43
-39
lines changed

crates/quote-verifier/src/crypto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use sha3::Keccak256;
77
/// using the provided data, signature, and public key.
88
/// # Arguments
99
/// * `data` - The data that was signed.
10-
/// * `signature` - The signature is the signature (in raw form [r][s]) of the data as a byte slice. (64 bytes)
11-
/// * `public_key` - The public key (in uncompressed form [4][x][y]) of the entity that signed the data. (65 bytes)
10+
/// * `signature` - The signature is the signature (in raw form \[r\]\[s\]) of the data as a byte slice. (64 bytes)
11+
/// * `public_key` - The public key (in uncompressed form \[4\]\[\x\]\[y\]) of the entity that signed the data. (65 bytes)
1212
/// # Returns
1313
/// * Returns true if the signature is valid, false otherwise.
1414
pub fn verify_p256_signature_bytes(data: &[u8], signature: &[u8], public_key: &[u8]) -> Result<()> {
@@ -22,7 +22,7 @@ pub fn verify_p256_signature_bytes(data: &[u8], signature: &[u8], public_key: &[
2222
/// # Arguments
2323
/// * `data` - The data that was signed.
2424
/// * `signature_der` - The der encoded signature of the data as a byte slice.
25-
/// * `public_key` - The public key (in uncompressed form [4][x][y]) of the entity that signed the data. (65 bytes)
25+
/// * `public_key` - The public key (in uncompressed form \[4\]\[\x\]\[y\]) of the entity that signed the data. (65 bytes)
2626
/// # Returns
2727
/// * Returns true if the signature is valid, false otherwise.
2828
pub fn verify_p256_signature_der(

crates/quote-verifier/src/tdx_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::str::FromStr;
88
/// ref. <https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/7e5b2a13ca5472de8d97dd7d7024c2ea5af9a6ba/Src/AttestationLibrary/src/Verifiers/Checks/TdxModuleCheck.cpp#L62-L97>
99
///
1010
/// # Arguments
11-
/// - `tee_tcb_svn`: The SVN of the TEE TCB extracted from the `TD10ReportBody::tee_tcb_svn`
11+
/// - `tee_tcb_svn`: The SVN of the TEE TCB extracted from the `TD10ReportBody`
1212
/// - `tcb_info_v3`: The TDX TCB Info V3
1313
/// # Returns
1414
/// - The TCB status of the TDX module

crates/types/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ pub mod quotes;
99
pub mod tcbinfo;
1010
pub mod utils;
1111

12+
// ref. p.37 <https://download.01.org/intel-sgx/sgx-dcap/1.22/linux/docs/Intel_TDX_DCAP_Quoting_Library_API.pdf>
1213
pub const SGX_TEE_TYPE: u32 = 0x00000000;
14+
// ref. p.37 <https://download.01.org/intel-sgx/sgx-dcap/1.22/linux/docs/Intel_TDX_DCAP_Quoting_Library_API.pdf>
1315
pub const TDX_TEE_TYPE: u32 = 0x00000081;
1416

17+
/// ref. p.68 <https://download.01.org/intel-sgx/sgx-dcap/1.22/linux/docs/Intel_SGX_ECDSA_QuoteLibReference_DCAP_API.pdf>
1518
pub const ECDSA_256_WITH_P256_CURVE: u16 = 2;
16-
17-
pub const HEADER_LEN: usize = 48;
18-
19-
pub const ENCLAVE_REPORT_LEN: usize = 384;
20-
pub const TD10_REPORT_LEN: usize = 584;
21-
pub const TD15_REPORT_LEN: usize = 684;
22-
19+
/// ref. p.68 <https://download.01.org/intel-sgx/sgx-dcap/1.22/linux/docs/Intel_SGX_ECDSA_QuoteLibReference_DCAP_API.pdf>
2320
pub const INTEL_QE_VENDOR_ID: [u8; 16] = [
2421
0x93, 0x9A, 0x72, 0x33, 0xF7, 0x9C, 0x4C, 0xA9, 0x94, 0x0A, 0x0D, 0xB3, 0x95, 0x7F, 0x06, 0x07,
2522
];
23+
/// ref. p.69 <https://download.01.org/intel-sgx/sgx-dcap/1.22/linux/docs/Intel_SGX_ECDSA_QuoteLibReference_DCAP_API.pdf>
24+
pub const ENCLAVE_REPORT_LEN: usize = 384;
25+
/// ref. p.37 <https://download.01.org/intel-sgx/sgx-dcap/1.22/linux/docs/Intel_TDX_DCAP_Quoting_Library_API.pdf>
26+
pub const TD10_REPORT_LEN: usize = 584;
2627

2728
pub(crate) type Result<T> = core::result::Result<T, anyhow::Error>;
2829

crates/types/src/quotes/body.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,20 @@ pub struct TD10ReportBody {
154154
/// Must be zero for TDX 1.0 [8 bytes]
155155
pub td_attributes: u64,
156156
/// TD Attributes [8 bytes]
157-
/// [0:7] : (TUD) TD Under Debug flags.
157+
/// \[0:7\] : (TUD) TD Under Debug flags.
158158
/// If any of the bits in this group are set to 1, the TD is untrusted.
159-
/// [0] - (DEBUG) Defines whether the TD runs in TD debug mode (set to 1) or not (set to 0).
159+
/// \[0\] - (DEBUG) Defines whether the TD runs in TD debug mode (set to 1) or not (set to 0).
160160
/// In TD debug mode, the CPU state and private memory are accessible by the host VMM.
161-
/// [1:7] - (RESERVED) Reserved for future TUD flags, must be 0.
162-
/// [8:31] : (SEC) Attributes that may impact the security of the TD
163-
/// [8:27] - (RESERVED) Reserved for future SEC flags, must be 0.
164-
/// [28] - (SEPT_VE_DISABLE) Disable EPT violation conversion to #VE on TD access of PENDING pages
165-
/// [29] - (RESERVED) Reserved for future SEC flags, must be 0.
166-
/// [30] - (PKS) TD is allowed to use Supervisor Protection Keys.
167-
/// [31] - (KL) TD is allowed to use Key Locker.
168-
/// [32:63] : (OTHER) Attributes that do not impact the security of the TD
169-
/// [32:62] - (RESERVED) Reserved for future OTHER flags, must be 0.
170-
/// [63] - (PERFMON) TD is allowed to use Perfmon and PERF_METRICS capabilities.
161+
/// \[1:7\] - (RESERVED) Reserved for future TUD flags, must be 0.
162+
/// \[8:31] : (SEC) Attributes that may impact the security of the TD
163+
/// \[8:27\] - (RESERVED) Reserved for future SEC flags, must be 0.
164+
/// \[28\] - (SEPT_VE_DISABLE) Disable EPT violation conversion to #VE on TD access of PENDING pages
165+
/// \[29\] - (RESERVED) Reserved for future SEC flags, must be 0.
166+
/// \[30\] - (PKS) TD is allowed to use Supervisor Protection Keys.
167+
/// \[31\] - (KL) TD is allowed to use Key Locker.
168+
/// \[32:63] : (OTHER) Attributes that do not impact the security of the TD
169+
/// \[32:62\] - (RESERVED) Reserved for future OTHER flags, must be 0.
170+
/// \[63\] - (PERFMON) TD is allowed to use Perfmon and PERF_METRICS capabilities.
171171
pub xfam: u64,
172172
/// (SHA384) Measurement of the initial contents of the TD. [48 bytes]
173173
pub mrtd: [u8; 48],

crates/types/src/quotes/version_4.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ use anyhow::bail;
44

55
#[derive(Clone, Debug)]
66
pub struct QuoteV4 {
7-
pub header: QuoteHeader, // [48 bytes]
8-
// Header of Quote data structure.
9-
// This field is transparent (the user knows its internal structure).
10-
// Rest of the Quote data structure can be treated as opaque (hidden from the user).
11-
pub quote_body: QuoteBody, // May either contain a SGX Enclave Report (384 bytes) or TD10 Report (584 bytes)
12-
pub signature_len: u32, // [4 bytes]
13-
// Size of the Quote Signature Data structure in bytes.
14-
pub signature: QuoteSignatureDataV4, // [variable bytes]
7+
/// Header of Quote data structure.
8+
/// This field is transparent (the user knows its internal structure).
9+
/// Rest of the Quote data structure can be treated as opaque (hidden from the user).
10+
pub header: QuoteHeader,
11+
/// May either contain a SGX Enclave Report (384 bytes) or TD10 Report (584 bytes)
12+
pub quote_body: QuoteBody,
13+
/// Size of the Quote Signature Data structure in bytes.
14+
pub signature_len: u32,
15+
/// Quote Signature Data
16+
pub signature: QuoteSignatureDataV4,
1517
}
1618

1719
impl QuoteV4 {
20+
/// Parse a byte slice into a `QuoteV4` structure.
1821
pub fn from_bytes(raw_bytes: &[u8]) -> Result<Self> {
1922
let header = QuoteHeader::from_bytes(&raw_bytes[0..48]);
2023
let quote_body;
@@ -55,17 +58,17 @@ impl QuoteV4 {
5558

5659
#[derive(Clone, Debug)]
5760
pub struct QuoteSignatureDataV4 {
58-
pub quote_signature: [u8; 64], // [64 bytes]
59-
// ECDSA signature, the r component followed by the s component, 2 x 32 bytes.
60-
// Public part of the Attestation Key generated by the Quoting Enclave.
61-
pub ecdsa_attestation_key: [u8; 64], // [64 bytes]
62-
// EC KT-I Public Key, the x-coordinate followed by the y-coordinate (on the RFC 6090 P-256 curve), 2 x 32 bytes.
63-
// Public part of the Attestation Key generated by the Quoting Enclave.
64-
pub qe_cert_data: CertData, // [variable bytes]
65-
// QE Cert Data
61+
/// ECDSA signature, the r component followed by the s component, 2 x 32 bytes.
62+
pub quote_signature: [u8; 64],
63+
/// Public part of the Attestation Key generated by the Quoting Enclave.
64+
/// EC KT-I Public Key, the x-coordinate followed by the y-coordinate (on the RFC 6090 P-256 curve), 2 x 32 bytes.
65+
pub ecdsa_attestation_key: [u8; 64],
66+
/// QE Cert Data
67+
pub qe_cert_data: CertData,
6668
}
6769

6870
impl QuoteSignatureDataV4 {
71+
/// Parse a byte slice into a `QuoteSignatureDataV4` structure.
6972
pub fn from_bytes(raw_bytes: &[u8]) -> Self {
7073
let mut quote_signature = [0; 64];
7174
quote_signature.copy_from_slice(&raw_bytes[0..64]);

0 commit comments

Comments
 (0)