This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #19 Signed-off-by: Yang, Longlong <[email protected]>
- Loading branch information
1 parent
e154fab
commit aa7d11c
Showing
17 changed files
with
1,485 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "idekm" | ||
license = "BSD-2-Clause-Patent" | ||
version = "0.1.0" | ||
authors = [ | ||
"Jiewen Yao <[email protected]>", | ||
"Xiaoyu Lu <[email protected]>", | ||
"Longlong Yang <[email protected]>" | ||
] | ||
edition = "2018" | ||
|
||
[dev-dependencies] | ||
|
||
[build-dependencies] | ||
|
||
[dependencies] | ||
codec = { path = "../codec" } | ||
zeroize = { version = "1.5.0", features = ["zeroize_derive"]} | ||
spdmlib = { path = "../spdmlib", default-features = false, features = ["spdm-ring"]} | ||
conquer-once = { version = "0.3.2", default-features = false } | ||
|
||
|
||
[features] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2023 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub const PCI_IDE_KM_LINK_IDE_REG_BLOCK_SUPPORTED_COUNT: usize = 4; | ||
pub const PCI_IDE_KM_SELECTIVE_IDE_REG_BLOCK_SUPPORTED_COUNT: usize = 8; | ||
pub const PCI_IDE_KM_SELECTIVE_IDE_ADDRESS_ASSOCIATION_REG_BLOCK_SUPPORTED_COUNT: usize = 1; | ||
|
||
pub const PCI_IDE_KM_IDE_REG_BLOCK_SUPPORTED_COUNT: usize = 2 | ||
+ 2 * PCI_IDE_KM_LINK_IDE_REG_BLOCK_SUPPORTED_COUNT | ||
+ (3 + 2 + 3 * PCI_IDE_KM_SELECTIVE_IDE_ADDRESS_ASSOCIATION_REG_BLOCK_SUPPORTED_COUNT) | ||
* PCI_IDE_KM_SELECTIVE_IDE_REG_BLOCK_SUPPORTED_COUNT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) 2023 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#![forbid(unsafe_code)] | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub mod config; | ||
pub mod pci_ide_km_requester; | ||
pub mod pci_ide_km_responder; | ||
pub mod pci_idekm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2023 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct IdekmReqContext; | ||
|
||
pub mod pci_ide_km_req_query; | ||
pub use pci_ide_km_req_query::*; | ||
|
||
pub mod pci_ide_km_req_key_prog; | ||
pub use pci_ide_km_req_key_prog::*; | ||
|
||
pub mod pci_ide_km_req_key_set_go; | ||
pub use pci_ide_km_req_key_set_go::*; | ||
|
||
pub mod pci_ide_km_req_key_set_stop; | ||
pub use pci_ide_km_req_key_set_stop::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) 2023 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use codec::Codec; | ||
use codec::Writer; | ||
use spdmlib::error::SpdmResult; | ||
use spdmlib::error::SPDM_STATUS_BUFFER_FULL; | ||
use spdmlib::error::SPDM_STATUS_INVALID_MSG_FIELD; | ||
use spdmlib::{ | ||
message::{VendorDefinedReqPayloadStruct, MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE}, | ||
requester::RequesterContext, | ||
}; | ||
|
||
use crate::pci_idekm::vendor_id; | ||
use crate::pci_idekm::KpAckDataObject; | ||
use crate::pci_idekm::STANDARD_ID; | ||
use crate::pci_idekm::{Aes256GcmKeyBuffer, KeyProgDataObject, KpAckStatus}; | ||
|
||
use super::IdekmReqContext; | ||
|
||
impl IdekmReqContext { | ||
pub async fn pci_ide_km_key_prog( | ||
&mut self, | ||
// IN | ||
spdm_requester: &mut RequesterContext, | ||
session_id: u32, | ||
stream_id: u8, | ||
key_set: u8, | ||
key_direction: u8, | ||
key_sub_stream: u8, | ||
port_index: u8, | ||
key_iv: Aes256GcmKeyBuffer, | ||
// OUT | ||
kp_ack_status: &mut KpAckStatus, | ||
) -> SpdmResult { | ||
let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { | ||
req_length: 0, | ||
vendor_defined_req_payload: [0u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE], | ||
}; | ||
|
||
let mut writer = | ||
Writer::init(&mut vendor_defined_req_payload_struct.vendor_defined_req_payload); | ||
|
||
vendor_defined_req_payload_struct.req_length = KeyProgDataObject { | ||
stream_id, | ||
key_set, | ||
key_direction, | ||
key_sub_stream, | ||
port_index, | ||
key_iv, | ||
} | ||
.encode(&mut writer) | ||
.map_err(|_| SPDM_STATUS_BUFFER_FULL)? | ||
as u16; | ||
|
||
let vendor_defined_rsp_payload_struct = spdm_requester | ||
.send_spdm_vendor_defined_request( | ||
Some(session_id), | ||
STANDARD_ID, | ||
vendor_id(), | ||
vendor_defined_req_payload_struct, | ||
) | ||
.await?; | ||
|
||
let kp_ack_data_object = KpAckDataObject::read_bytes( | ||
&vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload | ||
[..vendor_defined_rsp_payload_struct.rsp_length as usize], | ||
) | ||
.ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; | ||
|
||
if kp_ack_data_object.stream_id != stream_id | ||
|| kp_ack_data_object.key_set != key_set | ||
|| kp_ack_data_object.key_direction != key_direction | ||
|| kp_ack_data_object.key_sub_stream != key_sub_stream | ||
|| kp_ack_data_object.port_index != port_index | ||
{ | ||
return Err(SPDM_STATUS_INVALID_MSG_FIELD); | ||
} else { | ||
*kp_ack_status = kp_ack_data_object.status; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_go.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2023 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use codec::Codec; | ||
use codec::Writer; | ||
use spdmlib::error::SPDM_STATUS_BUFFER_FULL; | ||
use spdmlib::error::SPDM_STATUS_INVALID_MSG_FIELD; | ||
use spdmlib::{ | ||
error::SpdmResult, | ||
message::{VendorDefinedReqPayloadStruct, MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE}, | ||
requester::RequesterContext, | ||
}; | ||
|
||
use crate::pci_idekm::vendor_id; | ||
use crate::pci_idekm::KGoStopAckDataObject; | ||
use crate::pci_idekm::KSetGoDataObject; | ||
use crate::pci_idekm::STANDARD_ID; | ||
|
||
use super::IdekmReqContext; | ||
|
||
impl IdekmReqContext { | ||
pub async fn pci_ide_km_key_set_go( | ||
&mut self, | ||
// IN | ||
spdm_requester: &mut RequesterContext, | ||
session_id: u32, | ||
stream_id: u8, | ||
key_set: u8, | ||
key_direction: u8, | ||
key_sub_stream: u8, | ||
port_index: u8, | ||
) -> SpdmResult { | ||
let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { | ||
req_length: 0, | ||
vendor_defined_req_payload: [0u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE], | ||
}; | ||
|
||
let mut writer = | ||
Writer::init(&mut vendor_defined_req_payload_struct.vendor_defined_req_payload); | ||
|
||
vendor_defined_req_payload_struct.req_length = KSetGoDataObject { | ||
stream_id, | ||
key_set, | ||
key_direction, | ||
key_sub_stream, | ||
port_index, | ||
} | ||
.encode(&mut writer) | ||
.map_err(|_| SPDM_STATUS_BUFFER_FULL)? | ||
as u16; | ||
|
||
let vendor_defined_rsp_payload_struct = spdm_requester | ||
.send_spdm_vendor_defined_request( | ||
Some(session_id), | ||
STANDARD_ID, | ||
vendor_id(), | ||
vendor_defined_req_payload_struct, | ||
) | ||
.await?; | ||
|
||
let kgo_stop_ack_data_object = KGoStopAckDataObject::read_bytes( | ||
&vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload | ||
[..vendor_defined_rsp_payload_struct.rsp_length as usize], | ||
) | ||
.ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; | ||
|
||
if kgo_stop_ack_data_object.stream_id != stream_id | ||
|| kgo_stop_ack_data_object.key_set != key_set | ||
|| kgo_stop_ack_data_object.key_direction != key_direction | ||
|| kgo_stop_ack_data_object.key_sub_stream != key_sub_stream | ||
|| kgo_stop_ack_data_object.port_index != port_index | ||
{ | ||
Err(SPDM_STATUS_INVALID_MSG_FIELD) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_stop.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2023 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use codec::Codec; | ||
use codec::Writer; | ||
use spdmlib::error::SPDM_STATUS_BUFFER_FULL; | ||
use spdmlib::error::SPDM_STATUS_INVALID_MSG_FIELD; | ||
use spdmlib::{ | ||
error::SpdmResult, | ||
message::{VendorDefinedReqPayloadStruct, MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE}, | ||
requester::RequesterContext, | ||
}; | ||
|
||
use crate::pci_idekm::vendor_id; | ||
use crate::pci_idekm::KGoStopAckDataObject; | ||
use crate::pci_idekm::KSetStopDataObject; | ||
use crate::pci_idekm::STANDARD_ID; | ||
|
||
use super::IdekmReqContext; | ||
|
||
impl IdekmReqContext { | ||
pub async fn pci_ide_km_key_set_stop( | ||
&mut self, | ||
// IN | ||
spdm_requester: &mut RequesterContext, | ||
session_id: u32, | ||
stream_id: u8, | ||
key_set: u8, | ||
key_direction: u8, | ||
key_sub_stream: u8, | ||
port_index: u8, | ||
) -> SpdmResult { | ||
let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { | ||
req_length: 0, | ||
vendor_defined_req_payload: [0u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE], | ||
}; | ||
|
||
let mut writer = | ||
Writer::init(&mut vendor_defined_req_payload_struct.vendor_defined_req_payload); | ||
|
||
vendor_defined_req_payload_struct.req_length = KSetStopDataObject { | ||
stream_id, | ||
key_set, | ||
key_direction, | ||
key_sub_stream, | ||
port_index, | ||
} | ||
.encode(&mut writer) | ||
.map_err(|_| SPDM_STATUS_BUFFER_FULL)? | ||
as u16; | ||
|
||
let vendor_defined_rsp_payload_struct = spdm_requester | ||
.send_spdm_vendor_defined_request( | ||
Some(session_id), | ||
STANDARD_ID, | ||
vendor_id(), | ||
vendor_defined_req_payload_struct, | ||
) | ||
.await?; | ||
|
||
let kgo_stop_ack_data_object = KGoStopAckDataObject::read_bytes( | ||
&vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload | ||
[..vendor_defined_rsp_payload_struct.rsp_length as usize], | ||
) | ||
.ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; | ||
|
||
if kgo_stop_ack_data_object.stream_id != stream_id | ||
|| kgo_stop_ack_data_object.key_set != key_set | ||
|| kgo_stop_ack_data_object.key_direction != key_direction | ||
|| kgo_stop_ack_data_object.key_sub_stream != key_sub_stream | ||
|| kgo_stop_ack_data_object.port_index != port_index | ||
{ | ||
Err(SPDM_STATUS_INVALID_MSG_FIELD) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
} |
Oops, something went wrong.