7
7
#[ cfg( feature = "zeroize" ) ]
8
8
use cipher:: zeroize:: ZeroizeOnDrop ;
9
9
use cipher:: {
10
- consts:: { U16 , U4 , U8 } ,
11
- generic_array:: GenericArray ,
12
- inout:: { InOut , InOutBuf } ,
13
- AlgorithmName , Block , BlockCipher , BlockDecrypt , BlockSizeUser , Key , KeyInit , KeySizeUser ,
14
- ParBlocks , ParBlocksSizeUser , Unsigned ,
10
+ AlgorithmName , Block , BlockCipherDecBackend , BlockCipherDecClosure , BlockCipherDecrypt ,
11
+ BlockCipherEncBackend , BlockCipherEncClosure , BlockCipherEncrypt , BlockSizeUser , InOut , Key ,
12
+ KeyInit , KeySizeUser , ParBlocks , ParBlocksSizeUser ,
13
+ consts:: { U4 , U8 , U16 } ,
15
14
} ;
16
15
use cipher:: { BlockBackend , BlockEncrypt } ;
17
16
use core:: { arch:: aarch64:: * , fmt} ;
@@ -92,13 +91,10 @@ macro_rules! sm4_e {
92
91
}
93
92
}
94
93
95
- type ParBlocks4 < T > = GenericArray < Block < T > , U4 > ;
96
- type ParBlocks8 < T > = GenericArray < Block < T > , U8 > ;
97
-
98
94
#[ inline]
99
95
#[ target_feature( enable = "sm4" ) ]
100
- pub ( super ) unsafe fn sm4_encrypt4 < T : BlockSizeUser > (
101
- blocks : InOut < ' _ , ' _ , ParBlocks4 < T > > ,
96
+ pub ( super ) unsafe fn sm4_encrypt4 < T : ParBlocksSizeUser > (
97
+ blocks : InOut < ' _ , ' _ , ParBlocks < T > > ,
102
98
rk : & [ uint32x4_t ; 8 ] ,
103
99
) {
104
100
let ( in_ptr, out_ptr) = blocks. into_raw ( ) ;
@@ -127,8 +123,8 @@ pub(super) unsafe fn sm4_encrypt4<T: BlockSizeUser>(
127
123
128
124
#[ inline]
129
125
#[ target_feature( enable = "sm4" ) ]
130
- pub ( super ) unsafe fn sm4_encrypt8 < T : BlockSizeUser > (
131
- blocks : InOut < ' _ , ' _ , ParBlocks8 < T > > ,
126
+ pub ( super ) unsafe fn sm4_encrypt8 < T : ParBlocksSizeUser > (
127
+ blocks : InOut < ' _ , ' _ , ParBlocks < T > > ,
132
128
rk : & [ uint32x4_t ; 8 ] ,
133
129
) {
134
130
let ( in_ptr, out_ptr) = blocks. into_raw ( ) ;
@@ -165,7 +161,7 @@ pub(super) unsafe fn sm4_encrypt8<T: BlockSizeUser>(
165
161
166
162
#[ inline]
167
163
#[ target_feature( enable = "sm4" ) ]
168
- pub ( super ) unsafe fn sm4_encrypt1 < T : BlockSizeUser > (
164
+ pub ( super ) unsafe fn sm4_encrypt1 < T : BlocksSizeUser > (
169
165
block : InOut < ' _ , ' _ , Block < T > > ,
170
166
rk : & [ uint32x4_t ; 8 ] ,
171
167
) {
@@ -189,8 +185,8 @@ pub(super) unsafe fn sm4_encrypt1<T: BlockSizeUser>(
189
185
190
186
#[ inline]
191
187
#[ target_feature( enable = "sm4" ) ]
192
- pub ( super ) unsafe fn sm4_decrypt4 < T : BlockSizeUser > (
193
- blocks : InOut < ' _ , ' _ , ParBlocks4 < T > > ,
188
+ pub ( super ) unsafe fn sm4_decrypt4 < T : ParBlocksSizeUser > (
189
+ blocks : InOut < ' _ , ' _ , ParBlocks < T > > ,
194
190
rk : & [ uint32x4_t ; 8 ] ,
195
191
) {
196
192
let ( in_ptr, out_ptr) = blocks. into_raw ( ) ;
@@ -220,7 +216,7 @@ pub(super) unsafe fn sm4_decrypt4<T: BlockSizeUser>(
220
216
#[ inline]
221
217
#[ target_feature( enable = "sm4" ) ]
222
218
pub ( super ) unsafe fn sm4_decrypt8 < T : BlockSizeUser > (
223
- blocks : InOut < ' _ , ' _ , ParBlocks8 < T > > ,
219
+ blocks : InOut < ' _ , ' _ , ParBlocks < T > > ,
224
220
rk : & [ uint32x4_t ; 8 ] ,
225
221
) {
226
222
let ( in_ptr, out_ptr) = blocks. into_raw ( ) ;
@@ -286,8 +282,6 @@ pub struct Sm4 {
286
282
drk : [ uint32x4_t ; 8 ] ,
287
283
}
288
284
289
- impl BlockCipher for Sm4 { }
290
-
291
285
impl KeySizeUser for Sm4 {
292
286
type KeySize = U16 ;
293
287
}
@@ -359,8 +353,9 @@ impl BlockSizeUser for Sm4 {
359
353
type BlockSize = U16 ;
360
354
}
361
355
362
- impl BlockEncrypt for Sm4 {
363
- fn encrypt_with_backend ( & self , f : impl cipher:: BlockClosure < BlockSize = Self :: BlockSize > ) {
356
+ impl BlockCipherEncrypt for Sm4 {
357
+ #[ inline]
358
+ fn encrypt_with_backend ( & self , f : impl BlockCipherEncClosure < BlockSize = Self :: BlockSize > ) {
364
359
f. call ( & mut Sm4Enc ( self ) )
365
360
}
366
361
}
@@ -375,14 +370,14 @@ impl<'a> ParBlocksSizeUser for Sm4Enc<'a> {
375
370
type ParBlocksSize = U8 ;
376
371
}
377
372
378
- impl < ' a > BlockBackend for Sm4Enc < ' a > {
373
+ impl < ' a > BlockCipherEncBackend for Sm4Enc < ' a > {
379
374
#[ inline( always) ]
380
- fn proc_block ( & mut self , block : InOut < ' _ , ' _ , Block < Self > > ) {
375
+ fn encrypt_block ( & self , block : InOut < ' _ , ' _ , Block < Self > > ) {
381
376
unsafe { sm4_encrypt1 :: < Self > ( block, & self . 0 . erk ) }
382
377
}
383
378
384
379
#[ inline( always) ]
385
- fn proc_tail_blocks ( & mut self , blocks : InOutBuf < ' _ , ' _ , Block < Self > > ) {
380
+ fn encrypt_tail_blocks ( & self , blocks : InOutBuf < ' _ , ' _ , Block < Self > > ) {
386
381
assert ! ( blocks. len( ) < Self :: ParBlocksSize :: USIZE ) ;
387
382
388
383
let ( chunks, tail) = blocks. into_chunks :: < U4 > ( ) ;
@@ -396,13 +391,13 @@ impl<'a> BlockBackend for Sm4Enc<'a> {
396
391
}
397
392
398
393
#[ inline( always) ]
399
- fn proc_par_blocks ( & mut self , blocks : InOut < ' _ , ' _ , ParBlocks < Self > > ) {
394
+ fn encrypt_par_blocks ( & mut self , blocks : InOut < ' _ , ' _ , ParBlocks < Self > > ) {
400
395
unsafe { sm4_encrypt8 :: < Self > ( blocks, & self . 0 . erk ) }
401
396
}
402
397
}
403
398
404
- impl BlockDecrypt for Sm4 {
405
- fn decrypt_with_backend ( & self , f : impl cipher :: BlockClosure < BlockSize = Self :: BlockSize > ) {
399
+ impl BlockCipherDecrypt for Sm4 {
400
+ fn decrypt_with_backend ( & self , f : impl BlockCipherDecClosure < BlockSize = Self :: BlockSize > ) {
406
401
f. call ( & mut Sm4Dec ( self ) )
407
402
}
408
403
}
@@ -417,14 +412,14 @@ impl<'a> ParBlocksSizeUser for Sm4Dec<'a> {
417
412
type ParBlocksSize = U8 ;
418
413
}
419
414
420
- impl < ' a > BlockBackend for Sm4Dec < ' a > {
415
+ impl < ' a > BlockCipherDecBackend for Sm4Dec < ' a > {
421
416
#[ inline( always) ]
422
- fn proc_block ( & mut self , block : InOut < ' _ , ' _ , Block < Self > > ) {
417
+ fn decrypt_block ( & self , block : InOut < ' _ , ' _ , Block < Self > > ) {
423
418
unsafe { sm4_decrypt1 :: < Self > ( block, & self . 0 . drk ) }
424
419
}
425
420
426
421
#[ inline( always) ]
427
- fn proc_tail_blocks ( & mut self , blocks : InOutBuf < ' _ , ' _ , Block < Self > > ) {
422
+ fn decrypt_tail_blocks ( & self , blocks : InOutBuf < ' _ , ' _ , Block < Self > > ) {
428
423
assert ! ( blocks. len( ) < Self :: ParBlocksSize :: USIZE ) ;
429
424
430
425
let ( chunks, tail) = blocks. into_chunks :: < U4 > ( ) ;
@@ -438,7 +433,7 @@ impl<'a> BlockBackend for Sm4Dec<'a> {
438
433
}
439
434
440
435
#[ inline( always) ]
441
- fn proc_par_blocks ( & mut self , blocks : InOut < ' _ , ' _ , ParBlocks < Self > > ) {
436
+ fn decrypt_par_blocks ( & mut self , blocks : InOut < ' _ , ' _ , ParBlocks < Self > > ) {
442
437
unsafe { sm4_decrypt8 :: < Self > ( blocks, & self . 0 . drk ) }
443
438
}
444
439
}
0 commit comments