Skip to content

Commit 49eeff2

Browse files
committed
tests: Generate AES keys instead of DES3
The DES3 is not usable for anything and modern pkcs11 modules do not implement it. AES is much widely implemented. Signed-off-by: Jakub Jelen <[email protected]>
1 parent 7a65d85 commit 49eeff2

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

cryptoki/tests/basic.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,13 @@ fn session_find_objects() -> testresult::TestResult {
437437
Attribute::Token(true),
438438
Attribute::Encrypt(true),
439439
Attribute::Label(format!("key_{}", i).as_bytes().to_vec()),
440+
Attribute::ValueLen(32.into()),
440441
Attribute::Id("12345678".as_bytes().to_vec()), // reusing the same CKA_ID
441442
];
442443

443444
// generate a secret key
444445
let _key = session
445-
.generate_key(&Mechanism::Des3KeyGen, &key_template)
446+
.generate_key(&Mechanism::AesKeyGen, &key_template)
446447
.unwrap();
447448
});
448449

@@ -451,7 +452,7 @@ fn session_find_objects() -> testresult::TestResult {
451452
Attribute::Token(true),
452453
Attribute::Id("12345678".as_bytes().to_vec()),
453454
Attribute::Class(ObjectClass::SECRET_KEY),
454-
Attribute::KeyType(KeyType::DES3),
455+
Attribute::KeyType(KeyType::AES),
455456
];
456457

457458
let mut found_keys = session.find_objects(&key_search_template)?;
@@ -486,20 +487,21 @@ fn session_objecthandle_iterator() -> testresult::TestResult {
486487
let key_template = vec![
487488
Attribute::Token(true),
488489
Attribute::Encrypt(true),
490+
Attribute::ValueLen(32.into()),
489491
Attribute::Label(format!("key_{}", i).as_bytes().to_vec()),
490492
Attribute::Id("12345678".as_bytes().to_vec()), // reusing the same CKA_ID
491493
];
492494

493495
// generate a secret key
494-
session.generate_key(&Mechanism::Des3KeyGen, &key_template)?;
496+
session.generate_key(&Mechanism::AesKeyGen, &key_template)?;
495497
}
496498

497499
// retrieve these keys using this template
498500
let key_search_template = vec![
499501
Attribute::Token(true),
500502
Attribute::Id("12345678".as_bytes().to_vec()),
501503
Attribute::Class(ObjectClass::SECRET_KEY),
502-
Attribute::KeyType(KeyType::DES3),
504+
Attribute::KeyType(KeyType::AES),
503505
];
504506

505507
// test iter_objects_with_cache_size()
@@ -575,23 +577,23 @@ fn wrap_and_unwrap_key() {
575577

576578
let key_to_be_wrapped_template = vec![
577579
Attribute::Token(true),
580+
Attribute::ValueLen(32.into()),
578581
// the key needs to be extractable to be suitable for being wrapped
579582
Attribute::Extractable(true),
580583
Attribute::Encrypt(true),
581584
];
582585

583586
// generate a secret key that will be wrapped
584587
let key_to_be_wrapped = session
585-
.generate_key(&Mechanism::Des3KeyGen, &key_to_be_wrapped_template)
588+
.generate_key(&Mechanism::AesKeyGen, &key_to_be_wrapped_template)
586589
.unwrap();
587590

588-
// Des3Ecb input length must be a multiple of 8
589-
// see: PKCS#11 spec Table 10-10, DES-ECB Key And Data Length Constraints
591+
// AesEcb input length must be a multiple of 16
590592
let encrypted_with_original = session
591593
.encrypt(
592-
&Mechanism::Des3Ecb,
594+
&Mechanism::AesEcb,
593595
key_to_be_wrapped,
594-
&[1, 2, 3, 4, 5, 6, 7, 8],
596+
&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
595597
)
596598
.unwrap();
597599

@@ -631,17 +633,13 @@ fn wrap_and_unwrap_key() {
631633
Attribute::Private(true),
632634
Attribute::Encrypt(true),
633635
Attribute::Class(ObjectClass::SECRET_KEY),
634-
Attribute::KeyType(KeyType::DES3),
636+
Attribute::KeyType(KeyType::AES),
635637
],
636638
)
637639
.unwrap();
638640

639641
let encrypted_with_unwrapped = session
640-
.encrypt(
641-
&Mechanism::Des3Ecb,
642-
unwrapped_key,
643-
&[1, 2, 3, 4, 5, 6, 7, 8],
644-
)
642+
.encrypt(&Mechanism::AesEcb, unwrapped_key, &[1, 2, 3, 4, 5, 6, 7, 8])
645643
.unwrap();
646644
assert_eq!(encrypted_with_original, encrypted_with_unwrapped);
647645
}

0 commit comments

Comments
 (0)