Skip to content

Commit 22db5b9

Browse files
committed
Add Properties.EC_MAX_F2M_FIELD_SIZE for the org.bouncycastle.ec.max_f2m_field_size F2m field size bound (CVE-2024-29857) and use it in ECCurve rather than the inlined literal, mirroring the constant into the jdk1.4 overlay.
1 parent e8bf1bc commit 22db5b9

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

core/src/main/java/org/bouncycastle/math/ec/ECCurve.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ public static BigInteger inverse(int m, int[] ks, BigInteger x)
861861

862862
private static FiniteField buildField(int m, int k1, int k2, int k3)
863863
{
864-
if (m > Properties.asInteger("org.bouncycastle.ec.max_f2m_field_size", 1142)) // twice 571
864+
if (m > Properties.asInteger(Properties.EC_MAX_F2M_FIELD_SIZE, 1142)) // twice 571
865865
{
866866
throw new IllegalArgumentException("field size out of range: " + m);
867867
}

core/src/main/java/org/bouncycastle/util/Properties.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ public class Properties
309309
*/
310310
public static final String BKS_MAX_IT_COUNT = "org.bouncycastle.bks.max_it_count";
311311

312+
/**
313+
* Upper bound on the field size m accepted when building a characteristic-2 (F2m) elliptic curve.
314+
* The field polynomial is evaluated when the curve is constructed, and the cost grows with m, so
315+
* an unbounded value taken from a certificate's or key's explicit EC parameters is an import-time
316+
* CPU-exhaustion vector (CVE-2024-29857). Default 1142 (twice the 571 of the largest standardised
317+
* binary curve, B-571/K-571); a larger m is rejected with an {@code IllegalArgumentException}.
318+
* Read via {@link #asInteger(String, int)}.
319+
*/
320+
public static final String EC_MAX_F2M_FIELD_SIZE = "org.bouncycastle.ec.max_f2m_field_size";
321+
312322
private Properties()
313323
{
314324
}

core/src/main/jdk1.4/org/bouncycastle/util/Properties.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public class Properties
5858
*/
5959
public static final String X509_SGP22_NAME_CONSTRAINTS = "org.bouncycastle.x509.sgp22_name_constraints";
6060

61+
/**
62+
* Upper bound on the field size m accepted when building a characteristic-2 (F2m) elliptic curve;
63+
* an unbounded m from explicit EC parameters is an import-time CPU-exhaustion vector
64+
* (CVE-2024-29857). Default 1142 (twice 571).
65+
*/
66+
public static final String EC_MAX_F2M_FIELD_SIZE = "org.bouncycastle.ec.max_f2m_field_size";
67+
6168
private Properties()
6269
{
6370
}

0 commit comments

Comments
 (0)