summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-07-24 17:25:58 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-07-24 17:25:58 +0700
commit5e741168c3ecfb47f149ea6a66bf231528ea07e0 (patch)
tree93a589ada4d6ef397f42d419f8a045c5148311f6
parentAnother round of TLS porting from Java (diff)
downloadBouncyCastle.NET-ed25519-5e741168c3ecfb47f149ea6a66bf231528ea07e0.tar.xz
Add GetCipherType method and refactor
-rw-r--r--crypto/src/crypto/tls/TlsUtilities.cs82
1 files changed, 41 insertions, 41 deletions
diff --git a/crypto/src/crypto/tls/TlsUtilities.cs b/crypto/src/crypto/tls/TlsUtilities.cs
index a7932c9cc..ffb2fc3e6 100644
--- a/crypto/src/crypto/tls/TlsUtilities.cs
+++ b/crypto/src/crypto/tls/TlsUtilities.cs
@@ -789,6 +789,44 @@ namespace Org.BouncyCastle.Crypto.Tls
             return v;
         }
 
+        public static int GetCipherType(int ciphersuite)
+        {
+            switch (GetEncryptionAlgorithm(ciphersuite))
+            {
+            case EncryptionAlgorithm.AES_128_GCM:
+            case EncryptionAlgorithm.AES_256_GCM:
+            case EncryptionAlgorithm.AES_128_CCM:
+            case EncryptionAlgorithm.AES_128_CCM_8:
+            case EncryptionAlgorithm.AES_256_CCM:
+            case EncryptionAlgorithm.AES_256_CCM_8:
+            case EncryptionAlgorithm.CAMELLIA_128_GCM:
+            case EncryptionAlgorithm.CAMELLIA_256_GCM:
+            case EncryptionAlgorithm.AEAD_CHACHA20_POLY1305:
+                return CipherType.aead;
+
+            case EncryptionAlgorithm.RC2_CBC_40:
+            case EncryptionAlgorithm.IDEA_CBC:
+            case EncryptionAlgorithm.DES40_CBC:
+            case EncryptionAlgorithm.DES_CBC:
+            case EncryptionAlgorithm.cls_3DES_EDE_CBC:
+            case EncryptionAlgorithm.AES_128_CBC:
+            case EncryptionAlgorithm.AES_256_CBC:
+            case EncryptionAlgorithm.CAMELLIA_128_CBC:
+            case EncryptionAlgorithm.CAMELLIA_256_CBC:
+            case EncryptionAlgorithm.SEED_CBC:
+                return CipherType.block;
+
+            case EncryptionAlgorithm.RC4_40:
+            case EncryptionAlgorithm.RC4_128:
+            case EncryptionAlgorithm.ESTREAM_SALSA20:
+            case EncryptionAlgorithm.SALSA20:
+                return CipherType.stream;
+
+            default:
+                throw new TlsFatalAlert(AlertDescription.internal_error);
+            }
+        }
+
         public static int GetEncryptionAlgorithm(int ciphersuite)
         {
             switch (ciphersuite)
@@ -1206,55 +1244,17 @@ namespace Org.BouncyCastle.Crypto.Tls
 
         public static bool IsAeadCipherSuite(int ciphersuite)
         {
-            switch (GetEncryptionAlgorithm(ciphersuite))
-            {
-            case EncryptionAlgorithm.AES_128_GCM:
-            case EncryptionAlgorithm.AES_256_GCM:
-            case EncryptionAlgorithm.AES_128_CCM:
-            case EncryptionAlgorithm.AES_128_CCM_8:
-            case EncryptionAlgorithm.AES_256_CCM:
-            case EncryptionAlgorithm.AES_256_CCM_8:
-            case EncryptionAlgorithm.CAMELLIA_128_GCM:
-            case EncryptionAlgorithm.CAMELLIA_256_GCM:
-            case EncryptionAlgorithm.AEAD_CHACHA20_POLY1305:
-                return true;
-            default:
-                return false;
-            }
+            return CipherType.aead == GetCipherType(ciphersuite);
         }
 
         public static bool IsBlockCipherSuite(int ciphersuite)
         {
-            switch (GetEncryptionAlgorithm(ciphersuite))
-            {
-            case EncryptionAlgorithm.RC2_CBC_40:
-            case EncryptionAlgorithm.IDEA_CBC:
-            case EncryptionAlgorithm.DES40_CBC:
-            case EncryptionAlgorithm.DES_CBC:
-            case EncryptionAlgorithm.cls_3DES_EDE_CBC:
-            case EncryptionAlgorithm.AES_128_CBC:
-            case EncryptionAlgorithm.AES_256_CBC:
-            case EncryptionAlgorithm.CAMELLIA_128_CBC:
-            case EncryptionAlgorithm.CAMELLIA_256_CBC:
-            case EncryptionAlgorithm.SEED_CBC:
-                return true;
-            default:
-                return false;
-            }
+            return CipherType.block == GetCipherType(ciphersuite);
         }
 
         public static bool IsStreamCipherSuite(int ciphersuite)
         {
-            switch (GetEncryptionAlgorithm(ciphersuite))
-            {
-            case EncryptionAlgorithm.RC4_40:
-            case EncryptionAlgorithm.RC4_128:
-            case EncryptionAlgorithm.ESTREAM_SALSA20:
-            case EncryptionAlgorithm.SALSA20:
-                return true;
-            default:
-                return false;
-            }
+            return CipherType.stream == GetCipherType(ciphersuite);
         }
 
         public static bool IsValidCipherSuiteForVersion(int cipherSuite, ProtocolVersion serverVersion)