Commit 77592018a6e78ca8522242c70dad80d577020ce0
Committed by
Ye Li
1 parent
904f426e60
Exists in
smarc-8mp-android-11.0.0_2.0.0
and in
1 other branch
MA-18680-1 Support BKEK generation
Add support for generating BKEK, this is necessary to support derive the rpmb key from bkek. Test: BKEK generation. Change-Id: I4c192a3e1d080ca49655537705d31678d1ca689a Signed-off-by: Ji Luo <ji.luo@nxp.com> (cherry picked from commit 048934cebaa2035bf54dbd9bd32de3f782cb07df)
Showing 3 changed files with 41 additions and 0 deletions Side-by-side Diff
drivers/crypto/fsl/desc.h
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | |
16 | 16 | #define KEY_BLOB_SIZE 32 |
17 | 17 | #define MAC_SIZE 16 |
18 | +#define BKEK_SIZE 32 | |
18 | 19 | |
19 | 20 | /* Max size of any CAAM descriptor in 32-bit words, inclusive of header */ |
20 | 21 | #define MAX_CAAM_DESCSIZE 64 |
... | ... | @@ -462,6 +463,9 @@ |
462 | 463 | #define OP_PROTINFO_HASH_SHA256 0x00000180 |
463 | 464 | #define OP_PROTINFO_HASH_SHA384 0x00000200 |
464 | 465 | #define OP_PROTINFO_HASH_SHA512 0x00000280 |
466 | + | |
467 | +/* PROTINFO fields for Blob Operations */ | |
468 | +#define OP_PROTINFO_MKVB 0x00000002 | |
465 | 469 | |
466 | 470 | /* For non-protocol/alg-only op commands */ |
467 | 471 | #define OP_ALG_TYPE_SHIFT 24 |
drivers/crypto/fsl_caam.c
... | ... | @@ -250,6 +250,42 @@ |
250 | 250 | } |
251 | 251 | |
252 | 252 | /*! |
253 | + * Use CAAM to derive BKEK | |
254 | + * | |
255 | + * @param output_ptr Location address of the output data. | |
256 | + * | |
257 | + * @return SUCCESS or ERROR_XXX | |
258 | + */ | |
259 | +u32 caam_derive_bkek(u8 *output_ptr) | |
260 | +{ | |
261 | + u32 ret = SUCCESS; | |
262 | + u32 key_sz = sizeof(skeymod); | |
263 | + u32 *bkek_desc = g_jrdata.desc; | |
264 | + | |
265 | + /* initialize the output array */ | |
266 | + memset(output_ptr, 0, BKEK_SIZE); | |
267 | + | |
268 | + /* prepare job descriptor */ | |
269 | + init_job_desc(bkek_desc, 0); | |
270 | + append_load(bkek_desc, PTR2CAAMDMA(skeymod), key_sz, | |
271 | + LDST_CLASS_2_CCB | LDST_SRCDST_BYTE_KEY); | |
272 | + append_seq_out_ptr_intlen(bkek_desc, PTR2CAAMDMA(output_ptr), BKEK_SIZE, 0); | |
273 | + append_operation(bkek_desc, OP_TYPE_ENCAP_PROTOCOL | OP_PCLID_BLOB | OP_PROTINFO_MKVB); | |
274 | + | |
275 | + flush_dcache_range((uintptr_t)output_ptr & ALIGN_MASK, | |
276 | + ((uintptr_t)output_ptr & ALIGN_MASK) | |
277 | + + ROUND(BKEK_SIZE, ARCH_DMA_MINALIGN)); | |
278 | + | |
279 | + ret = do_job(bkek_desc); | |
280 | + | |
281 | + if (ret != SUCCESS) { | |
282 | + printf("Error: output bkek job failed 0x%x\n", ret); | |
283 | + } | |
284 | + | |
285 | + return ret; | |
286 | +} | |
287 | + | |
288 | +/*! | |
253 | 289 | * Initialize the CAAM. |
254 | 290 | * |
255 | 291 | */ |
include/fsl_caam.h
... | ... | @@ -74,6 +74,7 @@ |
74 | 74 | //////////////////////////////////////////////////////////////////////////////// |
75 | 75 | uint32_t caam_decap_blob(uint32_t plain_text, uint32_t blob_addr, uint32_t size); |
76 | 76 | uint32_t caam_hwrng(uint8_t *output_ptr, uint32_t output_len); |
77 | +uint32_t caam_derive_bkek(u8 *output_ptr); | |
77 | 78 | |
78 | 79 | #endif /* __CAAM_H__ */ |