Commit de975d8500dc9423d10faf8c8290f6463662144c
1 parent
68261e4ca3
Exists in
smarc-imx_v2018.03_4.14.78_1.0.0_ga
MA-13831-3 [trusty] Add command to generate rng with CAAM
Add new hwcrypto command to support rng generation with CAAM. Test: rng generated on imx8qxp_mek. Change-Id: I756f3e99423f0f9dfc2bcd30117a3f96e9f5f2f7 Signed-off-by: Ji Luo <ji.luo@nxp.com>
Showing 3 changed files with 39 additions and 0 deletions Side-by-side Diff
include/interface/hwcrypto/hwcrypto.h
... | ... | @@ -38,6 +38,7 @@ |
38 | 38 | |
39 | 39 | HWCRYPTO_HASH = (1 << HWCRYPTO_REQ_SHIFT), |
40 | 40 | HWCRYPTO_ENCAP_BLOB = (2 << HWCRYPTO_REQ_SHIFT), |
41 | + HWCRYPTO_GEN_RNG = (3 << HWCRYPTO_REQ_SHIFT), | |
41 | 42 | }; |
42 | 43 | |
43 | 44 | /** |
... | ... | @@ -96,5 +97,13 @@ |
96 | 97 | uint32_t blob_pa; |
97 | 98 | }hwcrypto_blob_msg; |
98 | 99 | |
100 | +/** | |
101 | + * @buf: physical start address of the output rng buf. | |
102 | + * @len: size of required rng. | |
103 | + */ | |
104 | +typedef struct hwcrypto_rng_msg { | |
105 | + uint32_t buf; | |
106 | + uint32_t len; | |
107 | +}hwcrypto_rng_msg; | |
99 | 108 | #endif /* TRUSTY_INTERFACE_HWCRYPTO_H_ */ |
include/trusty/hwcrypto.h
... | ... | @@ -66,5 +66,13 @@ |
66 | 66 | */ |
67 | 67 | int hwcrypto_gen_blob(uint32_t plain_pa, |
68 | 68 | uint32_t plain_size, uint32_t blob_pa); |
69 | + | |
70 | +/* Send request to secure side to generate rng with caam. | |
71 | + * Returns one of trusty_err. | |
72 | + * | |
73 | + * @buf: physical start address of the output rng buf. | |
74 | + * @len: size of required rng. | |
75 | + * */ | |
76 | +int hwcrypto_gen_rng(uint32_t buf, uint32_t len); | |
69 | 77 | #endif /* TRUSTY_HWCRYPTO_H_ */ |
lib/trusty/ql-tipc/hwcrypto.c
... | ... | @@ -218,4 +218,26 @@ |
218 | 218 | sizeof(req), NULL, 0, false); |
219 | 219 | return rc; |
220 | 220 | } |
221 | + | |
222 | +int hwcrypto_gen_rng(uint32_t buf, uint32_t len) | |
223 | +{ | |
224 | + hwcrypto_rng_msg req; | |
225 | + unsigned long start, end; | |
226 | + | |
227 | + /* check the address */ | |
228 | + if (buf == 0) | |
229 | + return TRUSTY_ERR_INVALID_ARGS; | |
230 | + /* fill the request buffer */ | |
231 | + req.buf = buf; | |
232 | + req.len = len; | |
233 | + | |
234 | + /* invalidate dcache for output buffer */ | |
235 | + start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1); | |
236 | + end = ALIGN((unsigned long)buf + len, ARCH_DMA_MINALIGN); | |
237 | + invalidate_dcache_range(start, end); | |
238 | + | |
239 | + int rc = hwcrypto_do_tipc(HWCRYPTO_GEN_RNG, (void*)&req, | |
240 | + sizeof(req), NULL, 0, false); | |
241 | + return rc; | |
242 | +} |