diff options
author | lloyd <[email protected]> | 2012-01-20 17:35:01 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-01-20 17:35:01 +0000 |
commit | 11545504a34dba54277345b5c39390ef3cdc74f4 (patch) | |
tree | de6809be5486c87a8a33d53de8db60262a1ec01a /src | |
parent | 50840e48f5b7bed3eb0de472d9d5ef15f231da83 (diff) |
Convert to using a switch statement here. It's faster, and offers
better checking (for instance, the DHE/RSA/SEED ciphersuite was not
there, instead the DHE/DSS/SEED ciphersuite value was being checked).
Diffstat (limited to 'src')
-rw-r--r-- | src/tls/tls_suites.cpp | 171 |
1 files changed, 88 insertions, 83 deletions
diff --git a/src/tls/tls_suites.cpp b/src/tls/tls_suites.cpp index 46bc4d501..9a541d124 100644 --- a/src/tls/tls_suites.cpp +++ b/src/tls/tls_suites.cpp @@ -16,128 +16,133 @@ namespace Botan { TLS_Ciphersuite TLS_Ciphersuite::lookup_ciphersuite(u16bit suite) { // RSA ciphersuites - if(suite == TLS_RSA_WITH_RC4_128_MD5) - return TLS_Ciphersuite("RSA", "", "MD5", "ARC4", 16); - if(suite == TLS_RSA_WITH_RC4_128_SHA) - return TLS_Ciphersuite("RSA", "", "SHA1", "ARC4", 16); + switch(suite) + { + case TLS_RSA_WITH_RC4_128_MD5: + return TLS_Ciphersuite("RSA", "", "MD5", "ARC4", 16); - if(suite == TLS_RSA_WITH_3DES_EDE_CBC_SHA) - return TLS_Ciphersuite("RSA", "", "SHA1", "TripleDES", 24); + case TLS_RSA_WITH_RC4_128_SHA: + return TLS_Ciphersuite("RSA", "", "SHA1", "ARC4", 16); - if(suite == TLS_RSA_WITH_AES_128_CBC_SHA) - return TLS_Ciphersuite("RSA", "", "SHA1", "AES-128", 16); + case TLS_RSA_WITH_3DES_EDE_CBC_SHA: + return TLS_Ciphersuite("RSA", "", "SHA1", "TripleDES", 24); - if(suite == TLS_RSA_WITH_AES_256_CBC_SHA) - return TLS_Ciphersuite("RSA", "", "SHA1", "AES-256", 32); + case TLS_RSA_WITH_AES_128_CBC_SHA: + return TLS_Ciphersuite("RSA", "", "SHA1", "AES-128", 16); - if(suite == TLS_RSA_WITH_SEED_CBC_SHA) - return TLS_Ciphersuite("RSA", "", "SHA1", "SEED", 16); + case TLS_RSA_WITH_AES_256_CBC_SHA: + return TLS_Ciphersuite("RSA", "", "SHA1", "AES-256", 32); - if(suite == TLS_RSA_WITH_AES_128_CBC_SHA256) - return TLS_Ciphersuite("RSA", "", "SHA-256", "AES-128", 16); + case TLS_RSA_WITH_SEED_CBC_SHA: + return TLS_Ciphersuite("RSA", "", "SHA1", "SEED", 16); - if(suite == TLS_RSA_WITH_AES_256_CBC_SHA256) - return TLS_Ciphersuite("RSA", "", "SHA-256", "AES-256", 32); + case TLS_RSA_WITH_AES_128_CBC_SHA256: + return TLS_Ciphersuite("RSA", "", "SHA-256", "AES-128", 16); - // DHE/DSS ciphersuites - if(suite == TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA) - return TLS_Ciphersuite("DSA", "DH", "SHA1", "TripleDES", 24); + case TLS_RSA_WITH_AES_256_CBC_SHA256: + return TLS_Ciphersuite("RSA", "", "SHA-256", "AES-256", 32); - if(suite == TLS_DHE_DSS_WITH_AES_128_CBC_SHA) - return TLS_Ciphersuite("DSA", "DH", "SHA1", "AES-128", 16); + // DHE/DSS ciphersuites + case TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA: + return TLS_Ciphersuite("DSA", "DH", "SHA1", "TripleDES", 24); - if(suite == TLS_DHE_DSS_WITH_SEED_CBC_SHA) - return TLS_Ciphersuite("DSA", "DH", "SHA1", "SEED", 16); + case TLS_DHE_DSS_WITH_AES_128_CBC_SHA: + return TLS_Ciphersuite("DSA", "DH", "SHA1", "AES-128", 16); - if(suite == TLS_DHE_DSS_WITH_RC4_128_SHA) - return TLS_Ciphersuite("DSA", "DH", "SHA1", "ARC4", 16); + case TLS_DHE_DSS_WITH_SEED_CBC_SHA: + return TLS_Ciphersuite("DSA", "DH", "SHA1", "SEED", 16); - if(suite == TLS_DHE_DSS_WITH_AES_256_CBC_SHA) - return TLS_Ciphersuite("DSA", "DH", "SHA1", "AES-256", 32); + case TLS_DHE_DSS_WITH_RC4_128_SHA: + return TLS_Ciphersuite("DSA", "DH", "SHA1", "ARC4", 16); - if(suite == TLS_DHE_DSS_WITH_AES_128_CBC_SHA256) - return TLS_Ciphersuite("DSA", "DH", "SHA-256", "AES-128", 16); + case TLS_DHE_DSS_WITH_AES_256_CBC_SHA: + return TLS_Ciphersuite("DSA", "DH", "SHA1", "AES-256", 32); - if(suite == TLS_DHE_DSS_WITH_AES_256_CBC_SHA256) - return TLS_Ciphersuite("DSA", "DH", "SHA-256", "AES-256", 32); + case TLS_DHE_DSS_WITH_AES_128_CBC_SHA256: + return TLS_Ciphersuite("DSA", "DH", "SHA-256", "AES-128", 16); - // DHE/RSA ciphersuites - if(suite == TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA) - return TLS_Ciphersuite("RSA", "DH", "SHA1", "TripleDES", 24); + case TLS_DHE_DSS_WITH_AES_256_CBC_SHA256: + return TLS_Ciphersuite("DSA", "DH", "SHA-256", "AES-256", 32); - if(suite == TLS_DHE_RSA_WITH_AES_128_CBC_SHA) - return TLS_Ciphersuite("RSA", "DH", "SHA1", "AES-128", 16); + // DHE/RSA ciphersuites + case TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA: + return TLS_Ciphersuite("RSA", "DH", "SHA1", "TripleDES", 24); - if(suite == TLS_DHE_DSS_WITH_SEED_CBC_SHA) - return TLS_Ciphersuite("RSA", "DH", "SHA1", "SEED", 16); + case TLS_DHE_RSA_WITH_AES_128_CBC_SHA: + return TLS_Ciphersuite("RSA", "DH", "SHA1", "AES-128", 16); - if(suite == TLS_DHE_RSA_WITH_AES_256_CBC_SHA) - return TLS_Ciphersuite("RSA", "DH", "SHA1", "AES-256", 32); + case TLS_DHE_RSA_WITH_SEED_CBC_SHA: + return TLS_Ciphersuite("RSA", "DH", "SHA1", "SEED", 16); - if(suite == TLS_DHE_RSA_WITH_AES_128_CBC_SHA256) - return TLS_Ciphersuite("RSA", "DH", "SHA-256", "AES-128", 16); + case TLS_DHE_RSA_WITH_AES_256_CBC_SHA: + return TLS_Ciphersuite("RSA", "DH", "SHA1", "AES-256", 32); - if(suite == TLS_DHE_RSA_WITH_AES_256_CBC_SHA256) - return TLS_Ciphersuite("RSA", "DH", "SHA-256", "AES-256", 32); + case TLS_DHE_RSA_WITH_AES_128_CBC_SHA256: + return TLS_Ciphersuite("RSA", "DH", "SHA-256", "AES-128", 16); - // SRP ciphersuites - if(suite == TLS_SRP_SHA_RSA_WITH_3DES_EDE_SHA) - return TLS_Ciphersuite("RSA", "SRP", "SHA1", "TripleDES", 24); + case TLS_DHE_RSA_WITH_AES_256_CBC_SHA256: + return TLS_Ciphersuite("RSA", "DH", "SHA-256", "AES-256", 32); - if(suite == TLS_SRP_SHA_DSS_WITH_3DES_EDE_SHA) - return TLS_Ciphersuite("DSA", "SRP", "SHA1", "TripleDES", 24); + // SRP ciphersuites + case TLS_SRP_SHA_RSA_WITH_3DES_EDE_SHA: + return TLS_Ciphersuite("RSA", "SRP", "SHA1", "TripleDES", 24); - if(suite == TLS_SRP_SHA_RSA_WITH_AES_128_SHA) - return TLS_Ciphersuite("RSA", "SRP", "SHA1", "AES-128", 16); + case TLS_SRP_SHA_DSS_WITH_3DES_EDE_SHA: + return TLS_Ciphersuite("DSA", "SRP", "SHA1", "TripleDES", 24); - if(suite == TLS_SRP_SHA_DSS_WITH_AES_128_SHA) - return TLS_Ciphersuite("DSA", "SRP", "SHA1", "AES-128", 16); + case TLS_SRP_SHA_RSA_WITH_AES_128_SHA: + return TLS_Ciphersuite("RSA", "SRP", "SHA1", "AES-128", 16); - if(suite == TLS_SRP_SHA_RSA_WITH_AES_256_SHA) - return TLS_Ciphersuite("RSA", "SRP", "SHA1", "AES-256", 32); + case TLS_SRP_SHA_DSS_WITH_AES_128_SHA: + return TLS_Ciphersuite("DSA", "SRP", "SHA1", "AES-128", 16); - if(suite == TLS_SRP_SHA_DSS_WITH_AES_256_SHA) - return TLS_Ciphersuite("DSA", "SRP", "SHA1", "AES-256", 32); + case TLS_SRP_SHA_RSA_WITH_AES_256_SHA: + return TLS_Ciphersuite("RSA", "SRP", "SHA1", "AES-256", 32); - // ECC ciphersuites - if(suite == TLS_ECDHE_ECDSA_WITH_RC4_128_SHA) - return TLS_Ciphersuite("ECDSA", "ECDH", "SHA1", "ARC4", 16); + case TLS_SRP_SHA_DSS_WITH_AES_256_SHA: + return TLS_Ciphersuite("DSA", "SRP", "SHA1", "AES-256", 32); - if(suite == TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA) - return TLS_Ciphersuite("ECDSA", "ECDH", "SHA1", "TripleDES", 24); + // ECC ciphersuites + case TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: + return TLS_Ciphersuite("ECDSA", "ECDH", "SHA1", "ARC4", 16); - if(suite == TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA) - return TLS_Ciphersuite("ECDSA", "ECDH", "SHA1", "AES-128", 16); + case TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA: + return TLS_Ciphersuite("ECDSA", "ECDH", "SHA1", "TripleDES", 24); - if(suite == TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA) - return TLS_Ciphersuite("ECDSA", "ECDH", "SHA1", "AES-256", 32); + case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: + return TLS_Ciphersuite("ECDSA", "ECDH", "SHA1", "AES-128", 16); - if(suite == TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) - return TLS_Ciphersuite("ECDSA", "ECDH", "SHA-256", "AES-128", 16); + case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: + return TLS_Ciphersuite("ECDSA", "ECDH", "SHA1", "AES-256", 32); - if(suite == TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384) - return TLS_Ciphersuite("ECDSA", "ECDH", "SHA384", "AES-256", 32); + case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: + return TLS_Ciphersuite("ECDSA", "ECDH", "SHA-256", "AES-128", 16); - if(suite == TLS_ECDHE_RSA_WITH_RC4_128_SHA) - return TLS_Ciphersuite("RSA", "ECDH", "SHA1", "ARC4", 16); + case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384: + return TLS_Ciphersuite("ECDSA", "ECDH", "SHA-384", "AES-256", 32); - if(suite == TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA) - return TLS_Ciphersuite("RSA", "ECDH", "SHA1", "TripleDES", 24); + case TLS_ECDHE_RSA_WITH_RC4_128_SHA: + return TLS_Ciphersuite("RSA", "ECDH", "SHA1", "ARC4", 16); - if(suite == TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) - return TLS_Ciphersuite("RSA", "ECDH", "SHA1", "AES-128", 16); + case TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: + return TLS_Ciphersuite("RSA", "ECDH", "SHA1", "TripleDES", 24); - if(suite == TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) - return TLS_Ciphersuite("RSA", "ECDH", "SHA1", "AES-256", 32); + case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: + return TLS_Ciphersuite("RSA", "ECDH", "SHA1", "AES-128", 16); - if(suite == TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) - return TLS_Ciphersuite("ECDSA", "ECDH", "SHA-256", "AES-128", 16); + case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: + return TLS_Ciphersuite("RSA", "ECDH", "SHA1", "AES-256", 32); - if(suite == TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) - return TLS_Ciphersuite("ECDSA", "ECDH", "SHA384", "AES-256", 32); + case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: + return TLS_Ciphersuite("ECDSA", "ECDH", "SHA-256", "AES-128", 16); - return TLS_Ciphersuite(); // some unknown ciphersuite + case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384: + return TLS_Ciphersuite("ECDSA", "ECDH", "SHA-384", "AES-256", 32); + + default: + return TLS_Ciphersuite(); // some unknown ciphersuite + } } TLS_Ciphersuite::TLS_Ciphersuite(const std::string& sig_algo, |