@@ -103,15 +103,30 @@ pub mod sensitive;
103103pub mod sensitive_create;
104104
105105pub mod auth {
106- buffer_type ! ( Auth , 64 , TPM2B_AUTH ) ;
106+ // Same size as TPM2B_DIGEST according to the specification.
107+ use crate :: tss2_esys:: TPMU_HA ;
108+ use std:: mem:: size_of;
109+ const TPM2B_AUTH_BUFFER_SIZE : usize = size_of :: < TPMU_HA > ( ) ;
110+ buffer_type ! ( Auth , TPM2B_AUTH_BUFFER_SIZE , TPM2B_AUTH ) ;
107111}
108112
109113pub mod data {
110- buffer_type ! ( Data , 64 , TPM2B_DATA ) ;
114+ // This should, according to the specification, be
115+ // size_of::<TPMT_HA>() but due to a bug in tpm2-tss
116+ // (https://github.com/tpm2-software/tpm2-tss/issues/2888)
117+ // it is the size of TPMU_HA
118+ use crate :: tss2_esys:: TPMU_HA ;
119+ use std:: mem:: size_of;
120+ const TPM2B_DATA_BUFFER_SIZE : usize = size_of :: < TPMU_HA > ( ) ;
121+ buffer_type ! ( Data , TPM2B_DATA_BUFFER_SIZE , TPM2B_DATA ) ;
111122}
112123
113124pub mod digest {
114- buffer_type ! ( Digest , 64 , TPM2B_DIGEST ) ;
125+ use crate :: tss2_esys:: TPMU_HA ;
126+ use std:: mem:: size_of;
127+ const TPM2B_DIGEST_BUFFER_SIZE : usize = size_of :: < TPMU_HA > ( ) ;
128+
129+ buffer_type ! ( Digest , TPM2B_DIGEST_BUFFER_SIZE , TPM2B_DIGEST ) ;
115130
116131 // Some implementations to get from Digest to [u8; N] for common values of N (sha* primarily)
117132 // This is used to work around the fact that Rust does not allow custom functions for general values of N in [T; N],
@@ -208,80 +223,101 @@ pub mod digest {
208223}
209224
210225pub mod ecc_parameter {
226+ use crate :: tss2_esys:: TPM2_MAX_ECC_KEY_BYTES ;
227+ const TPM2B_ECC_PARAMETER_BUFFER_SIZE : usize = TPM2_MAX_ECC_KEY_BYTES as usize ;
211228 buffer_type ! (
212229 EccParameter ,
213- crate :: tss2_esys :: TPM2_MAX_ECC_KEY_BYTES as usize ,
230+ TPM2B_ECC_PARAMETER_BUFFER_SIZE ,
214231 TPM2B_ECC_PARAMETER
215232 ) ;
216233}
217234
218235pub mod encrypted_secret {
219- named_field_buffer_type ! ( EncryptedSecret , 256 , TPM2B_ENCRYPTED_SECRET , secret) ;
236+ use crate :: tss2_esys:: TPMU_ENCRYPTED_SECRET ;
237+ use std:: mem:: size_of;
238+ const TPM2B_ENCRYPTED_SECRET_BUFFER_SIZE : usize = size_of :: < TPMU_ENCRYPTED_SECRET > ( ) ;
239+ named_field_buffer_type ! (
240+ EncryptedSecret ,
241+ TPM2B_ENCRYPTED_SECRET_BUFFER_SIZE ,
242+ TPM2B_ENCRYPTED_SECRET ,
243+ secret
244+ ) ;
220245}
221246
222247pub mod id_object {
223- named_field_buffer_type ! ( IdObject , 256 , TPM2B_ID_OBJECT , credential) ;
248+ use crate :: tss2_esys:: TPMS_ID_OBJECT ;
249+ use std:: mem:: size_of;
250+ const TPM2B_ID_OBJECT_BUFFER_SIZE : usize = size_of :: < TPMS_ID_OBJECT > ( ) ;
251+ named_field_buffer_type ! (
252+ IdObject ,
253+ TPM2B_ID_OBJECT_BUFFER_SIZE ,
254+ TPM2B_ID_OBJECT ,
255+ credential
256+ ) ;
224257}
225258
226259pub mod initial_value {
227- buffer_type ! (
228- InitialValue ,
229- crate :: tss2_esys:: TPM2_MAX_SYM_BLOCK_SIZE as usize ,
230- TPM2B_IV
231- ) ;
260+ use crate :: tss2_esys:: TPM2_MAX_SYM_BLOCK_SIZE ;
261+ const TPM2B_IV_BUFFER_SIZE : usize = TPM2_MAX_SYM_BLOCK_SIZE as usize ;
262+ buffer_type ! ( InitialValue , TPM2B_IV_BUFFER_SIZE , TPM2B_IV ) ;
232263}
233264
234265pub mod max_buffer {
235266 use crate :: tss2_esys:: TPM2_MAX_DIGEST_BUFFER ;
236- buffer_type ! ( MaxBuffer , TPM2_MAX_DIGEST_BUFFER as usize , TPM2B_MAX_BUFFER ) ;
267+ const TPM2B_MAX_BUFFER_BUFFER_SIZE : usize = TPM2_MAX_DIGEST_BUFFER as usize ;
268+ buffer_type ! ( MaxBuffer , TPM2B_MAX_BUFFER_BUFFER_SIZE , TPM2B_MAX_BUFFER ) ;
237269}
238270
239271pub mod max_nv_buffer {
240272 use crate :: tss2_esys:: TPM2_MAX_NV_BUFFER_SIZE ;
273+ const TPM2B_MAX_NV_BUFFER_BUFFER_SIZE : usize = TPM2_MAX_NV_BUFFER_SIZE as usize ;
241274 buffer_type ! (
242275 MaxNvBuffer ,
243- TPM2_MAX_NV_BUFFER_SIZE as usize ,
276+ TPM2B_MAX_NV_BUFFER_BUFFER_SIZE ,
244277 TPM2B_MAX_NV_BUFFER
245278 ) ;
246279}
247280
248281pub mod nonce {
249- buffer_type ! ( Nonce , 64 , TPM2B_NONCE ) ;
282+ // Same size as TPM2B_DIGEST according to the specification.
283+ use crate :: tss2_esys:: TPMU_HA ;
284+ use std:: mem:: size_of;
285+ const TPM2B_NONCE_BUFFER_SIZE : usize = size_of :: < TPMU_HA > ( ) ;
286+
287+ buffer_type ! ( Nonce , TPM2B_NONCE_BUFFER_SIZE , TPM2B_NONCE ) ;
250288}
251289
252290pub mod private_key_rsa {
253291 use crate :: tss2_esys:: TPM2_MAX_RSA_KEY_BYTES ;
292+ const TPM2B_PRIVATE_KEY_RSA_BUFFER_SIZE : usize = ( TPM2_MAX_RSA_KEY_BYTES as usize ) * 5 / 2 ;
254293
255- // The maximum size is given in the spec as:
256- // "RSA_PRIVATE_SIZE is a vendor specific value that can be (MAX_RSA_KEY_BYTES / 2) or
257- // ((MAX_RSA_KEY_BYTES * 5) ./ 2. The larger size would only apply to keys that have fixedTPM parents.
258- // The larger size was added in revision 01.53."
259- // The TSS stack we use only accepts the smaller of the two sizes described above (for now).
260294 buffer_type ! (
261295 PrivateKeyRsa ,
262- ( TPM2_MAX_RSA_KEY_BYTES / 2 ) as usize ,
296+ TPM2B_PRIVATE_KEY_RSA_BUFFER_SIZE ,
263297 TPM2B_PRIVATE_KEY_RSA
264298 ) ;
265299}
266300
267301pub mod private_vendor_specific {
268302 use crate :: tss2_esys:: TPM2_PRIVATE_VENDOR_SPECIFIC_BYTES ;
269-
303+ const TPM2B_PRIVATE_VENDOR_SPECIFIC_BUFFER_SIZE : usize =
304+ TPM2_PRIVATE_VENDOR_SPECIFIC_BYTES as usize ;
270305 // The spec states the maximum size as:
271306 // "The value for PRIVATE_VENDOR_SPECIFIC_BYTES is determined by the vendor."
272307 // Not very helpful, but the TSS exposes a generic value that we can use.
273308 buffer_type ! (
274309 PrivateVendorSpecific ,
275- TPM2_PRIVATE_VENDOR_SPECIFIC_BYTES as usize ,
310+ TPM2B_PRIVATE_VENDOR_SPECIFIC_BUFFER_SIZE ,
276311 TPM2B_PRIVATE_VENDOR_SPECIFIC
277312 ) ;
278313}
279314
280315pub mod public_key_rsa {
281316 use crate :: { interface_types:: key_bits:: RsaKeyBits , tss2_esys:: TPM2_MAX_RSA_KEY_BYTES } ;
317+ const TPM2B_PUBLIC_KEY_RSA_BUFFER_SIZE : usize = TPM2_MAX_RSA_KEY_BYTES as usize ;
282318 buffer_type ! (
283319 PublicKeyRsa ,
284- TPM2_MAX_RSA_KEY_BYTES as usize ,
320+ TPM2B_PUBLIC_KEY_RSA_BUFFER_SIZE ,
285321 TPM2B_PUBLIC_KEY_RSA
286322 ) ;
287323
@@ -359,45 +395,47 @@ pub mod sensitive_data {
359395 // versions of tpm2-tss supported by the crate so the fall back is to
360396 // calculate the max size by removing the size of the size parameter(UINT16)
361397 // from the total size of the buffer type.
398+ use std:: mem:: size_of;
362399 cfg_if:: cfg_if! {
363400 if #[ cfg( has_tpmu_sensitive_create) ] {
364401 use crate :: tss2_esys:: TPMU_SENSITIVE_CREATE ;
365- #[ allow( unused_qualifications) ]
366- const TPMU_SENSITIVE_CREATE_MEM_SIZE : usize = std:: mem:: size_of:: <TPMU_SENSITIVE_CREATE >( ) ;
402+ const TPM2B_SENSITIVE_DATA_BUFFER_SIZE : usize = size_of:: <TPMU_SENSITIVE_CREATE >( ) ;
367403 } else {
368404 use crate :: tss2_esys:: UINT16 ;
369- #[ allow( unused_qualifications) ]
370- const TPMU_SENSITIVE_CREATE_MEM_SIZE : usize = std:: mem:: size_of:: <TPM2B_SENSITIVE_DATA >( ) - std:: mem:: size_of:: <UINT16 >( ) ;
405+ const TPM2B_SENSITIVE_DATA_BUFFER_SIZE : usize = size_of:: <TPM2B_SENSITIVE_DATA >( ) - size_of:: <UINT16 >( ) ;
371406 }
372407 }
373408 buffer_type ! (
374409 SensitiveData ,
375- TPMU_SENSITIVE_CREATE_MEM_SIZE ,
410+ TPM2B_SENSITIVE_DATA_BUFFER_SIZE ,
376411 TPM2B_SENSITIVE_DATA
377412 ) ;
378413}
379414
380415pub mod symmetric_key {
381416 use crate :: tss2_esys:: TPM2_MAX_SYM_KEY_BYTES ;
382-
417+ const TPM2B_SYM_KEY_BUFFER_SIZE : usize = TPM2_MAX_SYM_KEY_BYTES as usize ;
383418 // The spec states the maximum size as:
384419 // "MAX_SYM_KEY_BYTES will be the larger of the largest symmetric key supported by the TPM and the
385420 // largest digest produced by any hashing algorithm implemented on the TPM"
386- buffer_type ! ( SymmetricKey , TPM2_MAX_SYM_KEY_BYTES as usize , TPM2B_SYM_KEY ) ;
421+ buffer_type ! ( SymmetricKey , TPM2B_SYM_KEY_BUFFER_SIZE , TPM2B_SYM_KEY ) ;
387422}
388423
389424pub mod timeout {
390- buffer_type ! ( Timeout , 8 , TPM2B_TIMEOUT ) ;
425+ use crate :: tss2_esys:: UINT64 ;
426+ use std:: mem:: size_of;
427+ const TPM2B_TIMEOUT_BUFFER_SIZE : usize = size_of :: < UINT64 > ( ) ;
428+ buffer_type ! ( Timeout , TPM2B_TIMEOUT_BUFFER_SIZE , TPM2B_TIMEOUT ) ;
391429}
392430
393431pub mod tpm_context_data {
394432 use crate :: tss2_esys:: TPMS_CONTEXT_DATA ;
433+ use std:: mem:: size_of;
395434
396- #[ allow( unused_qualifications) ]
397- const TPMS_CONTEXT_DATA_MEM_SIZE : usize = std:: mem:: size_of :: < TPMS_CONTEXT_DATA > ( ) ;
435+ const TPM2B_CONTEXT_DATA_BUFFER_SIZE : usize = size_of :: < TPMS_CONTEXT_DATA > ( ) ;
398436 buffer_type ! (
399437 TpmContextData ,
400- TPMS_CONTEXT_DATA_MEM_SIZE ,
438+ TPM2B_CONTEXT_DATA_BUFFER_SIZE ,
401439 TPM2B_CONTEXT_DATA
402440 ) ;
403441}
0 commit comments