@@ -170,8 +170,9 @@ int wh_DemoClient_CryptoRsaImport(whClientContext* clientContext)
170170 close (keyFd );
171171
172172 /* cache the key in the HSM, get HSM assigned keyId */
173- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
174- strlen (keyLabel ), keyBuf , keySz , & keyId );
173+ ret = wh_Client_KeyCache (
174+ clientContext , WH_NVM_FLAGS_USAGE_ENCRYPT | WH_NVM_FLAGS_USAGE_DECRYPT ,
175+ (uint8_t * )keyLabel , strlen (keyLabel ), keyBuf , keySz , & keyId );
175176 if (ret != 0 ) {
176177 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
177178 goto exit ;
@@ -359,8 +360,9 @@ int wh_DemoClient_CryptoCurve25519Import(whClientContext* clientContext)
359360
360361
361362 /* cache the key in the HSM, get HSM assigned keyId */
362- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
363- strlen (keyLabel ), keyBuf , keySz , & keyIdBob );
363+ ret = wh_Client_KeyCache (clientContext , WH_NVM_FLAGS_USAGE_DERIVE ,
364+ (uint8_t * )keyLabel , strlen (keyLabel ), keyBuf ,
365+ keySz , & keyIdBob );
364366 if (ret != 0 ) {
365367 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
366368 goto exit ;
@@ -394,8 +396,9 @@ int wh_DemoClient_CryptoCurve25519Import(whClientContext* clientContext)
394396 close (keyFd );
395397
396398 /* cache the key in the HSM, get HSM assigned keyId */
397- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
398- strlen (keyLabel ), keyBuf , keySz , & keyIdAlice );
399+ ret = wh_Client_KeyCache (clientContext , WH_NVM_FLAGS_USAGE_DERIVE ,
400+ (uint8_t * )keyLabel , strlen (keyLabel ), keyBuf ,
401+ keySz , & keyIdAlice );
399402 if (ret != 0 ) {
400403 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
401404 goto exit ;
@@ -649,8 +652,11 @@ int wh_DemoClient_CryptoEccImport(whClientContext* clientContext)
649652 close (keyFd );
650653 /* Cache the key in the HSM, get HSM assigned keyId. From here on out, the
651654 * keys are stored in the HSM and can be referred to by keyId */
652- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
653- strlen (keyLabel ), keyBuf , keySz , & keyIdAlice );
655+ ret = wh_Client_KeyCache (
656+ clientContext ,
657+ WH_NVM_FLAGS_USAGE_DERIVE | WH_NVM_FLAGS_USAGE_SIGN |
658+ WH_NVM_FLAGS_USAGE_VERIFY ,
659+ (uint8_t * )keyLabel , strlen (keyLabel ), keyBuf , keySz , & keyIdAlice );
654660 if (ret != 0 ) {
655661 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
656662 goto exit ;
@@ -694,8 +700,11 @@ int wh_DemoClient_CryptoEccImport(whClientContext* clientContext)
694700 }
695701 close (keyFd );
696702 /* Cache the key in the HSM, get HSM assigned keyId */
697- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
698- strlen (keyLabel ), keyBuf , keySz , & keyIdBob );
703+ ret = wh_Client_KeyCache (
704+ clientContext ,
705+ WH_NVM_FLAGS_USAGE_DERIVE | WH_NVM_FLAGS_USAGE_SIGN |
706+ WH_NVM_FLAGS_USAGE_VERIFY ,
707+ (uint8_t * )keyLabel , strlen (keyLabel ), keyBuf , keySz , & keyIdBob );
699708 if (ret != 0 ) {
700709 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
701710 goto exit ;
@@ -902,8 +911,9 @@ int wh_DemoClient_CryptoAesCbcImport(whClientContext* clientContext)
902911 }
903912
904913 /* cache the key on the HSM */
905- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
906- sizeof (keyLabel ), key , sizeof (key ), & keyId );
914+ ret = wh_Client_KeyCache (
915+ clientContext , WH_NVM_FLAGS_USAGE_ENCRYPT | WH_NVM_FLAGS_USAGE_DECRYPT ,
916+ (uint8_t * )keyLabel , sizeof (keyLabel ), key , sizeof (key ), & keyId );
907917 if (ret != 0 ) {
908918 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
909919 goto exit ;
@@ -1050,8 +1060,9 @@ int wh_DemoClient_CryptoAesGcmImport(whClientContext* clientContext)
10501060 }
10511061
10521062 /* cache the key on the HSM */
1053- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
1054- sizeof (keyLabel ), key , sizeof (key ), & keyId );
1063+ ret = wh_Client_KeyCache (
1064+ clientContext , WH_NVM_FLAGS_USAGE_ENCRYPT | WH_NVM_FLAGS_USAGE_DECRYPT ,
1065+ (uint8_t * )keyLabel , sizeof (keyLabel ), key , sizeof (key ), & keyId );
10551066 if (ret != 0 ) {
10561067 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
10571068 goto exit ;
@@ -1193,8 +1204,9 @@ int wh_DemoClient_CryptoCmacImport(whClientContext* clientContext)
11931204 }
11941205
11951206 /* cache the key on the HSM */
1196- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
1197- sizeof (keyLabel ), key , sizeof (key ), & keyId );
1207+ ret = wh_Client_KeyCache (
1208+ clientContext , WH_NVM_FLAGS_USAGE_SIGN | WH_NVM_FLAGS_USAGE_VERIFY ,
1209+ (uint8_t * )keyLabel , sizeof (keyLabel ), key , sizeof (key ), & keyId );
11981210 if (ret != 0 ) {
11991211 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
12001212 goto exit ;
@@ -1235,8 +1247,9 @@ int wh_DemoClient_CryptoCmacImport(whClientContext* clientContext)
12351247
12361248 /* cache the key on the HSM. This is required because the key is evicted
12371249 * after the non-DMA CMAC operation is finalized */
1238- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
1239- sizeof (keyLabel ), key , sizeof (key ), & keyId );
1250+ ret = wh_Client_KeyCache (
1251+ clientContext , WH_NVM_FLAGS_USAGE_SIGN | WH_NVM_FLAGS_USAGE_VERIFY ,
1252+ (uint8_t * )keyLabel , sizeof (keyLabel ), key , sizeof (key ), & keyId );
12401253 if (ret != 0 ) {
12411254 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
12421255 goto exit ;
@@ -1289,8 +1302,9 @@ int wh_DemoClient_CryptoCmacOneshotImport(whClientContext* clientContext)
12891302 }
12901303
12911304 /* cache the key on the HSM */
1292- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
1293- sizeof (keyLabel ), key , sizeof (key ), & keyId );
1305+ ret = wh_Client_KeyCache (
1306+ clientContext , WH_NVM_FLAGS_USAGE_SIGN | WH_NVM_FLAGS_USAGE_VERIFY ,
1307+ (uint8_t * )keyLabel , sizeof (keyLabel ), key , sizeof (key ), & keyId );
12941308 if (ret != 0 ) {
12951309 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
12961310 goto exit ;
@@ -1327,8 +1341,9 @@ int wh_DemoClient_CryptoCmacOneshotImport(whClientContext* clientContext)
13271341
13281342 /* cache the key on the HSM again, cmac keys are evicted after non-DMA CMAC
13291343 * operations are finalized is called */
1330- ret = wh_Client_KeyCache (clientContext , 0 , (uint8_t * )keyLabel ,
1331- sizeof (keyLabel ), key , sizeof (key ), & keyId );
1344+ ret = wh_Client_KeyCache (
1345+ clientContext , WH_NVM_FLAGS_USAGE_SIGN | WH_NVM_FLAGS_USAGE_VERIFY ,
1346+ (uint8_t * )keyLabel , sizeof (keyLabel ), key , sizeof (key ), & keyId );
13321347 if (ret != 0 ) {
13331348 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
13341349 goto exit ;
@@ -1419,7 +1434,7 @@ int wh_DemoClient_CryptoHkdfCache(whClientContext* clientContext)
14191434 const uint32_t outSz = 32 ; /* arbitrary output size */
14201435
14211436 /* Metadata flags/label for the cached key. Adjust to your requirements. */
1422- whNvmFlags flags = WH_NVM_FLAGS_NONEXPORTABLE ;
1437+ whNvmFlags flags = WH_NVM_FLAGS_NONEXPORTABLE | WH_NVM_FLAGS_USAGE_DERIVE ;
14231438 char label [] = "hkdf-derived key" ;
14241439
14251440 /* Request the HSM to derive HKDF output and store it in the key cache.
@@ -1467,9 +1482,9 @@ int wh_DemoClient_CryptoHkdfCacheInputKey(whClientContext* clientContext)
14671482 byte okm [32 ]; /* Output key material */
14681483
14691484 /* First, cache the input key material in the HSM */
1470- ret = wh_Client_KeyCache (clientContext , 0 , ( uint8_t * ) keyLabel ,
1471- (uint32_t )strlen (keyLabel ), ikm ,
1472- (uint32_t )sizeof (ikm ), & keyIdIn );
1485+ ret = wh_Client_KeyCache (clientContext , WH_NVM_FLAGS_USAGE_DERIVE ,
1486+ (uint8_t * ) keyLabel , ( uint32_t )strlen (keyLabel ),
1487+ ikm , (uint32_t )sizeof (ikm ), & keyIdIn );
14731488 if (ret != WH_ERROR_OK ) {
14741489 printf ("Failed to wh_Client_KeyCache %d\n" , ret );
14751490 return ret ;
@@ -1565,7 +1580,7 @@ int wh_DemoClient_CryptoCmacKdfCache(whClientContext* clientContext)
15651580{
15661581 int ret = 0 ;
15671582 whKeyId keyId = WH_KEYID_ERASED ;
1568- whNvmFlags flags = WH_NVM_FLAGS_NONEXPORTABLE ;
1583+ whNvmFlags flags = WH_NVM_FLAGS_NONEXPORTABLE | WH_NVM_FLAGS_USAGE_DERIVE ;
15691584 const char label [] = "cmac-kdf cache" ;
15701585
15711586 ret = wh_Client_CmacKdfMakeCacheKey (
@@ -1609,7 +1624,7 @@ int wh_DemoClient_CryptoCmacKdfCacheInputs(whClientContext* clientContext)
16091624 * as the salt is usually not sensitive information. If it is desired to use
16101625 * HSM-only information as salt, then this would likely be provisioned
16111626 * as an offline step */
1612- ret = wh_Client_KeyCache (clientContext , WH_NVM_FLAGS_NONE , NULL , 0 ,
1627+ ret = wh_Client_KeyCache (clientContext , WH_NVM_FLAGS_USAGE_DERIVE , NULL , 0 ,
16131628 demoCmacKdfSalt , (uint32_t )sizeof (demoCmacKdfSalt ),
16141629 & saltKeyId );
16151630 if (ret != WH_ERROR_OK ) {
@@ -1619,7 +1634,7 @@ int wh_DemoClient_CryptoCmacKdfCacheInputs(whClientContext* clientContext)
16191634
16201635 /* Cache the Z input. This would typically be done offline during the HSM
16211636 * provisioning step, but is shown here for completeness */
1622- ret = wh_Client_KeyCache (clientContext , WH_NVM_FLAGS_NONE , NULL , 0 ,
1637+ ret = wh_Client_KeyCache (clientContext , WH_NVM_FLAGS_USAGE_DERIVE , NULL , 0 ,
16231638 demoCmacKdfZ , (uint32_t )sizeof (demoCmacKdfZ ),
16241639 & zKeyId );
16251640 if (ret != WH_ERROR_OK ) {
0 commit comments