ThePassionate opened a new pull request, #21932:
URL: https://github.com/apache/nuttx/pull/21932

   ## Summary
   
   Add `CIOCCLONE`, which clones the sessions of a cryptodev file descriptor - 
including their running state - into a new descriptor. A hash / HMAC / CMAC 
session that is mid-way through its input can be forked this way, and the 
source and the clone then finish independently and produce identical results.
   
   * `crypto/cryptodev.h`: new `CIOCCLONE` ioctl (107) and a `cc_clone` driver 
hook next to the existing newsession/freesession hooks; `crypto_clonesession()` 
dispatch, mirroring `crypto_newsession()`.
   * `crypto/cryptodev.c`: the `CIOCCLONE` handler clones every session of the 
source descriptor into a freshly created descriptor. Keys are deep-copied per 
session (the session entries borrow the caller's key pointers, so the clone 
must own its own copies); the failure path wipes and frees them. 
`cryptof_close()` and the clone now share one `fcrypt_free()` helper. The 
rebuild-on-open behaviour of `cryptof_open()` is unchanged - it re-creates 
sessions from their parameters, while `CIOCCLONE` copies live state.
   * `crypto/cryptosoft.c`: `swcr_clone()` deep-copies a session: the algorithm 
context, the key schedule and the key material, so a cloned cipher session also 
works after the source descriptor is closed. Session-slot allocation is 
factored into `swcr_allocsid()`. The `cri_sid` special case in 
`swcr_newsession()` is removed - it predates `CIOCCLONE` and also indexes the 
session table with an unchecked 64-bit value.
   * `crypto/crypto.c` / `crypto_register2()`: drivers register a `cc_clone` 
hook (the existing `crypto_register()` keeps its signature and registers 
without one; `crypto_clonesession()` reports `ENOTSUP` for those).
   
   ## Impact
   
   * New ioctl and driver hook; no change to any existing path.
   * Sessions without a clone hook return `ENOTSUP`, descriptors and sessions 
otherwise behave exactly as before.
   
   ## Testing
   
   Board sim:crypto (nuttx master fb41e5e8cb3), with the companion test PR in 
nuttx-apps (`testing/crypto: add session clone test`):
   
   ```
   nsh> clone
   clone sha256 success        (update half -> clone -> both finish == one-shot)
   clone hmac-sha256 success
   clone aes-cmac success
   clone close-source success  (clone stays usable after the source fd is 
closed)
   clone aes-cbc success       (cipher session clone, key-schedule ownership)
   ```
   
   Regression: hmac 35 vectors, hash (md5/sha1/sha224/sha256/sha512, 
huge-block, unaligned), aescbc, aesctr, aesxts, des3cbc, chacha20, chachapoly 
all pass unchanged.
   
   Note: the `aescmac` 16-byte case fails on this branch, but it fails 
identically on plain master (same digest) - that is a pre-existing 
`swcr_authenc()` bug fixed separately in #21930.
   
   `tools/checkpatch.sh -c -u -m -g <base>..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]

Reply via email to