@@ -1902,6 +1902,43 @@ static void test_TPM2_ECC_Parameters_EcdaaResponseParse(void)
19021902 printf ("Test TPM Wrapper:\tEcdaaResponseParse:\t\tPassed\n" );
19031903}
19041904
1905+ /* TPM2_Packet_ParseSignature must explicitly recognize TPM_ALG_NULL as a
1906+ * zero-payload signature so subsequent fields stay aligned. The previous
1907+ * default-fallthrough lumped TPM_ALG_NULL together with unknown algorithms,
1908+ * making the property "Parse(Append(NULL signature)) consumes exactly the
1909+ * sigAlg bytes" depend on undocumented behavior. */
1910+ static void test_TPM2_ParseSignature_NullAlg (void )
1911+ {
1912+ TPM2_Packet packet ;
1913+ byte buf [16 ];
1914+ TPMT_SIGNATURE sig ;
1915+ UINT16 sentinel ;
1916+ int pos = 0 ;
1917+
1918+ XMEMSET (buf , 0 , sizeof (buf ));
1919+ XMEMSET (& packet , 0 , sizeof (packet ));
1920+
1921+ /* sigAlg = TPM_ALG_NULL */
1922+ buf [pos ++ ] = (byte )((TPM_ALG_NULL >> 8 ) & 0xFF );
1923+ buf [pos ++ ] = (byte )(TPM_ALG_NULL & 0xFF );
1924+ /* sentinel right after the (zero-length) signature payload */
1925+ buf [pos ++ ] = 0xDE ;
1926+ buf [pos ++ ] = 0xAD ;
1927+
1928+ XMEMSET (& sig , 0 , sizeof (sig ));
1929+ packet .buf = buf ;
1930+ packet .size = pos ;
1931+ packet .pos = 0 ;
1932+
1933+ TPM2_Packet_ParseSignature (& packet , & sig );
1934+ AssertIntEQ (sig .sigAlg , TPM_ALG_NULL );
1935+ AssertIntEQ (packet .pos , 2 );
1936+ sentinel = (UINT16 )((buf [packet .pos ] << 8 ) | buf [packet .pos + 1 ]);
1937+ AssertIntEQ (sentinel , 0xDEAD );
1938+
1939+ printf ("Test TPM Wrapper:\tParseSignature NULL alg:\tPassed\n" );
1940+ }
1941+
19051942/* TPM2_Packet_ParsePoint must resync to outerStart + point->size so a
19061943 * malformed wire blob with inner x.size / y.size disagreement can't
19071944 * desynchronize subsequent fields. */
@@ -3711,6 +3748,7 @@ int unit_tests(int argc, char *argv[])
37113748 test_TPM2_ParseAttest_NvDigest ();
37123749 test_TPM2_ParsePublic_OuterResync ();
37133750 test_TPM2_ParsePoint_OuterResync ();
3751+ test_TPM2_ParseSignature_NullAlg ();
37143752 test_TPM2_BrainpoolCurveMapping ();
37153753 test_wolfTPM2_RsaEncryptDecrypt_OversizedBufferE ();
37163754 test_wolfTPM2_SignHashScheme_DigestSize ();
0 commit comments