F-6904: return false for malformed LMS signatures in verify wrapper

pull/257/head
Chris Conlon 2026-08-13 15:38:07 -06:00
parent b8392ced50
commit 166993e265
3 changed files with 30 additions and 1 deletions

View File

@ -229,7 +229,8 @@ JNIEXPORT jboolean JNICALL Java_com_wolfssl_wolfcrypt_Lms_wc_1LmsKey_1verify
if (ret == 0) {
result = JNI_TRUE;
}
else if (ret != SIG_VERIFY_E) {
else if (ret != SIG_VERIFY_E && ret != SIG_TYPE_E && ret != BUFFER_E) {
/* Treat these returns as failed verification */
throwWolfCryptExceptionFromError(env, ret);
}

View File

@ -302,6 +302,20 @@ public class WolfCryptLmsSignatureTest {
tampered[tampered.length / 2] ^= (byte) 0xFF;
assertFalse("RFC 8554 TC1 tampered signature",
verify(pub, tampered, RFC8554_TC1_MSG));
/* Wrong length signature must report false, not throw */
byte[] truncated = new byte[RFC8554_TC1_SIG.length - 1];
System.arraycopy(RFC8554_TC1_SIG, 0, truncated, 0, truncated.length);
assertFalse("RFC 8554 TC1 truncated signature",
verify(pub, truncated, RFC8554_TC1_MSG));
/* Corrupted embedded OTS type field must report false, not throw.
* Type word sits after the 4 byte levels and 4 byte q fields for
* every parameter set. */
byte[] badType = RFC8554_TC1_SIG.clone();
badType[8] ^= (byte)0x01;
assertFalse("RFC 8554 TC1 corrupted type signature",
verify(pub, badType, RFC8554_TC1_MSG));
}
@Test

View File

@ -395,6 +395,20 @@ public class LmsTest {
byte[] tampered = sig.clone();
tampered[tampered.length / 2] ^= (byte) 0xFF;
assertFalse(name + " tampered signature", v.verify(tampered, msg));
/* Wrong length signature must report false, not throw */
byte[] truncated = new byte[sig.length - 1];
System.arraycopy(sig, 0, truncated, 0, truncated.length);
assertFalse(name + " truncated signature",
v.verify(truncated, msg));
/* Corrupted embedded OTS type field must report false, not throw.
* Type word sits after the 4 byte levels and 4 byte q fields for
* every parameter set. */
byte[] badType = sig.clone();
badType[8] ^= (byte)0x01;
assertFalse(name + " corrupted type signature",
v.verify(badType, msg));
} finally {
v.releaseNativeStruct();
}