Closed
Bug 660394
Opened 14 years ago
Closed 9 years ago
Timing attack on ECDSA (especially over binary curves)
Categories
(NSS :: Libraries, defect, P1)
NSS
Libraries
Tracking
(firefox6 affected, firefox7 affected, firefox8- affected, firefox9+ affected, firefox10+ affected, blocking1.9.2 -, status1.9.2 wontfix, status1.9.1 wontfix)
People
(Reporter: douglas, Assigned: douglas)
References
Details
(Keywords: sec-moderate, Whiteboard: [qa-])
Attachments
(2 files, 1 obsolete file)
|
1.68 KB,
patch
|
douglas
:
review+
|
Details | Diff | Splinter Review |
|
8.48 KB,
patch
|
Details | Diff | Splinter Review |
Brumley and Tuveri recently described a timing attack on the implementation of Montgomery multiplication for binary elliptic curve arithmetic in OpenSSL. They describe how to use this vulnerability to recover the long-term ECDSA private key of a TLS server both locally and over a local network (http://eprint.iacr.org/2011/232)
The ECC code in NSS has a similar vulnerability.
The paper above proposes a patch to the ECDSA code in OpenSSL, which has already been adopted by OpenSSL. However, I believe it may be more appropriate to patch the Montgomery multiplication code, not the ECDSA code, and I have emailed the authors to determine if that's the case. I will post a patch here when I know more.
| Assignee | ||
Comment 1•14 years ago
|
||
This patch is equivalent to the patch used in OpenSSL. I have not been able to confirm that all ECC code still runs correctly because running nss/tests/all.sh on my system (Mac OS X 10.6.7, x86_64) with NSS_ENABLE_ECC=1 results in a bunch of failures, even before this patch is applied.
Comment 2•14 years ago
|
||
Comment on attachment 536810 [details] [diff] [review]
Proposed patch
>+ /*
>+ ** We do not want timing information to leak the length of k,
>+ ** so we compute k*G using an equivalent scalar of fixed
>+ ** bit-length.
>+ ** Fix based on patch for ECDSA timing attack in the paper
>+ ** by Billy Bob Brumley and Nicola Tuveri at
>+ ** http://eprint.iacr.org/2011/232
>+ */
>+ CHECK_MPI_OK( mp_add(&k, &n, &k) );
>+ if (mpl_significant_bits(&k) <= mpl_significant_bits(&n)) {
>+ CHECK_MPI_OK( mp_add(&k, &n, &k) );
>+ }
In pseudo code, the above is:
k += n;
if (k is shorter or the same length as n) {
k += n;
}
I understand adding n (the group order) results in an equivalent
scalar, but I don't understand how your code makes it fixed bit
length. Could you explain? Thanks.
Attachment #536810 -
Flags: review?(nelson) → review?(wtc)
Updated•14 years ago
|
blocking1.9.2: --- → ?
status1.9.2:
--- → wanted
status-firefox10:
--- → affected
status-firefox6:
--- → affected
status-firefox7:
--- → affected
status-firefox8:
--- → affected
status-firefox9:
--- → affected
tracking-firefox10:
--- → ?
tracking-firefox8:
--- → ?
tracking-firefox9:
--- → ?
Whiteboard: [sg:high]
Comment 3•14 years ago
|
||
Minusing this for tracking against current releases since it's not release-specific BUT BUT BUT we would very much like to see approval requests on a reviewed patch, for inclusion in FF8, 9, and 10.
| Assignee | ||
Comment 4•14 years ago
|
||
(In reply to Wan-Teh Chang from comment #2)
> >+ CHECK_MPI_OK( mp_add(&k, &n, &k) );
> >+ if (mpl_significant_bits(&k) <= mpl_significant_bits(&n)) {
> >+ CHECK_MPI_OK( mp_add(&k, &n, &k) );
> >+ }
>
> In pseudo code, the above is:
> k += n;
> if (k is shorter or the same length as n) {
> k += n;
> }
>
> I understand adding n (the group order) results in an equivalent
> scalar, but I don't understand how your code makes it fixed bit
> length. Could you explain? Thanks.
k starts off as integer satisfying 0 <= k < n. Hence, n <= k+n < 2n. Now, it could be that k+n has either the same number of bits as n or one more bit than n. If k+n has the same number of bits as n, the second addition ensures that the final value has exactly one more bit than n. Thus, we always end up with a value that exactly one more bit than n.
Comment 5•14 years ago
|
||
The patch is to a function that isn't specific to binary elliptic curves. Does this mean it applies to elliptic curves over primes too?
This code is in the ECDSA signing code path. AFAICT, currently no Mozilla products can even use ECDSA signatures, because we build NSS without ECDSA signing support enabled. We even have an open bug about that: bug 367577. And, even if we were to have ECDSA signing support, we (Mozilla products) only support ECC using non-binary curves.
Comment 6•14 years ago
|
||
Douglas: I added your proof as a comment. Please review. Thanks.
I tested your patch with all.sh. All tests passed. (To run all.sh
with ECC, you also need to set NSS_ECC_MORE_THAN_SUITE_B=1.)
Attachment #536810 -
Attachment is obsolete: true
Attachment #536810 -
Flags: review?(wtc)
Attachment #562935 -
Flags: review?(douglas)
| Assignee | ||
Updated•14 years ago
|
Attachment #562935 -
Flags: review?(douglas) → review+
| Assignee | ||
Comment 7•14 years ago
|
||
(In reply to Brian Smith (:bsmith) from comment #5)
> The patch is to a function that isn't specific to binary elliptic curves.
> Does this mean it applies to elliptic curves over primes too?
Yes. The academic paper describing this attack implemented it against binary curves because their multiplication routine (Montgomery ladder) is most susceptible to this. They note that certain other types of point multiplication routines could be susceptible. I don't think the prime field ones used in NSS satisfy their constraint. But in ECDSA overall, one should avoid leaking any information about the scalar k, so having the patch affect the prime curve code path potentially eliminates an undiscovered vulnerability and is certainly no detriment.
> This code is in the ECDSA signing code path. AFAICT, currently no Mozilla
> products can even use ECDSA signatures, because we build NSS without ECDSA
> signing support enabled. We even have an open bug about that: bug 367577.
> And, even if we were to have ECDSA signing support, we (Mozilla products)
> only support ECC using non-binary curves.
When I go into about:config in my Firefox 6.0, 10 cipher suites are present that match the string ECDSA, 8 of which are enabled by default.
Comment 8•14 years ago
|
||
Douglas, a TLS client does not need to generate ECDSA signatures
when using an ECDSA cipher suite. But NSS supports the ecdsa_sign
client authentication method, so Mozilla products can still generate
ECDSA signatures.
Patch checked in on the NSS trunk (NSS 3.13).
Checking in ec.c;
/cvsroot/mozilla/security/nss/lib/freebl/ec.c,v <-- ec.c
new revision: 1.22; previous revision: 1.21
done
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Priority: -- → P1
Resolution: --- → FIXED
Target Milestone: --- → 3.13
Comment 9•14 years ago
|
||
(In reply to Douglas Stebila from comment #0)
>
> The paper above proposes a patch to the ECDSA code in OpenSSL, which has
> already been adopted by OpenSSL. However, I believe it may be more
> appropriate to patch the Montgomery multiplication code, not the ECDSA code,
> and I have emailed the authors to determine if that's the case. I will post
> a patch here when I know more.
Have the authors of the paper answered your question?
Comment 11•14 years ago
|
||
Thanks Wan-Teh for correcting my misunderstanding.
blocking1.9.1: --- → ?
Summary: Timing attack on binary elliptic curve cryptography → Timing attack on ECDSA (especially over binary curves)
Comment 12•14 years ago
|
||
We have a plan to land NSS 3.13 for Firefox soon, not sure if it's Fx8 or 9.
Comment 13•14 years ago
|
||
Is there a bug tracking the NSS 3.13 landing described in comment 12? if not I'll file one.
Comment 14•14 years ago
|
||
dveditz: you can use bug 669061 to track the NSS 3.13 landing.
Comment 15•14 years ago
|
||
---------------------------------[ Triage Comment ]---------------------------------
Dan, this will just land when NSS 3.13 lands? Are you not trying to take this patch on top of the NSS we have?
Keywords: #relman/triage/needs-info
Updated•14 years ago
|
Comment 16•14 years ago
|
||
Is there something QA can do to verify this fix?
Whiteboard: [sg:high] → [sg:high][qa?]
Comment 17•14 years ago
|
||
(In reply to Anthony Hughes, Mozilla QA (irc: ashughes) from comment #16)
> Is there something QA can do to verify this fix?
Not that I can think of, other than ensuring we are shipping NSS 3.13 or later.
Updated•14 years ago
|
blocking1.9.2: needed → -
Comment 18•9 years ago
|
||
Our fix is completely bogus.
https://dxr.mozilla.org/mozilla-central/source/security/nss/lib/freebl/ec.c?q=ec.c&redirect_type=direct#692
computes the scalar by adding a random multiple of the order, then calls
https://dxr.mozilla.org/mozilla-central/source/security/nss/lib/freebl/ec.c?q=%2Bfunction%3A%22ec_points_mul
which is a small wrapper around
https://dxr.mozilla.org/mozilla-central/source/security/nss/lib/freebl/ecl/ecl_mult.c?q=%2Bfunction%3A%22ECPoints_mul%28const+ECGroup+%2A%2C+const+mp_int+%2A%2C+const+mp_int+%2A%2C+const+mp_int+%2A%2C+const+mp_int+%2A%2C+mp_int+%2A%2C+mp_int+%2A%29%22&redirect_type=single#275
The first thing this function does is reduce the scalar modulo the group order, then passes the scalar to the multiplication routine.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Comment 19•9 years ago
|
||
Possible that some multiplication routines expect reduced input and will fail.
Attachment #8764980 -
Flags: review?(rrelyea)
Comment 20•9 years ago
|
||
Hi Watson: Thank you for the patch. In the future, it would be
better to open a new bug. Re-opening a very old bug that was
marked as fixed in an NSS release can make it hard to determine
which versions of NSS have the (incorrect) fix.
Comment 21•9 years ago
|
||
What's the next step for this bug? Did this patch get moved to a different bug and handled there, or is this a patch we still need to get reviewed and landed?
Flags: needinfo?(franziskuskiefer)
Keywords: sec-moderate
Updated•9 years ago
|
Whiteboard: [sg:high][qa-] → [qa-]
Comment 22•9 years ago
|
||
I'm currently investigating. I'll leave the ni here as a reminder until I take action.
Comment 23•9 years ago
|
||
I'll close this one as fixed again as the original problem was solved. The proposed patch doesn't work and most systems are currently covered and I don't think that the information we're leaking is significant enough to use for anything.
Status: REOPENED → RESOLVED
Closed: 14 years ago → 9 years ago
Flags: needinfo?(franziskuskiefer)
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•