Commit 0fb2d2e
committed
ecc: fix invalid-curve attack via missing on-curve validation
wc_ecc_import_x963_ex2 only checked whether an imported public point
lies on the intended curve when both USE_ECC_B_PARAM was compiled in
and the caller passed untrusted=1. In a default ./configure build,
USE_ECC_B_PARAM is not defined, so the check was compiled out entirely.
Additionally, the legacy wrapper wc_ecc_import_x963_ex unconditionally
passed untrusted=0, meaning ECIES (wc_ecc_decrypt), PKCS#7 KARI, and
the EVP ECDH layer never triggered the check even when the macro was
present. In the OpenSSL compatibility layer, wolfSSL_ECPoint_d2i
guarded its on-curve check behind !wolfSSL_BN_is_one(point->Z), but
wc_ecc_import_point_der_ex always sets Z=1 for uncompressed points,
making the check dead code.
An attacker who can supply an EC public key (e.g. via an ECIES
ciphertext, PKCS#7 enveloped-data, EVP_PKEY_derive, or
EC_POINT_oct2point + ECDH_compute_key) can choose a point on a twist
of the target curve with a smooth-order subgroup. Each ECDH query
leaks the victim's static private scalar modulo a small prime; CRT
reconstruction across enough queries recovers the full key
(Biehl-Meyer-Müller invalid-curve attack). Static-key ECIES and PKCS#7
KARI are directly affected; TLS is affected in default builds because
the USE_ECC_B_PARAM gate defeated the untrusted=1 flag that the
handshake does pass.
Four changes close the attack:
1. Remove the USE_ECC_B_PARAM gate completely in the code base so that
wc_ecc_point_is_on_curve() is compiled in all builds, not only
those with HAVE_COMP_KEY or OPENSSL_EXTRA (only set for legacy FIPS
builds in settings.h).
2. wc_ecc_import_x963_ex: pass untrusted=1 to wc_ecc_import_x963_ex2
so that ECIES, PKCS#7 KARI, and EVP callers that go through the
four-argument wrapper always validate the imported point.
3. wc_ecc_import_x963_ex2: use the lightweight sp_ecc_is_point_NNN
helpers (curve-equation check only) instead of sp_ecc_check_key_NNN
(which additionally performs a full point*order scalar multiply).
For prime-order curves (P-256, P-384, P-521, SM2) the on-curve
equation check y^2 = x^3 + ax + b is sufficient to defeat
invalid-curve attacks — every non-identity point on a prime-order
curve has the full group order, so the expensive order-multiply
check is unnecessary. This avoids the ~50% ECDH performance
regression caused by the redundant scalar multiplication.
4. wolfSSL_ECPoint_d2i (pk_ec.c): add unconditional on-curve
validation via wolfSSL_EC_POINT_is_on_curve after import. The
existing check was gated on !wolfSSL_BN_is_one(point->Z) and
therefore dead code for all uncompressed-point imports. This closes
the OpenSSL compat layer attack path (EC_POINT_oct2point followed
by ECDH_compute_key).
Non-SP curves fall back to wc_ecc_point_is_on_curve which performs the
same equation check using mp_int arithmetic.
Reported by: Nicholas Carlini (Anthropic) & Thai Duong (Calif.io)1 parent 1cd8edb commit 0fb2d2e
File tree
7 files changed
+103
-97
lines changed- src
- tests/api
- wolfcrypt
- src
- test
- wolfssl/wolfcrypt
7 files changed
+103
-97
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1532 | 1532 | | |
1533 | 1533 | | |
1534 | 1534 | | |
1535 | | - | |
| 1535 | + | |
1536 | 1536 | | |
1537 | 1537 | | |
1538 | 1538 | | |
| |||
1544 | 1544 | | |
1545 | 1545 | | |
1546 | 1546 | | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
1547 | 1559 | | |
1548 | 1560 | | |
1549 | 1561 | | |
| |||
1750 | 1762 | | |
1751 | 1763 | | |
1752 | 1764 | | |
1753 | | - | |
1754 | | - | |
| 1765 | + | |
1755 | 1766 | | |
1756 | 1767 | | |
1757 | 1768 | | |
| |||
1792 | 1803 | | |
1793 | 1804 | | |
1794 | 1805 | | |
1795 | | - | |
| 1806 | + | |
1796 | 1807 | | |
1797 | 1808 | | |
1798 | 1809 | | |
| |||
1985 | 1996 | | |
1986 | 1997 | | |
1987 | 1998 | | |
1988 | | - | |
1989 | | - | |
| 1999 | + | |
1990 | 2000 | | |
1991 | 2001 | | |
1992 | 2002 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1314 | 1314 | | |
1315 | 1315 | | |
1316 | 1316 | | |
| 1317 | + | |
1317 | 1318 | | |
1318 | 1319 | | |
1319 | 1320 | | |
| |||
1445 | 1446 | | |
1446 | 1447 | | |
1447 | 1448 | | |
1448 | | - | |
1449 | 1449 | | |
1450 | 1450 | | |
1451 | 1451 | | |
1452 | 1452 | | |
1453 | 1453 | | |
1454 | 1454 | | |
1455 | 1455 | | |
1456 | | - | |
1457 | 1456 | | |
1458 | 1457 | | |
1459 | 1458 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
479 | | - | |
480 | | - | |
| 479 | + | |
481 | 480 | | |
482 | 481 | | |
483 | 482 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | 53 | | |
56 | 54 | | |
57 | 55 | | |
| |||
1522 | 1520 | | |
1523 | 1521 | | |
1524 | 1522 | | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
| 1523 | + | |
1528 | 1524 | | |
1529 | 1525 | | |
1530 | 1526 | | |
1531 | 1527 | | |
1532 | 1528 | | |
1533 | 1529 | | |
1534 | 1530 | | |
1535 | | - | |
1536 | | - | |
1537 | | - | |
| 1531 | + | |
1538 | 1532 | | |
1539 | 1533 | | |
1540 | 1534 | | |
| |||
1554 | 1548 | | |
1555 | 1549 | | |
1556 | 1550 | | |
1557 | | - | |
1558 | 1551 | | |
1559 | | - | |
1560 | 1552 | | |
1561 | 1553 | | |
1562 | 1554 | | |
1563 | | - | |
1564 | 1555 | | |
1565 | 1556 | | |
1566 | | - | |
1567 | | - | |
1568 | | - | |
1569 | | - | |
1570 | 1557 | | |
1571 | 1558 | | |
1572 | 1559 | | |
| |||
1710 | 1697 | | |
1711 | 1698 | | |
1712 | 1699 | | |
1713 | | - | |
1714 | 1700 | | |
1715 | 1701 | | |
1716 | | - | |
1717 | 1702 | | |
1718 | 1703 | | |
1719 | 1704 | | |
| |||
1847 | 1832 | | |
1848 | 1833 | | |
1849 | 1834 | | |
1850 | | - | |
1851 | | - | |
1852 | | - | |
| 1835 | + | |
1853 | 1836 | | |
1854 | 1837 | | |
1855 | 1838 | | |
| |||
1868 | 1851 | | |
1869 | 1852 | | |
1870 | 1853 | | |
1871 | | - | |
1872 | 1854 | | |
1873 | 1855 | | |
1874 | 1856 | | |
1875 | | - | |
1876 | 1857 | | |
1877 | 1858 | | |
1878 | 1859 | | |
| |||
4762 | 4743 | | |
4763 | 4744 | | |
4764 | 4745 | | |
| 4746 | + | |
4765 | 4747 | | |
4766 | 4748 | | |
4767 | 4749 | | |
| |||
5274 | 5256 | | |
5275 | 5257 | | |
5276 | 5258 | | |
5277 | | - | |
5278 | 5259 | | |
5279 | 5260 | | |
5280 | 5261 | | |
| |||
5309 | 5290 | | |
5310 | 5291 | | |
5311 | 5292 | | |
5312 | | - | |
5313 | 5293 | | |
5314 | 5294 | | |
5315 | 5295 | | |
| |||
9969 | 9949 | | |
9970 | 9950 | | |
9971 | 9951 | | |
9972 | | - | |
9973 | | - | |
9974 | 9952 | | |
9975 | 9953 | | |
9976 | 9954 | | |
| |||
10147 | 10125 | | |
10148 | 10126 | | |
10149 | 10127 | | |
| 10128 | + | |
| 10129 | + | |
10150 | 10130 | | |
10151 | 10131 | | |
10152 | 10132 | | |
| |||
10514 | 10494 | | |
10515 | 10495 | | |
10516 | 10496 | | |
10517 | | - | |
10518 | | - | |
10519 | | - | |
10520 | | - | |
10521 | | - | |
10522 | | - | |
10523 | | - | |
10524 | | - | |
| 10497 | + | |
10525 | 10498 | | |
10526 | 10499 | | |
10527 | 10500 | | |
| |||
10573 | 10546 | | |
10574 | 10547 | | |
10575 | 10548 | | |
10576 | | - | |
10577 | | - | |
10578 | | - | |
10579 | | - | |
10580 | | - | |
10581 | | - | |
10582 | | - | |
10583 | | - | |
10584 | | - | |
10585 | | - | |
10586 | | - | |
10587 | | - | |
10588 | | - | |
10589 | | - | |
10590 | | - | |
| 10549 | + | |
10591 | 10550 | | |
10592 | 10551 | | |
10593 | 10552 | | |
| |||
10612 | 10571 | | |
10613 | 10572 | | |
10614 | 10573 | | |
10615 | | - | |
10616 | | - | |
10617 | | - | |
10618 | | - | |
10619 | | - | |
| 10574 | + | |
10620 | 10575 | | |
10621 | | - | |
10622 | | - | |
10623 | | - | |
10624 | | - | |
10625 | | - | |
10626 | | - | |
10627 | | - | |
10628 | 10576 | | |
10629 | 10577 | | |
10630 | | - | |
10631 | 10578 | | |
10632 | 10579 | | |
10633 | 10580 | | |
| |||
10684 | 10631 | | |
10685 | 10632 | | |
10686 | 10633 | | |
10687 | | - | |
10688 | | - | |
10689 | | - | |
10690 | | - | |
10691 | | - | |
10692 | 10634 | | |
10693 | 10635 | | |
10694 | 10636 | | |
| |||
11012 | 10954 | | |
11013 | 10955 | | |
11014 | 10956 | | |
11015 | | - | |
11016 | | - | |
11017 | | - | |
| 10957 | + | |
| 10958 | + | |
| 10959 | + | |
11018 | 10960 | | |
11019 | 10961 | | |
11020 | | - | |
11021 | | - | |
| 10962 | + | |
| 10963 | + | |
| 10964 | + | |
| 10965 | + | |
| 10966 | + | |
| 10967 | + | |
| 10968 | + | |
| 10969 | + | |
| 10970 | + | |
| 10971 | + | |
| 10972 | + | |
| 10973 | + | |
| 10974 | + | |
| 10975 | + | |
| 10976 | + | |
| 10977 | + | |
| 10978 | + | |
| 10979 | + | |
| 10980 | + | |
| 10981 | + | |
| 10982 | + | |
| 10983 | + | |
| 10984 | + | |
| 10985 | + | |
| 10986 | + | |
| 10987 | + | |
| 10988 | + | |
| 10989 | + | |
| 10990 | + | |
| 10991 | + | |
| 10992 | + | |
| 10993 | + | |
| 10994 | + | |
| 10995 | + | |
| 10996 | + | |
| 10997 | + | |
| 10998 | + | |
| 10999 | + | |
| 11000 | + | |
| 11001 | + | |
| 11002 | + | |
| 11003 | + | |
| 11004 | + | |
| 11005 | + | |
| 11006 | + | |
11022 | 11007 | | |
| 11008 | + | |
| 11009 | + | |
| 11010 | + | |
| 11011 | + | |
| 11012 | + | |
| 11013 | + | |
| 11014 | + | |
| 11015 | + | |
| 11016 | + | |
| 11017 | + | |
| 11018 | + | |
| 11019 | + | |
| 11020 | + | |
| 11021 | + | |
| 11022 | + | |
| 11023 | + | |
| 11024 | + | |
11023 | 11025 | | |
11024 | | - | |
11025 | 11026 | | |
11026 | 11027 | | |
11027 | 11028 | | |
| |||
11048 | 11049 | | |
11049 | 11050 | | |
11050 | 11051 | | |
11051 | | - | |
| 11052 | + | |
| 11053 | + | |
11052 | 11054 | | |
11053 | 11055 | | |
11054 | 11056 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38221 | 38221 | | |
38222 | 38222 | | |
38223 | 38223 | | |
| 38224 | + | |
38224 | 38225 | | |
38225 | 38226 | | |
38226 | 38227 | | |
| |||
0 commit comments