|
3 | 3 | #[cfg(feature = "v1-aead-extra")] |
4 | 4 | use super::aeadcipher::{ |
5 | 5 | Aes128Ccm, Aes128GcmSiv, Aes128OcbTag128, Aes192OcbTag128, Aes256Ccm, Aes256GcmSiv, |
6 | | - Aes256OcbTag128, AesSivCmac256, AesSivCmac384, AesSivCmac512, XChacha20Poly1305, |
| 6 | + Aes256OcbTag128, AesSivCmac256, AesSivCmac384, AesSivCmac512, Sm4Ccm, Sm4Gcm, |
| 7 | + XChacha20Poly1305, |
7 | 8 | }; |
8 | 9 | #[cfg(feature = "v1-aead")] |
9 | 10 | use super::aeadcipher::{Aes128Gcm, Aes256Gcm, Chacha20Poly1305}; |
@@ -242,6 +243,15 @@ pub enum CipherKind { |
242 | 243 | #[cfg_attr(docrs, doc(cfg(feature = "v1-aead-extra")))] |
243 | 244 | /// AEAD_XCHACHA20_POLY1305 |
244 | 245 | XCHACHA20_POLY1305, |
| 246 | + |
| 247 | + #[cfg(feature = "v1-aead-extra")] |
| 248 | + #[cfg_attr(docrs, doc(cfg(feature = "v1-aead-extra")))] |
| 249 | + /// AEAD_SM4_GCM |
| 250 | + SM4_GCM, |
| 251 | + #[cfg(feature = "v1-aead-extra")] |
| 252 | + #[cfg_attr(docrs, doc(cfg(feature = "v1-aead-extra")))] |
| 253 | + /// AEAD_SM4_CCM |
| 254 | + SM4_CCM, |
245 | 255 | } |
246 | 256 |
|
247 | 257 | impl CipherKind { |
@@ -303,7 +313,9 @@ impl CipherKind { |
303 | 313 | | AES_SIV_CMAC_512 |
304 | 314 | | AES_128_GCM_SIV |
305 | 315 | | AES_256_GCM_SIV |
306 | | - | XCHACHA20_POLY1305 => true, |
| 316 | + | XCHACHA20_POLY1305 |
| 317 | + | SM4_GCM |
| 318 | + | SM4_CCM => true, |
307 | 319 |
|
308 | 320 | _ => false, |
309 | 321 | } |
@@ -431,6 +443,11 @@ impl CipherKind { |
431 | 443 |
|
432 | 444 | #[cfg(feature = "v1-aead-extra")] |
433 | 445 | XCHACHA20_POLY1305 => XChacha20Poly1305::KEY_LEN, |
| 446 | + |
| 447 | + #[cfg(feature = "v1-aead-extra")] |
| 448 | + SM4_GCM => Sm4Gcm::KEY_LEN, |
| 449 | + #[cfg(feature = "v1-aead-extra")] |
| 450 | + SM4_CCM => Sm4Ccm::KEY_LEN, |
434 | 451 | } |
435 | 452 | } |
436 | 453 |
|
@@ -525,6 +542,11 @@ impl CipherKind { |
525 | 542 | #[cfg(feature = "v1-aead-extra")] |
526 | 543 | XCHACHA20_POLY1305 => XChacha20Poly1305::TAG_LEN, |
527 | 544 |
|
| 545 | + #[cfg(feature = "v1-aead-extra")] |
| 546 | + SM4_GCM => Sm4Gcm::TAG_LEN, |
| 547 | + #[cfg(feature = "v1-aead-extra")] |
| 548 | + SM4_CCM => Sm4Ccm::TAG_LEN, |
| 549 | + |
528 | 550 | _ => panic!("only support AEAD ciphers"), |
529 | 551 | } |
530 | 552 | } |
@@ -659,6 +681,11 @@ impl core::fmt::Display for CipherKind { |
659 | 681 |
|
660 | 682 | #[cfg(feature = "v1-aead-extra")] |
661 | 683 | CipherKind::XCHACHA20_POLY1305 => "xchacha20-ietf-poly1305", |
| 684 | + |
| 685 | + #[cfg(feature = "v1-aead-extra")] |
| 686 | + CipherKind::SM4_GCM => "sm4-gcm", |
| 687 | + #[cfg(feature = "v1-aead-extra")] |
| 688 | + CipherKind::SM4_CCM => "sm4-ccm", |
662 | 689 | }) |
663 | 690 | } |
664 | 691 | } |
@@ -803,6 +830,11 @@ impl core::str::FromStr for CipherKind { |
803 | 830 | #[cfg(feature = "v1-aead-extra")] |
804 | 831 | "xchacha20-ietf-poly1305" => Ok(XCHACHA20_POLY1305), |
805 | 832 |
|
| 833 | + #[cfg(feature = "v1-aead-extra")] |
| 834 | + "sm4-gcm" => Ok(SM4_GCM), |
| 835 | + #[cfg(feature = "v1-aead-extra")] |
| 836 | + "sm4-ccm" => Ok(SM4_CCM), |
| 837 | + |
806 | 838 | _ => Err(ParseCipherKindError), |
807 | 839 | } |
808 | 840 | } |
|
0 commit comments