|
|
@ -116,20 +116,20 @@ final class ReedSolomonGenerator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void getRemainder(byte[] data, byte[] result) {
|
|
|
|
public void getRemainder(byte[] data, int dataOff, int dataLen, byte[] result, int resultOff) {
|
|
|
|
Objects.requireNonNull(data);
|
|
|
|
Objects.requireNonNull(data);
|
|
|
|
Objects.requireNonNull(result);
|
|
|
|
Objects.requireNonNull(result);
|
|
|
|
if (result.length != multiplies.length)
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("Array length mismatch");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compute the remainder by performing polynomial division
|
|
|
|
// Compute the remainder by performing polynomial division
|
|
|
|
Arrays.fill(result, (byte)0);
|
|
|
|
int resultEnd = resultOff + multiplies.length;
|
|
|
|
for (byte b : data) {
|
|
|
|
Arrays.fill(result, resultOff, resultEnd, (byte)0);
|
|
|
|
int factor = (b ^ result[0]) & 0xFF;
|
|
|
|
for (int i = dataOff, dataEnd = dataOff + dataLen; i < dataEnd; i++) {
|
|
|
|
System.arraycopy(result, 1, result, 0, result.length - 1);
|
|
|
|
byte b = data[i];
|
|
|
|
result[result.length - 1] = 0;
|
|
|
|
int factor = (b ^ result[resultOff]) & 0xFF;
|
|
|
|
for (int i = 0; i < result.length; i++)
|
|
|
|
System.arraycopy(result, resultOff + 1, result, resultOff, multiplies.length - 1);
|
|
|
|
result[i] ^= multiplies[i][factor];
|
|
|
|
result[resultEnd - 1] = 0;
|
|
|
|
|
|
|
|
for (int j = 0; j < multiplies.length; j++)
|
|
|
|
|
|
|
|
result[resultOff + j] ^= multiplies[j][factor];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|