@@ -51593,6 +51593,49 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
5159351593 ERROR_OUT(WC_TEST_RET_ENC_I(sigSz), out);
5159451594 }
5159551595
51596+ /* Test wc_LmsKey_Sign input validation. */
51597+ {
51598+ word32 smallSz = 1;
51599+ wc_lms_write_private_key_cb saved_write_cb;
51600+ wc_lms_read_private_key_cb saved_read_cb;
51601+ void* saved_ctx;
51602+
51603+ /* Undersized sig buffer should return BUFFER_E. */
51604+ ret = wc_LmsKey_Sign(&signingKey, sig, &smallSz, (byte *) msg, msgSz);
51605+ if (ret != WC_NO_ERR_TRACE(BUFFER_E)) {
51606+ ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
51607+ }
51608+
51609+ /* NULL write callback should return BAD_FUNC_ARG. */
51610+ saved_write_cb = signingKey.write_private_key;
51611+ signingKey.write_private_key = NULL;
51612+ ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
51613+ signingKey.write_private_key = saved_write_cb;
51614+ if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
51615+ ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
51616+ }
51617+
51618+ /* NULL read callback should return BAD_FUNC_ARG. */
51619+ saved_read_cb = signingKey.read_private_key;
51620+ signingKey.read_private_key = NULL;
51621+ ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
51622+ signingKey.read_private_key = saved_read_cb;
51623+ if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
51624+ ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
51625+ }
51626+
51627+ /* NULL context should return BAD_FUNC_ARG. */
51628+ saved_ctx = signingKey.context;
51629+ signingKey.context = NULL;
51630+ ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
51631+ signingKey.context = saved_ctx;
51632+ if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
51633+ ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
51634+ }
51635+
51636+ ret = 0;
51637+ }
51638+
5159651639 /* 2 ** 5 should be the max number of signatures */
5159751640 for (i = 0; i < 32; ++i) {
5159851641 /* We should have remaining signstures. */
0 commit comments