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.git

commit 300a648ea4eafe61f21f76ade5e9ca60d221a240
Author: makejian <[email protected]>
AuthorDate: Mon Nov 23 15:07:41 2026 +0800

    crypto: add rpmsg crypto protocol definitions
    
    Add the wire protocol definitions shared by the rpmsg crypto client and
    server drivers:
    
    - include/nuttx/virtio/virtio-crypto.h: the CHACHA20 cipher id, the
      PBKDF2 HMAC MAC ids, the ECDH akcipher id, the AKCIPHER_GENKEY and
      AKCIPHER_DERIVE opcodes, a PBKDF2 iteration count in the hash/mac data
      request that fits in the existing op_flf union padding (wire layout
      unchanged), and a flag word in the key operation request.
    - include/crypto/virtio_crypto.h: block length and RSA DER size helpers,
      RSA public/private key DER encoders on top of the ASN.1 helpers, the
      CRK_* to VIRTIO_CRYPTO_AKCIPHER_* mapping, an AEAD algorithm mapping,
      the KEYID ctrl flag, and the CHACHA20, PBKDF2, SHA-224 HMAC, GMAC and
      AES-256-CMAC algorithm mappings.
    - drivers/crypto/rpmsg_crypto.h: the rpmsg message formats layered on
      the virtio crypto request structures.
    - include/nuttx/crypto/rpmsg_crypto.h: the client register and server
      init prototypes.
    
    The wire values and field layouts match the remote-core crypto offload
    protocol in use on Xiaomi Vela, so a Vela core and an upstream core can
    interoperate over rpmsg.
    
    Signed-off-by: makejian <[email protected]>
---
 drivers/crypto/rpmsg_crypto.h        |  96 ++++++++++++++
 include/crypto/virtio_crypto.h       | 235 ++++++++++++++++++++++++++++++++++-
 include/nuttx/crypto/rpmsg_crypto.h  |  79 ++++++++++++
 include/nuttx/virtio/virtio-crypto.h |  15 +++
 4 files changed, 424 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/rpmsg_crypto.h b/drivers/crypto/rpmsg_crypto.h
new file mode 100644
index 00000000000..3e62c1d4986
--- /dev/null
+++ b/drivers/crypto/rpmsg_crypto.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+ * drivers/crypto/rpmsg_crypto.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __DRIVERS_CRYPTO_RPMSG_CRYPTO_H
+#define __DRIVERS_CRYPTO_RPMSG_CRYPTO_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/virtio/virtio-crypto.h>
+
+/****************************************************************************
+ * Pre-processor definitions
+ ****************************************************************************/
+
+#define RPMSG_CRYPTO_NAME_PREFIX     "rpmsg-crypto"
+#define RPMSG_CRYPTO_NAME_PREFIX_LEN sizeof(RPMSG_CRYPTO_NAME_PREFIX)
+
+#define RPMSG_CRYPTO_NEWSESSION      0
+#define RPMSG_CRYPTO_PROCESS         1
+#define RPMSG_CRYPTO_FREESESSION     2
+#define RPMSG_CRYPTO_KPROCESS        3
+#define RPMSG_CRYPTO_KEYPROCESS      4
+#define RPMSG_CRYPTO_CANCEL          5
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+begin_packed_struct struct rpmsg_crypto_header_s
+{
+  uint32_t command;
+  int32_t  result;
+  uint64_t tid;
+  uint64_t cookie;
+  uint32_t reqid;
+} end_packed_struct;
+
+begin_packed_struct struct rpmsg_crypto_newsession_s
+{
+  struct rpmsg_crypto_header_s header;
+  struct virtio_crypto_op_ctrl_req_s ctrl;
+  char buf[];
+} end_packed_struct;
+
+#define rpmsg_crypto_freesession_s rpmsg_crypto_newsession_s
+
+begin_packed_struct struct rpmsg_crypto_process_s
+{
+  struct rpmsg_crypto_header_s header;
+  struct virtio_crypto_op_data_req_s data;
+  char buf[];
+} end_packed_struct;
+
+begin_packed_struct struct rpmsg_crypto_kprocess_s
+{
+  struct rpmsg_crypto_header_s header;
+  struct virtio_crypto_op_ctrl_req_s ctrl;
+  struct virtio_crypto_op_data_req_s data;
+  char buf[];
+} end_packed_struct;
+
+begin_packed_struct struct rpmsg_crypto_keyprocess_s
+{
+  struct rpmsg_crypto_header_s header;
+  struct virtio_key_op_req_s data;
+  char buf[];
+} end_packed_struct;
+
+begin_packed_struct struct rpmsg_crypto_cancel_s
+{
+  struct rpmsg_crypto_header_s header;
+  uint32_t op;
+} end_packed_struct;
+
+#endif /* __DRIVERS_CRYPTO_RPMSG_CRYPTO_H */
diff --git a/include/crypto/virtio_crypto.h b/include/crypto/virtio_crypto.h
index ca7589a4801..e0791d43fb1 100644
--- a/include/crypto/virtio_crypto.h
+++ b/include/crypto/virtio_crypto.h
@@ -28,6 +28,7 @@
  ****************************************************************************/
 
 #include <errno.h>
+#include <crypto/asn1.h>
 #include <crypto/cryptodev.h>
 #include <nuttx/virtio/virtio-crypto.h>
 
@@ -52,10 +53,153 @@
 #define VIRTIO_CRYPTO_CHACHAPOLY_TAG_LEN  16
 #define VIRTIO_CRYPTO_NOUNCE_LEN          4
 
+#define VIRTIO_CRYPTO_3DES_BLOCK_LEN      8
+#define VIRTIO_CRYPTO_AES_BLOCK_LEN       16
+#define VIRTIO_CRYPTO_CHACHA20_BLOCK_LEN  64
+
+#define VIRTIO_CRYPTO_KEYID               0x01
+
+/* RSA public keys:
+ *  SubjectPublicKeyInfo  ::=  SEQUENCE  {          1 + 3
+ *       algorithm            AlgorithmIdentifier,  1 + 1 (sequence)
+ *                                                + 1 + 1 + 9 (rsa oid)
+ *                                                + 1 + 1 (params null)
+ *       subjectPublicKey     BIT STRING }          1 + 3 + (1 + below)
+ *  RSAPublicKey ::= SEQUENCE {                     1 + 3
+ *      modulus           INTEGER,  -- n            1 + 3 + MPI_MAX + 1
+ *      publicExponent    INTEGER   -- e            1 + 3 + MPI_MAX + 1
+ *  }
+ */
+
+#define VIRTIO_CRYPTO_RSA_PUB_DER_MAX_BYTES(bits)  (38 + 2 * (bits) / 8)
+
+/* RSA private keys:
+ *  RSAPrivateKey ::= SEQUENCE {                    1 + 3
+ *      version           Version,                  1 + 1 + 1
+ *      modulus           INTEGER,                  1 + 3 + MPI_MAX + 1
+ *      publicExponent    INTEGER,                  1 + 3 + MPI_MAX + 1
+ *      privateExponent   INTEGER,                  1 + 3 + MPI_MAX + 1
+ *      prime1            INTEGER,                  1 + 3 + MPI_MAX / 2 + 1
+ *      prime2            INTEGER,                  1 + 3 + MPI_MAX / 2 + 1
+ *      exponent1         INTEGER,                  1 + 3 + MPI_MAX / 2 + 1
+ *      exponent2         INTEGER,                  1 + 3 + MPI_MAX / 2 + 1
+ *      coefficient       INTEGER,                  1 + 3 + MPI_MAX / 2 + 1
+ *      otherPrimeInfos   OtherPrimeInfos OPTIONAL  0 (not supported)
+ *  }
+ */
+
+#define VIRTIO_CRYPTO_RSA_MAX_SIZE_2(bits)  (((bits) / 8) / 2 +  \
+                                             ((bits) / 8) % 2)
+#define VIRTIO_CRYPTO_RSA_PRV_DER_MAX_BYTES(bits)              \
+                                  (47 + 3 * ((bits) / 8)         \
+                                  + 5 * VIRTIO_CRYPTO_RSA_MAX_SIZE_2(bits))
+#define VIRTIO_CRYPTO_RSA_DER_MAX_BYTES(bits, is_priv)         \
+        (is_priv ? VIRTIO_CRYPTO_RSA_PRV_DER_MAX_BYTES(bits) : \
+                   VIRTIO_CRYPTO_RSA_PUB_DER_MAX_BYTES(bits))
+
 /****************************************************************************
  * Inline Functions
  ****************************************************************************/
 
+/* RSAPublicKey ::= SEQUENCE {
+ *     modulus           INTEGER,  -- n
+ *     publicExponent    INTEGER   -- e
+ * }
+ */
+
+static inline_function ssize_t
+virtio_crypto_write_rsa_pubkey_der(FAR const unsigned char *n, size_t nlen,
+                                   FAR const unsigned char *e, size_t elen,
+                                   FAR unsigned char *buf, size_t size)
+{
+  FAR unsigned char *p;
+  ssize_t len = 0;
+
+  p = buf + size;
+
+  /* Export E */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&p, buf, e, elen));
+
+  /* Export N */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&p, buf, n, nlen));
+
+  ASN1_CHK_ADD(len, asn1_write_len(&p, buf, len));
+  ASN1_CHK_ADD(len, asn1_write_tag(&p, buf,
+                                   ASN1_CONSTRUCTED | ASN1_SEQUENCE));
+  return len;
+}
+
+/* RsaPrivKey ::= SEQUENCE {
+ *     version     INTEGER
+ *     n           INTEGER
+ *     e           INTEGER
+ *     d           INTEGER
+ *     p           INTEGER
+ *     q           INTEGER
+ *     dp          INTEGER
+ *     dq          INTEGER
+ *     u           INTEGER
+ *     otherPrimeInfos   OtherPrimeInfos OPTIONAL
+ * }
+ */
+
+static inline_function ssize_t
+virtio_crypto_write_rsa_key_der(FAR const unsigned char *n, size_t nlen,
+                                FAR const unsigned char *e, size_t elen,
+                                FAR const unsigned char *d, size_t dlen,
+                                FAR const unsigned char *p, size_t plen,
+                                FAR const unsigned char *q, size_t qlen,
+                                FAR const unsigned char *dp, size_t dplen,
+                                FAR const unsigned char *dq, size_t dqlen,
+                                FAR const unsigned char *qp, size_t qplen,
+                                FAR unsigned char *buf, size_t size)
+{
+  FAR unsigned char *pos;
+  ssize_t len = 0;
+
+  pos = buf + size;
+
+  /* Export QP */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&pos, buf, qp, qplen));
+
+  /* Export DQ */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&pos, buf, dq, dqlen));
+
+  /* Export DP */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&pos, buf, dp, dplen));
+
+  /* Export Q */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&pos, buf, q, qlen));
+
+  /* Export P */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&pos, buf, p, plen));
+
+  /* Export D */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&pos, buf, d, dlen));
+
+  /* Export E */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&pos, buf, e, elen));
+
+  /* Export N */
+
+  ASN1_CHK_ADD(len, asn1_write_mpi(&pos, buf, n, nlen));
+
+  ASN1_CHK_ADD(len, asn1_write_int(&pos, buf, 0));
+  ASN1_CHK_ADD(len, asn1_write_len(&pos, buf, len));
+  ASN1_CHK_ADD(len, asn1_write_tag(&pos, buf,
+                                   ASN1_CONSTRUCTED | ASN1_SEQUENCE));
+  return len;
+}
+
 static inline_function
 int virtio_crypto_get_errcode(int verr)
 {
@@ -80,6 +224,31 @@ int virtio_crypto_get_errcode(int verr)
   return -EINVAL;
 }
 
+static inline_function
+int virtio_crypto_get_blocksize(int alg)
+{
+  switch (alg)
+    {
+      case CRYPTO_3DES_CBC:
+        return VIRTIO_CRYPTO_3DES_BLOCK_LEN;
+      case CRYPTO_AES_CBC:
+      case CRYPTO_AES_192_CBC:
+      case CRYPTO_AES_256_CBC:
+      case CRYPTO_AES_CTR:
+      case CRYPTO_AES_XTS:
+      case CRYPTO_AES_OFB:
+      case CRYPTO_AES_CFB_8:
+      case CRYPTO_AES_CFB_128:
+      case CRYPTO_AES_GCM_16:
+        return VIRTIO_CRYPTO_AES_BLOCK_LEN;
+      case CRYPTO_CHACHA20:
+      case CRYPTO_CHACHA20_POLY1305:
+        return VIRTIO_CRYPTO_CHACHA20_BLOCK_LEN;
+    }
+
+  return -EINVAL;
+}
+
 static inline_function
 int virtio_crypto_get_tag_len(int valg)
 {
@@ -158,6 +327,7 @@ int virtio_crypto_get_service(int alg)
       case CRYPTO_AES_OFB:
       case CRYPTO_AES_CFB_8:
       case CRYPTO_AES_CFB_128:
+      case CRYPTO_CHACHA20:
         return VIRTIO_CRYPTO_SERVICE_CIPHER;
       case CRYPTO_MD5:
       case CRYPTO_POLY1305:
@@ -172,14 +342,20 @@ int virtio_crypto_get_service(int alg)
       case CRYPTO_MD5_HMAC:
       case CRYPTO_SHA1_HMAC:
       case CRYPTO_RIPEMD160_HMAC:
+      case CRYPTO_SHA2_224_HMAC:
       case CRYPTO_SHA2_256_HMAC:
       case CRYPTO_SHA2_384_HMAC:
       case CRYPTO_SHA2_512_HMAC:
-      case CRYPTO_AES_128_GMAC:
       case CRYPTO_AES_CMAC:
       case CRYPTO_AES_128_CMAC:
+      case CRYPTO_AES_256_CMAC:
+      case CRYPTO_PBKDF2_HMAC_SHA1:
+      case CRYPTO_PBKDF2_HMAC_SHA256:
         return VIRTIO_CRYPTO_SERVICE_MAC;
       case CRYPTO_AES_GCM_16:
+      case CRYPTO_AES_128_GMAC:
+      case CRYPTO_AES_192_GMAC:
+      case CRYPTO_AES_256_GMAC:
       case CRYPTO_CHACHA20_POLY1305:
       case CRYPTO_CHACHA20_POLY1305_MAC:
         return VIRTIO_CRYPTO_SERVICE_AEAD;
@@ -188,6 +364,30 @@ int virtio_crypto_get_service(int alg)
   return -EINVAL;
 }
 
+static inline_function
+int virtio_crypto_asym_get_alg(int kalg)
+{
+  switch (kalg)
+    {
+      case CRK_MOD_EXP:
+      case CRK_MOD_EXP_CRT:
+      case CRK_RSA_PKCS15_SIGN:
+      case CRK_RSA_PKCS15_VERIFY:
+      case CRK_RSA_PSS_SIGN:
+      case CRK_RSA_PSS_VERIFY:
+        return VIRTIO_CRYPTO_AKCIPHER_RSA;
+      case CRK_ECDSA_SECP256R1_SIGN:
+      case CRK_ECDSA_SECP256R1_VERIFY:
+      case CRK_ECDSA_SECP256R1_GENKEY:
+        return VIRTIO_CRYPTO_AKCIPHER_ECDSA;
+      case CRK_ECDH_GEN_PUBLIC:
+      case CRK_ECDH_COMPUTE_SHARED:
+        return VIRTIO_CRYPTO_AKCIPHER_ECDH;
+    }
+
+  return -EINVAL;
+}
+
 static inline_function
 int virtio_crypto_get_alg(int alg)
 {
@@ -203,10 +403,18 @@ int virtio_crypto_get_alg(int alg)
         return VIRTIO_CRYPTO_CIPHER_AES_CTR;
       case CRYPTO_AES_XTS:
         return VIRTIO_CRYPTO_CIPHER_AES_XTS;
+      case CRYPTO_CHACHA20:
+        return VIRTIO_CRYPTO_CIPHER_CHACHA20;
       case CRYPTO_MD5_HMAC:
         return VIRTIO_CRYPTO_MAC_HMAC_MD5;
       case CRYPTO_SHA1_HMAC:
         return VIRTIO_CRYPTO_MAC_HMAC_SHA1;
+      case CRYPTO_SHA2_224_HMAC:
+        return VIRTIO_CRYPTO_MAC_HMAC_SHA_224;
+      case CRYPTO_PBKDF2_HMAC_SHA1:
+        return VIRTIO_CRYPTO_MAC_PBKDF2_HMAC_SHA1;
+      case CRYPTO_PBKDF2_HMAC_SHA256:
+        return VIRTIO_CRYPTO_MAC_PBKDF2_HMAC_SHA256;
       case CRYPTO_SHA2_256_HMAC:
         return VIRTIO_CRYPTO_MAC_HMAC_SHA_256;
       case CRYPTO_SHA2_384_HMAC:
@@ -226,9 +434,12 @@ int virtio_crypto_get_alg(int alg)
       case CRYPTO_SHA2_512:
         return VIRTIO_CRYPTO_HASH_SHA_512;
       case CRYPTO_AES_128_GMAC:
+      case CRYPTO_AES_192_GMAC:
+      case CRYPTO_AES_256_GMAC:
         return VIRTIO_CRYPTO_MAC_GMAC_AES;
       case CRYPTO_AES_CMAC:
       case CRYPTO_AES_128_CMAC:
+      case CRYPTO_AES_256_CMAC:
         return VIRTIO_CRYPTO_MAC_CMAC_AES;
       case CRYPTO_AES_GCM_16:
         return VIRTIO_CRYPTO_AEAD_GCM;
@@ -253,6 +464,8 @@ int virtio_crypto_get_cipher_alg(int alg)
       return CRYPTO_AES_CTR;
     case VIRTIO_CRYPTO_CIPHER_AES_XTS:
       return CRYPTO_AES_XTS;
+    case VIRTIO_CRYPTO_CIPHER_CHACHA20:
+      return CRYPTO_CHACHA20;
   }
 
   return -EINVAL;
@@ -289,6 +502,12 @@ int virtio_crypto_get_mac_alg(int alg)
       return CRYPTO_MD5_HMAC;
     case VIRTIO_CRYPTO_MAC_HMAC_SHA1:
       return CRYPTO_SHA1_HMAC;
+    case VIRTIO_CRYPTO_MAC_HMAC_SHA_224:
+      return CRYPTO_SHA2_224_HMAC;
+    case VIRTIO_CRYPTO_MAC_PBKDF2_HMAC_SHA1:
+      return CRYPTO_PBKDF2_HMAC_SHA1;
+    case VIRTIO_CRYPTO_MAC_PBKDF2_HMAC_SHA256:
+      return CRYPTO_PBKDF2_HMAC_SHA256;
     case VIRTIO_CRYPTO_MAC_HMAC_SHA_256:
       return CRYPTO_SHA2_256_HMAC;
     case VIRTIO_CRYPTO_MAC_HMAC_SHA_384:
@@ -302,4 +521,18 @@ int virtio_crypto_get_mac_alg(int alg)
   return -EINVAL;
 }
 
+static inline_function
+int virtio_crypto_get_aead_alg(int alg)
+{
+  switch (alg)
+  {
+    case VIRTIO_CRYPTO_AEAD_GCM:
+      return CRYPTO_AES_GCM_16;
+    case VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305:
+      return CRYPTO_CHACHA20_POLY1305;
+  }
+
+  return -EINVAL;
+}
+
 #endif /* __INCLUDE_CRYPTO_VIRTIO_CRYPTO_H */
diff --git a/include/nuttx/crypto/rpmsg_crypto.h 
b/include/nuttx/crypto/rpmsg_crypto.h
new file mode 100644
index 00000000000..ec63e4d0c31
--- /dev/null
+++ b/include/nuttx/crypto/rpmsg_crypto.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * include/nuttx/crypto/rpmsg_crypto.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_CRYPTO_RPMSG_CRYPTO_H
+#define __INCLUDE_NUTTX_CRYPTO_RPMSG_CRYPTO_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/****************************************************************************
+ * Name: rpmsg_crypto_server_init
+ *
+ * Description:
+ *   Rpmsg-crypto server initialize function, the server cpu should call
+ *   this function.
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_CRYPTO_RPMSG_SERVER
+int rpmsg_crypto_server_init(void);
+#endif
+
+/****************************************************************************
+ * Name: rpmsg_crypto_register
+ *
+ * Description:
+ *   Rpmsg-crypto client initialize function, the client cpu should call
+ *   this function in the board initialize process.
+ *
+ * Input Parameters:
+ *   remotecpu  - the server cpu name
+ *
+ * Returned Values:
+ *   OK on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_CRYPTO_RPMSG
+int rpmsg_crypto_register(FAR const char *remotecpu);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __INCLUDE_NUTTX_CRYPTO_RPMSG_CRYPTO_H */
diff --git a/include/nuttx/virtio/virtio-crypto.h 
b/include/nuttx/virtio/virtio-crypto.h
index fd02f71c9b4..46807e51deb 100644
--- a/include/nuttx/virtio/virtio-crypto.h
+++ b/include/nuttx/virtio/virtio-crypto.h
@@ -79,6 +79,7 @@
 #define VIRTIO_CRYPTO_CIPHER_AES_F8                         12
 #define VIRTIO_CRYPTO_CIPHER_AES_XTS                        13
 #define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3                       14
+#define VIRTIO_CRYPTO_CIPHER_CHACHA20                       15
 
 /* HASH services */
 
@@ -115,6 +116,8 @@
 #define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9                  50
 #define VIRTIO_CRYPTO_MAC_XCBC_AES                          53
 #define VIRTIO_CRYPTO_MAC_ZUC_EIA3                          54
+#define VIRTIO_CRYPTO_MAC_PBKDF2_HMAC_SHA1                  55
+#define VIRTIO_CRYPTO_MAC_PBKDF2_HMAC_SHA256                56
 
 /* AEAD services */
 
@@ -128,6 +131,7 @@
 #define VIRTIO_CRYPTO_NO_AKCIPHER                           0
 #define VIRTIO_CRYPTO_AKCIPHER_RSA                          1
 #define VIRTIO_CRYPTO_AKCIPHER_ECDSA                        2
+#define VIRTIO_CRYPTO_AKCIPHER_ECDH                         3
 
 #define VIRTIO_CRYPTO_S_HW_READY                            (1 << 0)
 
@@ -238,6 +242,10 @@
   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x02)
 #define VIRTIO_CRYPTO_AKCIPHER_VERIFY \
   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x03)
+#define VIRTIO_CRYPTO_AKCIPHER_GENKEY \
+  VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x04)
+#define VIRTIO_CRYPTO_AKCIPHER_DERIVE \
+  VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x05)
 
 #define VIRTIO_CRYPTO_FLAG_SESSION_MODE                     1
 
@@ -523,6 +531,12 @@ begin_packed_struct struct virtio_crypto_hash_data_flf_s
   /* hash result length */
 
   uint32_t hash_result_len;
+
+  /* PBKDF2 iteration count (0 for plain hash/mac). Fits within the spare
+   * room of the op_flf union padding, so the wire layout is unchanged.
+   */
+
+  uint32_t iterations;
 } end_packed_struct;
 
 begin_packed_struct struct virtio_crypto_hash_data_flf_stateless_s
@@ -910,6 +924,7 @@ begin_packed_struct struct virtio_crypto_op_data_req_s
 begin_packed_struct struct virtio_key_op_req_s
 {
   uint32_t cmd;
+  uint32_t flag;
   uint32_t name_len;
   uint32_t src_data_len;
   uint32_t dst_data_len;

Reply via email to