summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJi Luo <ji.luo@nxp.com>2018-10-31 09:34:33 +0800
committerNitin Garg <nitin.garg@nxp.com>2018-11-02 20:50:09 -0500
commit4207a8df84dadbc68c99ed965661546a6af5a99c (patch)
tree17f2e6931008f428f65d845972b77481a2538190
parent86b33989f42cc97ef16dd8e57c26eb0fc96224c1 (diff)
MA-13275 [trusty] Add tipc command to generate blob with CAAM
Add new hwcrypto tipc command and handler to generate blob with CAAM. Test: Message exchange with trusty and blob encapsulate/decapsulate ok. Change-Id: I925b47cb3e22eeddf4c89e84a9c994d2f30423fe Signed-off-by: Ji Luo <ji.luo@nxp.com>
-rw-r--r--include/interface/hwcrypto/hwcrypto.h12
-rw-r--r--include/trusty/hwcrypto.h10
-rw-r--r--lib/trusty/ql-tipc/hwcrypto.c31
3 files changed, 53 insertions, 0 deletions
diff --git a/include/interface/hwcrypto/hwcrypto.h b/include/interface/hwcrypto/hwcrypto.h
index 116bfe079f..0a62ea2102 100644
--- a/include/interface/hwcrypto/hwcrypto.h
+++ b/include/interface/hwcrypto/hwcrypto.h
@@ -37,6 +37,7 @@ enum hwcrypto_command {
HWCRYPTO_RESP_BIT = 1,
HWCRYPTO_HASH = (1 << HWCRYPTO_REQ_SHIFT),
+ HWCRYPTO_ENCAP_BLOB = (2 << HWCRYPTO_REQ_SHIFT),
};
/**
@@ -84,4 +85,15 @@ typedef struct hwcrypto_hash_msg {
enum hwcrypto_hash_algo algo;
} hwcrypto_hash_msg;
+/**
+ * @plain_pa: physical start address of the plain blob buf.
+ * @plain_size: size of the plain blob.
+ * @blob: physical start addrss of the output buf.
+ */
+typedef struct hwcrypto_blob_msg {
+ uint32_t plain_pa;
+ uint32_t plain_size;
+ uint32_t blob_pa;
+}hwcrypto_blob_msg;
+
#endif /* TRUSTY_INTERFACE_HWCRYPTO_H_ */
diff --git a/include/trusty/hwcrypto.h b/include/trusty/hwcrypto.h
index fd522dfd4a..22f0835432 100644
--- a/include/trusty/hwcrypto.h
+++ b/include/trusty/hwcrypto.h
@@ -56,4 +56,14 @@ void hwcrypto_tipc_shutdown(struct trusty_ipc_dev *dev);
int hwcrypto_hash(uint32_t in_addr, uint32_t in_len, uint32_t out_addr,
uint32_t out_len, enum hwcrypto_hash_algo algo);
+/*
+ * Send request to secure side to generate blob with caam.
+ * Returns one of trusty_err.
+ *
+ * @plain_pa: physical start address of the plain blob buffer.
+ * @plain_size: size of the plain blob buffer.
+ * @blob_pa: physical start address of the generated blob buffer.
+ */
+int hwcrypto_gen_blob(uint32_t plain_pa,
+ uint32_t plain_size, uint32_t blob_pa);
#endif /* TRUSTY_HWCRYPTO_H_ */
diff --git a/lib/trusty/ql-tipc/hwcrypto.c b/lib/trusty/ql-tipc/hwcrypto.c
index 1cefdc46fa..69914a9762 100644
--- a/lib/trusty/ql-tipc/hwcrypto.c
+++ b/lib/trusty/ql-tipc/hwcrypto.c
@@ -30,6 +30,7 @@
#include "common.h"
#define LOCAL_LOG 0
+#define CAAM_KB_HEADER_LEN 48
static bool initialized;
static struct trusty_ipc_chan hwcrypto_chan;
@@ -187,3 +188,33 @@ int hwcrypto_hash(uint32_t in_addr, uint32_t in_len, uint32_t out_addr,
sizeof(req), NULL, 0, false);
return rc;
}
+
+int hwcrypto_gen_blob(uint32_t plain_pa,
+ uint32_t plain_size, uint32_t blob_pa)
+{
+ hwcrypto_blob_msg req;
+ unsigned long start, end;
+
+ /* check the address */
+ if (plain_pa == 0 || blob_pa == 0)
+ return TRUSTY_ERR_INVALID_ARGS;
+ /* fill the request buffer */
+ req.plain_pa = plain_pa;
+ req.plain_size = plain_size;
+ req.blob_pa = blob_pa;
+
+ /* flush dcache for input buffer */
+ start = (unsigned long)plain_pa & ~(ARCH_DMA_MINALIGN - 1);
+ end = ALIGN((unsigned long)plain_pa + plain_size, ARCH_DMA_MINALIGN);
+ flush_dcache_range(start, end);
+
+ /* invalidate dcache for output buffer */
+ start = (unsigned long)blob_pa & ~(ARCH_DMA_MINALIGN - 1);
+ end = ALIGN((unsigned long)blob_pa + plain_size +
+ CAAM_KB_HEADER_LEN, ARCH_DMA_MINALIGN);
+ invalidate_dcache_range(start, end);
+
+ int rc = hwcrypto_do_tipc(HWCRYPTO_ENCAP_BLOB, (void*)&req,
+ sizeof(req), NULL, 0, false);
+ return rc;
+}