3535
3636#ifdef WOLFHSM_CFG_KEYWRAP
3737
38- #define WH_TEST_KEKID 1
38+ #define WH_DEMO_KEYWRAP_KEKID 1
3939static int _InitServerKek (whClientContext * ctx )
4040{
4141 /* IMPORTANT NOTE: Server KEK is typically intrinsic or set during
4242 * provisioning. Uploading the KEK via the client is for testing purposes
4343 * only and not intended as a recommendation */
44- whKeyId serverKeyId = WH_TEST_KEKID ;
44+ whKeyId serverKeyId = WH_DEMO_KEYWRAP_KEKID ;
4545 whNvmFlags flags = WH_NVM_FLAGS_NONEXPORTABLE ;
4646 uint8_t label [WH_NVM_LABEL_LEN ] = "Server KEK key" ;
4747 uint8_t kek [] = {0x03 , 0x03 , 0x0d , 0xd9 , 0xeb , 0x18 , 0x17 , 0x2e ,
@@ -55,43 +55,42 @@ static int _InitServerKek(whClientContext* ctx)
5555
5656static int _CleanupServerKek (whClientContext * ctx )
5757{
58- return wh_Client_KeyErase (ctx , WH_TEST_KEKID );
58+ return wh_Client_KeyErase (ctx , WH_DEMO_KEYWRAP_KEKID );
5959}
6060
6161#ifndef NO_AES
6262#ifdef HAVE_AESGCM
6363
64- #define WH_TEST_AES_KEYSIZE 16
65- #define WH_TEST_AES_TEXTSIZE 16
66- #define WH_TEST_AES_IVSIZE 12
67- #define WH_TEST_AES_TAGSIZE 16
68- #define WH_TEST_AES_WRAPPED_KEYSIZE \
69- (WH_TEST_AES_IVSIZE + WH_TEST_AES_TAGSIZE + WH_TEST_AES_KEYSIZE + \
70- sizeof(whNvmMetadata))
71- #define WH_TEST_AESGCM_WRAPKEY_ID 8
64+ #define WH_DEMO_KEYWRAP_AES_KEYSIZE 16
65+ #define WH_DEMO_KEYWRAP_AES_TEXTSIZE 16
66+ #define WH_DEMO_KEYWRAP_AES_IVSIZE 12
67+ #define WH_DEMO_KEYWRAP_AES_TAGSIZE 16
68+ #define WH_DEMO_KEYWRAP_AES_WRAPPED_KEYSIZE \
69+ (WH_DEMO_KEYWRAP_AES_IVSIZE + WH_DEMO_KEYWRAP_AES_TAGSIZE + \
70+ WH_DEMO_KEYWRAP_AES_KEYSIZE + sizeof(whNvmMetadata))
71+ #define WH_DEMO_KEYWRAP_AESGCM_WRAPKEY_ID 8
7272
7373int wh_DemoClient_AesGcmKeyWrap (whClientContext * client )
7474{
7575 int ret = 0 ;
7676 Aes aes [1 ];
7777 WC_RNG rng [1 ];
78- uint8_t key [WH_TEST_AES_KEYSIZE ];
79- uint8_t exportedKey [WH_TEST_AES_KEYSIZE ];
80- whNvmMetadata metadata = {
81- .id = WH_MAKE_KEYID (WH_KEYTYPE_CRYPTO , 0 , WH_TEST_AESGCM_WRAPKEY_ID ),
82- .label = "AES Key Label" ,
83- .access = WH_NVM_ACCESS_ANY ,
84- .len = WH_TEST_AES_KEYSIZE };
78+ uint8_t key [WH_DEMO_KEYWRAP_AES_KEYSIZE ];
79+ uint8_t exportedKey [WH_DEMO_KEYWRAP_AES_KEYSIZE ];
80+ whNvmMetadata metadata = {.id = WH_DEMO_KEYWRAP_AESGCM_WRAPKEY_ID ,
81+ .label = "AES Key Label" ,
82+ .access = WH_NVM_ACCESS_ANY ,
83+ .len = WH_DEMO_KEYWRAP_AES_KEYSIZE };
8584 whNvmMetadata exportedMetadata ;
86- uint8_t wrappedKey [WH_TEST_AES_WRAPPED_KEYSIZE ];
85+ uint8_t wrappedKey [WH_DEMO_KEYWRAP_AES_WRAPPED_KEYSIZE ];
8786 whKeyId wrappedKeyId ;
8887
8988 const uint8_t plaintext [] = "hello, wolfSSL AES-GCM!" ;
9089 uint8_t ciphertext [sizeof (plaintext )];
9190 uint8_t decrypted [sizeof (plaintext )];
9291
93- uint8_t tag [WH_TEST_AES_TAGSIZE ];
94- uint8_t iv [WH_TEST_AES_IVSIZE ];
92+ uint8_t tag [WH_DEMO_KEYWRAP_AES_TAGSIZE ];
93+ uint8_t iv [WH_DEMO_KEYWRAP_AES_IVSIZE ];
9594 const uint8_t aad [] = {0xfe , 0xed , 0xfa , 0xce , 0xde , 0xad , 0xbe ,
9695 0xef , 0xfe , 0xed , 0xfa , 0xce , 0xde , 0xad ,
9796 0xbe , 0xef , 0xab , 0xad , 0xda , 0xd2 };
@@ -127,8 +126,8 @@ int wh_DemoClient_AesGcmKeyWrap(whClientContext* client)
127126
128127 /* Now we request the server to wrap the key using the KEK we
129128 * establish above in the first step. */
130- ret = wh_Client_KeyWrap (client , WC_CIPHER_AES_GCM , WH_TEST_KEKID , key ,
131- sizeof (key ), & metadata , wrappedKey ,
129+ ret = wh_Client_KeyWrap (client , WC_CIPHER_AES_GCM , WH_DEMO_KEYWRAP_KEKID ,
130+ key , sizeof (key ), & metadata , wrappedKey ,
132131 sizeof (wrappedKey ));
133132 if (ret != 0 ) {
134133 printf ("Failed to wh_Client_KeyWrap %d\n" , ret );
@@ -144,9 +143,9 @@ int wh_DemoClient_AesGcmKeyWrap(whClientContext* client)
144143 /* Request the server to unwrap and cache the wrapped key we just created.
145144 * This will provide us back a key ID that the client can use to do crypto
146145 * operations */
147- ret = wh_Client_KeyUnwrapAndCache (client , WC_CIPHER_AES_GCM , WH_TEST_KEKID ,
148- wrappedKey , sizeof ( wrappedKey ) ,
149- & wrappedKeyId );
146+ ret = wh_Client_KeyUnwrapAndCache (client , WC_CIPHER_AES_GCM ,
147+ WH_DEMO_KEYWRAP_KEKID , wrappedKey ,
148+ sizeof ( wrappedKey ), & wrappedKeyId );
150149 if (ret != 0 ) {
151150 printf ("Failed to wh_Client_KeyUnwrapAndCache %d\n" , ret );
152151 goto cleanup_rng ;
@@ -207,10 +206,10 @@ int wh_DemoClient_AesGcmKeyWrap(whClientContext* client)
207206 /* Exporting a wrapped key */
208207
209208 /* Request the server to unwrap and export the wrapped key we created */
210- ret = wh_Client_KeyUnwrapAndExport (client , WC_CIPHER_AES_GCM , WH_TEST_KEKID ,
211- wrappedKey , sizeof ( wrappedKey ) ,
212- & exportedMetadata , exportedKey ,
213- sizeof (exportedKey ));
209+ ret = wh_Client_KeyUnwrapAndExport (client , WC_CIPHER_AES_GCM ,
210+ WH_DEMO_KEYWRAP_KEKID , wrappedKey ,
211+ sizeof ( wrappedKey ), & exportedMetadata ,
212+ exportedKey , sizeof (exportedKey ));
214213 if (ret != 0 ) {
215214 printf ("Failed to wh_Client_KeyUnwrapAndCache %d\n" , ret );
216215 goto cleanup_aes ;
0 commit comments