This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a74b6e9977dafbff65f32031628fc9538c44a860
Author: makejian <[email protected]>
AuthorDate: Mon Nov 9 22:30:38 2026 +0800

    crypto/cryptodev: pass operation, key, padding and hash type to kprocess
    
    struct crypt_kop only carries the operation code and the bignum
    parameters, so a backend that receives a key operation has no way to
    tell, for example, 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.  The software backend does not need this, but
    drivers that forward the request to another processor or to a hardware
    engine do, because they have to describe the operation to the other
    side rather than just run a fixed algorithm.
    
    Add crk_optype, crk_keytype, crk_padding and crk_hash to struct
    crypt_kop, the matching krp_* fields to struct cryptkop, and copy them
    in cryptodev_key().  Define the values they take: CRYPTO_OP_SIGN /
    VERIFY / GENKEY next to the existing CRYPTO_OP_ENCRYPT / DECRYPT,
    CRYPTO_KEY_TYPE_*, CRYPTO_RSA_*_PADDING and CRYPTO_RSA_<hash>.
    
    All the new fields are zero for callers that clear struct crypt_kop
    before use, as the in-tree tests do, and zero means "decrypt, no key
    type, raw padding, no hash".  Backends that do not look at the fields
    behave exactly as before.
    
    Signed-off-by: makejian <[email protected]>
---
 crypto/cryptodev.c         |  4 ++++
 include/crypto/cryptodev.h | 43 +++++++++++++++++++++++++++++++++++++++----
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c
index fda2faf172a..6e52e14ab43 100644
--- a/crypto/cryptodev.c
+++ b/crypto/cryptodev.c
@@ -706,6 +706,10 @@ static int cryptodev_key(FAR struct fcrypt *fcr, FAR 
struct crypt_kop *kop)
   krp->krp_op = kop->crk_op;
   krp->krp_iparams = kop->crk_iparams;
   krp->krp_oparams = kop->crk_oparams;
+  krp->krp_keytype = kop->crk_keytype;
+  krp->krp_optype = kop->crk_optype;
+  krp->krp_padding = kop->crk_padding;
+  krp->krp_hash = kop->crk_hash;
   krp->krp_status = 0;
   krp->krp_flags = kop->crk_flags;
   krp->krp_reqid = kop->crk_reqid;
diff --git a/include/crypto/cryptodev.h b/include/crypto/cryptodev.h
index cefe056cedf..10da0154fb2 100644
--- a/include/crypto/cryptodev.h
+++ b/include/crypto/cryptodev.h
@@ -245,11 +245,38 @@ struct cryptop
   int crp_iter;
 };
 
-#define CRYPTO_BUF_IOV 0x1
-#define CRYPTO_BUF_MBUF 0x2
+#define CRYPTO_BUF_IOV            0x1
+#define CRYPTO_BUF_MBUF           0x2
 
-#define CRYPTO_OP_DECRYPT 0x0
-#define CRYPTO_OP_ENCRYPT 0x1
+/* Asymmetric operation type, key type, RSA padding and RSA hash passed
+ * with a key operation (crk_optype / crk_keytype / crk_padding /
+ * crk_hash), for backends that need them to select the algorithm.
+ */
+
+#define CRYPTO_OP_DECRYPT         0x0
+#define CRYPTO_OP_ENCRYPT         0x1
+#define CRYPTO_OP_SIGN            0x2
+#define CRYPTO_OP_VERIFY          0x3
+#define CRYPTO_OP_GENKEY          0x4
+
+#define CRYPTO_KEY_TYPE_NONE      0x0
+#define CRYPTO_KEY_TYPE_PUBLIC    0x1
+#define CRYPTO_KEY_TYPE_PRIVATE   0x2
+
+#define CRYPTO_RSA_RAW_PADDING    0x0
+#define CRYPTO_RSA_PKCS1_PADDING  0x1
+#define CRYPTO_RSA_OAEP_PADDING   0x2
+
+#define CRYPTO_RSA_NO_HASH        0x0
+#define CRYPTO_RSA_MD2            0x1
+#define CRYPTO_RSA_MD3            0x2
+#define CRYPTO_RSA_MD4            0x3
+#define CRYPTO_RSA_MD5            0x4
+#define CRYPTO_RSA_SHA1           0x5
+#define CRYPTO_RSA_SHA256         0x6
+#define CRYPTO_RSA_SHA384         0x7
+#define CRYPTO_RSA_SHA512         0x8
+#define CRYPTO_RSA_SHA224         0x9
 
 /* bignum parameter, in packed bytes, ... */
 
@@ -267,6 +294,10 @@ struct crypt_kop
   u_int crk_status;    /* return status */
   u_short crk_iparams; /* # of input parameters */
   u_short crk_oparams; /* # of output parameters */
+  u_short crk_optype;  /* ie. CRYPTO_OP_VERIFY or other */
+  u_short crk_keytype; /* ie. CRYPTO_KEY_TYPE_PUBLIC or other */
+  u_short crk_padding; /* ie. CRYPTO_RSA_PKCS1_PADDING or other in RSA */
+  u_short crk_hash;    /* ie. CRYPTO_RSA_SHA256 or other in RSA */
   u_int crk_flags;
   struct crparam crk_param[CRK_MAXPARAM];
   uint32_t crk_reqid;
@@ -335,6 +366,10 @@ struct cryptkop
   u_int krp_status;    /* return status */
   u_short krp_iparams; /* # of input parameters */
   u_short krp_oparams; /* # of output parameters */
+  u_short krp_optype;  /* ie. CRYPTO_OP_VERIFY or other */
+  u_short krp_keytype; /* ie. CRYPTO_KEY_TYPE_PUBLIC or other */
+  u_short krp_padding; /* ie. CRYPTO_RSA_PKCS1_PADDING or other in RSA */
+  u_short krp_hash;    /* ie. CRYPTO_RSA_SHA256 or other in RSA */
   uint32_t krp_hid;
   struct crparam krp_param[CRK_MAXPARAM]; /* kvm */
   CODE int (*krp_callback)(FAR struct cryptkop *);

Reply via email to