Skip to content
Open
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
31 changes: 8 additions & 23 deletions src/main/java/com/ibm/crypto/plus/provider/AESCCMCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
* but engineDoFinal(..) is declared to be able to throw it since it also
* handles user provided output buffers
*/
// OCKDebug.Msg(debPrefix, methodName, "OCKException seen");
// OCKDebug.Msg(debPrefix, methodName, "NativeException seen");
if (!encrypting) {
AEADBadTagException abte = new AEADBadTagException(
"Unable to perform engine doFinal; Possibly a bad tag or bad padding or illegalBlockSize");
provider.setOCKExceptionCause(abte, e);
provider.setExceptionCause(abte, e);
throw abte;
} else {
throw provider.providerException("unable to perform to engineDoFinal ", e);
Expand Down Expand Up @@ -199,11 +199,11 @@ protected int engineDoFinal(ByteBuffer inputByteBuffer, ByteBuffer outputByteBuf
* but engineDoFinal(..) is declared to be able to throw it since it also
* handles user provided output buffers
*/
// OCKDebug.Msg(debPrefix, methodName, "OCKException seen");
// OCKDebug.Msg(debPrefix, methodName, "NativeException seen");
if (!encrypting) {
AEADBadTagException abte = new AEADBadTagException(
"Uanble to perform engine doFinal; Possibly a bad tag or bad padding or illegalBlockSize");
provider.setOCKExceptionCause(abte, e);
provider.setExceptionCause(abte, e);
throw abte;
} else {
throw provider.providerException("unable to perform to engineDoFinal ", e);
Expand Down Expand Up @@ -287,31 +287,16 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[]
authData = null; // Before returning from doFinal(), restore AAD to uninitialized state
return ret;
}
} catch (AEADBadTagException e) {
AEADBadTagException abte = new AEADBadTagException(e.getMessage());
provider.setOCKExceptionCause(abte, e);
requireReinit = true;
throw abte;
} catch (BadPaddingException ock_bpe) {
BadPaddingException bpe = new BadPaddingException(ock_bpe.getMessage());
provider.setOCKExceptionCause(bpe, ock_bpe);
} catch (BadPaddingException | IllegalBlockSizeException bpe) {
requireReinit = true;
throw bpe;
} catch (IllegalBlockSizeException ock_ibse) {
IllegalBlockSizeException ibse = new IllegalBlockSizeException(ock_ibse.getMessage());
provider.setOCKExceptionCause(ibse, ock_ibse);
requireReinit = true;
throw ibse;
} catch (ShortBufferException ock_sbe) {
ShortBufferException sbe = new ShortBufferException(ock_sbe.getMessage());
provider.setOCKExceptionCause(sbe, ock_sbe);
} catch (ShortBufferException sbe) {
throw sbe;
} catch (com.ibm.crypto.plus.provider.base.OCKException ock_excp) {
} catch (com.ibm.crypto.plus.provider.base.NativeException ock_excp) {
requireReinit = true;
AEADBadTagException tagexcp = new AEADBadTagException(ock_excp.getMessage());
provider.setOCKExceptionCause(tagexcp, ock_excp);
provider.setExceptionCause(tagexcp, ock_excp);
throw tagexcp;

} catch (Exception e) {
requireReinit = true;
throw provider.providerException("Failure in engineDoFinal", e);
Expand Down
24 changes: 4 additions & 20 deletions src/main/java/com/ibm/crypto/plus/provider/AESCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,8 @@ protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
} else {
return output;
}
} catch (BadPaddingException ock_bpe) {
BadPaddingException bpe = new BadPaddingException(ock_bpe.getMessage());
provider.setOCKExceptionCause(bpe, ock_bpe);
} catch (BadPaddingException | IllegalBlockSizeException bpe) {
throw bpe;
} catch (IllegalBlockSizeException ock_ibse) {
IllegalBlockSizeException ibse = new IllegalBlockSizeException(ock_ibse.getMessage());
provider.setOCKExceptionCause(ibse, ock_ibse);
throw ibse;
} catch (Exception e) {
throw provider.providerException("Failure in engineDoFinal", e);
}
Expand Down Expand Up @@ -147,18 +141,8 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[]
} else {
return symmetricCipher.doFinal(input, inputOffset, inputLen, output, outputOffset);
}
} catch (BadPaddingException ock_bpe) {
BadPaddingException bpe = new BadPaddingException(ock_bpe.getMessage());
provider.setOCKExceptionCause(bpe, ock_bpe);
throw bpe;
} catch (IllegalBlockSizeException ock_ibse) {
IllegalBlockSizeException ibse = new IllegalBlockSizeException(ock_ibse.getMessage());
provider.setOCKExceptionCause(ibse, ock_ibse);
throw ibse;
} catch (ShortBufferException ock_sbe) {
ShortBufferException sbe = new ShortBufferException(ock_sbe.getMessage());
provider.setOCKExceptionCause(sbe, ock_sbe);
throw sbe;
} catch (BadPaddingException | IllegalBlockSizeException | ShortBufferException exc) {
throw exc;
} catch (Exception e) {
throw provider.providerException("Failure in engineDoFinal", e);
}
Expand Down Expand Up @@ -467,7 +451,7 @@ protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] o
}
} catch (ShortBufferException ock_sbe) {
ShortBufferException sbe = new ShortBufferException(ock_sbe.getMessage());
provider.setOCKExceptionCause(sbe, ock_sbe);
provider.setExceptionCause(sbe, ock_sbe);
throw sbe;
} catch (Exception e) {
throw provider.providerException("Failure in engineDoFinal", e);
Expand Down
75 changes: 21 additions & 54 deletions src/main/java/com/ibm/crypto/plus/provider/AESGCMCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package com.ibm.crypto.plus.provider;

import com.ibm.crypto.plus.provider.base.GCMCipher;
import com.ibm.crypto.plus.provider.base.OCKException;
import com.ibm.crypto.plus.provider.base.NativeException;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.security.AlgorithmParameters;
Expand Down Expand Up @@ -179,15 +179,15 @@ protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
resetVars(true);

throw e;
} catch (OCKException e) {
// OCKDebug.Msg(debPrefix, methodName, "OCKException encountered = " +
} catch (NativeException e) {
// OCKDebug.Msg(debPrefix, methodName, "NativeException encountered = " +
// e.getMessage());

if (!encrypting) {
AEADBadTagException abte = new AEADBadTagException(
"Unable to perform engine doFinal; "
+ "Possibly a bad tag or bad padding or illegalBlockSize");
provider.setOCKExceptionCause(abte, e);
provider.setExceptionCause(abte, e);
resetVars(true);
throw abte;
} else {
Expand Down Expand Up @@ -231,14 +231,14 @@ protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
* handles user provided output buffers
*/
resetVars(true);
// OCKDebug.Msg(debPrefix, methodName, "OCKException seen");
// OCKDebug.Msg(debPrefix, methodName, "NativeException seen");
if (!encrypting) {

AEADBadTagException abte = new AEADBadTagException(
"Unable to perform engine doFinal; "
+ "Possibly a bad tag or bad padding or illegalBlockSize");

provider.setOCKExceptionCause(abte, e);
provider.setExceptionCause(abte, e);
throw abte;
} else {
throw provider.providerException("unable to perform to engineDoFinal ", e);
Expand Down Expand Up @@ -284,15 +284,15 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[]
// requireReinit = true;

throw e;
} catch (OCKException e) {
} catch (NativeException e) {

//updateCalled = false;
//
//requireReinit = true;

if (!encrypting) {
AEADBadTagException abte = new AEADBadTagException(e.getMessage());
provider.setOCKExceptionCause(abte, e);
provider.setExceptionCause(abte, e);
// OCKDebug.Msg (debPrefix, methodName, "Ret from engineDoFinal: ");
resetVars(true);
throw abte;
Expand Down Expand Up @@ -357,30 +357,16 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[]
authData = null; // Before returning from doFinal(), restore AAD to uninitialized state
return ret;
}
} catch (AEADBadTagException e) {
} catch (BadPaddingException | IllegalBlockSizeException bpe) {
resetVars(true);
AEADBadTagException abte = new AEADBadTagException(e.getMessage());
provider.setOCKExceptionCause(abte, e);
throw abte;
} catch (BadPaddingException ock_bpe) {
resetVars(true);
BadPaddingException bpe = new BadPaddingException(ock_bpe.getMessage());
provider.setOCKExceptionCause(bpe, ock_bpe);
throw bpe;
} catch (IllegalBlockSizeException ock_ibse) {
resetVars(true);
IllegalBlockSizeException ibse = new IllegalBlockSizeException(ock_ibse.getMessage());
provider.setOCKExceptionCause(ibse, ock_ibse);
throw ibse;
} catch (ShortBufferException ock_sbe) {
} catch (ShortBufferException sbe) {
sbeInLastFinalEncrypt = encrypting;
ShortBufferException sbe = new ShortBufferException(ock_sbe.getMessage());
provider.setOCKExceptionCause(sbe, ock_sbe);
throw sbe;
} catch (com.ibm.crypto.plus.provider.base.OCKException ock_excp) {
} catch (com.ibm.crypto.plus.provider.base.NativeException ock_excp) {
resetVars(true);
AEADBadTagException tagexcp = new AEADBadTagException(ock_excp.getMessage());
provider.setOCKExceptionCause(tagexcp, ock_excp);
provider.setExceptionCause(tagexcp, ock_excp);
throw tagexcp;
} catch (Exception e) {
resetVars(true);
Expand All @@ -390,7 +376,7 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[]

private byte[] doFinalForUpdates(byte[] input, int inputOffset, int inputLen)
throws IllegalBlockSizeException, BadPaddingException, AEADBadTagException,
IllegalStateException, OCKException {
IllegalStateException, NativeException {
//final String methodName = "byte[] doFinalForUpdates";
// OCKDebug.Msg(debPrefix, methodName, "inputOffset=" + inputOffset + "
// inputLen=" + inputLen + " input[]", input);
Expand Down Expand Up @@ -433,7 +419,7 @@ private byte[] doFinalForUpdates(byte[] input, int inputOffset, int inputLen)

private int doFinalForUpdates(byte[] input, int inputOffset, int inputLen, byte[] output,
int outputOffset) throws ShortBufferException, IllegalBlockSizeException,
BadPaddingException, AEADBadTagException, IllegalStateException, OCKException {
BadPaddingException, AEADBadTagException, IllegalStateException, NativeException {
//final String methodName = "doFinalForUpdates";
checkReinit();

Expand Down Expand Up @@ -1110,35 +1096,16 @@ protected int doUpdate(byte[] input, int inputOffset, int inputLen, byte[] outpu
}
}

} catch (IllegalStateException ock_illse) {
sbeInLastUpdateEncrypt = false;
IllegalStateException illse = new IllegalStateException(ock_illse.getMessage());
provider.setOCKExceptionCause(illse, ock_illse);
throw illse;
} catch (AEADBadTagException e) {
sbeInLastUpdateEncrypt = false;
AEADBadTagException abte = new AEADBadTagException(e.getMessage());
provider.setOCKExceptionCause(abte, e);
throw abte;
} catch (BadPaddingException ock_bpe) {
sbeInLastUpdateEncrypt = false;
BadPaddingException bpe = new BadPaddingException(ock_bpe.getMessage());
provider.setOCKExceptionCause(bpe, ock_bpe);
throw bpe;
} catch (IllegalBlockSizeException ock_ibse) {
} catch (IllegalStateException | BadPaddingException | IllegalBlockSizeException exc) {
sbeInLastUpdateEncrypt = false;
IllegalBlockSizeException ibse = new IllegalBlockSizeException(ock_ibse.getMessage());
provider.setOCKExceptionCause(ibse, ock_ibse);
throw ibse;
} catch (ShortBufferException ock_sbe) {
throw exc;
} catch (ShortBufferException sbe) {
sbeInLastUpdateEncrypt = encrypting;
ShortBufferException sbe = new ShortBufferException(ock_sbe.getMessage());
provider.setOCKExceptionCause(sbe, ock_sbe);
throw sbe;
} catch (com.ibm.crypto.plus.provider.base.OCKException ock_excp) {
} catch (com.ibm.crypto.plus.provider.base.NativeException ock_excp) {
sbeInLastUpdateEncrypt = false;
AEADBadTagException tagexcp = new AEADBadTagException(ock_excp.getMessage());
provider.setOCKExceptionCause(tagexcp, ock_excp);
provider.setExceptionCause(tagexcp, ock_excp);
throw tagexcp;
} catch (Exception e) {
sbeInLastUpdateEncrypt = false;
Expand Down Expand Up @@ -1223,7 +1190,7 @@ protected void engineUpdateAAD(ByteBuffer src) {

private int fillOutputBuffer(byte[] finalBuf, int finalOffset, byte[] output, int outOfs,
int finalBufLen, byte[] input) throws ShortBufferException, BadPaddingException,
IllegalBlockSizeException, OCKException {
IllegalBlockSizeException, NativeException {
//final String methodName = "fillOutputBuffer";
// OCKDebug.Msg(debPrefix, methodName, "Entering finalOffset = ", finalBuf);
int len;
Expand All @@ -1245,7 +1212,7 @@ private int fillOutputBuffer(byte[] finalBuf, int finalOffset, byte[] output, in

private int finalNoPadding(byte[] in, int inOfs, byte[] out, int outOfs, int len)
throws IllegalBlockSizeException, AEADBadTagException, BadPaddingException,
ShortBufferException, OCKException {
ShortBufferException, NativeException {

//final String methodName = "finalNoPadding";
// OCKDebug.Msg(debPrefix, methodName, "Entering in" + in + " len=" + 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package com.ibm.crypto.plus.provider;

import com.ibm.crypto.plus.provider.base.AESKeyWrap;
import com.ibm.crypto.plus.provider.base.OCKException;
import com.ibm.crypto.plus.provider.base.NativeException;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
Expand Down Expand Up @@ -110,7 +110,7 @@ protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
} else {
out = cipher.unwrap(buffer, 0, bufSize);
}
} catch (OCKException ocke) {
} catch (NativeException ocke) {
throw new ProviderException("Operation doFinal failed", ocke);
}
this.bufSize = 0;
Expand Down
29 changes: 5 additions & 24 deletions src/main/java/com/ibm/crypto/plus/provider/ChaCha20Cipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,8 @@ protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
} else {
return output;
}
} catch (BadPaddingException ock_bpe) {
BadPaddingException bpe = new BadPaddingException(ock_bpe.getMessage());
provider.setOCKExceptionCause(bpe, ock_bpe);
throw bpe;
} catch (IllegalBlockSizeException ock_ibse) {
IllegalBlockSizeException ibse = new IllegalBlockSizeException(ock_ibse.getMessage());
provider.setOCKExceptionCause(ibse, ock_ibse);
throw ibse;
} catch (BadPaddingException | IllegalBlockSizeException exc) {
throw exc;
} catch (Exception e) {
throw provider.providerException("Failure in engineDoFinal", e);
} finally {
Expand All @@ -88,19 +82,8 @@ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[]
try {
int ret = symmetricCipher.doFinal(input, inputOffset, inputLen, output, outputOffset);
return ret;
} catch (BadPaddingException ock_bpe) {
BadPaddingException bpe = new BadPaddingException(ock_bpe.getMessage());
provider.setOCKExceptionCause(bpe, ock_bpe);
throw bpe;
} catch (IllegalBlockSizeException ock_ibse) {

IllegalBlockSizeException ibse = new IllegalBlockSizeException(ock_ibse.getMessage());
provider.setOCKExceptionCause(ibse, ock_ibse);
throw ibse;
} catch (ShortBufferException ock_sbe) {
ShortBufferException sbe = new ShortBufferException(ock_sbe.getMessage());
provider.setOCKExceptionCause(sbe, ock_sbe);
throw sbe;
} catch (BadPaddingException | IllegalBlockSizeException | ShortBufferException exc) {
throw exc;
} catch (Exception e) {
throw provider.providerException("Failure in engineDoFinal", e);
} finally {
Expand Down Expand Up @@ -326,9 +309,7 @@ protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] o

try {
return symmetricCipher.update(input, inputOffset, inputLen, output, outputOffset);
} catch (ShortBufferException ock_sbe) {
ShortBufferException sbe = new ShortBufferException(ock_sbe.getMessage());
provider.setOCKExceptionCause(sbe, ock_sbe);
} catch (ShortBufferException sbe) {
throw sbe;
} catch (Exception e) {
throw provider.providerException("Failure in engineUpdate", e);
Expand Down
Loading
Loading