Skip to content

Commit 2f43cc1

Browse files
Merge pull request #7332 from SparkiDev/asn_templ_neg_int_check
ASN.1 parsing: check for badly encode negative INTEGER
2 parents 81c5cf7 + 4068122 commit 2f43cc1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

wolfcrypt/src/asn.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,16 @@ static int GetASN_Integer(const byte* input, word32 idx, int length,
10651065
#endif
10661066
}
10671067
}
1068+
/* check for invalid padding on negative integer.
1069+
* c.f. X.690 (ISO/IEC 8825-2:2003 (E)) 10.4.6; RFC 5280 4.1
1070+
*/
1071+
else if ((length > 1) && (input[idx] == 0xff) &&
1072+
((input[idx + 1] & 0x80) != 0)) {
1073+
WOLFSSL_MSG("Bad INTEGER encoding of negative");
1074+
#ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
1075+
return ASN_EXPECT_0_E;
1076+
#endif /* WOLFSSL_ASN_INT_LEAD_0_ANY */
1077+
}
10681078
/* Check whether a leading zero byte was required. */
10691079
else if (positive && (input[idx] & 0x80)) {
10701080
WOLFSSL_MSG("INTEGER is negative");

0 commit comments

Comments
 (0)