Skip to content

Conversation

@testingapisname
Copy link
Contributor

Implements comprehensive AES-GCM testing using official Wycheproof test vectors from Google. Tests 313 valid cryptographic operations across multiple key sizes (128/192/256-bit), nonce lengths, tag sizes, and AAD configurations.

Fixes #187

Copy link
Collaborator

@Jakuje Jakuje 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 your contribution! Just two thoughts regarding the PKCS#11 3.* API

Comment on lines 43 to 44
// Skip tests with nonce sizes that exceed PKCS#11 limits (max 256 bytes)
if test.nonce.len() > 256 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

While the PKCS#11 2.40 has this limitation [1], the higher limit is defined in the current specification 3.2:

The length of the initialization vector can be any number between 1 and (2^32) - 1.

In the tests, you can detect the pkcs11 version and I think we can use the larger ones for the new modules.

Updating the documentation would be good too

[1] https://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/errata01/os/pkcs11-curr-v2.40-errata01-os-complete.html#_Toc441850509
[2] https://docs.oasis-open.org/pkcs11/pkcs11-spec/v3.2/pkcs11-spec-v3.2.html#_Toc195693377

};

// Test encryption
let encrypt_result = session.encrypt(&Mechanism::AesGcm(gcm_params), key, &test.pt);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we test also the PKCS#11 3 API with message-based encryption?

fn encrypt_decrypt_gcm_message_with_aad() -> TestResult {

testingapisname added a commit to testingapisname/rust-cryptoki that referenced this pull request Dec 19, 2025
- Implement PKCS#11 version detection to apply appropriate nonce size limits
  * PKCS#11 2.40: 256 bytes (ulIvBits in bits, per spec section 5.16.3)
  * PKCS#11 3.x: 2^32-1 bytes (ulIvLen in bytes, per spec section 5.15.3)
- Add aes_gcm_message_wycheproof() test for PKCS#11 3.0+ message API
  * Uses message_encrypt_init/encrypt_message/message_encrypt_final
  * Gracefully skips if provider doesn't support message-based encryption
  * Properly handles edge cases (zero-length plaintext, unusual nonce sizes)
  * Includes cleanup logic to prevent session state issues
- All 316 Wycheproof tests pass with both SoftHSM 2.40 and Kryoptic 3.0+

Addresses reviewer feedback from PR parallaxsecond#336
@testingapisname
Copy link
Contributor Author

@Jakuje I think I addressed your comments in this b8ec82d commit. I tested with softhsm and kyroptic. I am not sure what you mean by update the documentation. Can you please review?

Implements comprehensive AES-GCM testing using official Wycheproof
test vectors from Google. Tests 313 valid cryptographic operations
across multiple key sizes (128/192/256-bit), nonce lengths, tag sizes,
and AAD configurations.

Fixes parallaxsecond#187

Signed-off-by: James Eilers <eilersjames15@gmail.com>
- Implement PKCS#11 version detection to apply appropriate nonce size limits
  * PKCS#11 2.40: 256 bytes (ulIvBits in bits, per spec section 5.16.3)
  * PKCS#11 3.x: 2^32-1 bytes (ulIvLen in bytes, per spec section 5.15.3)
- Add aes_gcm_message_wycheproof() test for PKCS#11 3.0+ message API
  * Uses message_encrypt_init/encrypt_message/message_encrypt_final
  * Gracefully skips if provider doesn't support message-based encryption
  * Properly handles edge cases (zero-length plaintext, unusual nonce sizes)
  * Includes cleanup logic to prevent session state issues
- All 316 Wycheproof tests pass with both SoftHSM 2.40 and Kryoptic 3.0+

Addresses reviewer feedback from PR parallaxsecond#336

Signed-off-by: James Eilers <eilersjames15@gmail.com>
- Add provider limitation handling for nonces > 256 bytes
- Fix second test to handle already-initialized PKCS#11 context
- Restore detailed println output for all individual test results

Signed-off-by: James Eilers <eilersjames15@gmail.com>
Signed-off-by: James Eilers <eilersjames15@gmail.com>
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

2 participants