Closed Bug 660394 Opened 14 years ago Closed 9 years ago

Timing attack on ECDSA (especially over binary curves)

Categories

(NSS :: Libraries, defect, P1)

defect

Tracking

(firefox6 affected, firefox7 affected, firefox8- affected, firefox9+ affected, firefox10+ affected, blocking1.9.2 -, status1.9.2 wontfix, status1.9.1 wontfix)

RESOLVED FIXED
Tracking Status
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)

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.
Attached patch Proposed patch (obsolete) — Splinter Review
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.
Assignee: nobody → douglas
Status: NEW → ASSIGNED
Attachment #536810 - Flags: review?(nelson)
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)
blocking1.9.2: --- → ?
Whiteboard: [sg:high]
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.
(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.
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.
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)
Attachment #562935 - Flags: review?(douglas) → review+
(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.
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
(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?
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)
We have a plan to land NSS 3.13 for Firefox soon, not sure if it's Fx8 or 9.
Is there a bug tracking the NSS 3.13 landing described in comment 12? if not I'll file one.
blocking1.9.1: ? → ---
blocking1.9.2: ? → needed
dveditz: you can use bug 669061 to track the NSS 3.13 landing.
---------------------------------[ 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?
Is there something QA can do to verify this fix?
Whiteboard: [sg:high] → [sg:high][qa?]
(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.
Whiteboard: [sg:high][qa?] → [sg:high][qa-]
blocking1.9.2: needed → -
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Possible that some multiplication routines expect reduced input and will fail.
Attachment #8764980 - Flags: review?(rrelyea)
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.
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
Whiteboard: [sg:high][qa-] → [qa-]
I'm currently investigating. I'll leave the ni here as a reminder until I take action.
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 ago9 years ago
Flags: needinfo?(franziskuskiefer)
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: