Skip to content

Commit 54b673a

Browse files
committed
Add more in depth comments in header file for she.h
1 parent 97f43a1 commit 54b673a

File tree

5 files changed

+163
-40
lines changed

5 files changed

+163
-40
lines changed

.wolfssl_known_macro_extras

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,9 @@ WOLFSSL_SE050_NO_TRNG
888888
WOLFSSL_SECURE_RENEGOTIATION_ON_BY_DEFAULT
889889
WOLFSSL_SERVER_EXAMPLE
890890
WOLFSSL_SETTINGS_FILE
891+
WOLFSSL_SH224
891892
WOLFSSL_SHE
892893
WOLFSSL_SHE_EXTENDED
893-
WOLFSSL_SH224
894894
WOLFSSL_SHA256_ALT_CH_MAJ
895895
WOLFSSL_SHA512_HASHTYPE
896896
WOLFSSL_SHUTDOWNONCE

tests/api/test_she.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ int test_wc_SHE_SetM2M4Header(void)
428428

429429
#if defined(WOLF_CRYPTO_CB) && defined(WOLFSSL_SHE) && !defined(NO_AES)
430430

431-
/* SHE callback re-calls with software devId */
431+
/* SHE callback -- re-calls with software devId */
432432
static int test_she_crypto_cb(int devIdArg, wc_CryptoInfo* info, void* ctx)
433433
{
434434
wc_SHE* she;
@@ -513,7 +513,7 @@ static int test_she_crypto_cb(int devIdArg, wc_CryptoInfo* info, void* ctx)
513513
info->she.op.generateM4M5.m5Sz);
514514
break;
515515
case WC_SHE_EXPORT_KEY:
516-
/* Simulate hardware export fill with test pattern */
516+
/* Simulate hardware export -- fill with test pattern */
517517
if (info->she.op.exportKey.m1 != NULL) {
518518
XMEMSET(info->she.op.exportKey.m1, 0x11, WC_SHE_M1_SZ);
519519
}
@@ -572,7 +572,7 @@ int test_wc_SHE_CryptoCb(void)
572572
ExpectIntEQ(XMEMCMP(m4, sheTestExpM4, WC_SHE_M4_SZ), 0);
573573
ExpectIntEQ(XMEMCMP(m5, sheTestExpM5, WC_SHE_M5_SZ), 0);
574574

575-
/* ExportKey via callback simulated hardware */
575+
/* ExportKey via callback -- simulated hardware */
576576
#if !defined(NO_WC_SHE_EXPORTKEY)
577577
{
578578
byte em1[WC_SHE_M1_SZ];

wolfcrypt/src/she.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int wc_SHE_Init(wc_SHE* she, void* heap, int devId)
123123
ForceZero(she, sizeof(wc_SHE));
124124
she->heap = heap;
125125
she->devId = devId;
126-
/* kdfEncOverride/kdfMacOverride are zero from XMEMSET defaults used */
126+
/* kdfEncOverride/kdfMacOverride are zero from XMEMSET -- defaults used */
127127

128128
return 0;
129129
}
@@ -222,7 +222,7 @@ void wc_SHE_Free(wc_SHE* she)
222222
}
223223

224224
/* -------------------------------------------------------------------------- */
225-
/* GetUID callback required */
225+
/* GetUID -- callback required */
226226
/* */
227227
/* Dispatches to callback to fetch UID from hardware. */
228228
/* Buffer size validation is the callback's responsibility. */
@@ -241,7 +241,7 @@ int wc_SHE_GetUID(wc_SHE* she, byte* uid, word32 uidSz,
241241
#endif /* WOLF_CRYPTO_CB && !NO_WC_SHE_GETUID */
242242

243243
/* -------------------------------------------------------------------------- */
244-
/* GetCounter callback required */
244+
/* GetCounter -- callback required */
245245
/* */
246246
/* Dispatches to callback to read current counter from hardware. */
247247
/* Returns CRYPTOCB_UNAVAILABLE if no callback. */
@@ -425,13 +425,13 @@ int wc_SHE_GenerateM1M2M3(wc_SHE* she,
425425
WC_DECLARE_VAR(aes, Aes, 1, 0);
426426
WC_DECLARE_VAR(cmac, Cmac, 1, 0);
427427

428-
/* Validate SHE context first required for both callback and software */
428+
/* Validate SHE context first -- required for both callback and software */
429429
if (she == NULL) {
430430
return BAD_FUNC_ARG;
431431
}
432432

433433
#ifdef WOLF_CRYPTO_CB
434-
/* Try callback first callback handles its own parameter validation.
434+
/* Try callback first -- callback handles its own parameter validation.
435435
* This allows callers to pass NULL authKey/newKey when a secure element
436436
* holds the keys and the callback talks to it directly. */
437437
if (she->devId != INVALID_DEVID) {
@@ -448,7 +448,7 @@ int wc_SHE_GenerateM1M2M3(wc_SHE* she,
448448
}
449449
#endif
450450

451-
/* Software path validate all parameters */
451+
/* Software path -- validate all parameters */
452452
if (uid == NULL || uidSz != WC_SHE_UID_SZ ||
453453
authKey == NULL || authKeySz != WC_SHE_KEY_SZ ||
454454
newKey == NULL || newKeySz != WC_SHE_KEY_SZ ||
@@ -482,7 +482,7 @@ int wc_SHE_GenerateM1M2M3(wc_SHE* she,
482482
return MEMORY_E;
483483
}
484484

485-
/* Init AES once used by both MP16 and CBC */
485+
/* Init AES once -- used by both MP16 and CBC */
486486
ret = wc_AesInit(aes, she->heap, she->devId);
487487
if (ret != 0) {
488488
WC_FREE_VAR(aes, she->heap);
@@ -584,7 +584,7 @@ int wc_SHE_GenerateM4M5(wc_SHE* she,
584584
}
585585

586586
#ifdef WOLF_CRYPTO_CB
587-
/* Try callback first useful for uploading M1/M2/M3 to an HSM which
587+
/* Try callback first -- useful for uploading M1/M2/M3 to an HSM which
588588
* loads the key and returns the correct M4/M5 proof values. The callback
589589
* handles its own parameter validation. */
590590
if (she->devId != INVALID_DEVID) {
@@ -599,7 +599,7 @@ int wc_SHE_GenerateM4M5(wc_SHE* she,
599599
}
600600
#endif
601601

602-
/* Software path validate all parameters */
602+
/* Software path -- validate all parameters */
603603
if (uid == NULL || uidSz != WC_SHE_UID_SZ ||
604604
newKey == NULL || newKeySz != WC_SHE_KEY_SZ ||
605605
m4 == NULL || m4Sz < WC_SHE_M4_SZ ||
@@ -631,7 +631,7 @@ int wc_SHE_GenerateM4M5(wc_SHE* she,
631631
return MEMORY_E;
632632
}
633633

634-
/* Init AES once used by both MP16 and ECB */
634+
/* Init AES once -- used by both MP16 and ECB */
635635
ret = wc_AesInit(aes, she->heap, she->devId);
636636
if (ret != 0) {
637637
WC_FREE_VAR(aes, she->heap);
@@ -700,7 +700,7 @@ int wc_SHE_GenerateM4M5(wc_SHE* she,
700700
/* -------------------------------------------------------------------------- */
701701
#if defined(WOLF_CRYPTO_CB) && !defined(NO_WC_SHE_EXPORTKEY)
702702
/* -------------------------------------------------------------------------- */
703-
/* Export Key callback required */
703+
/* Export Key -- callback required */
704704
/* */
705705
/* Asks hardware to export a key slot as M1-M5 in SHE loadable format. */
706706
/* -------------------------------------------------------------------------- */

wolfcrypt/test/test.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55733,14 +55733,15 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t she_test(void)
5573355733
goto exit_SHE_Test;
5573455734
}
5573555735

55736+
#if defined(WOLF_CRYPTO_CB) || !defined(NO_WC_SHE_IMPORT_M123)
5573655737
/* ---- Import M1/M2/M3 and generate M4/M5 (only NewKey needed) ---- */
5573755738
wc_SHE_Free(she);
5573855739
ret = wc_SHE_Init(she, HEAP_HINT, devId);
5573955740
if (ret != 0) {
5574055741
goto exit_SHE_Test;
5574155742
}
5574255743

55743-
/* Import M1/M2/M3, then generate M4/M5 via one-shot */
55744+
/* Import M1/M2/M3, then generate M4/M5 */
5574455745
ret = wc_SHE_ImportM1M2M3(she,
5574555746
expM1, WC_SHE_M1_SZ,
5574655747
expM2, WC_SHE_M2_SZ,
@@ -55767,6 +55768,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t she_test(void)
5576755768
ret = WC_TEST_RET_ENC_NC;
5576855769
goto exit_SHE_Test;
5576955770
}
55771+
#endif /* WOLF_CRYPTO_CB || !NO_WC_SHE_IMPORT_M123 */
5577055772

5577155773
/* ---- One-shot M1/M2/M3 ---- */
5577255774
wc_SHE_Free(she);
@@ -55858,7 +55860,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t she_test(void)
5585855860
goto exit_SHE_Test;
5585955861
}
5586055862

55861-
/* Generate M4/M5 on second context completely independent */
55863+
/* Generate M4/M5 on second context -- completely independent */
5586255864
ret = wc_SHE_GenerateM4M5(she2,
5586355865
sheUid, sizeof(sheUid),
5586455866
WC_SHE_MASTER_ECU_KEY_ID, 4,
@@ -65989,7 +65991,7 @@ static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
6598965991
info->she.op.generateM4M5.m5Sz);
6599065992
break;
6599165993
case WC_SHE_EXPORT_KEY:
65992-
/* Simulate hardware export fill with test pattern */
65994+
/* Simulate hardware export -- fill with test pattern */
6599365995
if (info->she.op.exportKey.m1 != NULL) {
6599465996
XMEMSET(info->she.op.exportKey.m1, 0x11,
6599565997
WC_SHE_M1_SZ);

0 commit comments

Comments
 (0)