Skip to content

Commit

Permalink
Merge pull request #7332 from SparkiDev/asn_templ_neg_int_check
Browse files Browse the repository at this point in the history
ASN.1 parsing: check for badly encode negative INTEGER
  • Loading branch information
JacobBarthelmeh authored Mar 15, 2024
2 parents 81c5cf7 + 4068122 commit 2f43cc1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,16 @@ static int GetASN_Integer(const byte* input, word32 idx, int length,
#endif
}
}
/* check for invalid padding on negative integer.
* c.f. X.690 (ISO/IEC 8825-2:2003 (E)) 10.4.6; RFC 5280 4.1
*/
else if ((length > 1) && (input[idx] == 0xff) &&
((input[idx + 1] & 0x80) != 0)) {
WOLFSSL_MSG("Bad INTEGER encoding of negative");
#ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
return ASN_EXPECT_0_E;
#endif /* WOLFSSL_ASN_INT_LEAD_0_ANY */
}
/* Check whether a leading zero byte was required. */
else if (positive && (input[idx] & 0x80)) {
WOLFSSL_MSG("INTEGER is negative");
Expand Down

0 comments on commit 2f43cc1

Please sign in to comment.