Skip to content

Commit 3339b0e

Browse files
committed
Fixes API breaking changes.
Signed-off-by: Jesper Brynolf <[email protected]>
1 parent 9c7d580 commit 3339b0e

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

tss-esapi/src/abstraction/ak.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,26 @@ const POLICY_C_SM3_256: [u8; 32] = [
5656
0x56, 0x99, 0xa3, 0xe3, 0x9f, 0xc3, 0x55, 0x1b, 0xfe, 0xff, 0xcf, 0x13, 0x2b, 0x49, 0xe1, 0x1d,
5757
];
5858

59+
/// Creates a Public object for an AK key.
5960
fn create_ak_public<IKC: IntoKeyCustomization>(
61+
key_alg: AsymmetricAlgorithm,
62+
hash_alg: HashingAlgorithm,
63+
sign_alg: SignatureSchemeAlgorithm,
64+
key_customization: IKC,
65+
) -> Result<Public> {
66+
create_ak_public_2(
67+
AsymmetricAlgorithmSelection::try_from(key_alg)?,
68+
hash_alg,
69+
sign_alg,
70+
key_customization,
71+
)
72+
}
73+
74+
/// Creates a Public object for an AK key.
75+
///
76+
/// # Details
77+
/// This is only replace the `create_ak` API in the next major version.
78+
fn create_ak_public_2<IKC: IntoKeyCustomization>(
6079
key_alg: AsymmetricAlgorithmSelection,
6180
hash_alg: HashingAlgorithm,
6281
sign_alg: SignatureSchemeAlgorithm,
@@ -228,8 +247,36 @@ pub fn load_ak(
228247
Ok(key_handle)
229248
}
230249

231-
/// This creates an Attestation Key in the Endorsement hierarchy
250+
/// This creates an Attestation Key in the Endorsement hierarchy.
232251
pub fn create_ak<IKC: IntoKeyCustomization>(
252+
context: &mut Context,
253+
parent: KeyHandle,
254+
hash_alg: HashingAlgorithm,
255+
sign_alg: SignatureSchemeAlgorithm,
256+
ak_auth_value: Option<Auth>,
257+
key_customization: IKC,
258+
) -> Result<CreateKeyResult> {
259+
let key_alg = AsymmetricAlgorithm::try_from(sign_alg).map_err(|e| {
260+
// sign_alg is either HMAC or Null.
261+
error!("Could not retrieve asymmetric algorithm for provided signature scheme");
262+
e
263+
})?;
264+
create_ak_2(
265+
context,
266+
parent,
267+
hash_alg,
268+
AsymmetricAlgorithmSelection::try_from(key_alg)?,
269+
sign_alg,
270+
ak_auth_value,
271+
key_customization,
272+
)
273+
}
274+
275+
/// This creates an Attestation Key in the Endorsement hierarchy.
276+
///
277+
/// # Details
278+
/// This is only replace the `create_ak` API in the next major version.
279+
pub fn create_ak_2<IKC: IntoKeyCustomization>(
233280
context: &mut Context,
234281
parent: KeyHandle,
235282
hash_alg: HashingAlgorithm,

tss-esapi/src/abstraction/ek.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ const AUTH_POLICY_B_SM3_256: [u8; 32] = [
6161
/// Source: TCG EK Credential Profile for TPM Family 2.0; Level 0 Version 2.3 Revision 2
6262
/// Appendix B.3.3 and B.3.4
6363
pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
64+
alg: AsymmetricAlgorithm,
65+
key_customization: IKC,
66+
) -> Result<Public> {
67+
create_ek_public_from_default_template_2(
68+
AsymmetricAlgorithmSelection::try_from(alg)?,
69+
key_customization,
70+
)
71+
}
72+
73+
/// Get the [`Public`] representing a default Endorsement Key
74+
///
75+
/// **Note**: This only works for key algorithms specified in TCG EK Credential Profile for TPM Family 2.0.
76+
///
77+
/// Source: TCG EK Credential Profile for TPM Family 2.0; Level 0 Version 2.3 Revision 2
78+
/// Appendix B.3.3 and B.3.4
79+
///
80+
/// # Details
81+
/// This is only replace the `create_ek_public_from_default_template` API in the next major version.
82+
pub fn create_ek_public_from_default_template_2<IKC: IntoKeyCustomization>(
6483
alg: AsymmetricAlgorithmSelection,
6584
key_customization: IKC,
6685
) -> Result<Public> {
@@ -192,6 +211,22 @@ pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
192211

193212
/// Create the Endorsement Key object from the specification templates
194213
pub fn create_ek_object<IKC: IntoKeyCustomization>(
214+
context: &mut Context,
215+
alg: AsymmetricAlgorithm,
216+
key_customization: IKC,
217+
) -> Result<KeyHandle> {
218+
create_ek_object_2(
219+
context,
220+
AsymmetricAlgorithmSelection::try_from(alg)?,
221+
key_customization,
222+
)
223+
}
224+
225+
/// Create the Endorsement Key object from the specification templates
226+
///
227+
/// # Details
228+
/// This is only replace the `create_ek_object` API in the next major version.
229+
pub fn create_ek_object_2<IKC: IntoKeyCustomization>(
195230
context: &mut Context,
196231
alg: AsymmetricAlgorithmSelection,
197232
key_customization: IKC,

0 commit comments

Comments
 (0)