@@ -10,22 +10,24 @@ use std::{
1010use tss_esapi:: {
1111 abstraction:: { cipher:: Cipher , pcr:: PcrData } ,
1212 attributes:: ObjectAttributes ,
13- attributes:: { ObjectAttributesBuilder , SessionAttributesBuilder } ,
13+ attributes:: { NvIndexAttributesBuilder , ObjectAttributesBuilder , SessionAttributesBuilder } ,
1414 constants:: SessionType ,
15+ handles:: { NvIndexHandle , NvIndexTpmHandle } ,
1516 interface_types:: {
1617 algorithm:: SymmetricMode ,
1718 algorithm:: { HashingAlgorithm , PublicAlgorithm , RsaSchemeAlgorithm } ,
1819 key_bits:: RsaKeyBits ,
1920 key_bits:: { AesKeyBits , Sm4KeyBits } ,
20- resource_handles:: Hierarchy ,
21+ resource_handles:: { Hierarchy , NvAuth , Provision } ,
2122 session_handles:: PolicySession ,
2223 } ,
2324 structures:: {
2425 Digest , EccParameter , EccPoint , EccScheme , EccSignature , HashAgile , HashScheme , HmacScheme ,
25- KeyDerivationFunctionScheme , KeyedHashScheme , MaxBuffer , PcrSelectionListBuilder , PcrSlot ,
26- Public , PublicBuilder , PublicEccParameters , PublicKeyRsa , PublicKeyedHashParameters ,
27- PublicRsaParameters , RsaExponent , RsaScheme , RsaSignature , Sensitive , Signature ,
28- SymmetricCipherParameters , SymmetricDefinition , SymmetricDefinitionObject ,
26+ KeyDerivationFunctionScheme , KeyedHashScheme , MaxBuffer , MaxNvBuffer , NvPublicBuilder ,
27+ PcrSelectionListBuilder , PcrSlot , Public , PublicBuilder , PublicEccParameters , PublicKeyRsa ,
28+ PublicKeyedHashParameters , PublicRsaParameters , RsaExponent , RsaScheme , RsaSignature ,
29+ Sensitive , Signature , SymmetricCipherParameters , SymmetricDefinition ,
30+ SymmetricDefinitionObject ,
2931 } ,
3032 tcti_ldr:: TctiNameConf ,
3133 utils, Context ,
@@ -432,3 +434,45 @@ pub fn create_public_sealed_object() -> Public {
432434 . build ( )
433435 . expect ( "Failed to create public structure." )
434436}
437+
438+ #[ allow( dead_code) ]
439+ pub fn write_nv_index ( context : & mut Context , nv_index : NvIndexTpmHandle ) -> NvIndexHandle {
440+ // Create owner nv public.
441+ let owner_nv_index_attributes = NvIndexAttributesBuilder :: new ( )
442+ . with_owner_write ( true )
443+ . with_owner_read ( true )
444+ . with_pp_read ( true )
445+ . with_owner_read ( true )
446+ . build ( )
447+ . expect ( "Failed to create owner nv index attributes" ) ;
448+
449+ let owner_nv_public = NvPublicBuilder :: new ( )
450+ . with_nv_index ( nv_index)
451+ . with_index_name_algorithm ( HashingAlgorithm :: Sha256 )
452+ . with_index_attributes ( owner_nv_index_attributes)
453+ . with_data_area_size ( 1540 )
454+ . build ( )
455+ . unwrap ( ) ;
456+
457+ let owner_nv_index_handle = context
458+ . nv_define_space ( Provision :: Owner , None , owner_nv_public)
459+ . unwrap ( ) ;
460+
461+ let value = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ;
462+ let expected_data = MaxNvBuffer :: try_from ( value. to_vec ( ) ) . unwrap ( ) ;
463+
464+ // Write the data using Owner authorization
465+ context
466+ . nv_write (
467+ NvAuth :: Owner ,
468+ owner_nv_index_handle,
469+ expected_data. clone ( ) ,
470+ 0 ,
471+ )
472+ . unwrap ( ) ;
473+ context
474+ . nv_write ( NvAuth :: Owner , owner_nv_index_handle, expected_data, 1024 )
475+ . unwrap ( ) ;
476+
477+ owner_nv_index_handle
478+ }
0 commit comments