Skip to content

Commit

Permalink
8293886: The abstract keyword can be removed in AESCipher
Browse files Browse the repository at this point in the history
Reviewed-by: ascarpino, wetmore
  • Loading branch information
XueleiFan committed Nov 10, 2022
1 parent 54c986e commit d6468be
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/java.base/share/classes/com/sun/crypto/provider/AESCipher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,6 @@
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;
import java.nio.ByteBuffer;
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
Expand All @@ -50,21 +49,21 @@
*
* @author Valerie Peng
*
*
* @see AESCrypt
* @see CipherBlockChaining
* @see ElectronicCodeBook
* @see CipherFeedback
* @see OutputFeedback
*/

abstract class AESCipher extends CipherSpi {
class AESCipher extends CipherSpi {
public static final class General extends AESCipher {
public General() {
super(-1);
}
}
abstract static class OidImpl extends AESCipher {

static class OidImpl extends AESCipher {
protected OidImpl(int keySize, String mode, String padding) {
super(keySize);
try {
Expand All @@ -76,6 +75,7 @@ protected OidImpl(int keySize, String mode, String padding) {
}
}
}

public static final class AES128_ECB_NoPadding extends OidImpl {
public AES128_ECB_NoPadding() {
super(16, "ECB", "NOPADDING");
Expand Down Expand Up @@ -138,7 +138,7 @@ public AES256_CFB_NoPadding() {
}

// utility method used by AESCipher and AESWrapCipher
static final void checkKeySize(Key key, int fixedKeySize)
static void checkKeySize(Key key, int fixedKeySize)
throws InvalidKeyException {
if (fixedKeySize != -1) {
if (key == null) {
Expand All @@ -160,7 +160,7 @@ static final void checkKeySize(Key key, int fixedKeySize)
/*
* internal CipherCore object which does the real work.
*/
private CipherCore core = null;
private final CipherCore core;

/*
* needed to support AES oids which associates a fixed key size
Expand All @@ -186,6 +186,7 @@ protected AESCipher(int keySize) {
* @exception NoSuchAlgorithmException if the requested cipher mode does
* not exist
*/
@Override
protected void engineSetMode(String mode)
throws NoSuchAlgorithmException {
core.setMode(mode);
Expand All @@ -199,6 +200,7 @@ protected void engineSetMode(String mode)
* @exception NoSuchPaddingException if the requested padding mechanism
* does not exist
*/
@Override
protected void engineSetPadding(String paddingScheme)
throws NoSuchPaddingException {
core.setPadding(paddingScheme);
Expand All @@ -210,6 +212,7 @@ protected void engineSetPadding(String paddingScheme)
* @return the block size (in bytes), or 0 if the underlying algorithm is
* not a block cipher
*/
@Override
protected int engineGetBlockSize() {
return AESConstants.AES_BLOCK_SIZE;
}
Expand All @@ -231,6 +234,7 @@ protected int engineGetBlockSize() {
*
* @return the required output buffer size (in bytes)
*/
@Override
protected int engineGetOutputSize(int inputLen) {
return core.getOutputSize(inputLen);
}
Expand All @@ -247,6 +251,7 @@ protected int engineGetOutputSize(int inputLen) {
* underlying algorithm does not use an IV, or if the IV has not yet
* been set.
*/
@Override
protected byte[] engineGetIV() {
return core.getIV();
}
Expand All @@ -264,6 +269,7 @@ protected byte[] engineGetIV() {
* @return the parameters used with this cipher, or null if this cipher
* does not use any parameters.
*/
@Override
protected AlgorithmParameters engineGetParameters() {
return core.getParameters("AES");
}
Expand Down Expand Up @@ -298,6 +304,7 @@ protected AlgorithmParameters engineGetParameters() {
* @exception InvalidKeyException if the given key is inappropriate for
* initializing this cipher
*/
@Override
protected void engineInit(int opmode, Key key, SecureRandom random)
throws InvalidKeyException {
checkKeySize(key, fixedKeySize);
Expand Down Expand Up @@ -328,6 +335,7 @@ protected void engineInit(int opmode, Key key, SecureRandom random)
* @exception InvalidAlgorithmParameterException if the given algorithm
* parameters are inappropriate for this cipher
*/
@Override
protected void engineInit(int opmode, Key key,
AlgorithmParameterSpec params,
SecureRandom random)
Expand All @@ -336,6 +344,7 @@ protected void engineInit(int opmode, Key key,
core.init(opmode, key, params, random);
}

@Override
protected void engineInit(int opmode, Key key,
AlgorithmParameters params,
SecureRandom random)
Expand Down Expand Up @@ -363,6 +372,7 @@ protected void engineInit(int opmode, Key key,
* @exception IllegalStateException if this cipher is in a wrong state
* (e.g., has not been initialized)
*/
@Override
protected byte[] engineUpdate(byte[] input, int inputOffset,
int inputLen) {
return core.update(input, inputOffset, inputLen);
Expand Down Expand Up @@ -391,6 +401,7 @@ protected byte[] engineUpdate(byte[] input, int inputOffset,
* @exception ShortBufferException if the given output buffer is too small
* to hold the result
*/
@Override
protected int engineUpdate(byte[] input, int inputOffset, int inputLen,
byte[] output, int outputOffset)
throws ShortBufferException {
Expand Down Expand Up @@ -429,10 +440,10 @@ protected int engineUpdate(byte[] input, int inputOffset, int inputLen,
* and (un)padding has been requested, but the decrypted data is not
* bounded by the appropriate padding bytes
*/
@Override
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
throws IllegalBlockSizeException, BadPaddingException {
byte[] out = core.doFinal(input, inputOffset, inputLen);
return out;
return core.doFinal(input, inputOffset, inputLen);
}

/**
Expand Down Expand Up @@ -471,13 +482,13 @@ protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
* and (un)padding has been requested, but the decrypted data is not
* bounded by the appropriate padding bytes
*/
@Override
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen,
byte[] output, int outputOffset)
throws IllegalBlockSizeException, ShortBufferException,
BadPaddingException {
int outLen = core.doFinal(input, inputOffset, inputLen, output,
return core.doFinal(input, inputOffset, inputLen, output,
outputOffset);
return outLen;
}

/**
Expand All @@ -489,6 +500,7 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen,
*
* @exception InvalidKeyException if <code>key</code> is invalid.
*/
@Override
protected int engineGetKeySize(Key key) throws InvalidKeyException {
byte[] encoded = key.getEncoded();
Arrays.fill(encoded, (byte)0);
Expand All @@ -515,6 +527,7 @@ protected int engineGetKeySize(Key key) throws InvalidKeyException {
* wrap the key with this cipher (e.g., a hardware protected key is
* being passed to a software only cipher).
*/
@Override
protected byte[] engineWrap(Key key)
throws IllegalBlockSizeException, InvalidKeyException {
return core.wrap(key);
Expand All @@ -541,6 +554,7 @@ protected byte[] engineWrap(Key key)
* represent a wrapped key of type <code>wrappedKeyType</code> for
* the <code>wrappedKeyAlgorithm</code>.
*/
@Override
protected Key engineUnwrap(byte[] wrappedKey,
String wrappedKeyAlgorithm,
int wrappedKeyType)
Expand Down

1 comment on commit d6468be

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.