Skip to content

Commit 952e6c1

Browse files
feat: add attestation report fetch functionality to device (#73)
Enable applications to: Verify the authenticity of NVIDIA GPUs in confidential computing environments Generate attestation reports that can be used in remote attestation workflows Support secure GPU workloads in confidential computing scenarios
1 parent f949719 commit 952e6c1

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

nvml-wrapper/src/device.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,55 @@ impl<'nvml> Device<'nvml> {
743743
}
744744
}
745745

746+
/**
747+
Fetches the confidential compute attestation report for this [`Device`].
748+
749+
This method retrieves a comprehensive attestation report from the device, which includes:
750+
- A 32-byte nonce
751+
- The attestation report size (as big-endian bytes)
752+
- The attestation report data (up to 8192 bytes)
753+
- A flag indicating if CEC attestation is present (as big-endian bytes)
754+
- The CEC attestation report size (as big-endian bytes)
755+
- The CEC attestation report data (up to 4096 bytes)
756+
757+
The returned vector contains all these components concatenated together in the order listed above.
758+
759+
# Errors
760+
761+
* `Uninitialized`, if the library has not been successfully initialized
762+
* `InvalidArg`, if device is invalid or memory is NULL
763+
* `NotSupported`, if this query is not supported by the device
764+
* `Unknown`, on any unexpected error
765+
*/
766+
#[doc(alias = "nvmlDeviceGetAttestationReport")]
767+
pub fn confidential_compute_gpu_attestation_report(
768+
&self,
769+
nonce: [u8; NVML_CC_GPU_CEC_NONCE_SIZE as usize],
770+
) -> Result<ConfidentialComputeGpuAttestationReport, NvmlError> {
771+
let sym = nvml_sym(
772+
self.nvml
773+
.lib
774+
.nvmlDeviceGetConfComputeGpuAttestationReport
775+
.as_ref(),
776+
)?;
777+
778+
unsafe {
779+
let mut report: nvmlConfComputeGpuAttestationReport_st = mem::zeroed();
780+
report.nonce = nonce;
781+
782+
nvml_try(sym(self.device, &mut report))?;
783+
784+
let is_cec_attestation_report_present = report.isCecAttestationReportPresent == 1;
785+
Ok(ConfidentialComputeGpuAttestationReport {
786+
attestation_report_size: report.attestationReportSize,
787+
attestation_report: report.attestationReport.to_vec(),
788+
is_cec_attestation_report_present,
789+
cec_attestation_report_size: report.cecAttestationReportSize,
790+
cec_attestation_report: report.cecAttestationReport.to_vec(),
791+
})
792+
}
793+
}
794+
746795
/**
747796
Gets the current PCIe link generation.
748797

nvml-wrapper/src/structs/device.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ use crate::enum_wrappers::device::OperationMode;
44
#[cfg(feature = "serde")]
55
use serde_derive::{Deserialize, Serialize};
66

7+
/// Returned from `Device.confidential_compute_gpu_attestation_report_bytes()`
8+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
9+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10+
pub struct ConfidentialComputeGpuAttestationReport {
11+
/// The size of the attestation report.
12+
pub attestation_report_size: u32,
13+
/// The attestation report, of size
14+
/// `ffi::bindings::NVML_CC_GPU_ATTESTATION_REPORT_SIZE` == 8192 bytes.
15+
pub attestation_report: Vec<u8>,
16+
/// Whether the CEC attestation report is present.
17+
pub is_cec_attestation_report_present: bool,
18+
/// The size of the CEC attestation report.
19+
pub cec_attestation_report_size: u32,
20+
/// The CEC attestation report, of size
21+
/// `ffi::bindings::NVML_CC_GPU_CEC_ATTESTATION_REPORT_SIZE` == 4096 bytes.
22+
pub cec_attestation_report: Vec<u8>,
23+
}
24+
725
/// Returned from `Device.auto_boosted_clocks_enabled()`
826
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
927
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

0 commit comments

Comments
 (0)