This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 8ff87439b crypto/mbedtls: clone digest contexts with CIOCCLONE
8ff87439b is described below
commit 8ff87439bf4aa4b0ee88322cddc1dcfb052d56e6
Author: makejian <[email protected]>
AuthorDate: Mon Nov 23 10:46:36 2026 +0800
crypto/mbedtls: clone digest contexts with CIOCCLONE
cryptodev_clone() relied on dup2(), which reopens the cryptodev
descriptor through the driver's open method: the sessions are
recreated from their parameters with fresh state, without the
intermediate hash state. mbedtls_md_clone() built on it therefore
produced a context that restarted the digest, and a digest split over
several updates came out wrong.
Ask the kernel for an independent descriptor with CIOCCLONE instead,
which copies the running session state. If the driver behind the
session cannot clone, the ioctl fails and its error is returned to
the caller.
Build-tested with sim:sim/crypto and CONFIG_CRYPTO_MBEDTLS; not run
on hardware.
Signed-off-by: makejian <[email protected]>
---
crypto/mbedtls/source/dev_alt.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/crypto/mbedtls/source/dev_alt.c b/crypto/mbedtls/source/dev_alt.c
index 1c5c290af..adb2bc928 100644
--- a/crypto/mbedtls/source/dev_alt.c
+++ b/crypto/mbedtls/source/dev_alt.c
@@ -94,7 +94,16 @@ int cryptodev_crypt(FAR cryptodev_context_t *ctx)
int cryptodev_clone(FAR cryptodev_context_t *dst,
FAR const cryptodev_context_t *src)
{
+ int fd;
+
+ if (ioctl(src->fd, CIOCCLONE, &fd) < 0)
+ {
+ return -errno;
+ }
+
+ close(dst->fd);
+ dst->fd = fd;
dst->session = src->session;
dst->crypt = src->crypt;
- return dup2(src->fd, dst->fd);
+ return OK;
}