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

87 Commits

Author SHA1 Message Date
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
a3d297c30e TESTCASES: Don't set CKF_INTERFACE_FORK_SAFE to get interfaces
With the change of the previous commit, we must not set the
CKF_INTERFACE_FORK_SAFE flag when retrieving interfaces.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-10-05 08:35:13 +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
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
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
249c79719b TESTCASES: Prepare and test for PKCS#11 v3.2 function list
Enhance the test-case-common do_GetFunctionList() function, as well as
the get_interface test-case to get the PKCS#11 v3.2 function list.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02: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
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
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
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
977f262cb5 CONFIGURE: Add --enable-sanitizer option for easy sanitizer builds
Add '--enable-sanitizer' option to easily enable a build with sanitizer.
This requires that libasan and libubsan are available.

When running with sanitizer, disable unloading of the Opencryptoki
shared libraries, to produce useful stack traces.

For the same reason 'export LSAN_OPTIONS=fast_unwind_on_malloc=false'
might be required when running the built executable.
Attention: This may make it very slow!

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-11 14:37:25 +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
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
b639f1975c TESTCASES: Print CK_SESSION_INFO.ulDeviceError in case of CKR_FUNCTION_FAILED
Field ulDeviceError in struct CK_SESSION_INFO might be set in case of a
CKR_FUNCTION_FAILED. This can be due to a policy rejection (ulDeviceError
is CKR_POLICY_VIOLATION), or due to other token internal errors.

Print the value of ulDeviceError in case its non-zero and not indicating
a policy error.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-07-01 10:24:08 +02:00
Ingo Franzki
c339928d06 TESTCASES: Update tok2tok_transport to wrap/unwrap IBM Dilithium keys
The soft token as well as the EP11 token supports wrapping of IBM Dilithium
keys. The CCA token does not offer a wrapping mechanism that can wrap IBM
Dilithium keys due to the size of the keys.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-06-24 10:51:12 +02:00
Ingo Franzki
b55b205fad TESTCASES: Also run RSA key import with ME-only keys
To test if ME-only RSA keys are working for all tokens.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-06-17 10:00:51 +02:00
Ingo Franzki
9d45e90e09 TESTCASE: Reduce run time of RSA tests by caching RSA keys
A major part of the runtime of the RSA testcases is RSA key generation,
especially when running with the soft or ICA tokens.

While generating RSA keys with different parameters must certainly also be
tested, there is no need to generate RSA keys over and over again with the
same parameters.

Cache RSA keys so that an attempt to generate a new RSA key with the same
parameters in the same session is omitted, and a cached RSA key is used
instead (if available). Such potentially cached RSA key objects must not be
destroyed by the testcases, since this would make the cached keys unusable.
Instead, the cached keys of a session are destroyed when closing the session,
or at the very end of the testcase.

Unfortunately it is not easily possible to cache RSA keys across multiple
sessions, because a key object handle is only valid within the session it
was created, so a handle from session 1 can not be used on session 2.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-06-10 13:42:10 +02:00
Akash Kulhalli
d1785b5e54 testcases: miscellaneous updates
`random` returns a number within a range that includes 0; but the code does not
always handle that, leading to misleading error messages ("malloc failed" but
it was a request for a memory buffer of size 0) on test run. Those should now
be fixed.

The `ock_tests.sh.in` file has been slightly tweaked to account for some flags
that are not available on AIX. No functional differences expected across all
supported platforms.

On Linux, a null pointer is printed as "(null)", whereas on AIX nothing is
printed. Since this is only for tests, AIX now also prints the same string as
Linux when a nullptr is attempted to be printed.

Signed-off-by: Akash Kulhalli <akash.kulhalli@ibm.com>
2024-04-24 09:48:07 +02:00
Joerg Schmidbauer
4b6e534135 TESTCASES: Enable AES and EC tests for combined extract
A new parameter -combined-extract is introduced for the testcases. If this
parameter is specified, the CKA_IBM_PROTKEY_EXTRACTABLE attribute is always
set to TRUE for new key objects. Note that testcases will fail if combined
extract is not supported in the test environment! In addition to this, a
new token setup is added to ciconfig.sh to enable combined extract tests
in the CI.

Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2024-04-02 09:31:53 +02:00
Joerg Schmidbauer
7693070c73 CCA pkey option: enforce pkey usage in testcases
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2023-04-14 08:51:08 +02:00
Vishnudatha Kanjur
92720c8ef1 EP11: testcase changes for AES XTS mechanism.
Test case changes to include AES XTS mechanism for protected keys in the EP11 token.
Also, skip tests which try to create non protected AES XTS keys in EP11 token.
Also, skip p11sak AES XTS tests for EP11 token.

Signed-off-by: Vishnudatha Kanjur <kanjur@ibm.com>
2023-01-30 16:56:58 +01:00
Ingo Franzki
064195093f TESTCASES: Add tests for CKM_IBM_KYBER
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-01-24 14:52:11 +01:00
Ingo Franzki
f2519d1416 TESTCASES: Test Dilithium variants
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-01-24 14:52:11 +01:00
Ingo Franzki
af9ccf352d COMMON/EP11: Allow to select Dilithium variant via mode or key form attribute
Attributes CKA_IBM_DILITHIUM_KEYFORM or CKA_IBM_DILITHIUM_MODE can
be used to select the Dilithium variant to use.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-01-24 14:52:11 +01:00
Ingo Franzki
fc5b0da80b c99 fixes: strict prototypes and old-style definitions
The c99 standard requires strict prototypes and explicit definitions
of void functions.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-11-11 10:33:15 +01:00
Ingo Franzki
209d030493 testcases: Fixes for ICSF token
The ICSF token does not support certain attributes and/or combinations
of attributes, as well as only certain EC curves and RSA keys.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-10-19 11:33:30 +02:00
Ingo Franzki
be94804415 testcases: remove CKA_EC_POINT from EC private key
When creating an EC private key from clear key data, do not supply
CKA_EC_POINT, since PKCS#11 does not define it for an EC private key.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-10-19 11:33:30 +02:00
Ingo Franzki
f9bdcf06ea testcases: Add tests for AES-XTS
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-10-17 09:54:42 +02:00
Ingo Franzki
a163664c62 testcases: Skip tests in case of policy rejections
When a PKCS#11 function fails with CKR_FUNCTION_FAILED and
field ulDeviceError in CK_SESSION_INFO is CKR_POLICY_VIOLATION,
then this indicates that the operation is rejected due to policy.
Skip the testcase in this case, instead if failing it.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2021-11-08 16:29:24 +01:00
Juergen Christ
3b0a198aa9 Exploit mechanism table
Make use of mechanism table to translate between string and numeric format of
mechanisms.  Remove duplicated code dealing with mechanism translations.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2021-11-08 16:29:24 +01:00
Juergen Christ
2627c52020 COMMON: Fix bug introduced during load/unload refactoring
Make sure the TokData member is always freed.  Special care has to be taken
for the fork situation.  In that case, we have to free TokData but block all
paths to a dlclose.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2021-10-07 19:09:16 +02:00
Ingo Franzki
d6b4368ca8 TESTCASES: EC: Check if key is usable after C_DeriveKey()
Perform a HMAC sign operation with the derived key to check hat
this key is really usable (if the derived key is within the allowed
key sizes of the HMAC mechanism).

We recently encountered a problem with EP11 on a CEX5 where a derived
key blob might be invalid for certain key sizes due to a firmware bug.
This test would fail for such situations.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2021-08-23 16:53:51 +02:00
Ingo Franzki
376e664f08 TESTCASES: Remove RSA public exponent restriction for Soft token
Since commit "Allow small RSA exponents in the default provider"
254957f768
in OpenSSL 3.0, we do no longer need to restrict the tests for the Soft
token to RSA public exponents of 3 and 65537 only.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2021-08-13 19:59:16 +02:00
Ingo Franzki
ecf71404e8 TESTCASES: Soft: Skip tests with RSA publ.exp. not supported by OpenSSL
OpenSSL 3.0 only accepts public exponents of 3 and 65537 for RSA keys.
Skip the testcase if another public exponent is used.

Also fixed some ugly line breaks within messages.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2021-07-30 12:32:57 +02:00
Joerg Schmidbauer
d94799d52e Fix typo in comment
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2021-03-16 16:37:28 +01:00
Joerg Schmidbauer
3a9b93c3b4 EP11 pkey option: add testcases for EC / IBM ED
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2021-03-16 16:37:28 +01:00
Joerg Schmidbauer
8e942f697f EP11 pkey option: introduce pkey flag for testcases
Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2021-02-26 12:44:49 +01:00
Harald Freudenberger
1b16c5a565 TESTCASES: new testcase to test CCA opaque key token export and import
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
2020-12-09 13:54:19 +01:00
Patrick Steuer
2749f80687 Conform to PKCS 11 v3.0 Baseline Provider profile - part 1
Add required constants and declarations and implement the
required functions.

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
2020-10-14 10:59:54 +02:00
Juergen Christ
ef62794ca1 Replace deprecated ftime
Use gettimeofday instead.

Fixes #317

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2020-10-12 15:56:23 +02:00
Ingo Franzki
c256bc7051 TESTCASE: Add testcase to test token to token key transport
.. via key wrap on one token and unwrap on the other token.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2020-10-08 16:35:04 +02:00
Ingo Franzki
fd072239bd TESTCASES: Fix ICSF token detection
When the TPM token is present, the check for the ICSF token returns true,
although the TPM token is used.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2020-10-08 16:35:04 +02:00
Patrick Steuer
4ab1354547 Correct soft token model name everywhere
Fixup for 5d3d1e0.

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
2020-10-08 13:04:02 +02:00
Joerg Schmidbauer
2a07c6d35d EP11: Dilithium stage2: added testcases for Dilithium key import/transport
Added known-answer tests for Dilithium key import/transport with sign/verify.

Signed-off-by: Joerg Schmidbauer <jschmidb@de.ibm.com>
2020-04-24 14:29:22 +02:00
Ingo Franzki
33e58bc69b Fix build issue with gcc 10 and -fno-common
With gcc 10 -fno-common is the default.

Fixes: https://github.com/opencryptoki/opencryptoki/issues/271

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2020-02-03 13:08:59 +01:00
Ingo Franzki
edc32d714a TESTCASES: Enhance EC testcases to test Edwards and Montgomery curves
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2020-01-27 14:39:42 +01:00
Ingo Franzki
ac50293f40 TESTCASE: Enhance CKM_ECDH1_DERIVE tests for EP11
EP11 supports CKM_ECDH1_DERIVE with or without KDFs and shared data
dependent on the firmware version. Enhance the tests so that it skips
test test when it gets error CKR_MECHANISM_PARAM_INVALID when using the
EP11 token and a KDF other than CKD_NULL and/or shared data is used.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2019-10-21 16:30:44 +02:00