@@ -56,7 +56,9 @@ pub enum KeyParams {
56
56
scheme : RsaScheme ,
57
57
/// Public exponent of the key
58
58
///
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)
60
62
pub_exponent : RsaExponent ,
61
63
} ,
62
64
Ecc {
@@ -72,6 +74,9 @@ pub enum KeyParams {
72
74
/// The `public` field represents the public part of the key in plain text,
73
75
/// while `private` is the encrypted version of the private key.
74
76
///
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
+ ///
75
80
/// # Warning
76
81
///
77
82
/// If the Owner hierarchy is cleared, any key material generated
@@ -94,6 +99,13 @@ impl KeyMaterial {
94
99
}
95
100
}
96
101
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
97
109
#[ derive( Debug , Clone ) ]
98
110
pub struct ObjectWrapper {
99
111
pub material : KeyMaterial ,
@@ -106,11 +118,8 @@ pub struct ObjectWrapper {
106
118
/// The `TransientKeyContext` makes use of a root key from which the other, client-controlled
107
119
/// keyes are derived.
108
120
///
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.
114
123
#[ allow( clippy:: module_name_repetitions) ]
115
124
#[ derive( Debug ) ]
116
125
pub struct TransientKeyContext {
@@ -126,6 +135,10 @@ impl TransientKeyContext {
126
135
/// If successful, the result contains the [KeyMaterial] of the key and a vector of
127
136
/// bytes forming the authentication value for said key.
128
137
///
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
+ ///
129
142
/// # Constraints
130
143
/// * `auth_size` must be at most 32
131
144
///
@@ -170,7 +183,7 @@ impl TransientKeyContext {
170
183
171
184
/// Load the public part of a key.
172
185
///
173
- /// Returns the key context .
186
+ /// Returns the appropriate key material after verifying that the key can be loaded .
174
187
pub fn load_external_public_key (
175
188
& mut self ,
176
189
public_key : PublicKey ,
@@ -190,8 +203,10 @@ impl TransientKeyContext {
190
203
191
204
/// Encrypt a message with an existing key.
192
205
///
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.
195
210
pub fn rsa_encrypt (
196
211
& mut self ,
197
212
key_material : KeyMaterial ,
@@ -228,8 +243,10 @@ impl TransientKeyContext {
228
243
229
244
/// Decrypt ciphertext with an existing key.
230
245
///
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.
233
250
pub fn rsa_decrypt (
234
251
& mut self ,
235
252
key_material : KeyMaterial ,
@@ -266,7 +283,7 @@ impl TransientKeyContext {
266
283
267
284
/// Sign a digest with an existing key.
268
285
///
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.
270
287
pub fn sign (
271
288
& mut self ,
272
289
key_material : KeyMaterial ,
0 commit comments