--- a/src/java.base/share/classes/sun/security/util/ArrayUtil.java Fri Aug 17 13:40:17 2018 -0400
+++ b/src/java.base/share/classes/sun/security/util/ArrayUtil.java Fri Aug 17 14:37:01 2018 -0400
@@ -32,7 +32,7 @@
/**
- * This class holds the various utility methods for array range checks.
+ * This class holds the various utility methods for arrays.
*/
public final class ArrayUtil {
@@ -52,4 +52,22 @@
// NPE is thrown when array is null
Preconditions.checkFromIndexSize(offset, len, array.length, AIOOBE_SUPPLIER);
}
+
+
+ private static void swap(byte[] arr, int i, int j) {
+ byte tmp = arr[i];
+ arr[i] = arr[j];
+ arr[j] = tmp;
+ }
+
+ public static void reverse(byte [] arr) {
+ int i = 0;
+ int j = arr.length - 1;
+
+ while (i < j) {
+ swap(arr, i, j);
+ i++;
+ j--;
+ }
+ }
}
--- a/src/java.base/share/classes/sun/security/util/ECUtil.java Fri Aug 17 13:40:17 2018 -0400
+++ b/src/java.base/share/classes/sun/security/util/ECUtil.java Fri Aug 17 14:37:01 2018 -0400
@@ -230,7 +230,7 @@
public static BigInteger decodeXecPublicKey(byte[] key,
XECParameters params) {
- reverse(key);
+ ArrayUtil.reverse(key);
// clear the extra bits
int bitsMod8 = params.getBits() % 8;
@@ -256,7 +256,7 @@
XECParameters params) {
byte[] u_arr = u.toByteArray();
- ECUtil.reverse(u_arr);
+ ArrayUtil.reverse(u_arr);
// u_arr may be too large or too small, depending on the value of u
return Arrays.copyOf(u_arr, params.getBytes());
}
@@ -270,22 +270,5 @@
return encodeXecPublicKey(u, params);
}
- private static void swap(byte[] arr, int i, int j) {
- byte tmp = arr[i];
- arr[i] = arr[j];
- arr[j] = tmp;
- }
-
- public static void reverse(byte [] arr) {
- int i = 0;
- int j = arr.length - 1;
-
- while (i < j) {
- swap(arr, i, j);
- i++;
- j--;
- }
- }
-
private ECUtil() {}
}