Skip to content

Commit 9a11477

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 81bd2a9 commit 9a11477

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

cryptoki/tests/basic.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,13 @@ fn session_find_objects() -> testresult::TestResult {
449449
Attribute::Token(true),
450450
Attribute::Encrypt(true),
451451
Attribute::Label(format!("key_{}", i).as_bytes().to_vec()),
452+
Attribute::ValueLen(32.into()),
452453
Attribute::Id("12345678".as_bytes().to_vec()), // reusing the same CKA_ID
453454
];
454455

455456
// generate a secret key
456457
let _key = session
457-
.generate_key(&Mechanism::Des3KeyGen, &key_template)
458+
.generate_key(&Mechanism::AesKeyGen, &key_template)
458459
.unwrap();
459460
});
460461

@@ -463,7 +464,7 @@ fn session_find_objects() -> testresult::TestResult {
463464
Attribute::Token(true),
464465
Attribute::Id("12345678".as_bytes().to_vec()),
465466
Attribute::Class(ObjectClass::SECRET_KEY),
466-
Attribute::KeyType(KeyType::DES3),
467+
Attribute::KeyType(KeyType::AES),
467468
];
468469

469470
let mut found_keys = session.find_objects(&key_search_template)?;
@@ -498,20 +499,21 @@ fn session_objecthandle_iterator() -> testresult::TestResult {
498499
let key_template = vec![
499500
Attribute::Token(true),
500501
Attribute::Encrypt(true),
502+
Attribute::ValueLen(32.into()),
501503
Attribute::Label(format!("key_{}", i).as_bytes().to_vec()),
502504
Attribute::Id("12345678".as_bytes().to_vec()), // reusing the same CKA_ID
503505
];
504506

505507
// generate a secret key
506-
session.generate_key(&Mechanism::Des3KeyGen, &key_template)?;
508+
session.generate_key(&Mechanism::AesKeyGen, &key_template)?;
507509
}
508510

509511
// retrieve these keys using this template
510512
let key_search_template = vec![
511513
Attribute::Token(true),
512514
Attribute::Id("12345678".as_bytes().to_vec()),
513515
Attribute::Class(ObjectClass::SECRET_KEY),
514-
Attribute::KeyType(KeyType::DES3),
516+
Attribute::KeyType(KeyType::AES),
515517
];
516518

517519
// test iter_objects_with_cache_size()
@@ -587,23 +589,23 @@ fn wrap_and_unwrap_key() {
587589

588590
let key_to_be_wrapped_template = vec![
589591
Attribute::Token(true),
592+
Attribute::ValueLen(32.into()),
590593
// the key needs to be extractable to be suitable for being wrapped
591594
Attribute::Extractable(true),
592595
Attribute::Encrypt(true),
593596
];
594597

595598
// generate a secret key that will be wrapped
596599
let key_to_be_wrapped = session
597-
.generate_key(&Mechanism::Des3KeyGen, &key_to_be_wrapped_template)
600+
.generate_key(&Mechanism::AesKeyGen, &key_to_be_wrapped_template)
598601
.unwrap();
599602

600-
// Des3Ecb input length must be a multiple of 8
601-
// see: PKCS#11 spec Table 10-10, DES-ECB Key And Data Length Constraints
603+
// AesEcb input length must be a multiple of 16
602604
let encrypted_with_original = session
603605
.encrypt(
604-
&Mechanism::Des3Ecb,
606+
&Mechanism::AesEcb,
605607
key_to_be_wrapped,
606-
&[1, 2, 3, 4, 5, 6, 7, 8],
608+
&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
607609
)
608610
.unwrap();
609611

@@ -643,14 +645,14 @@ fn wrap_and_unwrap_key() {
643645
Attribute::Private(true),
644646
Attribute::Encrypt(true),
645647
Attribute::Class(ObjectClass::SECRET_KEY),
646-
Attribute::KeyType(KeyType::DES3),
648+
Attribute::KeyType(KeyType::AES),
647649
],
648650
)
649651
.unwrap();
650652

651653
let encrypted_with_unwrapped = session
652654
.encrypt(
653-
&Mechanism::Des3Ecb,
655+
&Mechanism::AesEcb,
654656
unwrapped_key,
655657
&[1, 2, 3, 4, 5, 6, 7, 8],
656658
)

0 commit comments

Comments
 (0)