MA-15017 Add new command to generate bkek from trusty
authorJi Luo <ji.luo@nxp.com>
Sat, 22 Jun 2019 02:18:01 +0000 (10:18 +0800)
committerJi Luo <ji.luo@nxp.com>
Thu, 25 Jul 2019 09:05:59 +0000 (17:05 +0800)
Add new command to generate bkek from trusty.

Test: generate and dump bkek.

Change-Id: I6b2a30b87c755eecd00ced7c53cfb86e432040de
Signed-off-by: Ji Luo <ji.luo@nxp.com>
include/interface/hwcrypto/hwcrypto.h
include/trusty/hwcrypto.h
lib/trusty/ql-tipc/hwcrypto.c

index 270c579..4579d8c 100644 (file)
@@ -39,6 +39,7 @@ enum hwcrypto_command {
     HWCRYPTO_HASH            = (1 << HWCRYPTO_REQ_SHIFT),
     HWCRYPTO_ENCAP_BLOB      = (2 << HWCRYPTO_REQ_SHIFT),
     HWCRYPTO_GEN_RNG         = (3 << HWCRYPTO_REQ_SHIFT),
+    HWCRYPTO_GEN_BKEK        = (4 << HWCRYPTO_REQ_SHIFT),
 };
 
 /**
@@ -105,4 +106,13 @@ typedef struct hwcrypto_rng_msg {
     uint32_t buf;
     uint32_t len;
 }hwcrypto_rng_msg;
+
+/**
+ * @buf:  physical start address of the output bkek buf.
+ * @len:  size of required rng.
+ */
+typedef struct hwcrypto_bkek_msg {
+    uint32_t buf;
+    uint32_t len;
+}hwcrypto_bkek_msg;
 #endif /* TRUSTY_INTERFACE_HWCRYPTO_H_ */
index 9a510a8..d6837d6 100644 (file)
@@ -74,4 +74,12 @@ int hwcrypto_gen_blob(uint32_t plain_pa,
  * @len: size of required rng.
  * */
 int hwcrypto_gen_rng(uint32_t buf, uint32_t len);
+
+/* Send request to secure side to generate bkek with caam.
+ * Returns one of trusty_err.
+ *
+ * @buf: physical start address of the output rng buf.
+ * @len: size of required rng.
+ * */
+int hwcrypto_gen_bkek(uint32_t buf, uint32_t len);
 #endif /* TRUSTY_HWCRYPTO_H_ */
index ccaf18b..50532b0 100644 (file)
@@ -240,3 +240,25 @@ int hwcrypto_gen_rng(uint32_t buf, uint32_t len)
                               sizeof(req), NULL, 0, false);
     return rc;
 }
+
+int hwcrypto_gen_bkek(uint32_t buf, uint32_t len)
+{
+    hwcrypto_bkek_msg req;
+    unsigned long start, end;
+
+    /* check the address */
+    if (buf == 0)
+        return TRUSTY_ERR_INVALID_ARGS;
+    /* fill the request buffer */
+    req.buf = buf;
+    req.len = len;
+
+    /* invalidate dcache for output buffer */
+    start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1);
+    end   = ALIGN((unsigned long)buf + len, ARCH_DMA_MINALIGN);
+    invalidate_dcache_range(start, end);
+
+    int rc = hwcrypto_do_tipc(HWCRYPTO_GEN_BKEK, (void*)&req,
+                              sizeof(req), NULL, 0, false);
+    return rc;
+}