]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
crypto/fsl: don't regenerate secure keys
authorMichael Walle <michael@walle.cc>
Sat, 27 Jun 2020 20:58:51 +0000 (22:58 +0200)
committerPriyanka Jain <priyanka.jain@nxp.com>
Mon, 27 Jul 2020 08:46:29 +0000 (14:16 +0530)
The secure keys (TDKEK, JDKEK, TDSK) can only be generated once after a
POR. Otherwise the RNG4 will throw an error.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>
drivers/crypto/fsl/jobdesc.c
drivers/crypto/fsl/jobdesc.h
drivers/crypto/fsl/jr.c
include/fsl_sec.h

index dbafb5b161728c594403b5c7864d6f93cb607d65..c30ea88cb0864531734be9d2ef94c3a4d94e6aed 100644 (file)
@@ -258,7 +258,7 @@ void inline_cnstr_jobdesc_blob_decap(uint32_t *desc, uint8_t *key_idnfr,
  * Descriptor to instantiate RNG State Handle 0 in normal mode and
  * load the JDKEK, TDKEK and TDSK registers
  */
-void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc, int handle)
+void inline_cnstr_jobdesc_rng_instantiation(u32 *desc, int handle, int do_sk)
 {
        u32 *jump_cmd;
 
@@ -269,7 +269,7 @@ void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc, int handle)
                        (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT);
 
        /* For SH0, Secure Keys must be generated as well */
-       if (handle == 0) {
+       if (!handle && do_sk) {
                /* wait for done */
                jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
                set_jump_tgt_here(desc, jump_cmd);
index d782c46b9db0a3c9049e5694e26beda22b114775..14b2a119d772e51a4d30830d10f7969c0755c43e 100644 (file)
@@ -39,7 +39,7 @@ void inline_cnstr_jobdesc_blob_decap(uint32_t *desc, uint8_t *key_idnfr,
                                     uint8_t *enc_blob, uint8_t *plain_txt,
                                     uint32_t out_sz);
 
-void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc, int handle);
+void inline_cnstr_jobdesc_rng_instantiation(u32 *desc, int handle, int do_sk);
 
 void inline_cnstr_jobdesc_pkha_rsaexp(uint32_t *desc,
                                      struct pk_in_params *pkin, uint8_t *out,
index 5275c50e8b24ffb5e4a05a11900cc50a147789f9..42865a6cd76e3d49702158961cc4a2771c1024cf 100644 (file)
@@ -446,7 +446,7 @@ int sec_reset(void)
        return sec_reset_idx(0);
 }
 #ifndef CONFIG_SPL_BUILD
-static int instantiate_rng(uint8_t sec_idx)
+static int instantiate_rng(u8 sec_idx, int gen_sk)
 {
        u32 *desc;
        u32 rdsta_val;
@@ -470,7 +470,7 @@ static int instantiate_rng(uint8_t sec_idx)
                if (rdsta_val & (1 << sh_idx))
                        continue;
 
-               inline_cnstr_jobdesc_rng_instantiation(desc, sh_idx);
+               inline_cnstr_jobdesc_rng_instantiation(desc, sh_idx, gen_sk);
                size = roundup(sizeof(uint32_t) * 6, ARCH_DMA_MINALIGN);
                flush_dcache_range((unsigned long)desc,
                                   (unsigned long)desc + size);
@@ -546,12 +546,13 @@ static void kick_trng(int ent_delay, uint8_t sec_idx)
 
 static int rng_init(uint8_t sec_idx)
 {
-       int ret, ent_delay = RTSDCTL_ENT_DLY_MIN;
+       int ret, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN;
        ccsr_sec_t __iomem *sec = (ccsr_sec_t __iomem *)SEC_ADDR(sec_idx);
        struct rng4tst __iomem *rng =
                        (struct rng4tst __iomem *)&sec->rng;
        u32 inst_handles;
 
+       gen_sk = !(sec_in32(&rng->rdsta) & RDSTA_SKVN);
        do {
                inst_handles = sec_in32(&rng->rdsta) & RNG_STATE_HANDLE_MASK;
 
@@ -574,7 +575,7 @@ static int rng_init(uint8_t sec_idx)
                 * interval, leading to a sucessful initialization of
                 * the RNG.
                 */
-               ret = instantiate_rng(sec_idx);
+               ret = instantiate_rng(sec_idx, gen_sk);
        } while ((ret == -1) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
        if (ret) {
                printf("SEC%u:  Failed to instantiate RNG\n", sec_idx);
index 8dce0bbb1bdcb57c23bd2855eabfe27daaea82eb..64b8751f2deed75f314400a0e9a41b0125a0a030 100644 (file)
@@ -69,6 +69,7 @@ struct rng4tst {
 #define RNG_STATE1_HANDLE_INSTANTIATED 0x00000002
 #define RNG_STATE_HANDLE_MASK  \
        (RNG_STATE0_HANDLE_INSTANTIATED | RNG_STATE1_HANDLE_INSTANTIATED)
+#define RDSTA_SKVN 0x40000000
        u32 rdsta;              /*RNG DRNG Status Register*/
        u32 rsvd2[15];
 };