OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #endif // SSL_USE_OPENSSL | 22 #endif // SSL_USE_OPENSSL |
23 | 23 |
24 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
25 | 25 |
26 namespace rtc { | 26 namespace rtc { |
27 | 27 |
28 // TODO(guoweis): Move this to SDP layer and use int form internally. | 28 // TODO(guoweis): Move this to SDP layer and use int form internally. |
29 // webrtc:5043. | 29 // webrtc:5043. |
30 const char CS_AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; | 30 const char CS_AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; |
31 const char CS_AES_CM_128_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32"; | 31 const char CS_AES_CM_128_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32"; |
32 const char CS_AEAD_AES_128_GCM[] = "AEAD_AES_128_GCM"; | |
33 const char CS_AEAD_AES_256_GCM[] = "AEAD_AES_256_GCM"; | |
32 | 34 |
33 std::string SrtpCryptoSuiteToName(int crypto_suite) { | 35 std::string SrtpCryptoSuiteToName(int crypto_suite) { |
34 if (crypto_suite == SRTP_AES128_CM_SHA1_32) | 36 switch (crypto_suite) { |
37 case SRTP_AES128_CM_SHA1_32: | |
35 return CS_AES_CM_128_HMAC_SHA1_32; | 38 return CS_AES_CM_128_HMAC_SHA1_32; |
36 if (crypto_suite == SRTP_AES128_CM_SHA1_80) | 39 case SRTP_AES128_CM_SHA1_80: |
37 return CS_AES_CM_128_HMAC_SHA1_80; | 40 return CS_AES_CM_128_HMAC_SHA1_80; |
38 return std::string(); | 41 case SRTP_AEAD_AES_128_GCM: |
42 return CS_AEAD_AES_128_GCM; | |
43 case SRTP_AEAD_AES_256_GCM: | |
44 return CS_AEAD_AES_256_GCM; | |
45 default: | |
46 return std::string(); | |
47 } | |
39 } | 48 } |
40 | 49 |
41 int SrtpCryptoSuiteFromName(const std::string& crypto_suite) { | 50 int SrtpCryptoSuiteFromName(const std::string& crypto_suite) { |
42 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_32) | 51 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_32) |
43 return SRTP_AES128_CM_SHA1_32; | 52 return SRTP_AES128_CM_SHA1_32; |
44 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_80) | 53 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_80) |
45 return SRTP_AES128_CM_SHA1_80; | 54 return SRTP_AES128_CM_SHA1_80; |
55 if (crypto_suite == CS_AEAD_AES_128_GCM) | |
56 return SRTP_AEAD_AES_128_GCM; | |
57 if (crypto_suite == CS_AEAD_AES_256_GCM) | |
58 return SRTP_AEAD_AES_256_GCM; | |
46 return SRTP_INVALID_CRYPTO_SUITE; | 59 return SRTP_INVALID_CRYPTO_SUITE; |
47 } | 60 } |
48 | 61 |
62 bool GetSrtpKeyAndSaltLengths(int crypto_suite, int *key_length, | |
63 int *salt_length) { | |
64 switch (crypto_suite) { | |
65 case SRTP_AES128_CM_SHA1_32: | |
66 case SRTP_AES128_CM_SHA1_80: | |
67 *key_length = 16; | |
68 *salt_length = 14; | |
69 break; | |
70 case SRTP_AEAD_AES_128_GCM: | |
71 *key_length = 16; | |
72 *salt_length = 12; | |
73 break; | |
74 case SRTP_AEAD_AES_256_GCM: | |
75 *key_length = 32; | |
76 *salt_length = 12; | |
pthatcher1
2016/01/30 00:54:33
Can you leave a comment saying where these values
joachim
2016/01/31 23:39:52
Done.
| |
77 break; | |
78 default: | |
79 return false; | |
80 } | |
81 return true; | |
82 } | |
83 | |
84 bool IsGcmCryptoSuite(int crypto_suite) { | |
85 return (crypto_suite == SRTP_AEAD_AES_256_GCM || | |
86 crypto_suite == SRTP_AEAD_AES_128_GCM); | |
87 } | |
88 | |
89 bool IsGcmCryptoSuiteName(const std::string& crypto_suite) { | |
90 return (crypto_suite == CS_AEAD_AES_256_GCM || | |
91 crypto_suite == CS_AEAD_AES_128_GCM); | |
92 } | |
93 | |
94 | |
49 SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) { | 95 SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) { |
50 #if SSL_USE_OPENSSL | 96 #if SSL_USE_OPENSSL |
51 return new OpenSSLStreamAdapter(stream); | 97 return new OpenSSLStreamAdapter(stream); |
52 #else // !SSL_USE_OPENSSL | 98 #else // !SSL_USE_OPENSSL |
53 return NULL; | 99 return NULL; |
54 #endif // SSL_USE_OPENSSL | 100 #endif // SSL_USE_OPENSSL |
55 } | 101 } |
56 | 102 |
57 bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { | 103 bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { |
58 return false; | 104 return false; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 } | 138 } |
93 | 139 |
94 std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { | 140 std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { |
95 return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite); | 141 return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite); |
96 } | 142 } |
97 #endif // SSL_USE_OPENSSL | 143 #endif // SSL_USE_OPENSSL |
98 | 144 |
99 /////////////////////////////////////////////////////////////////////////////// | 145 /////////////////////////////////////////////////////////////////////////////// |
100 | 146 |
101 } // namespace rtc | 147 } // namespace rtc |
OLD | NEW |