@@ -10,22 +10,24 @@ use std::{
10
10
use tss_esapi:: {
11
11
abstraction:: { cipher:: Cipher , pcr:: PcrData } ,
12
12
attributes:: ObjectAttributes ,
13
- attributes:: { ObjectAttributesBuilder , SessionAttributesBuilder } ,
13
+ attributes:: { NvIndexAttributesBuilder , ObjectAttributesBuilder , SessionAttributesBuilder } ,
14
14
constants:: SessionType ,
15
+ handles:: { NvIndexHandle , NvIndexTpmHandle } ,
15
16
interface_types:: {
16
17
algorithm:: SymmetricMode ,
17
18
algorithm:: { HashingAlgorithm , PublicAlgorithm , RsaSchemeAlgorithm } ,
18
19
key_bits:: RsaKeyBits ,
19
20
key_bits:: { AesKeyBits , Sm4KeyBits } ,
20
- resource_handles:: Hierarchy ,
21
+ resource_handles:: { Hierarchy , NvAuth , Provision } ,
21
22
session_handles:: PolicySession ,
22
23
} ,
23
24
structures:: {
24
25
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 ,
29
31
} ,
30
32
tcti_ldr:: TctiNameConf ,
31
33
utils, Context ,
@@ -432,3 +434,45 @@ pub fn create_public_sealed_object() -> Public {
432
434
. build ( )
433
435
. expect ( "Failed to create public structure." )
434
436
}
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