Skip to content

Commit 341dc6a

Browse files
authored
remove binary curve support (#14291)
* remove binary curve support binary curves are rarely used, contain additional dangers, and may not be supported in some of our alternate backends. * more sect * better assert * unwrap :feelsbadman:
1 parent de9dae3 commit 341dc6a

9 files changed

Lines changed: 37 additions & 516 deletions

File tree

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Changelog
1010

1111
* Support for Python 3.8 is deprecated and will be removed in the next
1212
``cryptography`` release.
13+
* **BACKWARDS INCOMPATIBLE:** Support for binary elliptic curves
14+
(``SECT*`` classes) has been removed. These curves are rarely used and
15+
have additional security considerations that make them undesirable.
1316
* **BACKWARDS INCOMPATIBLE:** Support for OpenSSL 1.1.x has been removed.
1417
OpenSSL 3.0.0 or later is now required. LibreSSL, BoringSSL, and AWS-LC
1518
continue to be supported.

docs/hazmat/primitives/asymmetric/ec.rst

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -395,87 +395,6 @@ All named curves are instances of :class:`EllipticCurve`.
395395
Brainpool curve specified in :rfc:`5639`. These curves are discouraged
396396
for new systems.
397397

398-
.. class:: SECT571K1
399-
400-
.. versionadded:: 0.5
401-
402-
SECG curve ``sect571k1``. Also called NIST K-571. These binary curves are
403-
discouraged for new systems.
404-
405-
406-
.. class:: SECT409K1
407-
408-
.. versionadded:: 0.5
409-
410-
SECG curve ``sect409k1``. Also called NIST K-409. These binary curves are
411-
discouraged for new systems.
412-
413-
414-
.. class:: SECT283K1
415-
416-
.. versionadded:: 0.5
417-
418-
SECG curve ``sect283k1``. Also called NIST K-283. These binary curves are
419-
discouraged for new systems.
420-
421-
422-
.. class:: SECT233K1
423-
424-
.. versionadded:: 0.5
425-
426-
SECG curve ``sect233k1``. Also called NIST K-233. These binary curves are
427-
discouraged for new systems.
428-
429-
430-
.. class:: SECT163K1
431-
432-
.. versionadded:: 0.5
433-
434-
SECG curve ``sect163k1``. Also called NIST K-163. These binary curves are
435-
discouraged for new systems.
436-
437-
438-
.. class:: SECT571R1
439-
440-
.. versionadded:: 0.5
441-
442-
SECG curve ``sect571r1``. Also called NIST B-571. These binary curves are
443-
discouraged for new systems.
444-
445-
446-
.. class:: SECT409R1
447-
448-
.. versionadded:: 0.5
449-
450-
SECG curve ``sect409r1``. Also called NIST B-409. These binary curves are
451-
discouraged for new systems.
452-
453-
454-
.. class:: SECT283R1
455-
456-
.. versionadded:: 0.5
457-
458-
SECG curve ``sect283r1``. Also called NIST B-283. These binary curves are
459-
discouraged for new systems.
460-
461-
462-
.. class:: SECT233R1
463-
464-
.. versionadded:: 0.5
465-
466-
SECG curve ``sect233r1``. Also called NIST B-233. These binary curves are
467-
discouraged for new systems.
468-
469-
470-
.. class:: SECT163R2
471-
472-
.. versionadded:: 0.5
473-
474-
SECG curve ``sect163r2``. Also called NIST B-163. These binary curves are
475-
discouraged for new systems.
476-
477-
478-
479398

480399
Key Interfaces
481400
~~~~~~~~~~~~~~
@@ -832,66 +751,6 @@ Elliptic Curve Object Identifiers
832751

833752
Corresponds to the dotted string ``"1.3.36.3.3.2.8.1.1.13"``.
834753

835-
.. attribute:: SECT163K1
836-
837-
.. versionadded:: 2.5
838-
839-
Corresponds to the dotted string ``"1.3.132.0.1"``.
840-
841-
.. attribute:: SECT163R2
842-
843-
.. versionadded:: 2.5
844-
845-
Corresponds to the dotted string ``"1.3.132.0.15"``.
846-
847-
.. attribute:: SECT233K1
848-
849-
.. versionadded:: 2.5
850-
851-
Corresponds to the dotted string ``"1.3.132.0.26"``.
852-
853-
.. attribute:: SECT233R1
854-
855-
.. versionadded:: 2.5
856-
857-
Corresponds to the dotted string ``"1.3.132.0.27"``.
858-
859-
.. attribute:: SECT283K1
860-
861-
.. versionadded:: 2.5
862-
863-
Corresponds to the dotted string ``"1.3.132.0.16"``.
864-
865-
.. attribute:: SECT283R1
866-
867-
.. versionadded:: 2.5
868-
869-
Corresponds to the dotted string ``"1.3.132.0.17"``.
870-
871-
.. attribute:: SECT409K1
872-
873-
.. versionadded:: 2.5
874-
875-
Corresponds to the dotted string ``"1.3.132.0.36"``.
876-
877-
.. attribute:: SECT409R1
878-
879-
.. versionadded:: 2.5
880-
881-
Corresponds to the dotted string ``"1.3.132.0.37"``.
882-
883-
.. attribute:: SECT571K1
884-
885-
.. versionadded:: 2.5
886-
887-
Corresponds to the dotted string ``"1.3.132.0.38"``.
888-
889-
.. attribute:: SECT571R1
890-
891-
.. versionadded:: 2.5
892-
893-
Corresponds to the dotted string ``"1.3.132.0.39"``.
894-
895754
.. function:: get_curve_for_oid(oid)
896755

897756
.. versionadded:: 2.6

src/cryptography/hazmat/primitives/asymmetric/ec.py

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ class EllipticCurveOID:
2525
BRAINPOOLP256R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.7")
2626
BRAINPOOLP384R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.11")
2727
BRAINPOOLP512R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.13")
28-
SECT163K1 = ObjectIdentifier("1.3.132.0.1")
29-
SECT163R2 = ObjectIdentifier("1.3.132.0.15")
30-
SECT233K1 = ObjectIdentifier("1.3.132.0.26")
31-
SECT233R1 = ObjectIdentifier("1.3.132.0.27")
32-
SECT283K1 = ObjectIdentifier("1.3.132.0.16")
33-
SECT283R1 = ObjectIdentifier("1.3.132.0.17")
34-
SECT409K1 = ObjectIdentifier("1.3.132.0.36")
35-
SECT409R1 = ObjectIdentifier("1.3.132.0.37")
36-
SECT571K1 = ObjectIdentifier("1.3.132.0.38")
37-
SECT571R1 = ObjectIdentifier("1.3.132.0.39")
3828

3929

4030
class EllipticCurve(metaclass=abc.ABCMeta):
@@ -227,66 +217,6 @@ def __deepcopy__(self, memo: dict) -> EllipticCurvePublicKey:
227217
EllipticCurvePublicNumbers = rust_openssl.ec.EllipticCurvePublicNumbers
228218

229219

230-
class SECT571R1(EllipticCurve):
231-
name = "sect571r1"
232-
key_size = 570
233-
group_order = 0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47 # noqa: E501
234-
235-
236-
class SECT409R1(EllipticCurve):
237-
name = "sect409r1"
238-
key_size = 409
239-
group_order = 0x10000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173 # noqa: E501
240-
241-
242-
class SECT283R1(EllipticCurve):
243-
name = "sect283r1"
244-
key_size = 282
245-
group_order = 0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307 # noqa: E501
246-
247-
248-
class SECT233R1(EllipticCurve):
249-
name = "sect233r1"
250-
key_size = 233
251-
group_order = 0x1000000000000000000000000000013E974E72F8A6922031D2603CFE0D7
252-
253-
254-
class SECT163R2(EllipticCurve):
255-
name = "sect163r2"
256-
key_size = 163
257-
group_order = 0x40000000000000000000292FE77E70C12A4234C33
258-
259-
260-
class SECT571K1(EllipticCurve):
261-
name = "sect571k1"
262-
key_size = 570
263-
group_order = 0x20000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001 # noqa: E501
264-
265-
266-
class SECT409K1(EllipticCurve):
267-
name = "sect409k1"
268-
key_size = 407
269-
group_order = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF # noqa: E501
270-
271-
272-
class SECT283K1(EllipticCurve):
273-
name = "sect283k1"
274-
key_size = 281
275-
group_order = 0x1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61 # noqa: E501
276-
277-
278-
class SECT233K1(EllipticCurve):
279-
name = "sect233k1"
280-
key_size = 232
281-
group_order = 0x8000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF
282-
283-
284-
class SECT163K1(EllipticCurve):
285-
name = "sect163k1"
286-
key_size = 163
287-
group_order = 0x4000000000000000000020108A2E0CC0D99F8A5EF
288-
289-
290220
class SECP521R1(EllipticCurve):
291221
name = "secp521r1"
292222
key_size = 521
@@ -356,16 +286,6 @@ class BrainpoolP512R1(EllipticCurve):
356286
"secp384r1": SECP384R1(),
357287
"secp521r1": SECP521R1(),
358288
"secp256k1": SECP256K1(),
359-
"sect163k1": SECT163K1(),
360-
"sect233k1": SECT233K1(),
361-
"sect283k1": SECT283K1(),
362-
"sect409k1": SECT409K1(),
363-
"sect571k1": SECT571K1(),
364-
"sect163r2": SECT163R2(),
365-
"sect233r1": SECT233R1(),
366-
"sect283r1": SECT283R1(),
367-
"sect409r1": SECT409R1(),
368-
"sect571r1": SECT571R1(),
369289
"brainpoolP256r1": BrainpoolP256R1(),
370290
"brainpoolP384r1": BrainpoolP384R1(),
371291
"brainpoolP512r1": BrainpoolP512R1(),
@@ -436,16 +356,6 @@ class ECDH:
436356
EllipticCurveOID.BRAINPOOLP256R1: BrainpoolP256R1,
437357
EllipticCurveOID.BRAINPOOLP384R1: BrainpoolP384R1,
438358
EllipticCurveOID.BRAINPOOLP512R1: BrainpoolP512R1,
439-
EllipticCurveOID.SECT163K1: SECT163K1,
440-
EllipticCurveOID.SECT163R2: SECT163R2,
441-
EllipticCurveOID.SECT233K1: SECT233K1,
442-
EllipticCurveOID.SECT233R1: SECT233R1,
443-
EllipticCurveOID.SECT283K1: SECT283K1,
444-
EllipticCurveOID.SECT283R1: SECT283R1,
445-
EllipticCurveOID.SECT409K1: SECT409K1,
446-
EllipticCurveOID.SECT409R1: SECT409R1,
447-
EllipticCurveOID.SECT571K1: SECT571K1,
448-
EllipticCurveOID.SECT571R1: SECT571R1,
449359
}
450360

451361

src/rust/cryptography-key-parsing/src/ec.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ pub(crate) fn group_to_curve_oid(
2929
openssl::nid::Nid::SECP384R1 => Some(cryptography_x509::oid::EC_SECP384R1),
3030
openssl::nid::Nid::SECP521R1 => Some(cryptography_x509::oid::EC_SECP521R1),
3131
openssl::nid::Nid::SECP256K1 => Some(cryptography_x509::oid::EC_SECP256K1),
32-
openssl::nid::Nid::SECT233R1 => Some(cryptography_x509::oid::EC_SECT233R1),
33-
openssl::nid::Nid::SECT283R1 => Some(cryptography_x509::oid::EC_SECT283R1),
34-
openssl::nid::Nid::SECT409R1 => Some(cryptography_x509::oid::EC_SECT409R1),
35-
openssl::nid::Nid::SECT571R1 => Some(cryptography_x509::oid::EC_SECT571R1),
36-
openssl::nid::Nid::SECT163R2 => Some(cryptography_x509::oid::EC_SECT163R2),
37-
openssl::nid::Nid::SECT163K1 => Some(cryptography_x509::oid::EC_SECT163K1),
38-
openssl::nid::Nid::SECT233K1 => Some(cryptography_x509::oid::EC_SECT233K1),
39-
openssl::nid::Nid::SECT283K1 => Some(cryptography_x509::oid::EC_SECT283K1),
40-
openssl::nid::Nid::SECT409K1 => Some(cryptography_x509::oid::EC_SECT409K1),
41-
openssl::nid::Nid::SECT571K1 => Some(cryptography_x509::oid::EC_SECT571K1),
4232
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]
4333
openssl::nid::Nid::BRAINPOOL_P256R1 => Some(cryptography_x509::oid::EC_BRAINPOOLP256R1),
4434
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]
@@ -63,19 +53,6 @@ pub(crate) fn ec_params_to_group(
6353

6454
&cryptography_x509::oid::EC_SECP256K1 => openssl::nid::Nid::SECP256K1,
6555

66-
&cryptography_x509::oid::EC_SECT233R1 => openssl::nid::Nid::SECT233R1,
67-
&cryptography_x509::oid::EC_SECT283R1 => openssl::nid::Nid::SECT283R1,
68-
&cryptography_x509::oid::EC_SECT409R1 => openssl::nid::Nid::SECT409R1,
69-
&cryptography_x509::oid::EC_SECT571R1 => openssl::nid::Nid::SECT571R1,
70-
71-
&cryptography_x509::oid::EC_SECT163R2 => openssl::nid::Nid::SECT163R2,
72-
73-
&cryptography_x509::oid::EC_SECT163K1 => openssl::nid::Nid::SECT163K1,
74-
&cryptography_x509::oid::EC_SECT233K1 => openssl::nid::Nid::SECT233K1,
75-
&cryptography_x509::oid::EC_SECT283K1 => openssl::nid::Nid::SECT283K1,
76-
&cryptography_x509::oid::EC_SECT409K1 => openssl::nid::Nid::SECT409K1,
77-
&cryptography_x509::oid::EC_SECT571K1 => openssl::nid::Nid::SECT571K1,
78-
7956
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]
8057
&cryptography_x509::oid::EC_BRAINPOOLP256R1 => openssl::nid::Nid::BRAINPOOL_P256R1,
8158
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]

src/rust/cryptography-x509/src/oid.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,6 @@ pub const EC_SECP521R1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 35);
5858

5959
pub const EC_SECP256K1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 10);
6060

61-
pub const EC_SECT233R1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 27);
62-
pub const EC_SECT283R1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 17);
63-
pub const EC_SECT409R1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 37);
64-
pub const EC_SECT571R1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 39);
65-
66-
pub const EC_SECT163R2: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 15);
67-
68-
pub const EC_SECT163K1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 1);
69-
pub const EC_SECT233K1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 26);
70-
pub const EC_SECT283K1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 16);
71-
pub const EC_SECT409K1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 36);
72-
pub const EC_SECT571K1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 132, 0, 38);
73-
7461
pub const EC_BRAINPOOLP256R1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 36, 3, 3, 2, 8, 1, 1, 7);
7562
pub const EC_BRAINPOOLP384R1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 36, 3, 3, 2, 8, 1, 1, 11);
7663
pub const EC_BRAINPOOLP512R1: asn1::ObjectIdentifier = asn1::oid!(1, 3, 36, 3, 3, 2, 8, 1, 1, 13);

src/rust/src/backend/ec.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,6 @@ fn curve_from_py_curve(
4747

4848
"secp256k1" => openssl::nid::Nid::SECP256K1,
4949

50-
"sect233r1" => openssl::nid::Nid::SECT233R1,
51-
"sect283r1" => openssl::nid::Nid::SECT283R1,
52-
"sect409r1" => openssl::nid::Nid::SECT409R1,
53-
"sect571r1" => openssl::nid::Nid::SECT571R1,
54-
55-
"sect163r2" => openssl::nid::Nid::SECT163R2,
56-
57-
"sect163k1" => openssl::nid::Nid::SECT163K1,
58-
"sect233k1" => openssl::nid::Nid::SECT233K1,
59-
"sect283k1" => openssl::nid::Nid::SECT283K1,
60-
"sect409k1" => openssl::nid::Nid::SECT409K1,
61-
"sect571k1" => openssl::nid::Nid::SECT571K1,
62-
6350
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]
6451
"brainpoolP256r1" => openssl::nid::Nid::BRAINPOOL_P256R1,
6552
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]
@@ -249,9 +236,11 @@ impl ECPrivateKey {
249236

250237
let len = deriver.len()?;
251238
Ok(pyo3::types::PyBytes::new_with(py, len, |b| {
252-
let n = py.detach(|| deriver.derive(b)).map_err(|_| {
253-
pyo3::exceptions::PyValueError::new_err("Error computing shared key.")
254-
})?;
239+
// Previously it was possible to have derive return an error
240+
// if a public key was in a subgroup. Now that we only
241+
// support cofactor 1 curves this should be unreachable
242+
// so we unwrap.
243+
let n = py.detach(|| deriver.derive(b)).unwrap();
255244
assert_eq!(n, b.len());
256245
Ok(())
257246
})?)
@@ -389,7 +378,13 @@ impl ECPublicKey {
389378
) -> CryptographyResult<ECPublicKey> {
390379
let ec = pkey.ec_key()?;
391380
check_key_infinity(&ec)?;
392-
381+
let mut bn_ctx = openssl::bn::BigNumContext::new()?;
382+
let mut cofactor = openssl::bn::BigNum::new()?;
383+
ec.group().cofactor(&mut cofactor, &mut bn_ctx)?;
384+
let one = openssl::bn::BigNum::from_u32(1)?;
385+
// We only support curves with a cofactor of 1.
386+
// Any change here requires more careful key checking
387+
assert_eq!(cofactor, one, "cofactor must be 1");
393388
Ok(ECPublicKey { pkey, curve })
394389
}
395390
}

0 commit comments

Comments
 (0)