Skip to content

Commit f40b08b

Browse files
committed
Expand documentation around TransientKeyContext
Expanding the documentation of structures present in the interface of `TransientKeyContext` to allow developers to more easily understand their contents, or to at least know to which sections of the spec to refer to. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent 7205c4c commit f40b08b

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

tss-esapi/src/abstraction/transient/mod.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ pub enum KeyParams {
5656
scheme: RsaScheme,
5757
/// Public exponent of the key
5858
///
59-
/// If set to 0, it will default to 2^16 - 1
59+
/// If set to 0, it will default to 2^16 - 1.
60+
///
61+
/// (Note that the default value for [`RsaExponent`] is 0)
6062
pub_exponent: RsaExponent,
6163
},
6264
Ecc {
@@ -72,6 +74,9 @@ pub enum KeyParams {
7274
/// The `public` field represents the public part of the key in plain text,
7375
/// while `private` is the encrypted version of the private key.
7476
///
77+
/// For information on public key formats, see the documentation of [`PublicKey`].
78+
/// The private part of the key should be treated as an opaque binary blob.
79+
///
7580
/// # Warning
7681
///
7782
/// If the Owner hierarchy is cleared, any key material generated
@@ -94,6 +99,13 @@ impl KeyMaterial {
9499
}
95100
}
96101

102+
/// Structure containing all the defining elements of a TPM key
103+
///
104+
/// - `material` identifies the numeric value of the key object
105+
/// - `params` identifies the algorithm to use on the key and other relevant
106+
/// parameters
107+
/// - `auth` identifies the optional authentication value to be used with the
108+
/// key
97109
#[derive(Debug, Clone)]
98110
pub struct ObjectWrapper {
99111
pub material: KeyMaterial,
@@ -106,11 +118,8 @@ pub struct ObjectWrapper {
106118
/// The `TransientKeyContext` makes use of a root key from which the other, client-controlled
107119
/// keyes are derived.
108120
///
109-
/// Currently, only functionality necessary for RSA key creation and usage (for signing,
110-
/// verifying signatures, encryption and decryption) is implemented. The RSA SSA
111-
/// asymmetric scheme with SHA256 is used for all created and imported signing keys.
112-
/// The RSA OAEP asymmetric scheme with SHA256 is used for all created and imported
113-
/// signing/encryption/decryption keys.
121+
/// The main goal of this abstraction is to make public key cryptography more accessible,
122+
/// focusing on asymmetric encryption and signatures in particular.
114123
#[allow(clippy::module_name_repetitions)]
115124
#[derive(Debug)]
116125
pub struct TransientKeyContext {
@@ -126,6 +135,10 @@ impl TransientKeyContext {
126135
/// If successful, the result contains the [KeyMaterial] of the key and a vector of
127136
/// bytes forming the authentication value for said key.
128137
///
138+
/// The following key attributes are always **set**: `fixed_tpm`, `fixed_parent`, `sensitive_data_origin`,
139+
/// `user_with_auth`. The `restricted` attribute is **not set**. See section 8.3 in the Structures
140+
/// spec for a detailed description of these attributes.
141+
///
129142
/// # Constraints
130143
/// * `auth_size` must be at most 32
131144
///
@@ -170,7 +183,7 @@ impl TransientKeyContext {
170183

171184
/// Load the public part of a key.
172185
///
173-
/// Returns the key context.
186+
/// Returns the appropriate key material after verifying that the key can be loaded.
174187
pub fn load_external_public_key(
175188
&mut self,
176189
public_key: PublicKey,
@@ -190,8 +203,10 @@ impl TransientKeyContext {
190203

191204
/// Encrypt a message with an existing key.
192205
///
193-
/// Takes the key as a parameter, encrypts the message and returns the ciphertext. A label (i.e.
194-
/// nonce) can also be provided.
206+
/// Takes the key as a set of parameters (`key_material`, `key_params`, `key_auth`), encrypts the message
207+
/// and returns the ciphertext. A label can also be provided which will be associated with the ciphertext.
208+
///
209+
/// Note: the data passed as `label` MUST end in a `0x00` byte.
195210
pub fn rsa_encrypt(
196211
&mut self,
197212
key_material: KeyMaterial,
@@ -228,8 +243,10 @@ impl TransientKeyContext {
228243

229244
/// Decrypt ciphertext with an existing key.
230245
///
231-
/// Takes the key as a parameter, decrypts the ciphertext and returns the plaintext. A label (i.e.
232-
/// nonce) can also be provided.
246+
/// Takes the key as a set of parameters (`key_material`, `key_params`, `key_auth`), decrypts the ciphertext
247+
/// and returns the plaintext. A label which was associated with the ciphertext can also be provided.
248+
///
249+
/// Note: the data passed as `label` MUST end in a `0x00` byte.
233250
pub fn rsa_decrypt(
234251
&mut self,
235252
key_material: KeyMaterial,
@@ -266,7 +283,7 @@ impl TransientKeyContext {
266283

267284
/// Sign a digest with an existing key.
268285
///
269-
/// Takes the key as a parameter, signs and returns the signature.
286+
/// Takes the key as a set of parameters (`key_material`, `key_params`, `key_auth`), signs and returns the signature.
270287
pub fn sign(
271288
&mut self,
272289
key_material: KeyMaterial,

tss-esapi/src/structures/signatures.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use log::error;
1010
use std::convert::{TryFrom, TryInto};
1111

1212
/// Type holding RSA signature information.
13+
///
14+
/// For more information about the contents of `signature` see Annex B
15+
/// in the Architecture spec.
1316
#[derive(Debug, Clone, PartialEq, Eq)]
1417
pub struct RsaSignature {
1518
hashing_algorithm: HashingAlgorithm,
@@ -70,6 +73,9 @@ impl TryFrom<TPMS_SIGNATURE_RSA> for RsaSignature {
7073
}
7174

7275
/// Type holding ECC signature information.
76+
///
77+
/// For more information about the contents of `signature_r` and `signature_s`
78+
/// see Annex B in the Architecture spec (or Annex D for SM2 signatures).
7379
#[derive(Debug, Clone, PartialEq, Eq)]
7480
pub struct EccSignature {
7581
hashing_algorithm: HashingAlgorithm,

tss-esapi/src/utils/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,20 @@ pub fn create_unrestricted_signing_ecc_public(
272272
.build()
273273
}
274274

275+
/// Container for public key values
275276
#[derive(Debug, Clone, Serialize, Deserialize, Zeroize, PartialEq, Eq)]
276277
pub enum PublicKey {
278+
/// RSA public modulus (see 27.5.3.4 in Architecture spec)
279+
///
280+
/// This is the value extracted from the `unique` part of `TPMT_PUBLIC`.
281+
/// The exponent is not included here as the expectation is that the
282+
/// exponent is always pinned to 65537 (2^16 + 1).
283+
///
284+
/// The modulus is in Big-Endian format.
277285
Rsa(Vec<u8>),
286+
/// Public elliptic curve point (see 27.5.3.5 in Architecture spec)
287+
///
288+
/// The x and y coordinates are given uncompressed.
278289
Ecc { x: Vec<u8>, y: Vec<u8> },
279290
}
280291

0 commit comments

Comments
 (0)