Hi,
if someone still looking for sample code for endcode/decode keys using CAAM (with Master key)
just try an attached (modified) code.
This module desn't stay in RAM by causing error (ENOMEM) intentionally.
Module parameter encrypt=1 mens: get data from dek.txt encrypt and save to blob.bin
Module parameter encrypt=0 mens: get data from blob.bin decrypt and show as a text.
It uses 32 bytes for a key.
#insmod alg_test.ko encrypt=1
[ 7368.080346] Read password file: /data2/dek.txt
[ 7368.081182] Security module: sec-v4.0 OK
[ 7368.081697] Encrypt & write password
[ 7368.082386] Causing error to remove module
insmod: failed to load alg_test.ko: Out of memory <== It's OK
1|root@tsr2_bl12080:/data2 # insmod alg_test.ko encrypt=0
[ 7370.370662] Read encrypted password file: /data2/blob.bin
[ 7370.371568] Security module: sec-v4.0 OK
[ 7370.372083] Decrypt password
[ 7370.372579] To jest tekst do zaszyfrowania p <== decrypted content of blob.bin
[ 7370.373490] Causing error to remove module
insmod: failed to load alg_test.ko: Out of memory