@@ -501,12 +501,6 @@ int wc_SHE_GenerateM1M2M3(wc_SHE* she,
501501 return BAD_FUNC_ARG ;
502502 }
503503
504- /* Reject values wider than their packed field */
505- if (counter > WC_SHE_COUNTER_MAX || flags > WC_SHE_FLAGS_MAX ||
506- authKeyId > WC_SHE_KEY_ID_MAX || targetKeyId > WC_SHE_KEY_ID_MAX ) {
507- return BAD_FUNC_ARG ;
508- }
509-
510504#ifdef WOLF_CRYPTO_CB
511505 /* Try callback first -- callback handles its own parameter validation.
512506 * This allows callers to pass NULL authKey/newKey when a secure element
@@ -525,6 +519,13 @@ int wc_SHE_GenerateM1M2M3(wc_SHE* she,
525519 }
526520#endif
527521
522+ /* Only the software path packs these into M1 and M2, so the widths
523+ * are checked here. A callback may use its own key numbering. */
524+ if (counter > WC_SHE_COUNTER_MAX || flags > WC_SHE_FLAGS_MAX ||
525+ authKeyId > WC_SHE_KEY_ID_MAX || targetKeyId > WC_SHE_KEY_ID_MAX ) {
526+ return BAD_FUNC_ARG ;
527+ }
528+
528529 /* Software path -- validate all parameters */
529530 if (uid == NULL || uidSz != WC_SHE_UID_SZ ||
530531 authKey == NULL || authKeySz != WC_SHE_KEY_SZ ||
@@ -682,12 +683,6 @@ int wc_SHE_GenerateM4M5(wc_SHE* she,
682683 return BAD_FUNC_ARG ;
683684 }
684685
685- /* Reject values wider than their packed field */
686- if (counter > WC_SHE_COUNTER_MAX ||
687- authKeyId > WC_SHE_KEY_ID_MAX || targetKeyId > WC_SHE_KEY_ID_MAX ) {
688- return BAD_FUNC_ARG ;
689- }
690-
691686#ifdef WOLF_CRYPTO_CB
692687 /* Try callback first -- useful for uploading M1/M2/M3 to an HSM which
693688 * loads the key and returns the correct M4/M5 proof values. The callback
@@ -705,6 +700,13 @@ int wc_SHE_GenerateM4M5(wc_SHE* she,
705700 }
706701#endif
707702
703+ /* Only the software path packs these into M4, so the widths are
704+ * checked here. A callback may use its own key numbering. */
705+ if (counter > WC_SHE_COUNTER_MAX ||
706+ authKeyId > WC_SHE_KEY_ID_MAX || targetKeyId > WC_SHE_KEY_ID_MAX ) {
707+ return BAD_FUNC_ARG ;
708+ }
709+
708710 /* Software path -- validate all parameters */
709711 if (uid == NULL || uidSz != WC_SHE_UID_SZ ||
710712 newKey == NULL || newKeySz != WC_SHE_KEY_SZ ||
0 commit comments