Skip to content

Commit 0f29e11

Browse files
committed
Use recommened static sizes for AES GCM IV and Tag
1 parent 51f171e commit 0f29e11

File tree

6 files changed

+20
-34
lines changed

6 files changed

+20
-34
lines changed

examples/demo/client/wh_demo_client_keystore.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ int wh_DemoClient_KeystoreAes(whClientContext* clientContext)
126126
{
127127
int ret;
128128
Aes aes = {0};
129-
uint8_t key[AES_128_KEY_SIZE] = {'0','1','2','3','4','5','6','7',
130-
'8','9','a','b','c','d','e','f'};
131-
uint8_t iv[AES_IV_SIZE] = {'1','2','3','4','5','6','7','8',
132-
'9','0','a','b','c','d','e','f'};
129+
uint8_t key[AES_128_KEY_SIZE] = {'0', '1', '2', '3', '4', '5', '6', '7',
130+
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
131+
uint8_t iv[AES_IV_SIZE] = {'1', '2', '3', '4', '5', '6', '7', '8',
132+
'9', '0', 'a', 'b', 'c', 'd', 'e', 'f'};
133133
uint8_t label[] = "my secret AES key";
134134
uint8_t plainText[] = "This is a test.";
135135
uint8_t cipherText[sizeof(plainText)];

examples/demo/client/wh_demo_client_keywrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define WH_TEST_AES_TEXTSIZE 16
4242
#define WH_TEST_AES_IVSIZE 12
4343
#define WH_TEST_AES_TAGSIZE 16
44-
#define WH_TEST_AES_WRAPPED_KEYSIZE \
44+
#define WH_TEST_AES_WRAPPED_KEYSIZE \
4545
(WH_TEST_AES_IVSIZE + WH_TEST_AES_TAGSIZE + WH_TEST_AES_KEYSIZE + \
4646
sizeof(whNvmMetadata))
4747
#define WH_TEST_WRAPKEY_ID 8

src/wh_server_keystore.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,18 @@ int wh_Server_KeystoreEraseKey(whServerContext* server, whNvmId keyId)
554554
#ifndef NO_AES
555555
#ifdef HAVE_AESGCM
556556

557+
#define WOLFHSM_KEYWRAP_AES_GCM_TAG_SIZE 16
558+
#define WOLFHSM_KEYWRAP_AES_GCM_IV_SIZE 12
559+
557560
static int _AesGcmWrapKey(whServerContext* server, whKeyId serverKeyId,
558561
uint8_t* keyIn, uint16_t keySz,
559562
whNvmMetadata* metadataIn, uint8_t* wrappedKeyOut,
560563
uint16_t wrappedKeySz)
561564
{
562565
int ret = 0;
563566
Aes aes[1];
564-
uint8_t authTag[WOLFHSM_CFG_KEYWRAP_AES_GCM_TAG_SIZE];
565-
uint8_t iv[WOLFHSM_CFG_KEYWRAP_AES_GCM_IV_SIZE];
567+
uint8_t authTag[WOLFHSM_KEYWRAP_AES_GCM_TAG_SIZE];
568+
uint8_t iv[WOLFHSM_KEYWRAP_AES_GCM_IV_SIZE];
566569
uint8_t serverKey[AES_MAX_KEY_SIZE];
567570
uint32_t serverKeySz = sizeof(serverKey);
568571

@@ -637,8 +640,8 @@ static int _AesGcmUnwrapKey(whServerContext* server, uint16_t serverKeyId,
637640
{
638641
int ret = 0;
639642
Aes aes[1];
640-
uint8_t authTag[WOLFHSM_CFG_KEYWRAP_AES_GCM_TAG_SIZE];
641-
uint8_t iv[WOLFHSM_CFG_KEYWRAP_AES_GCM_IV_SIZE];
643+
uint8_t authTag[WOLFHSM_KEYWRAP_AES_GCM_TAG_SIZE];
644+
uint8_t iv[WOLFHSM_KEYWRAP_AES_GCM_IV_SIZE];
642645
uint8_t serverKey[AES_MAX_KEY_SIZE];
643646
uint32_t serverKeySz = sizeof(serverKey);
644647
uint8_t* encBlob = (uint8_t*)wrappedKeyIn + sizeof(iv) + sizeof(authTag);
@@ -727,8 +730,8 @@ static int _HandleWrapKeyRequest(whServerContext* server,
727730
#ifndef NO_AES
728731
#ifdef HAVE_AESGCM
729732
case WC_CIPHER_AES_GCM: {
730-
uint16_t wrappedKeySz = WOLFHSM_CFG_KEYWRAP_AES_GCM_IV_SIZE +
731-
WOLFHSM_CFG_KEYWRAP_AES_GCM_TAG_SIZE +
733+
uint16_t wrappedKeySz = WOLFHSM_KEYWRAP_AES_GCM_IV_SIZE +
734+
WOLFHSM_KEYWRAP_AES_GCM_TAG_SIZE +
732735
sizeof(metadata) + req->keySz;
733736

734737
/* Check if the response data can fit the wrapped key */
@@ -792,8 +795,8 @@ static int _HandleUnwrapAndExportKeyRequest(
792795
#ifdef HAVE_AESGCM
793796
case WC_CIPHER_AES_GCM: {
794797
uint16_t keySz =
795-
req->wrappedKeySz - WOLFHSM_CFG_KEYWRAP_AES_GCM_IV_SIZE -
796-
WOLFHSM_CFG_KEYWRAP_AES_GCM_TAG_SIZE - sizeof(*metadata);
798+
req->wrappedKeySz - WOLFHSM_KEYWRAP_AES_GCM_IV_SIZE -
799+
WOLFHSM_KEYWRAP_AES_GCM_TAG_SIZE - sizeof(*metadata);
797800

798801
/* Check if the response data can fit the metadata + key */
799802
if (respDataSz < sizeof(*metadata) + keySz) {
@@ -862,8 +865,8 @@ _HandleUnwrapAndCacheKeyRequest(whServerContext* server,
862865
#ifndef NO_AES
863866
#ifdef HAVE_AESGCM
864867
case WC_CIPHER_AES_GCM: {
865-
keySz = req->wrappedKeySz - WOLFHSM_CFG_KEYWRAP_AES_GCM_IV_SIZE -
866-
WOLFHSM_CFG_KEYWRAP_AES_GCM_TAG_SIZE - sizeof(metadata);
868+
keySz = req->wrappedKeySz - WOLFHSM_KEYWRAP_AES_GCM_IV_SIZE -
869+
WOLFHSM_KEYWRAP_AES_GCM_TAG_SIZE - sizeof(metadata);
867870

868871
ret = _AesGcmUnwrapKey(server, req->serverKeyId, wrappedKey,
869872
req->wrappedKeySz, &metadata, key, keySz);

test/wh_test_keywrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#define WH_TEST_AES_TEXTSIZE 16
5151
#define WH_TEST_AES_IVSIZE 12
5252
#define WH_TEST_AES_TAGSIZE 16
53-
#define WH_TEST_AES_WRAPPED_KEYSIZE \
53+
#define WH_TEST_AES_WRAPPED_KEYSIZE \
5454
(WH_TEST_AES_IVSIZE + WH_TEST_AES_TAGSIZE + WH_TEST_AES_KEYSIZE + \
5555
sizeof(whNvmMetadata))
5656

wolfhsm/wh_message_comm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ enum WH_INFO_ENUM {
5050
};
5151

5252

53-
5453
/* Generic error response message. */
5554
typedef struct {
5655
int return_code;

wolfhsm/wh_settings.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@
4040
* can be wrapped
4141
* Default: 512
4242
*
43-
* WOLFHSM_CFG_KEYWRAP_AES_GCM_TAG_SIZE - The size (in bytes) of the auth
44-
* tag attached to an AES GCM wrapped key
45-
* Default: 16
46-
*
47-
* WOLFHSM_CFG_KEYWRAP_AES_GCM_IV_SIZE - The size (in bytes) of the IV
48-
* attached to an AES GCM wrapped key
49-
* Default: 12
50-
*
5143
* WOLFHSM_CFG_HEXDUMP - If defined, include wh_Utils_HexDump functionality
5244
* using stdio.h
5345
* Default: Not defined
@@ -245,15 +237,7 @@
245237
#if defined(HAVE_AESGCM)
246238

247239
#ifndef WOLFHSM_CFG_KEYWRAP_MAX_KEY_SIZE
248-
#define WOLFHSM_CFG_KEYWRAP_MAX_KEY_SIZE 512
249-
#endif
250-
251-
#ifndef WOLFHSM_CFG_KEYWRAP_AES_GCM_TAG_SIZE
252-
#define WOLFHSM_CFG_KEYWRAP_AES_GCM_TAG_SIZE 16
253-
#endif
254-
255-
#ifndef WOLFHSM_CFG_KEYWRAP_AES_GCM_IV_SIZE
256-
#define WOLFHSM_CFG_KEYWRAP_AES_GCM_IV_SIZE 12
240+
#define WOLFHSM_CFG_KEYWRAP_MAX_KEY_SIZE 2000
257241
#endif
258242

259243
#endif

0 commit comments

Comments
 (0)