Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8188046

java.lang.Math.mutliplyHigh does not run in constant time

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 18
    • None
    • core-libs
    • b05

      The pure Java implementation of mutliplyHigh looks like this:

          public static long multiplyHigh(long x, long y) {
              if (x < 0 || y < 0) {
                  // Use technique from section 8-2 of Henry S. Warren, Jr.,
                  // Hacker's Delight (2nd ed.) (Addison Wesley, 2013), 173-174.
              } else {
                  // Use Karatsuba technique with two base 2^32 digits.
              }

      This two-way branch gains very little in speed but potentially leaks information to a timing attack. What little the fast path gains from one fewer multiply it loses on the conditional branch: I've not been able to measure any significant difference in speed.

            bpb Brian Burkhalter
            aph Andrew Haley
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: