@@ -91,7 +91,7 @@ static int _RsaMakeKey(whClientContext* ctx, uint32_t size, uint32_t e,
9191
9292#ifdef HAVE_HKDF
9393/* Generate HKDF output on the server based on the flags */
94- static int _HkdfMakeKey (whClientContext * ctx , int hashType ,
94+ static int _HkdfMakeKey (whClientContext * ctx , int hashType , whKeyId keyIdIn ,
9595 const uint8_t * inKey , uint32_t inKeySz ,
9696 const uint8_t * salt , uint32_t saltSz ,
9797 const uint8_t * info , uint32_t infoSz , whNvmFlags flags ,
@@ -2491,7 +2491,7 @@ int wh_Client_RsaGetSize(whClientContext* ctx, const RsaKey* key, int* out_size)
24912491
24922492#ifdef HAVE_HKDF
24932493/* Internal helper function to generate HKDF output on the server */
2494- static int _HkdfMakeKey (whClientContext * ctx , int hashType ,
2494+ static int _HkdfMakeKey (whClientContext * ctx , int hashType , whKeyId keyIdIn ,
24952495 const uint8_t * inKey , uint32_t inKeySz ,
24962496 const uint8_t * salt , uint32_t saltSz ,
24972497 const uint8_t * info , uint32_t infoSz , whNvmFlags flags ,
@@ -2506,7 +2506,7 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType,
25062506 uint16_t action = WC_ALGO_TYPE_KDF ;
25072507 whKeyId key_id = WH_KEYID_ERASED ;
25082508
2509- if ((ctx == NULL ) || (inKey == NULL )) {
2509+ if ((ctx == NULL ) || (( inKey == NULL ) && ( inKeySz != 0 ) )) {
25102510 return WH_ERROR_BADARGS ;
25112511 }
25122512
@@ -2531,7 +2531,8 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType,
25312531
25322532 /* Populate request body */
25332533 req -> flags = flags ;
2534- req -> keyId = key_id ;
2534+ req -> keyIdIn = keyIdIn ;
2535+ req -> keyIdOut = key_id ;
25352536 req -> hashType = hashType ;
25362537 req -> inKeySz = inKeySz ;
25372538 req -> saltSz = saltSz ;
@@ -2551,8 +2552,10 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType,
25512552 uint8_t * data_ptr = (uint8_t * )(req + 1 );
25522553
25532554 /* Copy input key material */
2554- memcpy (data_ptr , inKey , inKeySz );
2555- data_ptr += inKeySz ;
2555+ if ((inKey != NULL ) && (inKeySz > 0 )) {
2556+ memcpy (data_ptr , inKey , inKeySz );
2557+ data_ptr += inKeySz ;
2558+ }
25562559
25572560 /* Copy salt if provided */
25582561 if (salt != NULL && saltSz > 0 ) {
@@ -2594,7 +2597,7 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType,
25942597
25952598 if (ret == WH_ERROR_OK ) {
25962599 /* Key is cached on server or is ephemeral */
2597- key_id = (whKeyId )(res -> keyId );
2600+ key_id = (whKeyId )(res -> keyIdOut );
25982601
25992602 /* Update output variable if requested */
26002603 if (inout_key_id != NULL ) {
@@ -2623,35 +2626,35 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType,
26232626}
26242627
26252628int wh_Client_HkdfMakeCacheKey (whClientContext * ctx , int hashType ,
2626- const uint8_t * inKey , uint32_t inKeySz ,
2627- const uint8_t * salt , uint32_t saltSz ,
2628- const uint8_t * info , uint32_t infoSz ,
2629- whKeyId * inout_key_id , whNvmFlags flags ,
2630- const uint8_t * label , uint32_t label_len ,
2631- uint32_t outSz )
2629+ whKeyId keyIdIn , const uint8_t * inKey ,
2630+ uint32_t inKeySz , const uint8_t * salt ,
2631+ uint32_t saltSz , const uint8_t * info ,
2632+ uint32_t infoSz , whKeyId * inout_key_id ,
2633+ whNvmFlags flags , const uint8_t * label ,
2634+ uint32_t label_len , uint32_t outSz )
26322635{
26332636 if ((ctx == NULL ) || (inout_key_id == NULL )) {
26342637 return WH_ERROR_BADARGS ;
26352638 }
26362639
2637- return _HkdfMakeKey (ctx , hashType , inKey , inKeySz , salt , saltSz , info ,
2638- infoSz , flags , label_len , label , inout_key_id , NULL ,
2639- outSz );
2640+ return _HkdfMakeKey (ctx , hashType , keyIdIn , inKey , inKeySz , salt , saltSz ,
2641+ info , infoSz , flags , label_len , label , inout_key_id ,
2642+ NULL , outSz );
26402643}
26412644
26422645int wh_Client_HkdfMakeExportKey (whClientContext * ctx , int hashType ,
2643- const uint8_t * inKey , uint32_t inKeySz ,
2644- const uint8_t * salt , uint32_t saltSz ,
2645- const uint8_t * info , uint32_t infoSz ,
2646- uint8_t * out , uint32_t outSz )
2646+ whKeyId keyIdIn , const uint8_t * inKey ,
2647+ uint32_t inKeySz , const uint8_t * salt ,
2648+ uint32_t saltSz , const uint8_t * info ,
2649+ uint32_t infoSz , uint8_t * out , uint32_t outSz )
26472650{
26482651 if ((ctx == NULL ) || (out == NULL )) {
26492652 return WH_ERROR_BADARGS ;
26502653 }
26512654
2652- return _HkdfMakeKey (ctx , hashType , inKey , inKeySz , salt , saltSz , info ,
2653- infoSz , WH_NVM_FLAGS_EPHEMERAL , 0 , NULL , NULL , out ,
2654- outSz );
2655+ return _HkdfMakeKey (ctx , hashType , keyIdIn , inKey , inKeySz , salt , saltSz ,
2656+ info , infoSz , WH_NVM_FLAGS_EPHEMERAL , 0 , NULL , NULL ,
2657+ out , outSz );
26552658}
26562659
26572660#endif /* HAVE_HKDF */
0 commit comments