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
5 changes: 3 additions & 2 deletions src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidParameterException;
import java.security.InvalidKeyException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
Expand Down Expand Up @@ -522,8 +523,8 @@ private void wolfCryptSetDirection(int opmode)
break;

default:
throw new InvalidKeyException(
"Cipher opmode must be ENCRYPT_MODE or DECRPYT_MODE");
throw new InvalidParameterException(
"Cipher opmode must be ENCRYPT_MODE or DECRYPT_MODE");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.security.InvalidKeyException;
import java.security.InvalidAlgorithmParameterException;
import java.security.AlgorithmParameters;
import java.security.InvalidParameterException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.AlgorithmParameters;

Expand Down Expand Up @@ -194,6 +195,35 @@ public void testGetBlockSize()
}
}

@Test
public void testAesInvalidModeThrowsInvalidParameterException()
throws NoSuchProviderException, NoSuchAlgorithmException,
NoSuchPaddingException, InvalidKeyException,
InvalidAlgorithmParameterException {

Cipher cipher;

try {
cipher = Cipher.getInstance("AES/CBC/NoPadding", jceProvider);
} catch (NoSuchAlgorithmException e) {
/* skip if AES-CBC is not enabled */
return;
}

SecretKeySpec keySpec = new SecretKeySpec(new byte[16], "AES");
IvParameterSpec ivSpec = new IvParameterSpec(new byte[16]);

int invalidMode = 100;

try {
cipher.init(invalidMode, keySpec, ivSpec);
fail("Cipher.init() with invalid mode should throw " +
"InvalidParameterException");
} catch (InvalidParameterException e) {
/* expected */
}
}

@Test
public void testAesCbcNoPadding()
throws NoSuchProviderException, NoSuchAlgorithmException,
Expand Down
Loading