summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-02-11 17:05:43 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-02-11 17:05:43 +0000
commited1580603b0e13298592b25fb4b5662fc8006f61 (patch)
tree7e894aa1eb2652a1fbe2c3a85d06876e2d4e2b40
parent3882bf4552a2b8f3be5eda9df035288005e8d3b7 (diff)
parent1854476568c6f2feb9eef50343b7e2a18e072e35 (diff)
downloadbouncycastle-ed1580603b0e13298592b25fb4b5662fc8006f61.tar.gz
Merge "Match ciphers by exact mode name" am: fc2c71d093 am: 1854476568
Change-Id: I0be92422ca6b9bd6b501b400302e1038597b1f8c
-rw-r--r--bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
index d3d04db4..269edf67 100644
--- a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
+++ b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
@@ -300,18 +300,23 @@ public class BaseBlockCipher
{
modeName = Strings.toUpperCase(mode);
- if (modeName.equals("ECB"))
+ // Android-changed: Ignore case since modes are case insensitive
+ // https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html
+ if (modeName.equalsIgnoreCase("ECB"))
{
ivLength = 0;
cipher = new BufferedGenericBlockCipher(baseEngine);
}
- else if (modeName.equals("CBC"))
+ // Android-changed: Ignore case since modes are case insensitive
+ // https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html
+ else if (modeName.equalsIgnoreCase("CBC"))
{
ivLength = baseEngine.getBlockSize();
cipher = new BufferedGenericBlockCipher(
new CBCBlockCipher(baseEngine));
}
- else if (modeName.startsWith("OFB"))
+ // Android-changed: Use equals instead of startsWith to avoid unintentional matches
+ else if (modeName.equalsIgnoreCase("OFB"))
{
ivLength = baseEngine.getBlockSize();
if (modeName.length() != 3)
@@ -327,7 +332,8 @@ public class BaseBlockCipher
new OFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
}
}
- else if (modeName.startsWith("CFB"))
+ // Android-changed: Use equals instead of startsWith to avoid unintentional matches
+ else if (modeName.equalsIgnoreCase("CFB"))
{
ivLength = baseEngine.getBlockSize();
if (modeName.length() != 3)
@@ -372,7 +378,8 @@ public class BaseBlockCipher
}
*/
// END Android-removed: Unsupported modes
- else if (modeName.startsWith("CTR"))
+ // Android-changed: Use equals instead of startsWith to avoid unintentional matches
+ else if (modeName.equalsIgnoreCase("CTR"))
{
ivLength = baseEngine.getBlockSize();
fixedIv = false;
@@ -408,12 +415,14 @@ public class BaseBlockCipher
}
*/
// END Android-removed: Unsupported modes
- else if (modeName.startsWith("CTS"))
+ // Android-changed: Use equals instead of startsWith to avoid unintentional matches
+ else if (modeName.equalsIgnoreCase("CTS"))
{
ivLength = baseEngine.getBlockSize();
cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(new CBCBlockCipher(baseEngine)));
}
- else if (modeName.startsWith("CCM"))
+ // Android-changed: Use equals instead of startsWith to avoid unintentional matches
+ else if (modeName.equalsIgnoreCase("CCM"))
{
ivLength = 12; // CCM nonce 7..13 bytes
// BEGIN Android-removed: Unsupported algorithms