ThePassionate opened a new pull request, #21619:
URL: https://github.com/apache/nuttx/pull/21619
## Summary
Two framework steps that the rpmsg / virtio / vhost crypto transports (to
follow in separate PRs) build on, plus one style-only cleanup.
* crypto: split backend registration from the /dev/crypto interface
`devcrypto_register()` created the /dev/crypto character device and also
registered the software and hardware crypto backends into the driver table. The
two serve different users: the driver table is what in-kernel callers of
`crypto_newsession()` / `crypto_invoke()` use, while /dev/crypto is the BSD
compatible ioctl interface for user space. The backend registration
(`swcr_init()`, `swkey_init()`, `hwcr_init()`) moves to a new
`crypto_backends_init()` in crypto/backends.c, and `drivers_initialize()` calls
the two independently, so a build can have the backends without compiling
cryptodev.c. The new hidden `CRYPTO_BACKENDS` option is selected by
`CRYPTO_CRYPTODEV`, and the software cipher / software key management /
hardware options now depend on it instead of `CRYPTO_CRYPTODEV`.
* crypto/cryptodev: pass operation, key, padding and hash type to kprocess
`struct crypt_kop` only carried the operation code and the bignum
parameters, so a backend that receives a key operation could not tell whether
an RSA request is an encryption or a signature, whether the key is public or
private, or which padding and digest the caller wants. Drivers that forward the
request to another processor or to a hardware engine need that information to
describe the operation to the other side. Add `crk_optype`, `crk_keytype`,
`crk_padding` and `crk_hash` to `struct crypt_kop`, the matching `krp_*` fields
to `struct cryptkop`, and the value definitions (`CRYPTO_OP_SIGN` / `VERIFY` /
`GENKEY`, `CRYPTO_KEY_TYPE_*`, `CRYPTO_RSA_*_PADDING`, `CRYPTO_RSA_<hash>`).
All new fields are zero for callers that clear the struct before use, and zero
means "decrypt, no key type, raw padding, no hash", so backends that do not
look at them behave exactly as before.
* include/crypto: fix an nxstyle error in cryptodev.h
Style-only: one long-standing declaration on two lines is split so the
file passes `tools/checkpatch.sh` as-is.
## Impact
* No configuration break: `CRYPTO_CRYPTODEV` selects `CRYPTO_BACKENDS`, so
every existing defconfig (e.g. sim:crypto) builds unchanged; no defconfig
changes are needed.
* New optional fields in `struct crypt_kop` / `struct cryptkop`, zero-filled
meaning "as before"; no behavioral change for existing callers or backends.
* In-kernel crypto users (rpmsg crypto, virtio-crypto, vhost-crypto) will
select `CRYPTO_BACKENDS` and consume the kprocess type fields; those drivers
are not in tree yet and follow in separate PRs.
## Testing
Host: Ubuntu 22.04.5 LTS, x86_64, gcc 13.1.0
Board: sim:crypto
nuttx: this branch on top of master 066314c6373
apps: master 8c81529153 + apache/nuttx-apps#3996
(https://github.com/apache/nuttx-apps/pull/3996)
Build steps:
```
./tools/configure.sh -l sim:crypto
# extra options so that the new backend registration and key management
paths compile
CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT=y
CONFIG_MTD=y
CONFIG_MTD_CONFIG=y
CONFIG_MTD_CONFIG_NAMED=y
CONFIG_NSH_BUILTIN_APPS=y
make olddefconfig
make
```
Result: build completes with no errors and no new warnings; `.config` shows
`CRYPTO_BACKENDS=y` selected by `CRYPTO_CRYPTODEV=y`.
Run `./nuttx` and the tests from apps/testing/drivers/crypto:
```
nsh> aescbc
aescbc test ok
nsh> aesctr
OK test vector 0..8
nsh> aesxts
OK encrypt/decrypt test vector 0..13
nsh> 3descbc
ok, encrypt with /dev/crypto, decrypt with /dev/crypto
nsh> chacha20
chacha20: all tests passed
nsh> chachapoly
chachapoly: all tests passed
nsh> hmac
hmac md5/sha1/sha224/sha256 success (20 vectors, includes 131-byte key cases)
nsh> hash
(hash vectors pass)
```
The symmetric suite and hmac/hash pass. rsa / ecdsa / dhm, which exercise
the kprocess path through the new fields, are covered by zero-filled structs
and behave as before; the dedicated asymmetric test runs are appended below.
`tools/checkpatch.sh -c -u -m -g $(git merge-base origin/master HEAD)..HEAD`
passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]