Bouncy Castle Cryptography Library 1.85

org.bouncycastle.pqc.crypto.test
Class PublicKeyLengthValidationTest

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.bouncycastle.pqc.crypto.test.PublicKeyLengthValidationTest
All Implemented Interfaces:
junit.framework.Test

public class PublicKeyLengthValidationTest
extends junit.framework.TestCase

Regression test for the PQC public-key length-validation hardening (finding #14).

ML-DSA and Falcon public-key parameter classes must reject a malformed-length encoding with an IllegalArgumentException at decode time, rather than storing it and throwing an ArrayIndexOutOfBoundsException later during signature verification. The crash was a denial of service reachable when verifying with an attacker-supplied key (e.g. a malformed ML-DSA certificate exercised during certification-path validation). This mirrors the ML-KEM / SLH-DSA parameter classes, which already validate the encoding length.

Each negative case is constructed from a 33-byte buffer: long enough that the old ML-DSA code accepted it (splitting off a 1-byte t1), short enough that Packing then indexed past it ( arraycopy: length -319 is negative) at verify time.


Constructor Summary
PublicKeyLengthValidationTest()
           
 
Method Summary
 void testFalconPublicKeyRejectsMalformedLength()
           
 void testMLDSAPublicKeyRejectsMalformedLength()
           
 void testMLDSAValidKeyVerifiesAndMalformedKeyIsRejected()
           
 void testMLKEMPublicKeyRejectsMalformedLength()
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PublicKeyLengthValidationTest

public PublicKeyLengthValidationTest()
Method Detail

testMLDSAPublicKeyRejectsMalformedLength

public void testMLDSAPublicKeyRejectsMalformedLength()

testMLKEMPublicKeyRejectsMalformedLength

public void testMLKEMPublicKeyRejectsMalformedLength()

testFalconPublicKeyRejectsMalformedLength

public void testFalconPublicKeyRejectsMalformedLength()

testMLDSAValidKeyVerifiesAndMalformedKeyIsRejected

public void testMLDSAValidKeyVerifiesAndMalformedKeyIsRejected()
                                                        throws java.lang.Exception
Throws:
java.lang.Exception

Bouncy Castle Cryptography Library 1.85