1
1
pub mod cipher_suite_aes_128_ccm;
2
2
pub mod cipher_suite_aes_128_gcm_sha256;
3
3
pub mod cipher_suite_aes_256_cbc_sha;
4
+ pub mod cipher_suite_chacha20_poly1305_sha256;
4
5
pub mod cipher_suite_tls_ecdhe_ecdsa_with_aes_128_ccm;
5
6
pub mod cipher_suite_tls_ecdhe_ecdsa_with_aes_128_ccm8;
6
7
pub mod cipher_suite_tls_psk_with_aes_128_ccm;
@@ -12,6 +13,7 @@ use std::marker::{Send, Sync};
12
13
13
14
use cipher_suite_aes_128_gcm_sha256:: * ;
14
15
use cipher_suite_aes_256_cbc_sha:: * ;
16
+ use cipher_suite_chacha20_poly1305_sha256:: * ;
15
17
use cipher_suite_tls_ecdhe_ecdsa_with_aes_128_ccm:: * ;
16
18
use cipher_suite_tls_ecdhe_ecdsa_with_aes_128_ccm8:: * ;
17
19
use cipher_suite_tls_psk_with_aes_128_ccm:: * ;
@@ -43,6 +45,10 @@ pub enum CipherSuiteId {
43
45
Tls_Psk_With_Aes_128_Ccm_8 = 0xc0a8 ,
44
46
Tls_Psk_With_Aes_128_Gcm_Sha256 = 0x00a8 ,
45
47
48
+ // CHACHA20_POLY1305_SHA256
49
+ Tls_Ecdhe_Rsa_With_ChaCha20_Poly1305_Sha256 = 0xcca8 ,
50
+ Tls_Ecdhe_Ecdsa_With_ChaCha20_Poly1305_Sha256 = 0xcca9 ,
51
+
46
52
Unsupported ,
47
53
}
48
54
@@ -72,6 +78,13 @@ impl fmt::Display for CipherSuiteId {
72
78
CipherSuiteId :: Tls_Psk_With_Aes_128_Gcm_Sha256 => {
73
79
write ! ( f, "TLS_PSK_WITH_AES_128_GCM_SHA256" )
74
80
}
81
+ CipherSuiteId :: Tls_Ecdhe_Rsa_With_ChaCha20_Poly1305_Sha256 => {
82
+ write ! ( f, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" )
83
+ }
84
+ CipherSuiteId :: Tls_Ecdhe_Ecdsa_With_ChaCha20_Poly1305_Sha256 => {
85
+ write ! ( f, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" )
86
+ }
87
+
75
88
_ => write ! ( f, "Unsupported CipherSuiteID" ) ,
76
89
}
77
90
}
@@ -96,6 +109,43 @@ impl From<u16> for CipherSuiteId {
96
109
0xc0a8 => CipherSuiteId :: Tls_Psk_With_Aes_128_Ccm_8 ,
97
110
0x00a8 => CipherSuiteId :: Tls_Psk_With_Aes_128_Gcm_Sha256 ,
98
111
112
+ // CHACHA20_POLY1305_SHA256
113
+ 0xcca8 => CipherSuiteId :: Tls_Ecdhe_Rsa_With_ChaCha20_Poly1305_Sha256 ,
114
+ 0xcca9 => CipherSuiteId :: Tls_Ecdhe_Ecdsa_With_ChaCha20_Poly1305_Sha256 ,
115
+
116
+ _ => CipherSuiteId :: Unsupported ,
117
+ }
118
+ }
119
+ }
120
+
121
+ impl From < & str > for CipherSuiteId {
122
+ fn from ( val : & str ) -> Self {
123
+ match val {
124
+ "TLS_ECDHE_ECDSA_WITH_AES_128_CCM" => CipherSuiteId :: Tls_Ecdhe_Ecdsa_With_Aes_128_Ccm ,
125
+ "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" => {
126
+ CipherSuiteId :: Tls_Ecdhe_Ecdsa_With_Aes_128_Ccm_8
127
+ }
128
+ "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" => {
129
+ CipherSuiteId :: Tls_Ecdhe_Ecdsa_With_Aes_128_Gcm_Sha256
130
+ }
131
+ "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" => {
132
+ CipherSuiteId :: Tls_Ecdhe_Rsa_With_Aes_128_Gcm_Sha256
133
+ }
134
+ "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" => {
135
+ CipherSuiteId :: Tls_Ecdhe_Ecdsa_With_Aes_256_Cbc_Sha
136
+ }
137
+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" => {
138
+ CipherSuiteId :: Tls_Ecdhe_Rsa_With_Aes_256_Cbc_Sha
139
+ }
140
+ "TLS_PSK_WITH_AES_128_CCM" => CipherSuiteId :: Tls_Psk_With_Aes_128_Ccm ,
141
+ "TLS_PSK_WITH_AES_128_CCM_8" => CipherSuiteId :: Tls_Psk_With_Aes_128_Ccm_8 ,
142
+ "TLS_PSK_WITH_AES_128_GCM_SHA256" => CipherSuiteId :: Tls_Psk_With_Aes_128_Gcm_Sha256 ,
143
+ "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" => {
144
+ CipherSuiteId :: Tls_Ecdhe_Rsa_With_ChaCha20_Poly1305_Sha256
145
+ }
146
+ "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" => {
147
+ CipherSuiteId :: Tls_Ecdhe_Ecdsa_With_ChaCha20_Poly1305_Sha256
148
+ }
99
149
_ => CipherSuiteId :: Unsupported ,
100
150
}
101
151
}
@@ -167,6 +217,13 @@ pub fn cipher_suite_for_id(id: CipherSuiteId) -> Result<Box<dyn CipherSuite + Se
167
217
CipherSuiteId :: Tls_Psk_With_Aes_128_Gcm_Sha256 => {
168
218
Ok ( Box :: < CipherSuiteTlsPskWithAes128GcmSha256 > :: default ( ) )
169
219
}
220
+ CipherSuiteId :: Tls_Ecdhe_Rsa_With_ChaCha20_Poly1305_Sha256 => {
221
+ Ok ( Box :: new ( CipherSuiteChaCha20Poly1305Sha256 :: new ( true ) ) )
222
+ }
223
+ CipherSuiteId :: Tls_Ecdhe_Ecdsa_With_ChaCha20_Poly1305_Sha256 => {
224
+ Ok ( Box :: new ( CipherSuiteChaCha20Poly1305Sha256 :: new ( false ) ) )
225
+ }
226
+
170
227
_ => Err ( Error :: ErrInvalidCipherSuite ) ,
171
228
}
172
229
}
@@ -178,6 +235,7 @@ pub(crate) fn default_cipher_suites() -> Vec<Box<dyn CipherSuite + Send + Sync>>
178
235
Box :: new( CipherSuiteAes256CbcSha :: new( false ) ) ,
179
236
Box :: new( CipherSuiteAes128GcmSha256 :: new( true ) ) ,
180
237
Box :: new( CipherSuiteAes256CbcSha :: new( true ) ) ,
238
+ Box :: new( CipherSuiteChaCha20Poly1305Sha256 :: new( false ) ) ,
181
239
]
182
240
}
183
241
@@ -192,6 +250,8 @@ fn all_cipher_suites() -> Vec<Box<dyn CipherSuite + Send + Sync>> {
192
250
Box :: new( new_cipher_suite_tls_psk_with_aes_128_ccm( ) ) ,
193
251
Box :: new( new_cipher_suite_tls_psk_with_aes_128_ccm8( ) ) ,
194
252
Box :: <CipherSuiteTlsPskWithAes128GcmSha256 >:: default ( ) ,
253
+ Box :: new( CipherSuiteChaCha20Poly1305Sha256 :: new( false ) ) ,
254
+ Box :: new( CipherSuiteChaCha20Poly1305Sha256 :: new( true ) ) ,
195
255
]
196
256
}
197
257
0 commit comments