@@ -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], 
@@ -216,11 +231,27 @@ pub mod ecc_parameter {
216231} 
217232
218233pub  mod  encrypted_secret { 
219-     named_field_buffer_type ! ( EncryptedSecret ,  256 ,  TPM2B_ENCRYPTED_SECRET ,  secret) ; 
234+     use  crate :: tss2_esys:: TPMU_ENCRYPTED_SECRET ; 
235+     use  std:: mem:: size_of; 
236+     const  TPMU_ENCRYPTED_SECRET_MEM_SIZE :  usize  = size_of :: < TPMU_ENCRYPTED_SECRET > ( ) ; 
237+     named_field_buffer_type ! ( 
238+         EncryptedSecret , 
239+         TPMU_ENCRYPTED_SECRET_MEM_SIZE , 
240+         TPM2B_ENCRYPTED_SECRET , 
241+         secret
242+     ) ; 
220243} 
221244
222245pub  mod  id_object { 
223-     named_field_buffer_type ! ( IdObject ,  256 ,  TPM2B_ID_OBJECT ,  credential) ; 
246+     use  crate :: tss2_esys:: TPMS_ID_OBJECT ; 
247+     use  std:: mem:: size_of; 
248+     const  TPMS_ID_OBJECT_MEM_SIZE :  usize  = size_of :: < TPMS_ID_OBJECT > ( ) ; 
249+     named_field_buffer_type ! ( 
250+         IdObject , 
251+         TPMS_ID_OBJECT_MEM_SIZE , 
252+         TPM2B_ID_OBJECT , 
253+         credential
254+     ) ; 
224255} 
225256
226257pub  mod  initial_value { 
@@ -246,42 +277,45 @@ pub mod max_nv_buffer {
246277} 
247278
248279pub  mod  nonce { 
249-     buffer_type ! ( Nonce ,  64 ,  TPM2B_NONCE ) ; 
280+     // Same size as TPM2B_DIGEST according to the specification. 
281+     use  crate :: tss2_esys:: TPMU_HA ; 
282+     use  std:: mem:: size_of; 
283+     const  TPM2B_NONCE_BUFFER_SIZE :  usize  = size_of :: < TPMU_HA > ( ) ; 
284+ 
285+     buffer_type ! ( Nonce ,  TPM2B_NONCE_BUFFER_SIZE ,  TPM2B_NONCE ) ; 
250286} 
251287
252288pub  mod  private_key_rsa { 
253289    use  crate :: tss2_esys:: TPM2_MAX_RSA_KEY_BYTES ; 
290+     const  TPM2B_PRIVATE_KEY_RSA_BUFFER_SIZE :  usize  = ( TPM2_MAX_RSA_KEY_BYTES  as  usize )  *  5  / 2 ; 
254291
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). 
260292    buffer_type ! ( 
261293        PrivateKeyRsa , 
262-         ( TPM2_MAX_RSA_KEY_BYTES  /  2 )   as   usize , 
294+         TPM2B_PRIVATE_KEY_RSA_BUFFER_SIZE , 
263295        TPM2B_PRIVATE_KEY_RSA 
264296    ) ; 
265297} 
266298
267299pub  mod  private_vendor_specific { 
268300    use  crate :: tss2_esys:: TPM2_PRIVATE_VENDOR_SPECIFIC_BYTES ; 
269- 
301+     const  TPM2B_PRIVATE_VENDOR_SPECIFIC_BUFFER_SIZE :  usize  =
302+         TPM2_PRIVATE_VENDOR_SPECIFIC_BYTES  as  usize ; 
270303    // The spec states the maximum size as: 
271304    // "The value for PRIVATE_VENDOR_SPECIFIC_BYTES is determined by the vendor." 
272305    // Not very helpful, but the TSS exposes a generic value that we can use. 
273306    buffer_type ! ( 
274307        PrivateVendorSpecific , 
275-         TPM2_PRIVATE_VENDOR_SPECIFIC_BYTES   as   usize , 
308+         TPM2B_PRIVATE_VENDOR_SPECIFIC_BUFFER_SIZE , 
276309        TPM2B_PRIVATE_VENDOR_SPECIFIC 
277310    ) ; 
278311} 
279312
280313pub  mod  public_key_rsa { 
281314    use  crate :: { interface_types:: key_bits:: RsaKeyBits ,  tss2_esys:: TPM2_MAX_RSA_KEY_BYTES } ; 
315+     const  TPM2B_PUBLIC_KEY_RSA_BUFFER_SIZE :  usize  = TPM2_MAX_RSA_KEY_BYTES  as  usize ; 
282316    buffer_type ! ( 
283317        PublicKeyRsa , 
284-         TPM2_MAX_RSA_KEY_BYTES   as   usize , 
318+         TPM2B_PUBLIC_KEY_RSA_BUFFER_SIZE , 
285319        TPM2B_PUBLIC_KEY_RSA 
286320    ) ; 
287321
@@ -359,45 +393,47 @@ pub mod sensitive_data {
359393    // versions of tpm2-tss supported by the crate so the fall back is to 
360394    // calculate the max size by removing the size of the size parameter(UINT16) 
361395    // from the total size of the buffer type. 
396+     use  std:: mem:: size_of; 
362397    cfg_if:: cfg_if! { 
363398        if  #[ cfg( has_tpmu_sensitive_create) ]  { 
364399            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 >( ) ; 
400+             const  TPM2B_SENSITIVE_DATA_BUFFER_SIZE :  usize  = size_of:: <TPMU_SENSITIVE_CREATE >( ) ; 
367401        }  else { 
368402            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 >( ) ; 
403+             const  TPM2B_SENSITIVE_DATA_BUFFER_SIZE :  usize  = size_of:: <TPM2B_SENSITIVE_DATA >( )  - size_of:: <UINT16 >( ) ; 
371404        } 
372405    } 
373406    buffer_type ! ( 
374407        SensitiveData , 
375-         TPMU_SENSITIVE_CREATE_MEM_SIZE , 
408+         TPM2B_SENSITIVE_DATA_BUFFER_SIZE , 
376409        TPM2B_SENSITIVE_DATA 
377410    ) ; 
378411} 
379412
380413pub  mod  symmetric_key { 
381414    use  crate :: tss2_esys:: TPM2_MAX_SYM_KEY_BYTES ; 
382- 
415+      const   TPM2B_SYM_KEY_BUFFER_SIZE :   usize  =  TPM2_MAX_SYM_KEY_BYTES   as   usize ; 
383416    // The spec states the maximum size as: 
384417    // "MAX_SYM_KEY_BYTES will be the larger of the largest symmetric key supported by the TPM and the 
385418    // 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 ) ; 
419+     buffer_type ! ( SymmetricKey ,  TPM2B_SYM_KEY_BUFFER_SIZE ,  TPM2B_SYM_KEY ) ; 
387420} 
388421
389422pub  mod  timeout { 
390-     buffer_type ! ( Timeout ,  8 ,  TPM2B_TIMEOUT ) ; 
423+     use  crate :: tss2_esys:: UINT64 ; 
424+     use  std:: mem:: size_of; 
425+     const  TPM2B_TIMEOUT_BUFFER_SIZE :  usize  = size_of :: < UINT64 > ( ) ; 
426+     buffer_type ! ( Timeout ,  TPM2B_TIMEOUT_BUFFER_SIZE ,  TPM2B_TIMEOUT ) ; 
391427} 
392428
393429pub  mod  tpm_context_data { 
394430    use  crate :: tss2_esys:: TPMS_CONTEXT_DATA ; 
431+     use  std:: mem:: size_of; 
395432
396-     #[ allow( unused_qualifications) ]  
397-     const  TPMS_CONTEXT_DATA_MEM_SIZE :  usize  = std:: mem:: size_of :: < TPMS_CONTEXT_DATA > ( ) ; 
433+     const  TPM2B_CONTEXT_DATA_BUFFER_SIZE :  usize  = size_of :: < TPMS_CONTEXT_DATA > ( ) ; 
398434    buffer_type ! ( 
399435        TpmContextData , 
400-         TPMS_CONTEXT_DATA_MEM_SIZE , 
436+         TPM2B_CONTEXT_DATA_BUFFER_SIZE , 
401437        TPM2B_CONTEXT_DATA 
402438    ) ; 
403439} 
0 commit comments