The BigInteger method
private static final int[] squareToLen(int[] x, int len, int[] z)
may compute incorrect results when invoked via reflection and z.length > 2 * len. For example:
x = {1, 2}
len = 2
with z.length = 4: {0, 1, 4, 4} (as expected)
with z.length = 5: {0, 1, 0, 8, 0} instead of {0, 1, 4, 4, 0}
The core issue is in implMulAdd(), where 'offset' is set to
"out.length-offset - 1"
instead of
"zlen - offset - 1"
(which requires to add zlen as argument).
Calling a private method as such is not guaranteed to work, but if there is an error, it should probably be fixed.
private static final int[] squareToLen(int[] x, int len, int[] z)
may compute incorrect results when invoked via reflection and z.length > 2 * len. For example:
x = {1, 2}
len = 2
with z.length = 4: {0, 1, 4, 4} (as expected)
with z.length = 5: {0, 1, 0, 8, 0} instead of {0, 1, 4, 4, 0}
The core issue is in implMulAdd(), where 'offset' is set to
"out.length-offset - 1"
instead of
"zlen - offset - 1"
(which requires to add zlen as argument).
Calling a private method as such is not guaranteed to work, but if there is an error, it should probably be fixed.