@@ -23,6 +23,8 @@ use std::thread;
23
23
use cryptoki:: mechanism:: ekdf:: AesCbcDeriveParams ;
24
24
use testresult:: TestResult ;
25
25
26
+ const AES128_BLOCK_SIZE : usize = 128 / 8 ;
27
+
26
28
#[ test]
27
29
#[ serial]
28
30
fn sign_verify ( ) -> TestResult {
@@ -446,7 +448,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
446
448
let template = vec ! [
447
449
Attribute :: Token ( true ) ,
448
450
Attribute :: Private ( false ) ,
449
- Attribute :: ValueLen ( ( 128 / 8 ) . into( ) ) ,
451
+ Attribute :: ValueLen ( ( AES128_BLOCK_SIZE as u64 ) . into( ) ) ,
450
452
Attribute :: Encrypt ( true ) ,
451
453
Attribute :: Decrypt ( true ) ,
452
454
] ;
@@ -455,14 +457,16 @@ fn encrypt_decrypt_multipart() -> TestResult {
455
457
// Data to encrypt
456
458
let data = vec ! [
457
459
0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 , 0x99 , 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 , 0x99 ,
458
- 0x77 ,
460
+ 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 , 0x99 , 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 ,
461
+ 0x99 , 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 , 0x99 , 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB ,
462
+ 0x33 , 0x99 , 0x77 ,
459
463
] ;
460
464
461
- // Encrypt data in parts
465
+ // // Encrypt data in parts
462
466
session. encrypt_init ( & Mechanism :: AesEcb , key) ?;
463
467
464
468
let mut encrypted_data = vec ! [ ] ;
465
- for part in data. chunks ( 3 ) {
469
+ for part in data. chunks ( AES128_BLOCK_SIZE ) {
466
470
encrypted_data. extend ( session. encrypt_update ( part) ?) ;
467
471
}
468
472
encrypted_data. extend ( session. encrypt_final ( ) ?) ;
@@ -471,7 +475,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
471
475
session. decrypt_init ( & Mechanism :: AesEcb , key) ?;
472
476
473
477
let mut decrypted_data = vec ! [ ] ;
474
- for part in encrypted_data. chunks ( 3 ) {
478
+ for part in encrypted_data. chunks ( AES128_BLOCK_SIZE ) {
475
479
decrypted_data. extend ( session. decrypt_update ( part) ?) ;
476
480
}
477
481
decrypted_data. extend ( session. decrypt_final ( ) ?) ;
@@ -555,7 +559,7 @@ fn encrypt_decrypt_multipart_already_initialized() -> TestResult {
555
559
let template = vec ! [
556
560
Attribute :: Token ( true ) ,
557
561
Attribute :: Private ( false ) ,
558
- Attribute :: ValueLen ( ( 128 / 8 ) . into( ) ) ,
562
+ Attribute :: ValueLen ( ( AES128_BLOCK_SIZE as u64 ) . into( ) ) ,
559
563
Attribute :: Encrypt ( true ) ,
560
564
Attribute :: Decrypt ( true ) ,
561
565
] ;
0 commit comments