@@ -12,7 +12,7 @@ use belt_block::BeltBlock;
1212use cipher:: {
1313 AlgorithmName , Block , BlockCipherDecrypt , BlockCipherEncBackend , BlockCipherEncClosure ,
1414 BlockCipherEncrypt , BlockSizeUser , InOut , InnerIvInit , Iv , IvSizeUser , IvState , ParBlocks ,
15- ParBlocksSizeUser , StreamCipherBackend , StreamCipherClosure , StreamCipherCore ,
15+ ParBlocksSizeUser , SetIvState , StreamCipherBackend , StreamCipherClosure , StreamCipherCore ,
1616 StreamCipherCoreWrapper , StreamCipherSeekCore , array:: Array , common:: InnerUser , consts:: U16 ,
1717} ;
1818use core:: fmt;
@@ -41,11 +41,13 @@ impl<C> StreamCipherCore for GenericBeltCtrCore<C>
4141where
4242 C : BlockCipherEncrypt + BlockSizeUser < BlockSize = U16 > ,
4343{
44+ #[ inline]
4445 fn remaining_blocks ( & self ) -> Option < usize > {
4546 let used = self . s . wrapping_sub ( self . s_init ) ;
4647 ( u128:: MAX - used) . try_into ( ) . ok ( )
4748 }
4849
50+ #[ inline]
4951 fn process_with_backend ( & mut self , f : impl StreamCipherClosure < BlockSize = Self :: BlockSize > ) {
5052 struct Closure < ' a , C : StreamCipherClosure < BlockSize = U16 > > {
5153 s : & ' a mut u128 ,
@@ -75,10 +77,12 @@ where
7577{
7678 type Counter = u128 ;
7779
80+ #[ inline]
7881 fn get_block_pos ( & self ) -> Self :: Counter {
7982 self . s . wrapping_sub ( self . s_init )
8083 }
8184
85+ #[ inline]
8286 fn set_block_pos ( & mut self , pos : Self :: Counter ) {
8387 self . s = self . s_init . wrapping_add ( pos) ;
8488 }
@@ -126,17 +130,31 @@ impl<C> IvState for GenericBeltCtrCore<C>
126130where
127131 C : BlockCipherEncrypt + BlockCipherDecrypt + BlockSizeUser < BlockSize = U16 > ,
128132{
133+ #[ inline]
129134 fn iv_state ( & self ) -> Iv < Self > {
130135 let mut t = self . s . to_le_bytes ( ) . into ( ) ;
131136 self . cipher . decrypt_block ( & mut t) ;
132137 t
133138 }
134139}
135140
141+ impl < C > SetIvState for GenericBeltCtrCore < C >
142+ where
143+ C : BlockCipherEncrypt + BlockCipherDecrypt + BlockSizeUser < BlockSize = U16 > ,
144+ {
145+ #[ inline]
146+ fn set_iv ( & mut self , iv : & Iv < Self > ) {
147+ let mut iv = * iv;
148+ self . cipher . encrypt_block ( & mut iv) ;
149+ self . s = u128:: from_le_bytes ( iv. 0 ) ;
150+ }
151+ }
152+
136153impl < C > AlgorithmName for GenericBeltCtrCore < C >
137154where
138155 C : BlockCipherEncrypt + BlockSizeUser < BlockSize = U16 > + AlgorithmName ,
139156{
157+ #[ inline]
140158 fn write_alg_name ( f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
141159 f. write_str ( "BeltCtr<" ) ?;
142160 <C as AlgorithmName >:: write_alg_name ( f) ?;
@@ -160,6 +178,7 @@ impl<C: BlockCipherEncrypt> Drop for GenericBeltCtrCore<C>
160178where
161179 C : BlockCipherEncrypt + BlockSizeUser < BlockSize = U16 > ,
162180{
181+ #[ inline]
163182 fn drop ( & mut self ) {
164183 #[ cfg( feature = "zeroize" ) ]
165184 {
0 commit comments