Skip to contentSkip to conversation

crypto/fsl: instantiate all rng state handles

PATCH New Lukas Auer 5 participants 7 messages Jan 25, 2018 – Feb 12, 2018 Crypto API

lore
Share & tools
lore

Lukas Auer

author
#0 lore raw

PATCH 1/1 crypto/fsl: instantiate all rng state handles

Extend the instantiate_rng() function and the corresponding CAAM job descriptor to instantiate all RNG state handles. This moves the RNG instantiation code in line with the CAAM kernel driver.

Previously, only the first state handle was instantiated. The second one was instantiated by the CAAM kernel driver. This works if the kernel runs in secure mode, but fails in non-secure mode since the kernel driver uses DEC0 directly instead of over the job ring interface. Instantiating all RNG state handles in u-boot removes the need for using DEC0 in the kernel driver, making it possible to use the CAAM in non-secure mode.

---

 drivers/crypto/fsl/jobdesc.c | 35 ++++++++++++++-------------
 drivers/crypto/fsl/jobdesc.h |  2 +-
 drivers/crypto/fsl/jr.c      | 57 +++++++++++++++++++++++++++-----------------
 drivers/crypto/fsl/jr.h      |  2 ++
 include/fsl_sec.h            |  3 +++
 5 files changed, 60 insertions(+), 39 deletions(-)
drivers/crypto/fsl/jobdesc.c +19 -16
index 375ff9d0e3..aadf851101 100644
@@ -257,7 +257,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)
+void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc, int handle)
 {
 	u32 *jump_cmd;
 
@@ -265,21 +265,24 @@ void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc)
 
 	/* INIT RNG in non-test mode */
 	append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
-			 OP_ALG_AS_INIT);
-
-	/* wait for done */
-	jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
-	set_jump_tgt_here(desc, jump_cmd);
-
-	/*
-	 * load 1 to clear written reg:
-	 * resets the done interrrupt and returns the RNG to idle.
-	 */
-	append_load_imm_u32(desc, 1, LDST_SRCDST_WORD_CLRW);
-
-	/* generate secure keys (non-test) */
-	append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
-			 OP_ALG_RNG4_SK);
+			(handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT);
+
+	/* For SH0, Secure Keys must be generated as well */
+	if (handle == 0) {
+		/* wait for done */
+		jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
+		set_jump_tgt_here(desc, jump_cmd);
+
+		/*
+		 * load 1 to clear written reg:
+		 * resets the done interrupt and returns the RNG to idle.
+		 */
+		append_load_imm_u32(desc, 1, LDST_SRCDST_WORD_CLRW);
+
+		/* generate secure keys (non-test) */
+		append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
+				OP_ALG_RNG4_SK);
+	}
 }
 
 /* Change key size to bytes form bits in calling function*/
drivers/crypto/fsl/jobdesc.h +1 -1
index 112404c74d..75c9424c4a 100644
@@ -40,7 +40,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);
+void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc, int handle);
 
 void inline_cnstr_jobdesc_pkha_rsaexp(uint32_t *desc,
 				      struct pk_in_params *pkin, uint8_t *out,
drivers/crypto/fsl/jr.c +35 -22

92 lines not on this page · raw message

drivers/crypto/fsl/jr.h +2 -0
index 72f7501812..258b0b85f0 100644
@@ -40,6 +40,8 @@
 #define JQ_DEQ_TO_ERR		-2
 #define JQ_ENQ_ERR		-3
 
+#define RNG4_MAX_HANDLES	2
+
 struct op_ring {
 	phys_addr_t desc;
 	uint32_t status;
include/fsl_sec.h +3 -0
index a2f5f5a5f1..4cbdb2d65a 100644
@@ -67,6 +67,9 @@ struct rng4tst {
 	};
 	u32 rsvd1[40];
 #define RNG_STATE0_HANDLE_INSTANTIATED	0x00000001
+#define RNG_STATE1_HANDLE_INSTANTIATED	0x00000002
+#define RNG_STATE_HANDLE_MASK	\
+	(RNG_STATE0_HANDLE_INSTANTIATED | RNG_STATE1_HANDLE_INSTANTIATED)
 	u32 rdsta;		/*RNG DRNG Status Register*/
 	u32 rsvd2[15];
 };
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/1 crypto/fsl: instantiate all rng state handles

Quoted 12 lines · Lukas Auer

Extend the instantiate_rng() function and the corresponding CAAM job descriptor to instantiate all RNG state handles. This moves the RNG instantiation code in line with the CAAM kernel driver.

Previously, only the first state handle was instantiated. The second one was instantiated by the CAAM kernel driver. This works if the kernel runs in secure mode, but fails in non-secure mode since the kernel driver uses DEC0 directly instead of over the job ring interface. Instantiating all RNG state handles in u-boot removes the need for using DEC0 in the kernel driver, making it possible to use the CAAM in non-secure mode.

Quoted 1 line

git apply < \[PATCH\]\ crypto_fsl\:\ instantiate\ all\ rng\ state\
handles.eml
<stdin>:107: trailing whitespace.
void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc, int handle) <stdin>:130: trailing whitespace.

			(handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT);

<stdin>:131: trailing whitespace.

<stdin>:132: trailing whitespace.

	/* For SH0, Secure Keys must be generated as well */
<stdin>:133: trailing whitespace.
	if (handle == 0) {

error: patch failed: drivers/crypto/fsl/jobdesc.c:257
error: drivers/crypto/fsl/jobdesc.c: patch does not apply
error: patch failed: drivers/crypto/fsl/jobdesc.h:40
error: drivers/crypto/fsl/jobdesc.h: patch does not apply
error: patch failed: drivers/crypto/fsl/jr.c:444
error: drivers/crypto/fsl/jr.c: patch does not apply
error: patch failed: drivers/crypto/fsl/jr.h:40
error: drivers/crypto/fsl/jr.h: patch does not apply
error: patch failed: include/fsl_sec.h:67
error: include/fsl_sec.h: patch does not apply

git show HEAD
commit c761a7e29d703d60208585bb7d8415e00aa22556

Author: Tom Rini <[email protected]>
Date:   Mon Jan 22 21:06:41 2018 -0500

Revert "travis-ci: Add qemu-x86_64 target"

#2 lore raw

PATCH 1/1 crypto/fsl: instantiate all rng state handles

Quoted 15 lines · Bryan O'Donoghue
Quoted 12 lines · Lukas Auer

Extend the instantiate_rng() function and the corresponding CAAM job descriptor to instantiate all RNG state handles. This moves the RNG instantiation code in line with the CAAM kernel driver.

Previously, only the first state handle was instantiated. The second one was instantiated by the CAAM kernel driver. This works if the kernel runs in secure mode, but fails in non-secure mode since the kernel driver uses DEC0 directly instead of over the job ring interface. Instantiating all RNG state handles in u-boot removes the need for using DEC0 in the kernel driver, making it possible to use the CAAM in non-secure mode.

Quoted 4 lines
Quoted 1 line

git apply < \[PATCH\]\ crypto_fsl\:\ instantiate\ all\ rng\ state\
handles.eml

doh

git am <

#3 lore raw

PATCH 1/1 crypto/fsl: instantiate all rng state handles

In reply to Bryan O'Donoghue
Quoted 44 lines · Bryan O'Donoghue
Quoted 16 lines · Lukas Auer

Extend the instantiate_rng() function and the corresponding CAAM job
descriptor to instantiate all RNG state handles. This moves the RNG instantiation code in line with the CAAM kernel driver.

Previously, only the first state handle was instantiated. The second one
was instantiated by the CAAM kernel driver. This works if the kernel
runs in secure mode, but fails in non-secure mode since the kernel driver uses DEC0 directly instead of over the job ring interface. Instantiating all RNG state handles in u-boot removes the need for using
DEC0 in the kernel driver, making it possible to use the CAAM in non-secure mode.

Quoted 1 line

git apply < \[PATCH\]\ crypto_fsl\:\ instantiate\ all\ rng\ state\
handles.eml
<stdin>:107: trailing whitespace.
void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc, int handle)
<stdin>:130: trailing whitespace.

			(handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT);

<stdin>:131: trailing whitespace.

<stdin>:132: trailing whitespace.

	/* For SH0, Secure Keys must be generated as well */
<stdin>:133: trailing whitespace.
	if (handle == 0) {

error: patch failed: drivers/crypto/fsl/jobdesc.c:257
error: drivers/crypto/fsl/jobdesc.c: patch does not apply
error: patch failed: drivers/crypto/fsl/jobdesc.h:40
error: drivers/crypto/fsl/jobdesc.h: patch does not apply
error: patch failed: drivers/crypto/fsl/jr.c:444
error: drivers/crypto/fsl/jr.c: patch does not apply
error: patch failed: drivers/crypto/fsl/jr.h:40
error: drivers/crypto/fsl/jr.h: patch does not apply
error: patch failed: include/fsl_sec.h:67
error: include/fsl_sec.h: patch does not apply

Quoted 7 lines

git show HEAD
commit c761a7e29d703d60208585bb7d8415e00aa22556

Author: Tom Rini <[email protected]>
Date:   Mon Jan 22 21:06:41 2018 -0500

Revert "travis-ci: Add qemu-x86_64 target"

I'm still fairly new to working with patches over mailing list, so I'm not sure what's going wrong.

Can you try using git am to apply the patch? It's working on my machine this way.

#4 lore raw

PATCH 1/1 crypto/fsl: instantiate all rng state handles

In reply to Bryan O'Donoghue
Quoted 25 lines · Bryan O'Donoghue
Quoted 12 lines · Lukas Auer

Extend the instantiate_rng() function and the corresponding CAAM job descriptor to instantiate all RNG state handles. This moves the RNG instantiation code in line with the CAAM kernel driver.

Previously, only the first state handle was instantiated. The second one was instantiated by the CAAM kernel driver. This works if the kernel runs in secure mode, but fails in non-secure mode since the kernel driver uses DEC0 directly instead of over the job ring interface. Instantiating all RNG state handles in u-boot removes the need for using DEC0 in the kernel driver, making it possible to use the CAAM in non-secure mode.

Quoted 1 line

git apply < \[PATCH\]\ crypto_fsl\:\ instantiate\ all\ rng\ state\
handles.eml
<stdin>:107: trailing whitespace.
void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc, int handle) <stdin>:130: trailing whitespace.
            (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT); <stdin>:131: trailing whitespace.

Quoted 14 lines

<stdin>:132: trailing whitespace.
    /* For SH0, Secure Keys must be generated as well */ <stdin>:133: trailing whitespace.
    if (handle == 0) {
error: patch failed: drivers/crypto/fsl/jobdesc.c:257
error: drivers/crypto/fsl/jobdesc.c: patch does not apply
error: patch failed: drivers/crypto/fsl/jobdesc.h:40
error: drivers/crypto/fsl/jobdesc.h: patch does not apply
error: patch failed: drivers/crypto/fsl/jr.c:444
error: drivers/crypto/fsl/jr.c: patch does not apply
error: patch failed: drivers/crypto/fsl/jr.h:40
error: drivers/crypto/fsl/jr.h: patch does not apply
error: patch failed: include/fsl_sec.h:67
error: include/fsl_sec.h: patch does not apply

The patch provided by Lukas is applicable to git HEAD (fb4413295c765aa8c013650984dc2d908964c81d).

File MAINTAINERS does not indicate another git repository for drivers/crypto/fsl/jobdesc.c.

Pleae, rebase your local repository.

Best regards

Heinrich

Quoted 9 lines

git show HEAD
commit c761a7e29d703d60208585bb7d8415e00aa22556
Author: Tom Rini <[email protected]>
Date:   Mon Jan 22 21:06:41 2018 -0500

    Revert "travis-ci: Add qemu-x86_64 target"

#5 lore raw

PATCH 1/1 crypto/fsl: instantiate all rng state handles

In reply to Lukas Auer
Quoted 12 lines · Lukas Auer

Extend the instantiate_rng() function and the corresponding CAAM job descriptor to instantiate all RNG state handles. This moves the RNG instantiation code in line with the CAAM kernel driver.

Previously, only the first state handle was instantiated. The second one was instantiated by the CAAM kernel driver. This works if the kernel runs in secure mode, but fails in non-secure mode since the kernel driver uses DEC0 directly instead of over the job ring interface. Instantiating all RNG state handles in u-boot removes the need for using DEC0 in the kernel driver, making it possible to use the CAAM in non-secure mode.

Quoted 1 line

So Lukas this patch along with my series for the job-ring ownership means we can drop detection of TrustZone in the Linux CAAM driver.

Applied
#6 lore raw

PATCH 1/1 crypto/fsl: instantiate all rng state handles

In reply to Lukas Auer
Quoted 12 lines · Lukas Auer

Extend the instantiate_rng() function and the corresponding CAAM job descriptor to instantiate all RNG state handles. This moves the RNG instantiation code in line with the CAAM kernel driver.

Previously, only the first state handle was instantiated. The second one was instantiated by the CAAM kernel driver. This works if the kernel runs in secure mode, but fails in non-secure mode since the kernel driver uses DEC0 directly instead of over the job ring interface. Instantiating all RNG state handles in u-boot removes the need for using DEC0 in the kernel driver, making it possible to use the CAAM in non-secure mode.

Quoted 2 lines

---

Applied to fsl-qoriq master, awaiting upstream. Thanks.

York