Hi @Uc_S ,
There are three supported paths from Linux user-space to the SE051. All three are available with Plug & Trust MW v04.07.01:
| Path |
Library |
Best For |
| PKCS#11 |
libsss_pkcs11.so |
AES, RSA key gen/sign/verify/enc/dec via pkcs11-tool |
| OpenSSL Provider (3.x) |
libsss_provider.so |
RSA sign/verify/enc/dec via openssl pkeyutl |
| ssscli |
Python CLI |
Key injection / provisioning only |
Important note for OP-TEE environment: In your OP-TEE setup (CFG_NXP_SE05X=y), the SE051 is accessed by OP-TEE core directly via the native I2C driver. Linux user-space applications do not own the I2C bus. All three paths above work correctly because the Plug & Trust MW Access Manager (accessManager) or the T1oI2C socket interface routes commands through OP-TEE's trusted world to the SE051.
Operation 1: Generate an AES Key and Store It in SE051
Use ssscli to generate an AES-256 key at a specific Key ID (object ID in SE051):
# Generate AES-256 key at Key ID 0x20000001
ssscli generate aes 0x20000001 256
To verify the key exists:
ssscli get aes 0x20000001 aes_key_info.txt
Note: AES keys are symmetric and cannot be exported from SE051. The Key ID 0x20000001 is a 32-bit object identifier stored persistently in SE051 NVM.
Operation 2: Generate an RSA Key Pair and Store It in SE051
Option A — Using pkcs11-tool (recommended)
RSA key labels use the format sss:<keyId_hex>:
# Generate RSA-2048 key pair at Key ID 0x10101010
pkcs11-tool --module $PKCS11_MODULE --keypairgen --key-type rsa:2048 --label "sss:10101010"
Option B — Using ssscli
ssscli generate rsa 0x10101010 2048
AN13030 Section 3.3.8.3 notes: RSA key pairs must be DER encoded using PKCS#8 or traditional OpenSSL format when injecting externally. When retrieved via sss_key_store_get_key(), only the public key is returned.
Operation 3: Encrypt a File Using the AES Key in SE051
AES symmetric encryption is performed via the SSS API (sss_cipher_one_go) or, for command-line use, through a small wrapper application. The MW provides a built-in symmetric example at:
simw-top/sss/ex/symmetric/ex_sss_symmetric.c
For direct command-line use, build and run the example:
# After building the MW examples:
./se05x_symmetric_aes_cbc_encrypt --keyid 0x20000001 --input plaintext.bin --output ciphertext.bin --iv 00000000000000000000000000000000
The MW supports: kAlgorithm_SSS_AES_ECB, kAlgorithm_SSS_AES_CBC, kAlgorithm_SSS_AES_CTR, kAlgorithm_SSS_AES_GCM, kAlgorithm_SSS_AES_CCM (from Section 3.3.9.1 of AN13030).
Operation 4: Decrypt a File Using the AES Key in SE051
./se05x_symmetric_aes_cbc_decrypt --keyid 0x20000001 --input ciphertext.bin --output decrypted.bin --iv 00000000000000000000000000000000
The SSS API uses kMode_SSS_Decrypt mode with sss_cipher_one_go() for one-shot decryption, or the multi-step sss_cipher_init() / sss_cipher_update() / sss_cipher_finish() sequence for streaming.
Operation 5: Sign Data Using the RSA Private Key in SE051
Using pkcs11-tool (key stays in SE051)
# Sign with RSA private key (key never leaves SE051)
pkcs11-tool --module $PKCS11_MODULE --sign --label sss:10101010 -m SHA256-RSA-PKCS --slot 1 -i in.der -o signature.der
Supported sign mechanisms via PKCS#11:
SHA256-RSA-PKCS (RSASSA-PKCS1-v1_5 with SHA-256)
SHA1-RSA-PKCS, SHA384-RSA-PKCS, SHA512-RSA-PKCS
RSA-PKCS-PSS (PSS padding)
Using OpenSSL Provider (v3.x)
# Configure OpenSSL to use the NXP provider (see /etc/ssl/openssl.cnf)
openssl pkeyutl -provider nxp -sign -inkey "pkcs11:token=sss;object=sss:10101010;type=private" -in in.txt -out signature.der
Operation 6: Verify Signature Using the RSA Public Key in SE051
Step 1 — Export public key from SE051
# Method A: via ssscli
ssscli get rsa pub 0x10101010 rsa_pub.der
# Method B: via pkcs11-tool
pkcs11-tool --module $PKCS11_MODULE --read-object --type pubkey --slot 1 --label sss:10101010 -o pubkey.der
# Convert DER to PEM for OpenSSL
openssl rsa -in pubkey.der -inform der -out pubkey.pem -outform pem -pubin
Step 2 — Verify (host-side, no SE051 required)
openssl dgst -keyform PEM -verify pubkey.pem -sha256 -signature signature.der in.txt
# Expected output: Verified OK
Operation 7: Encrypt Data Using the RSA Public Key in SE051
RSA encryption uses the public key (no secure element needed for encrypt):
# Encrypt with public key (host side)
openssl rsautl -encrypt -inkey pubkey.pem -in in.txt -pubin -out crypt.txt
For OAEP padding (recommended), use:
openssl pkeyutl -encrypt -inkey pubkey.pem -pubin > -pkeyopt rsa_padding_mode:oaep > -pkeyopt rsa_oaep_md:sha256 > -in in.txt -out crypt.txt
AN13030 Section 3.3.5.6 lists supported algorithms including kAlgorithm_SSS_RSAES_PKCS1_OAEP_SHA256 and kAlgorithm_SSS_RSAES_PKCS1_V1_5.
Operation 8: Decrypt Data Using the RSA Private Key in SE051
The RSA private key decryption is performed entirely inside SE051. The private key never leaves the secure element.
Using pkcs11-tool
pkcs11-tool --module $PKCS11_MODULE --decrypt --label sss:10101010 --slot 1 -i crypt.txt -o decrypt.txt
cat decrypt.txt
Using OpenSSL Provider (v3.x)
openssl pkeyutl -provider nxp -decrypt -inkey "pkcs11:token=sss;object=sss:10101010;type=private" -in crypt.txt -out decrypt.txt
AN13030 Section 2.3.4 confirms: "RSA Encrypt and decrypt feature added in provider" (from v04.05.03 onwards, included in v04.07.01).
Key ID Label Convention
When using pkcs11-tool with the NXP PKCS#11 library, the Key ID label format is:
sss:<keyId_hex_without_0x>
For example, Key ID 0x10101010 → label sss:10101010
Breaking change in v04.07.00 (PKCS#11 v4.7): The CKA_ID attribute (--id) is now treated as a byte array to avoid byte swapping. Pass the ID without changing endianness.
PKCS#11 Token Initialization (First-Time Setup)
Before using pkcs11-tool, you may need to initialize the token slot:
# Initialize slot 0
pkcs11-tool --module $PKCS11_MODULE --init-token --slot 0 --label "SE051_Token" --so-pin 12345678
# Set user PIN
pkcs11-tool --module $PKCS11_MODULE --init-pin --slot 0 --login --so-pin 12345678 --pin 87654321
OpenSSL 3.x Provider Configuration
Add to /etc/ssl/openssl.cnf (or a custom config file):
[openssl_init]
providers = provider_sect
[provider_sect]
default = default_sect
nxp = nxp_sect
[default_sect]
activate = 1
[nxp_sect]
module = /usr/local/lib/libsss_provider.so
activate = 1
The OpenSSL provider source is also available at: https://github.com/NXPPlugNTrust/se05x-openssl-provider
Source Code Examples (in simw-top)
The following built-in examples in the MW package directly demonstrate these operations:
| Operation |
Example Path |
| AES encrypt/decrypt |
simw-top/sss/ex/symmetric/ex_sss_symmetric.c |
| RSA sign/verify |
simw-top/sss/ex/rsa/ (Section 5.2.1.2 of AN13030) |
| ECC sign/verify |
simw-top/sss/ex/ecc/ (Section 5.2.1.1 of AN13030) |
| PKCS#11 scripts |
simw-top/sss/plugin/pkcs11/scripts/ |
| OpenSSL Provider RSA enc |
simw-top/sss/plugin/openssl_provider/scripts/openssl_RsaEnc.py |
Known Limitations in OP-TEE Context
- AES offload to SE051 from OP-TEE kernel side depends on
CFG_NXP_SE05X_CTR_DRV being enabled. User-space AES via PKCS#11 goes through the Access Manager and is separate from the OP-TEE crypto driver offload.
- RSA key generation in SE051 is CRT format by default in v04.07.01 (
RSA_CRT support added in PKCS11 v4.8). Use PKCS11_ENABLE_RSA_KEY_GEN_CRT cmake option to switch between CRT and plain RSA.
- SE051 NVM is limited. Many RSA key pair generations may exhaust persistent storage — delete unused objects with
ssscli delete <keyId>.
- For concurrent multi-process access (e.g., multiple user-space apps), use the Access Manager at
simw-top/hostlib/hostlib/accessManager. Build with -DSMCOM:STRING=JRCP_V1_AM.
Reference Documents
| Document |
Description |
| AN13030 |
Plug & Trust MW Documentation (primary reference) |
| AN12660 |
IEC 62443 compliance with SE05x — includes SSS API example pointers |
simw-top/doc/ (local HTML) |
Full documentation for your installed version v04.08.01 |
simw-top/doc/plugins/pkcs11.html |
PKCS#11 Standalone Library documentation |
simw-top/doc/demos.html |
Complete list of available demo examples |
Hope that helps,
Have a great day,
Kan
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------