Commit 929dd99
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. wc_ecc_shared_secret performed no on-curve validation at all.
An attacker who can supply an EC public key (e.g. via an ECIES
ciphertext, PKCS#7 enveloped-data, or EVP_PKEY_derive) 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.
Three changes close the attack:
1. Define USE_ECC_B_PARAM unconditionally in ecc.h so that
wc_ecc_point_is_on_curve() is compiled in all builds, not only
those with HAVE_COMP_KEY or OPENSSL_EXTRA.
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_shared_secret: add defense-in-depth on-curve check before
scalar multiplication, catching any import path that bypassed the
import-time validation (e.g. direct wc_ecc_import_x963_ex2 with
untrusted=0).
Both new validation sites dispatch to sp_ecc_check_key_NNN for
SP-supported curves (P-256/384/521, SM2) when WOLFSSL_HAVE_SP_ECC is
defined, keeping the mp_int stack cost off embedded targets. Non-SP
curves fall back to wc_ecc_point_is_on_curve.
Reported by: Nicholas Carlini (Anthropic) & Thai Duong (Calif.io)1 parent f207e18 commit 929dd99
2 files changed
Lines changed: 156 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4761 | 4761 | | |
4762 | 4762 | | |
4763 | 4763 | | |
| 4764 | + | |
| 4765 | + | |
| 4766 | + | |
| 4767 | + | |
| 4768 | + | |
| 4769 | + | |
| 4770 | + | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
| 4774 | + | |
| 4775 | + | |
| 4776 | + | |
| 4777 | + | |
| 4778 | + | |
| 4779 | + | |
| 4780 | + | |
| 4781 | + | |
| 4782 | + | |
| 4783 | + | |
| 4784 | + | |
| 4785 | + | |
| 4786 | + | |
| 4787 | + | |
| 4788 | + | |
| 4789 | + | |
| 4790 | + | |
| 4791 | + | |
| 4792 | + | |
| 4793 | + | |
| 4794 | + | |
| 4795 | + | |
| 4796 | + | |
| 4797 | + | |
| 4798 | + | |
| 4799 | + | |
| 4800 | + | |
| 4801 | + | |
| 4802 | + | |
| 4803 | + | |
| 4804 | + | |
| 4805 | + | |
| 4806 | + | |
| 4807 | + | |
| 4808 | + | |
| 4809 | + | |
| 4810 | + | |
| 4811 | + | |
| 4812 | + | |
| 4813 | + | |
| 4814 | + | |
| 4815 | + | |
| 4816 | + | |
| 4817 | + | |
| 4818 | + | |
| 4819 | + | |
| 4820 | + | |
| 4821 | + | |
| 4822 | + | |
| 4823 | + | |
| 4824 | + | |
| 4825 | + | |
| 4826 | + | |
| 4827 | + | |
| 4828 | + | |
| 4829 | + | |
| 4830 | + | |
| 4831 | + | |
| 4832 | + | |
| 4833 | + | |
| 4834 | + | |
| 4835 | + | |
4764 | 4836 | | |
4765 | 4837 | | |
4766 | 4838 | | |
| |||
11011 | 11083 | | |
11012 | 11084 | | |
11013 | 11085 | | |
11014 | | - | |
11015 | | - | |
| 11086 | + | |
| 11087 | + | |
| 11088 | + | |
| 11089 | + | |
| 11090 | + | |
| 11091 | + | |
| 11092 | + | |
| 11093 | + | |
| 11094 | + | |
| 11095 | + | |
| 11096 | + | |
| 11097 | + | |
| 11098 | + | |
| 11099 | + | |
| 11100 | + | |
| 11101 | + | |
| 11102 | + | |
| 11103 | + | |
| 11104 | + | |
| 11105 | + | |
| 11106 | + | |
| 11107 | + | |
| 11108 | + | |
| 11109 | + | |
| 11110 | + | |
| 11111 | + | |
| 11112 | + | |
| 11113 | + | |
| 11114 | + | |
| 11115 | + | |
| 11116 | + | |
| 11117 | + | |
| 11118 | + | |
| 11119 | + | |
| 11120 | + | |
| 11121 | + | |
| 11122 | + | |
| 11123 | + | |
| 11124 | + | |
| 11125 | + | |
| 11126 | + | |
| 11127 | + | |
| 11128 | + | |
| 11129 | + | |
| 11130 | + | |
| 11131 | + | |
| 11132 | + | |
| 11133 | + | |
| 11134 | + | |
| 11135 | + | |
| 11136 | + | |
| 11137 | + | |
| 11138 | + | |
| 11139 | + | |
| 11140 | + | |
| 11141 | + | |
| 11142 | + | |
| 11143 | + | |
| 11144 | + | |
| 11145 | + | |
11016 | 11146 | | |
11017 | 11147 | | |
11018 | 11148 | | |
11019 | 11149 | | |
11020 | | - | |
| 11150 | + | |
11021 | 11151 | | |
| 11152 | + | |
| 11153 | + | |
| 11154 | + | |
| 11155 | + | |
| 11156 | + | |
| 11157 | + | |
| 11158 | + | |
| 11159 | + | |
| 11160 | + | |
| 11161 | + | |
| 11162 | + | |
| 11163 | + | |
| 11164 | + | |
| 11165 | + | |
11022 | 11166 | | |
11023 | 11167 | | |
| 11168 | + | |
11024 | 11169 | | |
11025 | 11170 | | |
11026 | 11171 | | |
| |||
11047 | 11192 | | |
11048 | 11193 | | |
11049 | 11194 | | |
11050 | | - | |
| 11195 | + | |
| 11196 | + | |
11051 | 11197 | | |
11052 | 11198 | | |
11053 | 11199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
0 commit comments