Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
<property name="arrayInitIndent" value="8"/>
<property name="caseIndent" value="4"/>
</module>
<module name="LeftCurly"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="RedundantImport"/>
<module name="RightCurly"/>
<module name="StringLiteralEquality"/>
<module name="StringLiteralEquality"/>
<module name="UnusedImports"/>
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/ibm/crypto/plus/provider/AESCCMCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[]
throw new ShortBufferException(
"The output buffer is too small to hold the encryption result.");
}
} else // decrypting
{
} else { // decrypting
if ((output.length - outputOffset) < (input.length - tagLenInBytes)) {
throw new ShortBufferException(
"The output buffer is too small to hold the decryption result.");
Expand Down Expand Up @@ -276,8 +275,7 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[]

} else { // else decrypting

if ((input == null) || (input.length == 0)) // If this doFinal( ) carries no data to be encrypted
{
if ((input == null) || (input.length == 0)) { // If this doFinal( ) carries no data to be encrypted
return 0;
}

Expand Down Expand Up @@ -715,8 +713,7 @@ protected void engineUpdateAAD(ByteBuffer src) {
if (this.authData == null) {
this.authData = new byte[src.remaining()];
src.get(this.authData, 0, this.authData.length);
} else // else this.authData != null
{
} else { // else this.authData != null
byte[] tempAuthData = new byte[this.authData.length + src.remaining()];
System.arraycopy(this.authData, 0, tempAuthData, 0, this.authData.length);
src.get(tempAuthData, this.authData.length, src.remaining());
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/ibm/crypto/plus/provider/AESGCMCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,7 @@ protected int doUpdate(byte[] input, int inputOffset, int inputLen, byte[] outpu
// GCMCipher.do_GCM_UpdForUpdateDecrypt=" + outLen);

// outLen = cipher.decrypt(buffer, 0, len, output, outputOffset);
} // decrypting
else {
} else { // decrypting
// OCKDebug.Msg(debPrefix, methodName, "Encrypting");
// OCKDebug.Msg(debPrefix, methodName, "FirstUpdate generateIV");

Expand Down Expand Up @@ -1093,8 +1092,7 @@ protected int doUpdate(byte[] input, int inputOffset, int inputLen, byte[] outpu
tagLenInBytes, buffer, 0, buffered, output, outputOffset,
authData, provider);
// outLen = cipher.decrypt(buffer, 0, buffered, output, outputOffset);
} // decrypting
else {
} else { // decrypting
outLen = GCMCipher.do_GCM_UpdForUpdateEncrypt(ockContext, Key.getValue(), IV,
tagLenInBytes, buffer, 0, buffered, output, outputOffset,
authData, provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ protected void engineInit(byte[] encoded) throws IOException {
if (value.getData().available() != 0) {
throw new IOException("CCM parameter parsing error: Extra data is present.");
}
} else // else no tag length present
{
} else { // else no tag length present
throw new InvalidParameterException(
"CCM parameters parsing error: No tag length is present.");
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/ibm/crypto/plus/provider/DESedeCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
* modeUpperCase.equals("CFB")
*/) {
this.mode = modeUpperCase;
} /*
* else if (modeUpperCase.equals("CFB64")) { this.mode = "CFB"; }
*/ else {
} else {
throw new NoSuchAlgorithmException("Cipher mode: " + mode + " not found");
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/ibm/crypto/plus/provider/PBEKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ public boolean isDestroyed() {
*/
@java.io.Serial
private void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException
{
throws IOException, ClassNotFoundException {
s.defaultReadObject();
if (key == null) {
throw new InvalidObjectException(
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/ibm/crypto/plus/provider/PBEKeyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public PBEWithHmacSHA512_256AndAES_256(OpenJCEPlusProvider provider) {
* is inappropriate for this key factory to produce a public key.
*/
protected SecretKey engineGenerateSecret(KeySpec keySpec)
throws InvalidKeySpecException
{
throws InvalidKeySpecException {
if (!(keySpec instanceof PBEKeySpec)) {
throw new InvalidKeySpecException("Invalid key spec");
}
Expand Down Expand Up @@ -194,8 +193,7 @@ protected KeySpec engineGetKeySpec(SecretKey key, Class<?> keySpecCl)
* this key factory.
*/
protected SecretKey engineTranslateKey(SecretKey key)
throws InvalidKeyException
{
throws InvalidKeyException {
try {
if ((key != null) && (key.getFormat() != null) && (key.getFormat().equalsIgnoreCase("RAW"))) {

Expand Down
15 changes: 5 additions & 10 deletions src/main/java/com/ibm/crypto/plus/provider/PBES2Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
}

protected void engineInit(AlgorithmParameterSpec paramSpec)
throws InvalidParameterSpecException
{
throws InvalidParameterSpecException {
if (!(paramSpec instanceof PBEParameterSpec)) {
throw new InvalidParameterSpecException ("Inappropriate parameter specification");
}
Expand All @@ -192,8 +191,7 @@ protected void engineInit(AlgorithmParameterSpec paramSpec)
}

protected void engineInit(byte[] encoded)
throws IOException
{
throws IOException {
DerValue pBES2_params = new DerValue(encoded);
if (pBES2_params.tag != DerValue.tag_Sequence) {
throw new IOException("PBE parameter parsing error: "
Expand Down Expand Up @@ -307,15 +305,13 @@ private String parseES(DerValue encryptionScheme) throws IOException {
}

protected void engineInit(byte[] encoded, String decodingMethod)
throws IOException
{
throws IOException {
engineInit(encoded);
}

protected <T extends AlgorithmParameterSpec>
T engineGetParameterSpec(Class<T> paramSpec)
throws InvalidParameterSpecException
{
throws InvalidParameterSpecException {
if (paramSpec.isAssignableFrom(PBEParameterSpec.class)) {
return paramSpec.cast(
new PBEParameterSpec(this.salt, this.iCount, this.cipherParam));
Expand Down Expand Up @@ -368,8 +364,7 @@ protected byte[] engineGetEncoded() throws IOException {
}

protected byte[] engineGetEncoded(String encodingMethod)
throws IOException
{
throws IOException {
return engineGetEncoded();
}

Expand Down
20 changes: 5 additions & 15 deletions src/main/java/com/ibm/crypto/plus/provider/RSAPSSSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,47 +381,37 @@ protected void engineSetParameter(AlgorithmParameterSpec params)
|| mgfMessageDigest.equalsIgnoreCase("SHA")) {
throwException = false;
}
}

else if (messageDigest.equalsIgnoreCase("SHA224")
} else if (messageDigest.equalsIgnoreCase("SHA224")
|| messageDigest.equalsIgnoreCase("SHA-224")) {
if (mgfMessageDigest.equalsIgnoreCase("SHA224")
|| mgfMessageDigest.equalsIgnoreCase("SHA-224")) {
throwException = false;
}
}

else if (messageDigest.equalsIgnoreCase("SHA256")
} else if (messageDigest.equalsIgnoreCase("SHA256")
|| messageDigest.equalsIgnoreCase("SHA-256")
|| messageDigest.equalsIgnoreCase("SHA2")) {
if (mgfMessageDigest.equalsIgnoreCase("SHA256")
|| mgfMessageDigest.equalsIgnoreCase("SHA-256")
|| mgfMessageDigest.equalsIgnoreCase("SHA2")) {
throwException = false;
}
}

else if (messageDigest.equalsIgnoreCase("SHA384")
} else if (messageDigest.equalsIgnoreCase("SHA384")
|| messageDigest.equalsIgnoreCase("SHA-384")
|| messageDigest.equalsIgnoreCase("SHA3")) {
if (mgfMessageDigest.equalsIgnoreCase("SHA384")
|| mgfMessageDigest.equalsIgnoreCase("SHA-384")
|| mgfMessageDigest.equalsIgnoreCase("SHA3")) {
throwException = false;
}
}

else if (messageDigest.equalsIgnoreCase("SHA512")
} else if (messageDigest.equalsIgnoreCase("SHA512")
|| messageDigest.equalsIgnoreCase("SHA-512")
|| messageDigest.equalsIgnoreCase("SHA5")) {
if (mgfMessageDigest.equalsIgnoreCase("SHA512")
|| mgfMessageDigest.equalsIgnoreCase("SHA-512")
|| mgfMessageDigest.equalsIgnoreCase("SHA5")) {
throwException = false;
}
}

else if (messageDigest.equalsIgnoreCase("SHA512/224")
} else if (messageDigest.equalsIgnoreCase("SHA512/224")
|| messageDigest.equalsIgnoreCase("SHA-512/224")) {
if (mgfMessageDigest.equalsIgnoreCase("SHA512/224")
|| mgfMessageDigest.equalsIgnoreCase("SHA-512/224")) {
Expand Down
16 changes: 4 additions & 12 deletions src/test/java/ibm/jceplus/junit/base/BaseTestAES.java
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,7 @@ protected void encryptDecrypt(String algorithm, boolean requireLengthMultipleBlo
// Run encrypt/decrypt test using just doFinal calls
//
protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMultipleBlockSize,
AlgorithmParameters algParams, byte[] message, Cipher cp) throws Exception

{
AlgorithmParameters algParams, byte[] message, Cipher cp) throws Exception {
if (algParams == null) {
cp.init(Cipher.ENCRYPT_MODE, key);
} else {
Expand Down Expand Up @@ -914,9 +912,7 @@ protected void encryptDecryptPartialUpdate(String algorithm,
//
protected void encryptDecryptReuseObject(String algorithm,
boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message, Cipher cp)
throws Exception

{
throws Exception {
if (algParams == null) {
cp.init(Cipher.ENCRYPT_MODE, key);
} else {
Expand Down Expand Up @@ -960,9 +956,7 @@ protected void encryptDecryptReuseObject(String algorithm,
//
protected void encryptDecryptDoFinalCopySafe(String algorithm,
boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message, Cipher cp)
throws Exception

{
throws Exception {
if (algParams == null) {
cp.init(Cipher.ENCRYPT_MODE, key);
} else {
Expand Down Expand Up @@ -1007,9 +1001,7 @@ protected void encryptDecryptDoFinalCopySafe(String algorithm,
//
protected void encryptDecryptUpdateCopySafe(String algorithm,
boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message, Cipher cp)
throws Exception

{
throws Exception {
if (algParams == null) {
cp.init(Cipher.ENCRYPT_MODE, key);
} else {
Expand Down
39 changes: 11 additions & 28 deletions src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ public void testAESCCM() throws Exception {
if (printJunitTrace)
System.out.println(toHexString(cipherText));
}
} else // else cipherText == null
{
if (printJunitTrace)
} else { // else cipherText == null
if (printJunitTrace) {
System.out.println(
"BaseTestAESCCM.java: testAESCCM(): ERROR: The encrypted text is NULL. Iteration counter = "
+ iterationCounter);
}
RuntimeException rtex = new RuntimeException();
rtex.printStackTrace(System.out);
Assertions.fail();
Expand Down Expand Up @@ -370,9 +370,7 @@ private byte[] encrypt(byte[] plaintext, SecretKey key, byte[] IV, int ccmTagLen
// All the encryption was performed on Cipher.doFinal( )
cipherText = new byte[cipherText2.length];
System.arraycopy(cipherText2, 0, cipherText, 0, cipherText2.length);
}

else if (whichMethod == 1) {
} else if (whichMethod == 1) {
if (printJunitTrace)
System.out.println("BaseTestAESCCM.java: encrypt(): METHOD CHOSEN = 1");

Expand All @@ -393,9 +391,7 @@ else if (whichMethod == 1) {
// All the encryption was performed on Cipher.doFinal( )
cipherText = new byte[cipherText2.length];
System.arraycopy(cipherText2, 0, cipherText, 0, cipherText2.length);
}

else if (whichMethod == 2) {
} else if (whichMethod == 2) {
if (printJunitTrace)
System.out.println("BaseTestAESCCM.java: encrypt(): METHOD CHOSEN = 2");
int outputSizeNeeded = cipher.getOutputSize(plaintext.length);
Expand Down Expand Up @@ -434,9 +430,7 @@ else if (whichMethod == 2) {
// All the encryption was performed on Cipher.doFinal( )
cipherText = new byte[cipherText2.length];
System.arraycopy(cipherText2, 0, cipherText, 0, cipherText2.length);
}

else if (whichMethod == 3) {
} else if (whichMethod == 3) {
if (printJunitTrace)
System.out.println("BaseTestAESCCM.java: encrypt(): METHOD CHOSEN = 3");
int outputSizeNeeded = cipher.getOutputSize(plaintext.length);
Expand Down Expand Up @@ -476,9 +470,7 @@ else if (whichMethod == 3) {
// All the encryption was performed on Cipher.doFinal( )
cipherText = new byte[cipherText2.length];
System.arraycopy(cipherText2, 0, cipherText, 0, cipherText2.length);
}

else if (whichMethod == 4) {
} else if (whichMethod == 4) {
if (printJunitTrace)
System.out.println("BaseTestAESCCM.java: encrypt(): METHOD CHOSEN = 4");

Expand Down Expand Up @@ -629,9 +621,7 @@ private String decrypt(byte[] cipherText, SecretKey key, byte[] IV, int ccmTagLe
// All the decryption was performed on Cipher.doFinal( )
decryptedText = new byte[decryptedText2.length];
System.arraycopy(decryptedText2, 0, decryptedText, 0, decryptedText2.length);
}

else if (whichMethod == 1) {
} else if (whichMethod == 1) {
if (printJunitTrace)
System.out.println("BaseTestAESCCM.java: decrypt(): METHOD CHOSEN = 1");

Expand All @@ -654,9 +644,7 @@ else if (whichMethod == 1) {
decryptedText = new byte[decryptedText2.length];
System.arraycopy(decryptedText2, 0, decryptedText, 0, decryptedText2.length);

}

else if (whichMethod == 2) {
} else if (whichMethod == 2) {
if (printJunitTrace)
System.out.println("BaseTestAESCCM.java: decrypt(): METHOD CHOSEN = 2");
int outputSizeNeeded = cipher.getOutputSize(cipherText.length);
Expand Down Expand Up @@ -695,9 +683,7 @@ else if (whichMethod == 2) {
// All the decryption was performed on Cipher.doFinal( )
decryptedText = new byte[decryptedText2.length];
System.arraycopy(decryptedText2, 0, decryptedText, 0, decryptedText2.length);
}

else if (whichMethod == 3) {
} else if (whichMethod == 3) {
if (printJunitTrace)
System.out.println("BaseTestAESCCM.java: decrypt(): METHOD CHOSEN = 3");
int outputSizeNeeded = cipher.getOutputSize(cipherText.length);
Expand Down Expand Up @@ -736,9 +722,7 @@ else if (whichMethod == 3) {
// All the decryption was performed on Cipher.doFinal( )
decryptedText = new byte[decryptedText2.length];
System.arraycopy(decryptedText2, 0, decryptedText, 0, decryptedText2.length);
}

else if (whichMethod == 4) {
} else if (whichMethod == 4) {
if (printJunitTrace)
System.out.println("BaseTestAESCCM.java: decrypt(): METHOD CHOSEN = 4");
int outputSizeNeeded = cipher.getOutputSize(cipherText.length);
Expand Down Expand Up @@ -780,7 +764,6 @@ else if (whichMethod == 4) {
decryptedText = new byte[decryptedText2.length];
System.arraycopy(decryptedText2, 0, decryptedText, 0, decryptedText2.length);
}

} catch (AEADBadTagException abte) {
if (printJunitTrace)
System.out.println(
Expand Down
Loading