Skip to content

test: Add Wycheproof-based AES-CBC-PKCS5 tests#363

Open
testingapisname wants to merge 2 commits into
parallaxsecond:mainfrom
testingapisname:main
Open

test: Add Wycheproof-based AES-CBC-PKCS5 tests#363
testingapisname wants to merge 2 commits into
parallaxsecond:mainfrom
testingapisname:main

Conversation

@testingapisname
Copy link
Copy Markdown
Contributor

Implements comprehensive AES-CBC-PKCS5 testing using official Wycheproof test vectors from Google. Tests 216 valid cryptographic operations across multiple key sizes (128/192/256-bit) with PKCS#7 padding.

Fixes #187

Comment thread cryptoki/tests/wycheproof.rs Outdated
Comment on lines +628 to +632
// The main requirement is that Valid tests pass
assert_eq!(failed, 0, "Some valid Wycheproof tests failed");

session.close()?;
pkcs11.finalize()?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to close and then assert, since if the assert panics the finalization will not happen (maybe I'm paranoid 😅).

Suggested change
// The main requirement is that Valid tests pass
assert_eq!(failed, 0, "Some valid Wycheproof tests failed");
session.close()?;
pkcs11.finalize()?;
session.close()?;
pkcs11.finalize()?;
// The main requirement is that Valid tests pass
assert_eq!(failed, 0, "Some valid Wycheproof tests failed");

Implements comprehensive AES-CBC-PKCS5 testing using official Wycheproof test
vectors from Google. Tests 216 valid cryptographic operations across multiple key
sizes (128/192/256-bit) with PKCS#7 padding.

Fixes parallaxsecond#187

Signed-off-by: James Eilers <eilersjames15@gmail.com>
Move session.close() and pkcs11.finalize() before the assert so that if the
assert panics, resources are guaranteed to be cleaned up properly.

Signed-off-by: James Eilers <eilersjames15@gmail.com>
Copy link
Copy Markdown
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding those!

passed += 1;
}
// Invalid test that succeeded - Note: HSM may not catch all invalid cases
(wycheproof::TestResult::Invalid, Ok(_)) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that actually happen with some of the test cases? Maybe it would be safe to double-check those and filter-out on invalid cases we do not support?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of the Invalid tasks have BadPadding flag. which can be used to filter it more precisely.

https://github.com/randombit/wycheproof-rs/blob/master/src/data/aes_cbc_pkcs5_test.json#L424

failed += 1;
}
// Acceptable tests can go either way
(wycheproof::TestResult::Acceptable, Ok(_)) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the | condition on Acceptable above and move it here like:

// Acceptable tests can go either way
(wycheproof::TestResult::Acceptable, Ok(_) | Err(_)) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going through the source file for this input, I do not see any tests marked Acceptable:

https://github.com/randombit/wycheproof-rs/blob/master/src/data/aes_cbc_pkcs5_test.json

Could we prune the branches that are not executed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Wycheproof-based tests

4 participants