1
0
mirror of https://github.com/opencryptoki/opencryptoki.git synced 2026-10-24 05:39:17 +03:00

275 Commits

Author SHA1 Message Date
Ingo Franzki
1cf361530d TESTCASES: Add tests for CKR_BUFFER_TOO_SMALL on encrypt and decrypt
Check that an encrypt or decrypt call with a too small buffer correctly
returns CKR_BUFFER_TOO_SMALL, update the output buffer length to the
required size, and does not write to the output buffer beyond the
provided output buffer length. Furthermore, the operation must stay
active and a retry must be possible.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-22 12:53:13 +02:00
Alexandre Laroche
e8cadb2484 TESTCASES: Check unwrapped DH, ML-DSA and ML-KEM private keys too
Run check_unwrap_sensitive_extractable() after the private key unwrap in
the ML-DSA and ML-KEM key transfer tests, for every test vector, and add
do_WrapUnwrapDHKey(), which wraps a generated DH private key under an AES
key with CKM_AES_CBC_PAD and runs the same check.

DSA is not covered: the soft token is built with -DNODSA, so no DSA test
runs there.

Signed-off-by: Alexandre Laroche <larochealexandre@hotmail.com>
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-19 13:52:53 +02:00
Alexandre Laroche
7131685d35 TESTCASES: Check CKA_SENSITIVE and CKA_EXTRACTABLE of unwrapped keys
Add check_unwrap_sensitive_extractable() to the common test code. It
unwraps the same data with each combination of CKA_SENSITIVE and
CKA_EXTRACTABLE, and with neither, and checks every new key: the
attributes match the template (any value is accepted when the template
does not set them, since the defaults are token specific);
CKA_ALWAYS_SENSITIVE and CKA_NEVER_EXTRACTABLE are FALSE; and the key
value cannot be read from a sensitive key. When the unwrapping key's
CKA_UNWRAP_TEMPLATE sets one of the attributes, a key unwrapped without
it gets that value, and a template asking for the other value must fail
with CKR_TEMPLATE_INCONSISTENT.

CKA_ALWAYS_SENSITIVE and CKA_NEVER_EXTRACTABLE are not checked on the
ICSF token, which unwraps on the ICSF server and takes these attributes
from it.

Run it from do_WrapUnwrapAES() for secret keys, from do_WrapUnwrapRSA()
for RSA private keys, and from both EC key transfer tests for EC private
keys, whose transport key's CKA_UNWRAP_TEMPLATE sets CKA_EXTRACTABLE =
FALSE. Add do_UnwrapTemplateAES(), which unwraps under a wrapping key
whose CKA_UNWRAP_TEMPLATE sets CKA_SENSITIVE = TRUE and CKA_EXTRACTABLE =
FALSE, for every AES wrap mechanism.

Signed-off-by: Alexandre Laroche <larochealexandre@hotmail.com>
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-19 13:52:53 +02:00
Ingo Franzki
da1daeaaab TESTCASES: Use a DH key that is complaint per NIST SP 800-56A R3 5.6.2.1.2
ICSF enforces NIST SP 800-56A compliance for private key validation during
key agreement. The key DH_PRIVATE_B does not pass this validation.

Update the testcase to use a valid private DH key that is complaint per
NIST SP 800-56A R3 5.6.2.1.2.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-08 12:37:09 +02:00
Ingo Franzki
afb7209dd0 TESTCASE: Let run_DeriveECDHKeyKAT() continue with next vector on error
In case run_DeriveECDHKeyKAT() finds an error with one test vector, continue
with the next one.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-23 13:25:13 +02:00
Ingo Franzki
6d329a4549 TESTCASES: Skip unsupported curves and KDFs for the ICSF token
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-09-23 13:25:13 +02:00
Ingo Franzki
ab96be64ec TESTCASES: Fix resource leak in run_DeriveBTC
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-07-22 13:17:14 +02:00
Ingo Franzki
26e3591e02 TESTCASES: Add tests for the CKM_IBM_ETH_DERIVE mechanism
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-07-22 13:17:14 +02:00
Ingo Franzki
e5314ff05f TESTCASES: Skip if CKR_FUNCTION_CANCELED with ML-KEM with ECDH
CKR_FUNCTION_CANCELED usually indicates that a control point prohibits
an operation, or that the operation is not allowed due to some other
policy. Skip the test in that case.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-05-13 13:18:08 +02:00
Ingo Franzki
67f2819789 TESTCASES: Skip if CKR_KEY_SIZE_RANGE at C_DeriveKey
C_DeriveKey may return CKR_KEY_SIZE_RANGE when CCA enforces the NIST
security strength requirements regarding ECC curve type (input) and
derived key-length.

Skip the test in such cases.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-05-13 13:18:08 +02:00
Ingo Franzki
ba2550b01f TESTCASES: Fix memory leak in run_EncapsDecapsECDH
Fixes: c2ab1d9b8c

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-28 13:31:01 +02:00
Ingo Franzki
5847880151 TESTCASES: Fix memory leak in do_EnDecapsulateDHKey
Fixes: 6acd311005

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-28 13:31:01 +02:00
Ingo Franzki
4abd6fa0d1 TESTCASES: Allow additional public exponent values for CCA
Update the list of valid RSA public exponents for CCA.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-17 11:20:24 +02:00
Ingo Franzki
f2ff1dcf2b TESTCASES: Fix ECDH en-/decapsulation tests for older EP11 cards
Older EP11 firmware does not support ECDH with KDFs other than CKD_NULL, or
with non-empty shared data. This fails with CKR_MECHANISM_PARAM_INVALID
and must be skipped as unsupported properly. This error might only be
reported for the non-size-query call to C_EncapsulateKey.

Add a test vector with CKD_NULL and empty shared data to have at least one
supported test for such older EP11 cards.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-14 15:34:31 +02:00
Ingo Franzki
f38928daff TESTCASES: Add tests for ML-KEM of PKCS#11 v3.2
Test ML-KEM of PKCS#11 v3.2.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
5a83dac640 TESTCASES: Add tests for ML-DSA of PKCS#11 v3.2
Test ML-DSA of PKCS#11 v3.2.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
6acd311005 TESTCASES: Add tests for DH encapsulate/decapsulate
Test DH encapsulation and decapsulation.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
c2ab1d9b8c TESTCASES: Add tests for ECDH encapsulate/decapsulate
Test ECDH encapsulation and decapsulation with different curves, key sizes
and key types.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
a6c55e463e TESTCASES: Add tests for RSA encapsulate/decapsulate
Test RSA encapsulation and decapsulation with different key sizes and different
symmetric key types.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
9dcfc3361e TESTCASES: Add tests for C_VerifySignature[Init/Update/Final]
Enhance the digest test to use both, C_VerifyInit as well as
C_VerifySignatureInit for the HMAC tests.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
8a81b718cb TESTCASES: Fix Coverity finding: Out-of-bounds read
In case the testcase is skipped due to CKR_CURVE_NOT_SUPPORTED, use the right
array (i.e. der_ec_edwards_supported instead of montgomery_ecdh_tv) to get
the testcases name from.

Fixes: 9298f52ba4

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-07 09:15:49 +02:00
Ingo Franzki
4dd1d73463 TESTCASES: Fix wrap/unwrap tests for IBM ML-DSA and IBM ML-KEM
Use the unwrapped private key for further processing to check if the
unwrapped key can be used, not the original private key.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-02-16 11:43:03 +01:00
Ingo Franzki
31f1ab75db TESTCASES: Add tests for ECDH in cofactor mode
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-02-04 14:31:15 +01:00
Ingo Franzki
9298f52ba4 TESTCASES: Add tests for Edwards key type and mechanisms
Enhance the existing testcases to also test Edwards and Montgomery crypto
operations.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-01-27 08:14:16 +01:00
Ingo Franzki
d0ef380bfe TESTCASES: Fix code scan finding: Initialize key handle arrays
Otherwise the loop at the testcase_cleanup label to destroy the keys
might use uninitialized memory and try to destroy garbage handles.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-11-03 14:58:27 +01:00
Ingo Franzki
9b7d410f8e TESTCASES: Enhance test for CKM_IBM_ML_KEM_WITH_ECDH
Enhance the ibm_ml_kem as well as the tok2tok_transport test to also
perform the CKM_IBM_ML_KEM_WITH_ECDH mechanism.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-10-31 14:15:14 +01:00
Ingo Franzki
7f387c9731 TESTCASES: Add testcases for IBM ML-DSA and IBM ML_KEM
Add new test cases for testing ML-DSA and ML-KEM.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-10-31 14:15:14 +01:00
Vishnudatha Kanjur
c11452dcae Testcase Update for BLS12 381 mechanism.
This commit contains testcase updates to include BLS12 381 curve as part of
EC tests in opencryptoki. It includes testcase changes to import public private
key pair for BLS 12 381.

Signed-off-by: Vishnudatha Kanjur <kanjur@ibm.com>
2025-10-29 14:27:12 +01:00
Ingo Franzki
ce665a9728 TESTCASES: Add tests for CKM_RSA_X9_31_KEY_PAIR_GEN
Perform some of the RSA tests with keys generated by mechanism
CKM_RSA_X9_31_KEY_PAIR_GEN.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-08-11 08:27:39 +02:00
Ingo Franzki
2159b3762f TESTCASES: Fix AES-CTR testcases to use the correct counter size (in bits)
Setup the AES-CTR mechanism parameter using the current counter width in
bits (not bytes). Also make sure that it uses the counter value and width
from the known answer test vectors, not the hard-coded one (although they
are the same currently)

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-08-07 15:39:21 +02:00
Ingo Franzki
360b6836be TESTCASES: Add tests for SHA-HMAC key types and key gen mechanisms
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-06-27 10:23:41 +02:00
Ingo Franzki
d4002a507e TESTCASES: Add tests for SHA512-224/256 key derivation mechanisms
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-06-27 10:23:41 +02:00
Ingo Franzki
c04897acbd TESTCASES: Add test vectors for larger RSA key sizes
Also adjust the testcases to support larger RSA keys, i.e. for RSA 8192 bit
keys.

Running tests with larger RSA sizes increase the run time dramatically.
Thus, the RSA 8192 bit tests are disabled by default, but can be enabled
by running the test with the '-rsa8k' option.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-06-24 08:20:59 +02:00
Ingo Franzki
07e6175b06 TESTCASES: Adjust AES tests to cover CCA's support of AES-GCM
The CCA token supports AES-GCM in single-chunk mode only.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-05-26 13:11:59 +02:00
Ingo Franzki
2b84e82345 TESTCASES: Minor fixes in EC tests
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-02-03 16:45:33 +01:00
Ingo Franzki
824f38749c TESTCASES: RSA tests: Check for CKR_KEY_SIZE_RANGE and skip
In case RSA key generation fails with CKR_KEY_SIZE_RANGE, skip the test.
CKR_KEY_SIZE_RANGE indicates that the size of a key part (modulus or
public exponent) is not supported by the token.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-01-13 17:05:24 +01:00
Ingo Franzki
3f6f6d43cf TESTCASES: Skip test if C_WrapKey fails with CKR_WRAPPING_KEY_SIZE_RANGE
Only a certain amount of data can be encrypted with RSA-OAEP for a given
RSA key size and OAEP digest. Skip the test if the temporary AES key of
a CKM_RSA_AES_KEY_WRAP key wrap operation can not be wrapped due to these
size restrictions.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-12 16:37:37 +01:00
Ingo Franzki
c6a22fb682 TESTCASES: Add tests for the CKM_RSA_AES_KEY_WRAP mechanism
Perform wrap/unwrap with the CKM_RSA_AES_KEY_WRAP mechanism.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-11 14:37:58 +01:00
Ingo Franzki
7de37d554b TESTCASES: Add tests for CKM_AES_KEY_WRAP[_*] mechanisms
Perform encrypt/decrypt, as well as wrap/unwrap with the
CKM_AES_KEY_WRAP[_*] mechanisms.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-11 14:37:58 +01:00
Ingo Franzki
5f133f19d6 TESTCASES: Fix checking of OAEP parameters for CCA
Coverity findings: hashAlg or mgf cannot be equal to two different values
at the same time.

Fixes: fdff7ca5e2

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-03 11:00:16 +01:00
Ingo Franzki
48d143e903 TESTCASES: Skip ECDH test if not allowed due to control point
Check for CKR_FUNCTION_CANCELED and skip the test. CKR_FUNCTION_CANCELED
means that the operation is not allowed due to a control point setting.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-11-28 10:49:12 +01:00
Ingo Franzki
7955c8d586 TESTCASES: Fix out of bounds access
Do the memcmp with the right length. Using a wrong length may cause
it to overrun the buffers, or compare in a wrong length. Both most
likely result in the false assumption that the testcase would have
failed, because the two buffers would not be the same.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-11-26 15:02:54 +01:00
Ingo Franzki
41863463ba TESTCASES: Adapt ECDH testcase for use with the CCA token
The CCA token only supports to derive AES-256 keys. Skip all attempts to
derive different key sizes.

The EC testcase usually derives keys of type CKK_GENERIC_SECRET, to allow
various key sizes. It checks that the derived keys are usable and correct
by performing an HMAC operation with them (if supported by the token).

If the test runs against the CCA token, derive AES-256 keys instead, and
perform an AES encrypt operation with them to test the usability and
correctness.

Known answer tests (KAT) for ECDH are not possible with the CCA token, because
CCA only allows to perform ECDH with randomly generated EC keys, but not
with EC keys imported from clear. However, for KATs, we would need to use
imported keys.

Furthermore, ECC keys imported from clear can not have CKA_DERIVE=TRUE for
the CCA token. Make sure CKA_DERIVE is TRUE only for those cases where it
really is required.

The cca_export_import_test is changed to import an ECC private key blob
with CKA_DERIVE=TRUE. This is safe since it did generate the key blob just
before with the CCA token, so it should have everything that is needed to
support key derivation.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-11-25 09:18:31 +01:00
Ingo Franzki
097dbc9a07 EP11: Fix handling of bPrepend flag in CK_IBM_KYBER_PARAMS
The bPrepend flag in CK_IBM_KYBER_PARAMS can not be used as an indication
if the hSecret key handle is valid or not. The bPrepend flag only determines
if the hybrid secret is prepended to the Kyber secret, or appended.

To check if a hybrid secret is specified check if the hSecret handle
is CK_INVALID_HANDLE or a valid object handle value.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-11-18 10:39:58 +01:00
Ingo Franzki
f5703b6f91 testcases: Wrapping CCA AES CIPHER keys can not work, skip it
When the CCA token is configured to use CCA AES CIPHER keys, then wrapping
such keys is not possible, and an attempt to do so fails with
CKR_KEY_NOT_WRAPPABLE. Don't treat this as an error but skip the test.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-11-12 15:13:10 +01:00
Ingo Franzki
0d8c133913 TESTCASE: Add SHAKE key derivation tests
Enhance the list of hash based key derivation mechanisms to also
include the two SHAKE key derivation mechanisms.

According to the PKCS#11 standard, SHAKE key derivation needs to
have a key type and/or a length provided in the template. Skip the
tests where either no key type and length is specified at all, or
no length is specified together with a key type of CKK_GENERIC_SECRET.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-10-01 14:40:28 +02:00
Joerg Schmidbauer
96dcaaf89d TEST: add CKA_IBM_PROTKEY_EXTRACTABLE=true to EC public keys
Explicitly give EC public keys CKA_IBM_PROTKEY_EXTRACTABLE=true. But
even if this attribute is not contained in the template, EC public keys
would get it internally when creating the object.

Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2024-08-15 16:39:54 +02:00
Ingo Franzki
9574ab98ba TESTCASES: Generate unique label for do_EncryptDecryptAESPkey() test
To allow running the testcase concurrently against the same token, generate a
unique name, so that one process does not find another process's token object,
because this would cause the testcase to fail, although its not a real failure,
just an effect of running concurrently.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-07-10 08:44:32 +02:00
Ingo Franzki
54912870d8 TESTCASES: The soft token uses randomized Dilithium signatures
... thus no known answer tests (KATs) are possible. Just skip the
signature comparison, but keep the signature size check, and verify
the known answer signature via C_Verify using the key. The known
answer signature as well as the (randomized) actual signature must
both verify OK with the current key.

Currently only the soft token (i.e. the oqsprovider, or more precisely
liboqs) uses randomized signatures, EP11 and CCA use deterministic
signatures.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-06-24 10:51:12 +02:00
Ingo Franzki
a7ebee5a9c COMMON: Add aliases for CKM_SHA3_nnn_KEY_DERIVE
PKCS#11 v3.0 adds mechanisms like CKM_SHA3_nnn_KEY_DERIVE for SHA3 based key
derivation. For whatever reason, the SHA3 variants of those mechanisms are
called like ..._KEY_DERIVE while the SHA1 and SHA2 variants are called like
..._KEY_DERIVATION.

In PKCS#11 v3.1 this has been aligned and these mechanisms are now called
CKM_SHA3_nnn_KEY_DERIVATION, but there are aliases for the old mechanism
names like CKM_SHA3_nnn_KEY_DERIVE to map to the new names.

Update the code to use the new names, but also add the aliases so that
existing applications that use the old names continue to work. Also add
the aliases to the policy parser, to allow parsing existing policy files
that use the old names.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-06-17 13:18:42 +02:00