8320743: AEAD ciphers throw undocumented exceptions on overflow

Reviewed-by: ascarpino
This commit is contained in:
Kevin Driver 2024-11-18 16:41:57 +00:00
parent 207832952b
commit 3e78ff16d3
2 changed files with 7 additions and 7 deletions
src/java.base/share/classes/com/sun/crypto/provider

@ -245,7 +245,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
params.init((new DerValue(
DerValue.tag_OctetString, nonceData).toByteArray()));
} catch (NoSuchAlgorithmException | IOException exc) {
throw new RuntimeException(exc);
throw new ProviderException(exc);
}
}
@ -353,7 +353,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
break;
default:
// Should never happen
throw new RuntimeException("ChaCha20 in unsupported mode");
throw new ProviderException("ChaCha20 in unsupported mode");
}
init(opmode, key, newNonce);
}
@ -426,7 +426,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
}
break;
default:
throw new RuntimeException("Invalid mode: " + mode);
throw new ProviderException("Invalid mode: " + mode);
}
// Continue with initialization
@ -730,7 +730,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
try {
engine.doFinal(in, inOfs, inLen, output, 0);
} catch (ShortBufferException | KeyException exc) {
throw new RuntimeException(exc);
throw new ProviderException(exc);
} finally {
// Reset the cipher's state to post-init values.
resetStartState();
@ -767,7 +767,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
try {
bytesUpdated = engine.doFinal(in, inOfs, inLen, out, outOfs);
} catch (KeyException ke) {
throw new RuntimeException(ke);
throw new ProviderException(ke);
} finally {
// Reset the cipher's state to post-init values.
resetStartState();

@ -241,7 +241,7 @@ abstract class GaloisCounterMode extends CipherSpi {
params.init(spec);
return params;
} catch (NoSuchAlgorithmException | InvalidParameterSpecException e) {
throw new RuntimeException(e);
throw new ProviderException(e);
}
}
@ -781,7 +781,7 @@ abstract class GaloisCounterMode extends CipherSpi {
int mergeBlock(byte[] buffer, int bufOfs, int bufLen, byte[] in,
int inOfs, int inLen, byte[] block) {
if (bufLen > blockSize) {
throw new RuntimeException("mergeBlock called on an ibuffer " +
throw new ProviderException("mergeBlock called on an ibuffer " +
"too big: " + bufLen + " bytes");
}