JCE: remove switches on Strings for Android

pull/2/merge
Chris Conlon 2017-03-24 10:42:49 -06:00
parent 7036d06d19
commit b4be3b3655
2 changed files with 35 additions and 42 deletions

View File

@ -129,26 +129,22 @@ public class WolfCryptCipher extends CipherSpi {
int supported = 0;
switch (mode) {
case "ECB":
/* RSA is ECB mode */
if (cipherType == CipherType.WC_RSA) {
cipherMode = CipherMode.WC_ECB;
supported = 1;
}
break;
if (mode.equals("ECB")) {
case "CBC":
/* AES and 3DES support CBC */
if (cipherType == CipherType.WC_AES ||
cipherType == CipherType.WC_DES3 ) {
cipherMode = CipherMode.WC_CBC;
supported = 1;
}
break;
/* RSA is ECB mode */
if (cipherType == CipherType.WC_RSA) {
cipherMode = CipherMode.WC_ECB;
supported = 1;
}
default:
break;
} else if (mode.equals("CBC")) {
/* AES and 3DES support CBC */
if (cipherType == CipherType.WC_AES ||
cipherType == CipherType.WC_DES3 ) {
cipherMode = CipherMode.WC_CBC;
supported = 1;
}
}
if (supported == 0) {
@ -163,24 +159,20 @@ public class WolfCryptCipher extends CipherSpi {
int supported = 0;
switch (padding) {
case "NoPadding":
if (cipherType == CipherType.WC_AES ||
cipherType == CipherType.WC_DES3) {
paddingType = PaddingType.WC_NONE;
supported = 1;
}
break;
if (padding.equals("NoPadding")) {
case "PKCS1Padding":
if (cipherType == CipherType.WC_RSA) {
paddingType = PaddingType.WC_PKCS1;
supported = 1;
}
break;
if (cipherType == CipherType.WC_AES ||
cipherType == CipherType.WC_DES3) {
paddingType = PaddingType.WC_NONE;
supported = 1;
}
default:
break;
} else if (padding.equals("PKCS1Padding")) {
if (cipherType == CipherType.WC_RSA) {
paddingType = PaddingType.WC_PKCS1;
supported = 1;
}
}
if (supported == 0) {

View File

@ -285,14 +285,15 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi {
byte secret[] = engineGenerateSecret();
switch (algorithm) {
case "DES":
return (SecretKey)new DESKeySpec(secret);
case "DESede":
return (SecretKey)new DESedeKeySpec(secret);
case "AES":
default:
return new SecretKeySpec(secret, algorithm);
if (algorithm.equals("DES")) {
return (SecretKey)new DESKeySpec(secret);
} else if (algorithm.equals("DESede")) {
return (SecretKey)new DESedeKeySpec(secret);
} else {
/* AES and default */
return new SecretKeySpec(secret, algorithm);
}
}