Skip to content

Commit 53df12a

Browse files
authored
Merge pull request #189 from AlexLanzano/enable-keywrap-macro
Implement configure option to enable key wrap feature
2 parents 75c6832 + 641722e commit 53df12a

File tree

9 files changed

+32
-7
lines changed

9 files changed

+32
-7
lines changed

examples/demo/client/wh_demo_client_all.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ int wh_DemoClient_All(whClientContext* clientContext)
4646
}
4747
#endif
4848

49+
#ifdef WOLFHSM_CFG_KEYWRAP
4950
rc = wh_DemoClient_KeyWrapBasic(clientContext);
5051
if (rc != 0) {
5152
return rc;
5253
}
54+
#endif /* WOLFHSM_CFG_KEYWRAP */
5355

5456
/**Crypto demos */
5557
#ifndef NO_RSA

examples/demo/client/wh_demo_client_keywrap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333

3434
#include "wh_demo_client_keywrap.h"
3535

36+
#ifdef WOLFHSM_CFG_KEYWRAP
37+
3638
#ifndef NO_AES
37-
#define HAVE_AESGCM
3839
#ifdef HAVE_AESGCM
3940

4041
#define WH_TEST_AES_KEYSIZE 16
@@ -160,3 +161,4 @@ int wh_DemoClient_KeyWrapBasic(whClientContext* clientContext)
160161
wc_FreeRng(rng);
161162
return ret;
162163
}
164+
#endif /* WOLFHSM_CFG_KEYWRAP */

examples/posix/tcp/wh_client_tcp/wolfhsm_cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
#define WOLFHSM_CFG_ENABLE_CLIENT
3030
#define WOLFHSM_CFG_HEXDUMP
3131
#define WOLFHSM_CFG_COMM_DATA_LEN 1280
32-
32+
#define WOLFHSM_CFG_KEYWRAP
3333

3434
#endif /* WOLFHSM_CFG_H_ */

examples/posix/tcp/wh_server_tcp/wolfhsm_cfg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@
4545
#define WOLFHSM_CFG_CERTIFICATE_MANAGER_ACERT
4646

4747
#define XMEMFENCE() __atomic_thread_fence(__ATOMIC_SEQ_CST)
48+
#define WOLFHSM_CFG_KEYWRAP
4849

4950
#endif /* WOLFHSM_CFG_H_ */

src/wh_server_keystore.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ static int _FindInCache(whServerContext* server, whKeyId keyId, int* out_index,
344344
return ret;
345345
}
346346

347+
#ifdef WOLFHSM_CFG_KEYWRAP
347348
static int _ExistsInCache(whServerContext* server, whKeyId keyId)
348349
{
349350
int ret = 0;
@@ -364,6 +365,8 @@ static int _ExistsInCache(whServerContext* server, whKeyId keyId)
364365
return 1;
365366
}
366367

368+
#endif /* WOLFHSM_CFG_KEYWRAP */
369+
367370
/* try to put the specified key into cache if it isn't already, return pointers
368371
* to meta and the cached data*/
369372
int wh_Server_KeystoreFreshenKey(whServerContext* server, whKeyId keyId,
@@ -551,6 +554,7 @@ int wh_Server_KeystoreEraseKey(whServerContext* server, whNvmId keyId)
551554
return wh_Nvm_DestroyObjects(server->nvm, 1, &keyId);
552555
}
553556

557+
#ifdef WOLFHSM_CFG_KEYWRAP
554558
#ifndef NO_AES
555559
#ifdef HAVE_AESGCM
556560

@@ -898,6 +902,8 @@ _HandleUnwrapAndCacheKeyRequest(whServerContext* server,
898902
return wh_Server_KeystoreCacheKey(server, &metadata, key);
899903
}
900904

905+
#endif /* WOLFHSM_CFG_KEYWRAP */
906+
901907
int wh_Server_HandleKeyRequest(whServerContext* server, uint16_t magic,
902908
uint16_t action, uint16_t req_size,
903909
const void* req_packet, uint16_t* out_resp_size,
@@ -1180,6 +1186,8 @@ int wh_Server_HandleKeyRequest(whServerContext* server, uint16_t magic,
11801186
*out_resp_size = sizeof(resp);
11811187
}
11821188
} break;
1189+
1190+
#ifdef WOLFHSM_CFG_KEYWRAP
11831191
case WH_KEY_WRAP: {
11841192
whMessageKeystore_WrapRequest wrapReq = {0};
11851193
whMessageKeystore_WrapResponse wrapResp = {0};
@@ -1290,6 +1298,8 @@ int wh_Server_HandleKeyRequest(whServerContext* server, uint16_t magic,
12901298

12911299
} break;
12921300

1301+
#endif /* WOLFHSM_CFG_KEYWRAP */
1302+
12931303
default:
12941304
ret = WH_ERROR_BADARGS;
12951305
break;

test/config/wolfhsm_cfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@
4646
/* Enable Image Manager feature */
4747
#define WOLFHSM_CFG_SERVER_IMG_MGR
4848

49+
#define WOLFHSM_CFG_KEYWRAP
50+
4951
#endif /* WOLFHSM_CFG_H_ */

test/wh_test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ int whTest_ClientConfig(whClientConfig* clientCfg)
111111

112112
#if !defined(WOLFHSM_CFG_NO_CRYPTO)
113113
WH_TEST_RETURN_ON_FAIL(whTest_CryptoClientConfig(clientCfg));
114+
115+
#if defined(WOLFHSM_CFG_KEYWRAP)
114116
WH_TEST_RETURN_ON_FAIL(whTest_KeyWrapClientConfig(clientCfg));
117+
#endif /*WOLFHSM_CFG_KEYWRAP */
118+
115119
#endif /* !WOLFHSM_CFG_NO_CRYPTO */
116120

117121
#if defined(WOLFHSM_CFG_SHE_EXTENSION)

test/wh_test_keywrap.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#include "wolfhsm/wh_error.h"
3131

32+
#ifdef WOLFHSM_CFG_KEYWRAP
33+
3234
#ifdef WOLFHSM_CFG_ENABLE_CLIENT
3335
#include "wolfhsm/wh_client.h"
3436
#include "wolfhsm/wh_client_crypto.h"
@@ -199,5 +201,6 @@ int whTest_KeyWrapClientConfig(whClientConfig* config)
199201

200202
return ret;
201203
}
202-
#endif /* WOLFHSM_CFG_ENABLE_CLIENT */
203204
#endif /* !WOLFHSM_CFG_NO_CRYPTO */
205+
#endif /* WOLFHSM_CFG_ENABLE_CLIENT */
206+
#endif /* WOLFHSM_CFG_KEYWRAP */

wolfhsm/wh_settings.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
* WOLFHSM_CFG_SHE_EXTENSION - If defined, include AutoSAR SHE functionality
3737
* Default: Not defined
3838
*
39+
* WOLFHSM_CFG_KEYWRAP - If defined, include the key wrap functionality
40+
* Default: Not defined
41+
*
3942
* WOLFHSM_CFG_KEYWRAP_MAX_KEY_SIZE - The maximum size (in bytes) of a key that
4043
* can be wrapped
4144
* Default: 512
@@ -233,15 +236,12 @@
233236
#endif
234237
#endif
235238

236-
#if !defined(NO_AES)
237-
#if defined(HAVE_AESGCM)
239+
#if defined(WOLFHSM_CFG_KEYWRAP)
238240

239241
#ifndef WOLFHSM_CFG_KEYWRAP_MAX_KEY_SIZE
240242
#define WOLFHSM_CFG_KEYWRAP_MAX_KEY_SIZE 2000
241243
#endif
242244

243-
#endif
244-
#endif
245245

246246
#if defined(WOLFHSM_CFG_NO_CRYPTO)
247247
#error "WOLFHSM_CFG_KEYWRAP is incompatible with WOLFHSM_CFG_NO_CRYPTO"
@@ -252,6 +252,7 @@
252252
"WOLFHSM_CFG_KEYWRAP requires NO_AES to be undefined and HAVE_AESGCM to be defined"
253253
#endif
254254

255+
#endif /* WOLFHSM_CFG_KEYWRAP */
255256

256257
#if defined(WOLFHSM_CFG_CERTIFICATE_MANAGER_ACERT)
257258
#if !defined(WOLFSSL_ACERT) || !defined(WOLFSSL_ASN_TEMPLATE)

0 commit comments

Comments
 (0)