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

203 Commits

Author SHA1 Message Date
Ingo Franzki
8a252633d0 PKCSSLOTD: Reduce the number of admin connections to 32
Accepting too many concurrent admin connections dramatically increases the
risk of a denial-of-service attack. An malicious admin connection might
flood the connection with events, which requires a huge amount of memory
to pass these events to the applications. Especially when the events
require a reply, then this can add up to a lot of memory, causing the
pkcsslotd to run into out-of-memory situations. This might cause it to
drop application connections, which can have bad effects.

32 concurrent admin connections should be more than enough at the moment.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-08-25 13:03:17 +02:00
Ingo Franzki
899173b27f PKCSSLOTD: Simplify copying slot info in PopulateSlotInfo()
Instead of copying each member separately, copy the entire struct at once.
This also fixes a bug where the string fields uses memcpy with strlen,
which does not copy the trailing NUL character. The target struct is
zeroed before, so there anyway is a NUL character, but that is subtle.

While at it remove the unused field shm_addr.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-08-19 08:27:40 +02:00
Ingo Franzki
4c4c47f451 COMMON: Add definitions for CKM_IBM_ETH_DERIVE mechanism
Add definitions for the IBM-specific Ethereum 2.0 key derivation mechanism
CKM_IBM_ETH_DERIVE. It can be used to perform Ethereum 2.0 key derivation of
BLS12-381 EC keys using the mechanism described in EIP-2333. It is used with
C_DeriveKey() and has a mechanism parameter defined by structure
CK_IBM_ETH_DERIVE_PARAMS

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-07-22 13:17:14 +02:00
Ingo Franzki
bb8733875f COMMON: Fix typo in ML-KEM OID define and constant
External define OCK_ML_KEM_786 has a typo, it must be OCK_ML_KEM_768. Fix
this, but keep the old define for backward compatibility.

Also constant ml_kem_786 has the same typo, it must be ml_kem_768. Fix
this also (not externally visible).

Fixes: 1440e408f8

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-22 13:07:57 +02:00
Ingo Franzki
cfc3b8ad4f COMMON: Add CKM_PUB_KEY_FROM_PRIV_KEY to pkcs11types.h, policy and mechtable
Add the define for CKM_PUB_KEY_FROM_PRIV_KEY to pkcs11types.h. Also add this
mechanism to the mechanism table and the policy code.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-22 13:07:43 +02:00
Ingo Franzki
1c008f8524 COMMON: Add CKM_ECDH_*_AES_KEY_WRAP to pkcs11types.h, policy and statistics
Add defines for CKM_ECDH_X_AES_KEY_WRAP and CKM_ECDH_COF_AES_KEY_WRAP to
pkcs11types.h. Also add these mechanisms to policy and statistics code.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-22 13:07:43 +02:00
Ingo Franzki
bbf50cdfd7 CCA: Add support for keygen and import of PKCS#11 v3.2 ML-DSA keys
CCA uses distinct key types for Pure-ML-DSA and Prehash-ML-DSA. That type
must be selected at key generation or import already.

Add a CCA token configuration option to select the ML-DSA mode to use
by default, as well as an attribute CKA_IBM_CCA_ML_DSA_KEY_MODE that
can be supplied during key generation or import to select the desired
mode. If attribute CKA_IBM_CCA_ML_DSA_KEY_MODE is not present in the
template at key generation or import, the token configuration option
determines the mode to use for the new key. For key generation,
CKA_IBM_CCA_ML_DSA_KEY_MODE must be specified in the private key template
only, and can not be specified in the public key template. When importing
a public key, it can also be specified in the public key template.

ML-DSA keys in 'PURE' mode can be used for Pure-ML-DSA sign/verify only,
that is, only mechanism CKM_ML_DSA can be used with them. ML-DSA keys in
'PREHASH' mode can be used for PreHash-ML-DSA sign/verify only, that is,
only mechanisms CKM_HASH_ML_DSA[_xxx] can be used with them.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
795fedccca COMMON: Add ML-DSA and ML-KEM PKCS#11 v3.2 defines to pkcstypes.h
Add defines for the PKCS#11 v3.2 key types CKK_ML_KEM and CKK_ML_DSA, as
well as attributes, mechanisms, and mechanism parameter structures specific
for those key types.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
eccccc8c80 COMMON: Implement C_En/DecapsulateKey functions
Implement C_En/DecapsulateKey functions by routing them through to the
tokens. Also add base support for en-/decapsulation in the key manager.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
2bcebe8831 COMMON: Implement C_VerifySignature[Init/Update/Final] functions
PKCS#11 v3.2 states: "Any mechanism that supports C_VerifyInit must also
support C_VerifySignatureInit."

Use common code for both variants, C_VerifyInit, C_Verify, C_VerifyUpdate,
C_VerifyFinal, as well as C_VerifySignatureInit, C_VerifySignature,
C_VerifySignatureUpdate, C_VerifySignatureFinal.

The only difference is that for C_VerifySignatureInit the signature to be
verified is passed at the init call, while for C_VerifyInit, it is passed
only at the final call.

C_VerifySignatureInit saves the signature in the context, so that it is
available later when the final verification is performed. That way the
tokens do not need to implement both variants, but can support both
transparently.

It is ensured that the sequence of calls can not be mixed. Otherwise
CKR_OPERATION_NOT_INITIALIZED is returned.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
f08c175a36 COMMON: Add base support for PKCS#11 v3.2
Add support for the new PKCS#11 v3.2 function list and the new functions
(all of them return CKR_FUNCTION_NOT_SUPPORTED as of now), as well as
for the new encapsulate/decvapsulate attributes.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
30099e6135 COMMON: Add PKCS#11 v3.2 base defines to pkcstypes.h
Add defines for the new PKCS#11 v3.2 function list, return codes, flags,
and attributes to pkcstypes.h.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-04-13 14:39:43 +02:00
Ingo Franzki
ed9954c9da COMMON: Add defines for Edwards and Montgomery key types and mechanisms
Add defines for the Edwards and Montgomery key types CKK_EC_EDWARDS, and
CKK_EC_MONTGOMERY, mechanisms CKM_EDDSA, CKM_EC_EDWARDS_KEY_PAIR_GEN,
and CKM_EC_MONTGOMERY_KEY_PAIR_GEN, as well as the mechanism parameter
structure CK_EDDSA_PARAMS to the pkcs11types.h header file.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2026-01-27 08:14:16 +01:00
Ingo Franzki
1a41c4940e COMMON: Add defines for CKM_IBM_ML_KEM_WITH_ECDH mechanism
Add defines for mechanism CKM_IBM_ML_KEM_WITH_ECDH and its
mechanism parameter CK_IBM_ML_KEM_WITH_ECDH_PARAMS to pkcs11types.h

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-10-31 14:15:14 +01:00
Ingo Franzki
1440e408f8 COMMON: Add OIDs of ML-DSA and ML-KEM algorithms
While at it, rename the length info element for dilithium to ml_dsa,
and use it for both, Dilithium as well as ML-DSA. The key components
are the same, just different sizes dependent on the variant.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-10-31 14:15:14 +01:00
Ingo Franzki
71b8ce2fee COMMON: Add ML-DSA and ML-KEM definitions to pkcstypes.h
ML-DSA and ML-KEM use common definitions with IBM Dilithium and IBM Kyber,
such as the attribute types for the key components, as well as the KEM
mechanism parameter. Those definitions are changed to be named for ML-DSA
and ML-KEM respectively, but there are aliases for the old Dilithium and
Kyber names that map to the new definitions.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-10-31 14:15:14 +01:00
Vishnudatha Kanjur
84a349204c EP11: BLS 12 381 curve aggregation inclusion using CKM_IBM_EC_AGGREGATE
This commit includes CKM_IBM_EC_AGGREGATE mechanism in opencryptoki for EP11 token.

Signed-off-by: Vishnudatha Kanjur <kanjur@ibm.com>
2025-10-29 14:27:12 +01:00
Vishnudatha Kanjur
2d0bed0820 EP11: Generate Key, Sign and Verify support for BLS 12 381 curve
The commit adds support for BLS 12 381 curve as part of CKM_IBM_ECDSA_OTHER
with CKM_IBM_BLS submechanism for EP11 token.

Signed-off-by: Vishnudatha Kanjur <kanjur@ibm.com>
2025-10-29 14:27:12 +01:00
Ingo Franzki
c2f43a8a86 COMMON: Add defines for SHA-HMAC key types and key gen mechanisms
Add key types like CKK_SHAxxx_HMAC and the corresponding key generation
mechanisms CKM_SHAxxx_KEY_GEN. These key types are similar to the generic
secret key type (CKK_GENERIC_SECRET). Keys of these types can be used
for the corresponding HMAC-SHA mechanisms (CKM_SHAxxx_HMAC and
CKM_SHAxxx_HMAC_GENERAL), along with generic secret keys.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-06-27 10:23:41 +02:00
Ingo Franzki
a788d23611 COMMON: Add defines for SHA512-224/256 key derivation mechanisms
Add the mechanism CKM_SHA512_224_KEY_DERIVATION and
CKM_SHA512_256_KEY_DERIVATION to pkcstypes.h

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2025-06-27 10:23:41 +02:00
Ingo Franzki
f0aa5a632b COMMON: Add CKM_ECDH_AES_KEY_WRAP mechanism defines
Add defines for mechanism CKM_ECDH_AES_KEY_WRAP to the header file, the
mechanism table, as well as the policy and statistics code.

Field ulAESKeyBits of the CK_ECDH_AES_KEY_WRAP_PARAMS mechanism parameter
may not be set when performing unwrap. For unwrap, the size of the
temporary AES key is a result of unwrapping, and may not be known
by the caller. Field ulAESKeyBits should be set to zero if unknown.
In such cases the policy check can not check if the size of the
temporary AES key is according to the used policy.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-11 14:37:58 +01:00
Ingo Franzki
8a7242772e COMMON: Add CKM_RSA_AES_KEY_WRAP mechanism defines
Add defines for mechanism CKM_RSA_AES_KEY_WRAP to the header file, the
mechanism table, as well as the policy and statistics code.

Field ulAESKeyBits of the CK_RSA_AES_KEY_WRAP_PARAMS mechanism parameter
may not be set when performing unwrap. For unwrap, the size of the
temporary AES key is a result of unwrapping, and may not be known
by the caller. Field ulAESKeyBits should be set to zero if unknown.
In such cases the policy check can not check if the size of the
temporary AES key is according to the used policy.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-11 14:37:58 +01:00
Ingo Franzki
b193833e41 COMMON: Add CKM_AES_KEY_WRAP[_*] mechanism defines
Add defines for CKM_AES_KEY_WRAP, CKM_AES_KEY_WRAP_PAD, CKM_AES_KEY_WRAP_KWP,
and CKM_AES_KEY_WRAP_PKCS7 (PKCS#11 v3.1) to the header file, the mechanism
table, and the policy code.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-11 14:37:58 +01:00
Ingo Franzki
90dc9231a0 CCA: Allow to choose CCA AES secure key mode via CKA_IBM_CCA_AES_KEY_MODE
When generating or importing an AES key, the template can contain attribute
CKA_IBM_CCA_AES_KEY_MODE to specify the mode of the CCA secure key to generate
or import. Possible choices are DATA key (CK_IBM_CCA_AES_DATA_KEY) or
CIPHER key (CK_IBM_CCA_AES_CIPHER_KEY).

If the CKA_IBM_CCA_AES_KEY_MODE attribute is not contained in the
template, then the CCA config option 'AES_KEY_MODE' or the overall default
defines the mode of the secure key that is generated or imported.

In either case, attribute CKA_IBM_CCA_AES_KEY_MODE is added to the AES key
object denoting the mode of the CCA secure key.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-11-11 09:36:47 +01:00
Ingo Franzki
a11fcfd8ee COMMON: Add defines from PKCS#11 v3.0 for SHAKE key derivation
Add defines for SHAKE mechanisms like CKM_SHAKE_128_KEY_DERIVATION and
CKM_SHAKE_256_KEY_DERIVATION.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-10-01 14:40:28 +02:00
Ingo Franzki
fe511af72f PKCSSLOTD/API/COMMON: Allow to configure a token user group
A new optional key value pair named 'usergroup' can be specified within a
slot structure to specify the user group name that is set as the owner of
the token directory. Only users that are members of this group have access
to the token and its objects. Users that are not a member of this group
will not see the token as being available (e.g. via 'pkcsconf -t' or via
'C_GetTokenInfo').

If no token group is specified, then the token is owned by the 'pkcs11' group
like before this change.

If a token user group is specified, then the pkcsslotd checks if that group
exists, and if all members of that group are also members of the 'pkcs11'
group. This is required to be able to access the pkcsslotd socket at all.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-08-12 14:46:21 +02:00
Ingo Franzki
e97a52bfd8 COMMON: Add defines for always-authenticate support
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-08-07 10:38:30 +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
Ingo Franzki
97f95aa65e COMMON: Add support for *_SP800 KDFs for ECDH
The *_SP800 KDFs use the algorithm defined by FIPS SP800-56A/SP800-56C
instead of the algorithm defined by ANSI X9.63.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-06-10 13:42:10 +02:00
Ingo Franzki
3ab34c3bb4 COMMON: Add defines from PKCS#11 v3.0 for SHA3
Add defines for SHA3 mechanisms like CKM_SHA3_nnn, CKM_SHA3_nnn_HMAC,
CKM_SHA3_nnn_HMAC_GENERAL, CKM_SHA3_nnn_KEY_DERIVE, but also for
combined digest-sign mechanisms like CKM_ECDSA_SHA3_nnn,
CKM_SHA3_nnn_RSA_PKCS, and CKM_SHA3_nnn_RSA_PKCS_PSS, as well as
MGFs like CKG_MGF1_SHA3_nnn and KDFs like CKD_SHA3_nnn_KDF

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-06-10 13:42:10 +02:00
Ingo Franzki
304941d826 COMMON: Add flag defines CKF_EC_OID and CKF_EC_CURVENAME
CKF_EC_OID is the same as CKF_EC_NAMEDCURVE, and CKF_EC_NAMEDCURVE is
deprecated since PKCS#11 v3.0.

CKF_EC_CURVENAME is set if the token supports CKA_EC_PARAMS to use
the curveName choice (i.e. the curve name as printable string)
instead of the OID.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-06-10 13:42:10 +02:00
Akash Kulhalli
b85c7088e2 slotd: Add AIX-specific changes to daemon polling routines
`epoll` is Linux-specific. AIX has an epoll clone, but it's called `pollset`.
The API signatures are nearly identical, and is intended to be the `epoll`
equivalent for AIX. AIX-specific code blocks have been added to account for it.

Privilege management on AIX is also significantly different than on Linux. AIX
has a different set of privileges that pkcsslotd does not need, and therefore
has all of them disabled at runtime. Due to platform restrictions, the slot
daemon runs under user `slotd`, instead of the usual `pkcsslotd` on Linux.
Later versions of AIX (7.3+) do not have this restriction, but are bottlenecked
by this restriction present on 7.2. Earlier releases of AIX do not have an
equivalent implementation of pollset and are therefore not supported.

Finally, file paths that use tmpfs have been adjusted according to the platform.
On Linux, it will unconditionally use the tmpfs-directories for the appropriate
files (pid and socket files under /run), while on AIX it will use the
prefix that was mentioned during configure time. This is because AIX mounts
/var as a normal jfs2 mount point, not tmpfs as Linux does. This means AIX does
not have any advantage with using /run directly, and is therefore better to
keep the install directory self-contained. /run is not a separate mount point on
AIX either.

Signed-off-by: Akash Kulhalli <akash.kulhalli@ibm.com>
2024-04-24 09:48:07 +02:00
Akash Kulhalli
0243d13625 headers: Set up platform-specific headers
To avoid nasty preprocessor defines everywhere, encapsulate everything into a
new header `platform.h`, that handles everything automatically. Doing this also
avoids situations where the preprocessor goes into a recursive header lookup,
trying to look for a header first under usr/include and finding the same file
that triggered the search in the first place. All AIX-specific headers now
live under their own folder at usr/lib/common/aix and are automatically
included when platform.h demands it.

None of these headers are not meant to be included directly - use platform.h
instead.

Signed-off-by: Akash Kulhalli <akash.kulhalli@ibm.com>
2024-04-24 09:48:07 +02:00
Ingo Franzki
e8850bc138 COMMON: Add support for a global token specific counter in pkcsslotd's shm
Similar to the global session and R/W session counters in pkcsslotds shared
memory segment, add another counter field that a token can use for counting
token specific things.

The pkcsslotd also tracks this counter, and ensures that if a process dies
without decreasing its counter properly, then pkcsslotd adjusts the global
counter automatically during garbage collection to maintain a consistent
counter value across all processes.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2024-02-01 08:37:27 +01:00
Ingo Franzki
9e6d1e7cd3 Remove support for --disable-locks (transactional memory)
The use of transactional memory has never really worked for openCryptoki.
Also, many code places use locks, even with '--disable-locks'.
Option '--enable-locks' has been the default so far.

To retain backward compatibility, continue to accept the '--disable-locks'
option during configuration, but ignore it if it is specified. A warning
message is issued if --disable-locks' is still used.

With this change, there is no longer a need to maintain 2 copies of the
btree.c and sess_mgr.c source (btree.c and lock_btree.c, sess_mgr.c and
lock_sess_mgr.c), which contained the same code except the differences for
supporting transactional memory versus locks. Now only the version with
locks is retained, but it is renamed to not contain the 'lock_' prefix any
more.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-04-25 16:28:27 +02:00
Ingo Franzki
ff52d11160 Make pkcsslotd user and pkcs11 group configurable
Allow to specify the pkcsslotd user and the pkcs11 group during
configuration.

Use '--with-pkcsslotd-user=USER' and/or '--with-pkcs-group=GROUP'
to specify the user and group name. The defaults are 'pkcsslotd'
and 'pkcs11'.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-04-20 15:13:44 +02:00
Ingo Franzki
9b977a5954 Run pkcsslotd under the pkcsslotd user and not under root
Create the unix sockets and the PID file in /run/opencryptoki, and make
sure the /run/opencryptoki directory as well as the lock and log directories
are created during 'make install' as well as during system startup via
tmpfiles.d. Since the /run directory usually is within a tmpfs file system,
it won't exist after a system restart otherwise.

Also make the /run/opencryptoki directory be owned by the 'pkcsslotd' user
and the 'pkcs11' group, and only writable by the 'pkcsslotd' user.
That way, pkcsslotd can only be started by the 'pkcsslotd' user (or root).
Nevertheless, members of the 'pkcs11' group can still connect to the sockets,
and thus can still communicate with pkcsslotd.

The 'pkcsslotd' user is created (if not already existent) during 'make install'
and RPM installation, together with the 'pkcs11' group.

When the pkcsslotd is started as 'root', change its uid to 'pkcsslotd' to drop
privileges and capabilities. Any capabilities set on the executable file
are retained, regardless if started as root or as pkcsslotd user.

If started as root, pkcsslotd can create any missing base directories, otherwise
an error is reported. It is expected that the base directories have been created
during package installation and/or tmpfiles.d prior to starting pkcsslotd.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-04-20 15:13:44 +02:00
Ingo Franzki
46b7e485ca HSM MK change: Use define for 'HSM_MK_CHANGE' directory
Add a define OCK_HSM_MK_CHANGE_PATH for the path to the HSM MK change data,
and adjust the code to use that define instead of hard-coding it.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-04-20 15:13:44 +02:00
Ingo Franzki
466cdc4463 Common: Check for lock init errors and proper error handling
Check errors for all RW-lock or mutex initialization calls, and perform
proper error handling and cleanup if it fails.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-04-17 08:35:30 +02:00
Ingo Franzki
20f3cafe5c common: Add attribute for re-encrypted and old secure key blob
Secure key tokens store the secure key blob in attribute CKA_IBM_OPAQUE
in their key object. During an HSM master key change, the secure key blob
is being re-enciphered with the new master key. This re-enciphered secure
key blob is stored in attribute CKA_IBM_OPAQUE_REENC while the HSM master
key change operation is active.

When a HSM master key change operation is finalized, the secure key blob
enciphered with the old master key is backed up into attribute CKA_IBM_OPAQUE_OLD,
and the re-enciphered secure key blob from CKA_IBM_OPAQUE_REENC becomes
the current one in CKA_IBM_OPAQUE.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-03-14 10:19:10 +01:00
Ingo Franzki
7d2bb834c4 API/EP11: Lock API functions against HSM MK change state changes
Avoid race conditions between an API function being called in a
thread, and any HSM master key state changes being done in the event
thread. Each API function that involves objects or sessions state
acquire a read lock on the per-slot HSM MK change R/W lock. Anyone
that changes the HSM MK change state acquires a write lock. That
way the API functions can run concurrently unless a HSM MK change
state changing operation is performed.

This is implemented in the API layer so that tokens do not have to
care about this themselves. Tokens that support HSM MK changes,
initialize the R/W lock and thus tell the API layer to perform locking
on each API call. Tokens that do not support HSM MK changes, are
not affected, and do not use an R/W lock.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-03-14 10:19:10 +01:00
Ingo Franzki
72b05938d2 events: Add HSM master key change events
Add definitions for HSM master key change events used for communicating
between the pkcshsm_mk_change tool and the tokens.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-03-14 10:19:10 +01:00
Ingo Franzki
6d46d0c0f3 hsm_mk_change: Add utilities for managing MK change operations
Add utility functions to serialize and de-serialize master key operation
state information, and allow to store and load them to/from files.

These functions will be used by the pkcshsm_mk_change tool, as well
as by tokens supporting concurrent master key changes.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-03-14 10:19:10 +01:00
Ingo Franzki
1ec297c8a3 COMMON: Add post-quantum algorithm OIDs
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-01-24 14:52:11 +01:00
Ingo Franzki
27854339f9 COMMON: Add defines for Kyber
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-01-24 14:52:11 +01:00
Ingo Franzki
4753dea5b4 COMMON: Add defines for Dilithium round 2 and 3 variants
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2023-01-24 14:52:11 +01:00
Vishnudatha Kanjur
dce327363f common: Add support for AES-XTS in common code
Add mechanisms CKM_AES_XTS and CKM_AES_XTS_KEY_GEN as well as
key type CKK_AES_XTS according to PKCS#11 version 3.0.

Add common code support for generating AES-XTS keys, perform
encryption/decryption as well as wrap/unwrap with AES-XTS keys.

Signed-off-by: Vishnudatha Kanjur <kanjur@ibm.com>
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-10-17 09:54:42 +02:00
Ingo Franzki
35cf7c1a8c COMMON: Add defines for IBM specific mechanisms
Add defines for mechanisms CKM_IBM_ECDSA_OTHER and CKM_IBM_BTC_DERIVE
and there mechanism parameter structures.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-09-15 15:57:17 +02:00
Ingo Franzki
1bbebe8686 common: Add support for C_SessionCancel function (PKCS#11 v3.0)
C_SessionCancel terminates active session based operations.

To identify which operation(s) should be terminated, the flags parameter
should be assigned the logical bitwise OR of one or more of the bit
flags defined in the CK_MECHANISM_INFO structure.

If no flags are set, the session state will not be modified and CKR_OK
will be returned.

If a flag is set for an operation that has not been initialized in the
session, the operation flag will be ignored and C_SessionCancel will
behave as if the operation flag was not set.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-09-14 08:53:50 +02:00
Ingo Franzki
e17f0f8899 common: Supply useful information in CK_TOKEN_INFO.ulRwSessionCount
Currently only CK_TOKEN_INFO.ulSessionCount is maintained with the
total number of sessions open by a token, but ulRwSessionCount is
set to CK_UNAVAILABLE_INFORMATION.

Besides the total number of sessions also maintain the number of R/W
sessions, so that ulRwSessionCount can be returned with accurate
information.

Similar as for the total number of sessions, the counter is kept in
the shared memory segment of the pkcsslotd. It exists once as global
counter, and once per process. When a process dies without unregistering
from pkcsslotd, the garbage collector of pkcsslotd decrements the global
counter by the amount of the per-process counter to keep the global
counter consistent.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2022-08-24 10:53:08 +02:00