diff --git a/doc/dox_comments/header_files-ja/wc_she.h b/doc/dox_comments/header_files-ja/wc_she.h index d79a8772e67..e45030f2401 100644 --- a/doc/dox_comments/header_files-ja/wc_she.h +++ b/doc/dox_comments/header_files-ja/wc_she.h @@ -661,7 +661,7 @@ int wc_SHE_LoadKey_Verify_Label( \brief ハードウェアから鍵をSHEのロード可能な形式(M1〜M5)でエクスポートします。一部のHSMでは特定の鍵スロット(例: RAM鍵)のエクスポートが許可されており、後からSHEの鍵更新プロトコルで再ロードできます。WOLF_CRYPTO_CBが有効で、かつNO_WC_SHE_EXPORTKEYが定義されていないことが必要です。出力バッファはいずれもNULLにでき、その場合そのメッセージはスキップされます。 \return 0 成功した場合に返されます - \return BAD_FUNC_ARG sheがNULLの場合に返されます + \return BAD_FUNC_ARG sheがNULLの場合、またはNULLでない出力バッファのサイズがそのメッセージのサイズより小さい場合に返されます \return CRYPTOCB_UNAVAILABLE コールバックが登録されていない場合に返されます \param she 初期化済みのSHEコンテキスト diff --git a/doc/dox_comments/header_files/wc_she.h b/doc/dox_comments/header_files/wc_she.h index 405ae323c58..896b003d2e3 100644 --- a/doc/dox_comments/header_files/wc_she.h +++ b/doc/dox_comments/header_files/wc_she.h @@ -724,7 +724,8 @@ int wc_SHE_LoadKey_Verify_Label( output buffer may be NULL to skip that message. \return 0 on success - \return BAD_FUNC_ARG if she is NULL + \return BAD_FUNC_ARG if she is NULL, or a non-NULL output buffer is + smaller than its message size \return CRYPTOCB_UNAVAILABLE if no callback is registered \param she initialized SHE context diff --git a/tests/api/test_she.c b/tests/api/test_she.c index b20ac93b73f..39c2024adbb 100644 --- a/tests/api/test_she.c +++ b/tests/api/test_she.c @@ -628,6 +628,36 @@ int test_wc_SHE_CryptoCb(void) em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ, em5, WC_SHE_M5_SZ, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ - 1, em2, WC_SHE_M2_SZ, + em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ, + em5, WC_SHE_M5_SZ, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ, em2, WC_SHE_M2_SZ - 1, + em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ, + em5, WC_SHE_M5_SZ, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ, em2, WC_SHE_M2_SZ, + em3, WC_SHE_M3_SZ - 1, em4, WC_SHE_M4_SZ, + em5, WC_SHE_M5_SZ, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ, em2, WC_SHE_M2_SZ, + em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ - 1, + em5, WC_SHE_M5_SZ, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ, em2, WC_SHE_M2_SZ, + em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ, + em5, WC_SHE_M5_SZ - 1, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + + /* NULL buffers skip that message, so their size is not checked */ + ExpectIntEQ(wc_SHE_ExportKey(&she, + NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL), + 0); } #endif diff --git a/wolfcrypt/src/async.c b/wolfcrypt/src/async.c index ca02a28750f..c25e87fe83d 100644 --- a/wolfcrypt/src/async.c +++ b/wolfcrypt/src/async.c @@ -342,6 +342,9 @@ int wolfAsync_DevOpenThread(int *pDevId, void* threadId) int ret = 0; int devId = INVALID_DEVID; + if (pDevId == NULL) + return BAD_FUNC_ARG; + #ifdef HAVE_CAVIUM ret = NitroxOpenDeviceDefault(); if (ret >= 0) @@ -363,9 +366,7 @@ int wolfAsync_DevOpenThread(int *pDevId, void* threadId) (void)threadId; - /* return devId if requested */ - if (*pDevId) - *pDevId = devId; + *pDevId = devId; return ret; } @@ -989,6 +990,9 @@ int wc_AsyncThreadCreate_ex(pthread_t *thread, pthread_attr_t attr; struct sched_param param; + if (thread == NULL || function == NULL) + return BAD_FUNC_ARG; + status = pthread_attr_init(&attr); if (status !=0) { fprintf(stderr, "pthread_attr_init error: %d\n", status); diff --git a/wolfcrypt/src/wc_she.c b/wolfcrypt/src/wc_she.c index 523e65637c8..070e822a4c7 100644 --- a/wolfcrypt/src/wc_she.c +++ b/wolfcrypt/src/wc_she.c @@ -1148,7 +1148,12 @@ int wc_SHE_ExportKey(wc_SHE* she, byte* m5, word32 m5Sz, const void* ctx) { - if (she == NULL) { + if (she == NULL || + (m1 != NULL && m1Sz < WC_SHE_M1_SZ) || + (m2 != NULL && m2Sz < WC_SHE_M2_SZ) || + (m3 != NULL && m3Sz < WC_SHE_M3_SZ) || + (m4 != NULL && m4Sz < WC_SHE_M4_SZ) || + (m5 != NULL && m5Sz < WC_SHE_M5_SZ)) { return BAD_FUNC_ARG; }