-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EC2N::DecodePoint can crash if exponents are not in descending order #1248
Comments
Thanks @roadicing. I got to thinking about things... I don't think we should try to fix things for the user, like sorting exponents in descending order. The problem is, we can 'fix' the GF2NT::GF2NT(unsigned int c0, unsigned int c1, unsigned int c2)
: GF2NP(PolynomialMod2::Trinomial(c0, c1, c2))
, t0(c0), t1(c1)
, result((word)0, m)
{
// Asserts and checks due to Bing Shi
CRYPTOPP_ASSERT(c0 > c1 && c1 > c2 && c2==0);
// The test is relaxed because of ECIES<EC2N>. The high order exponent is t0,
// but the other exponents are not in descending order.
if (c1 > c0 || c2 > c0)
throw InvalidArgument("GF2NT: exponents must be in descending order");
} What we added was a check to ensure other exponents were less that |
EC2N::DecodePoint
function leads to a DOS attack
Yes, and this should be sufficient to fix this issue, thank you for your assistance. |
Hi, recently I found a security issue in the
Crypto++
library that would cause a segmentation fault when parsing DER public key files of theF(2^m)
class curves, an attacker could potentially craft a malformed DER public key file, and any user or server attempting to read this public key file in processes such asECDSA
may be susceptible to a DOS attack.Issue
The main reason of this issue is that when parsing the DER public key file of the
F(2^m)
class curve (EC2N::DecodePoint), there is no check that the degree of each term in the polynomial is strictly decreasing.For example, for curve
sect193r1
, it uses polynomialf(x) = x^193 + x^15 + 1
, then under normal circumstances, DER public key file would store their exponents in the following sequential order in ASN.1 format:The above snippet is taken from a regular
sect193r1
public key file. However, if we reverse the order of the exponents, for instance, if we swap the positions ofC1
and0F
, and repackage it into a DER file, then any attempt to read and parse this DER file inCrypto++
will trigger a segmentation fault immediately.To figure out the exact location, I debugged it using
gdb
, and here is the result:From the debugging results of gdb, we can see that the function that actually triggers the problem is GF2NT::Reduced, since this function will only be called when the point is in the form of compression encoding, we need to ensure that the points in the constructed DER file are in compressed form (start with
02
or03
).Fix
To fix this issue, the simplest method is to check whether the coefficients of the polynomial satisfy strict decreasing, which should at least close the entry point that triggers this issue.
However, based on the gdb debugging results, it seems that the issue ultimately arises in . Therefore, fixing the actual cause of the segmentation fault from this function is also a feasible option, but it is still advisable to check whether the coefficients of the polynomial meet our requirements.
Update
The current fix of this issue can be seen here, thanks for @noloader 's help.
The text was updated successfully, but these errors were encountered: