33//! See the [RustCrypto/stream-ciphers](https://github.com/RustCrypto/stream-ciphers) repository
44//! for ciphers implementation.
55
6- use crate :: block:: { BlockModeDecrypt , BlockModeEncrypt } ;
7- use common:: Block ;
86use inout:: { InOutBuf , NotEqualError } ;
97
108mod core_api;
@@ -20,78 +18,6 @@ pub use errors::{OverflowError, StreamCipherError};
2018#[ cfg( feature = "stream-wrapper" ) ]
2119pub use wrapper:: StreamCipherCoreWrapper ;
2220
23- /// Asynchronous stream cipher trait.
24- pub trait AsyncStreamCipher : Sized {
25- /// Encrypt data using `InOutBuf`.
26- fn encrypt_inout ( mut self , data : InOutBuf < ' _ , ' _ , u8 > )
27- where
28- Self : BlockModeEncrypt ,
29- {
30- let ( blocks, mut tail) = data. into_chunks ( ) ;
31- self . encrypt_blocks_inout ( blocks) ;
32- let n = tail. len ( ) ;
33- if n != 0 {
34- let mut block = Block :: < Self > :: default ( ) ;
35- block[ ..n] . copy_from_slice ( tail. get_in ( ) ) ;
36- self . encrypt_block ( & mut block) ;
37- tail. get_out ( ) . copy_from_slice ( & block[ ..n] ) ;
38- }
39- }
40-
41- /// Decrypt data using `InOutBuf`.
42- fn decrypt_inout ( mut self , data : InOutBuf < ' _ , ' _ , u8 > )
43- where
44- Self : BlockModeDecrypt ,
45- {
46- let ( blocks, mut tail) = data. into_chunks ( ) ;
47- self . decrypt_blocks_inout ( blocks) ;
48- let n = tail. len ( ) ;
49- if n != 0 {
50- let mut block = Block :: < Self > :: default ( ) ;
51- block[ ..n] . copy_from_slice ( tail. get_in ( ) ) ;
52- self . decrypt_block ( & mut block) ;
53- tail. get_out ( ) . copy_from_slice ( & block[ ..n] ) ;
54- }
55- }
56- /// Encrypt data in place.
57- fn encrypt ( self , buf : & mut [ u8 ] )
58- where
59- Self : BlockModeEncrypt ,
60- {
61- self . encrypt_inout ( buf. into ( ) ) ;
62- }
63-
64- /// Decrypt data in place.
65- fn decrypt ( self , buf : & mut [ u8 ] )
66- where
67- Self : BlockModeDecrypt ,
68- {
69- self . decrypt_inout ( buf. into ( ) ) ;
70- }
71-
72- /// Encrypt data from buffer to buffer.
73- ///
74- /// # Errors
75- /// Returns [`NotEqualError`] if provided `in_buf` and `out_buf` have different lengths.
76- fn encrypt_b2b ( self , in_buf : & [ u8 ] , out_buf : & mut [ u8 ] ) -> Result < ( ) , NotEqualError >
77- where
78- Self : BlockModeEncrypt ,
79- {
80- InOutBuf :: new ( in_buf, out_buf) . map ( |b| self . encrypt_inout ( b) )
81- }
82-
83- /// Decrypt data from buffer to buffer.
84- ///
85- /// # Errors
86- /// Returns [`NotEqualError`] if provided `in_buf` and `out_buf` have different lengths.
87- fn decrypt_b2b ( self , in_buf : & [ u8 ] , out_buf : & mut [ u8 ] ) -> Result < ( ) , NotEqualError >
88- where
89- Self : BlockModeDecrypt ,
90- {
91- InOutBuf :: new ( in_buf, out_buf) . map ( |b| self . decrypt_inout ( b) )
92- }
93- }
94-
9521/// Stream cipher trait.
9622///
9723/// This trait applies only to synchronous stream ciphers, which generate a keystream and
0 commit comments