@@ -7,12 +7,20 @@ mod aes_gcm;
77mod aes_gcm_siv;
88mod chacha20_poly1305;
99#[ cfg( feature = "v1-aead-extra" ) ]
10+ mod sm4_ccm;
11+ #[ cfg( feature = "v1-aead-extra" ) ]
12+ mod sm4_gcm;
13+ #[ cfg( feature = "v1-aead-extra" ) ]
14+ mod sm4_gcm_cipher;
15+ #[ cfg( feature = "v1-aead-extra" ) ]
1016mod xchacha20_poly1305;
1117
1218#[ cfg( feature = "v1-aead-extra" ) ]
1319pub use self :: {
1420 aes_ccm:: { Aes128Ccm , Aes256Ccm } ,
1521 aes_gcm_siv:: { Aes128GcmSiv , Aes256GcmSiv } ,
22+ sm4_ccm:: Sm4Ccm ,
23+ sm4_gcm:: Sm4Gcm ,
1624 xchacha20_poly1305:: XChaCha20Poly1305 ,
1725} ;
1826pub use self :: {
@@ -34,6 +42,10 @@ enum AeadCipherVariant {
3442 Aes128Ccm ( Aes128Ccm ) ,
3543 #[ cfg( feature = "v1-aead-extra" ) ]
3644 Aes256Ccm ( Aes256Ccm ) ,
45+ #[ cfg( feature = "v1-aead-extra" ) ]
46+ Sm4Gcm ( Sm4Gcm ) ,
47+ #[ cfg( feature = "v1-aead-extra" ) ]
48+ Sm4Ccm ( Sm4Ccm ) ,
3749}
3850
3951impl AeadCipherVariant {
@@ -52,6 +64,10 @@ impl AeadCipherVariant {
5264 CipherKind :: AES_128_CCM => AeadCipherVariant :: Aes128Ccm ( Aes128Ccm :: new ( key) ) ,
5365 #[ cfg( feature = "v1-aead-extra" ) ]
5466 CipherKind :: AES_256_CCM => AeadCipherVariant :: Aes256Ccm ( Aes256Ccm :: new ( key) ) ,
67+ #[ cfg( feature = "v1-aead-extra" ) ]
68+ CipherKind :: SM4_GCM => AeadCipherVariant :: Sm4Gcm ( Sm4Gcm :: new ( key) ) ,
69+ #[ cfg( feature = "v1-aead-extra" ) ]
70+ CipherKind :: SM4_CCM => AeadCipherVariant :: Sm4Ccm ( Sm4Ccm :: new ( key) ) ,
5571 _ => unreachable ! ( "{:?} is not an AEAD cipher" , kind) ,
5672 }
5773 }
@@ -71,6 +87,10 @@ impl AeadCipherVariant {
7187 AeadCipherVariant :: Aes128Ccm ( ..) => Aes128Ccm :: nonce_size ( ) ,
7288 #[ cfg( feature = "v1-aead-extra" ) ]
7389 AeadCipherVariant :: Aes256Ccm ( ..) => Aes256Ccm :: nonce_size ( ) ,
90+ #[ cfg( feature = "v1-aead-extra" ) ]
91+ AeadCipherVariant :: Sm4Gcm ( ..) => Sm4Gcm :: nonce_size ( ) ,
92+ #[ cfg( feature = "v1-aead-extra" ) ]
93+ AeadCipherVariant :: Sm4Ccm ( ..) => Sm4Ccm :: nonce_size ( ) ,
7494 }
7595 }
7696
@@ -89,6 +109,10 @@ impl AeadCipherVariant {
89109 AeadCipherVariant :: Aes128Ccm ( ..) => CipherKind :: AES_128_CCM ,
90110 #[ cfg( feature = "v1-aead-extra" ) ]
91111 AeadCipherVariant :: Aes256Ccm ( ..) => CipherKind :: AES_256_CCM ,
112+ #[ cfg( feature = "v1-aead-extra" ) ]
113+ AeadCipherVariant :: Sm4Gcm ( ..) => CipherKind :: SM4_GCM ,
114+ #[ cfg( feature = "v1-aead-extra" ) ]
115+ AeadCipherVariant :: Sm4Ccm ( ..) => CipherKind :: SM4_CCM ,
92116 }
93117 }
94118
@@ -107,6 +131,10 @@ impl AeadCipherVariant {
107131 AeadCipherVariant :: Aes128Ccm ( ref mut c) => c. encrypt ( nonce, plaintext_in_ciphertext_out) ,
108132 #[ cfg( feature = "v1-aead-extra" ) ]
109133 AeadCipherVariant :: Aes256Ccm ( ref mut c) => c. encrypt ( nonce, plaintext_in_ciphertext_out) ,
134+ #[ cfg( feature = "v1-aead-extra" ) ]
135+ AeadCipherVariant :: Sm4Gcm ( ref mut c) => c. encrypt ( nonce, plaintext_in_ciphertext_out) ,
136+ #[ cfg( feature = "v1-aead-extra" ) ]
137+ AeadCipherVariant :: Sm4Ccm ( ref mut c) => c. encrypt ( nonce, plaintext_in_ciphertext_out) ,
110138 }
111139 }
112140
@@ -125,6 +153,10 @@ impl AeadCipherVariant {
125153 AeadCipherVariant :: Aes128Ccm ( ref mut c) => c. decrypt ( nonce, ciphertext_in_plaintext_out) ,
126154 #[ cfg( feature = "v1-aead-extra" ) ]
127155 AeadCipherVariant :: Aes256Ccm ( ref mut c) => c. decrypt ( nonce, ciphertext_in_plaintext_out) ,
156+ #[ cfg( feature = "v1-aead-extra" ) ]
157+ AeadCipherVariant :: Sm4Gcm ( ref mut c) => c. decrypt ( nonce, ciphertext_in_plaintext_out) ,
158+ #[ cfg( feature = "v1-aead-extra" ) ]
159+ AeadCipherVariant :: Sm4Ccm ( ref mut c) => c. decrypt ( nonce, ciphertext_in_plaintext_out) ,
128160 }
129161 }
130162}
0 commit comments