Fix incrementing the invocation_counter part of the IV used in GCM cipher.
Since the invocation_counter part of the IV is treated as a uint64,
guarding against overflow by using Math.addExact() would incorrectly
throw an ArithmeticException when it hits Long.MAX_VALUE.
@@ -90,7 +90,7 @@ public class BaseGCMCipher extends BaseCipher {
protected void incrementCounter() {
int off = iv.length - Long.BYTES;
long counter = BufferUtils.getLong(iv, off, Long.BYTES);
- BufferUtils.putLong(Math.addExact(counter, 1L), iv, off, Long.BYTES);
+ BufferUtils.putLong(counter + 1L, iv, off, Long.BYTES);
}
@Override
