Skip to content

Commit b616cd2

Browse files
Fixed tests that require updates of length a multiple of the cipher block size
Signed-off-by: Jacob Prud'homme <2160185+jacobprudhomme@users.noreply.github.com>
1 parent f0e9e21 commit b616cd2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cryptoki/tests/basic.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use std::thread;
2323
use cryptoki::mechanism::ekdf::AesCbcDeriveParams;
2424
use testresult::TestResult;
2525

26+
const AES128_BLOCK_SIZE: usize = 128 / 8;
27+
2628
#[test]
2729
#[serial]
2830
fn sign_verify() -> TestResult {
@@ -446,7 +448,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
446448
let template = vec![
447449
Attribute::Token(true),
448450
Attribute::Private(false),
449-
Attribute::ValueLen((128 / 8).into()),
451+
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
450452
Attribute::Encrypt(true),
451453
Attribute::Decrypt(true),
452454
];
@@ -455,14 +457,16 @@ fn encrypt_decrypt_multipart() -> TestResult {
455457
// Data to encrypt
456458
let data = vec![
457459
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,
459463
];
460464

461-
// Encrypt data in parts
465+
// // Encrypt data in parts
462466
session.encrypt_init(&Mechanism::AesEcb, key)?;
463467

464468
let mut encrypted_data = vec![];
465-
for part in data.chunks(3) {
469+
for part in data.chunks(AES128_BLOCK_SIZE) {
466470
encrypted_data.extend(session.encrypt_update(part)?);
467471
}
468472
encrypted_data.extend(session.encrypt_final()?);
@@ -471,7 +475,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
471475
session.decrypt_init(&Mechanism::AesEcb, key)?;
472476

473477
let mut decrypted_data = vec![];
474-
for part in encrypted_data.chunks(3) {
478+
for part in encrypted_data.chunks(AES128_BLOCK_SIZE) {
475479
decrypted_data.extend(session.decrypt_update(part)?);
476480
}
477481
decrypted_data.extend(session.decrypt_final()?);
@@ -555,7 +559,7 @@ fn encrypt_decrypt_multipart_already_initialized() -> TestResult {
555559
let template = vec![
556560
Attribute::Token(true),
557561
Attribute::Private(false),
558-
Attribute::ValueLen((128 / 8).into()),
562+
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
559563
Attribute::Encrypt(true),
560564
Attribute::Decrypt(true),
561565
];

0 commit comments

Comments
 (0)