Skip to content

Feature/patch caam huk#3149

Closed
cneveux wants to merge 9 commits intoOP-TEE:masterfrom
cneveux:feature/patch_caam_huk
Closed

Feature/patch caam huk#3149
cneveux wants to merge 9 commits intoOP-TEE:masterfrom
cneveux:feature/patch_caam_huk

Conversation

@cneveux
Copy link
Copy Markdown
Contributor

@cneveux cneveux commented Jul 24, 2019

Add the NXP CAAM drivers:

  • Hardware Unique Key

This PR includes the PR #2962, PR #3135 and PR #3136. The latest commit "core:driver implementation NXP CAAM Driver - ECC" is added to the PR #3136

This patch implementation is a preliminary implementation because of missing correct SNVS driver that will be in a separated patch.

cneveux added 8 commits July 22, 2019 08:17
  Add C inline function to execute assembly instruction
  WFE/SEV use in C code

Signed-off-by: Cedric Neveux <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
   Add registers to handle CAAM clocks

Signed-off-by: Cedric Neveux <[email protected]>
   Add dt functions:
    - dt_get_irq
         get the interrupt number of a node

    - dt_node_offset_by_compatible_status
         find a node compatible with specified 'compatible' input
         and check if the node status correspond to the expected
         one

    - dt_disable_status
         disable the 'status' field of node's prop

    - dt_set_secure_status
         set 'secure-status' field of node's prop and disable
         the 'status' field in the same time

Signed-off-by: Cedric Neveux <[email protected]>
   To allow any driver or initialization function to change the
   DT, moved the DT pack operation at the end of the generic boot.
   Move from update_external_dt to release_external_dt

Signed-off-by: Cedric Neveux <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
   Add the NXP CAAM drivers:
     - Random generator (instantiation and random generation)
     - Hash

   Add a generic cryptographic driver interface connecting
   TEE Crypto generic APIs to HW driver interface

  The Generic Crypto Driver interface in the
     core/driver/crypto/crypto_api
  is implemented to be able to use an other HW driver that
  is not the CAAM driver.

Signed-off-by: Cedric Neveux <[email protected]>
   Add the NXP CAAM drivers:
     - Cipher (AES/DES/DES3)

   Add a generic Cipher cryptographic driver interface connecting
   TEE Crypto generic APIs to HW driver interface

Signed-off-by: Cedric Neveux <[email protected]>
   Add the NXP CAAM drivers:
     - Asymmetric ECC

   Add a generic ECC cryptographic driver interface connecting
   TEE Crypto generic APIs to HW driver interface

Signed-off-by: Cedric Neveux <[email protected]>
   If supported, the cryptographic driver must be call during the
   system cryptographic initialization.
   This is needed to be able to respond to the crypto operation
   during the boot (e.g, HUK generation)

Signed-off-by: Cedric Neveux <[email protected]>
@Emantor
Copy link
Copy Markdown
Contributor

Emantor commented Jul 24, 2019

Looking at this I doubt this is working as intended. Take tee_fs_init_key_manager as an example:

  • service_init_late runs before driver_init
  • tee_fs_init_key_manager calls huk_subkey_derive which calls tee_otp_get_hw_unique_key
  • your implementation of tee_otp_get_hw_unique_key tries to use the CAAM, but CAAM is not initialized yet (due to initcall ordering) and returns the zero key.
  • The platform runs the zero key as before wihtout the tee_otp_get_hw_unique_key implementation.

So only callers of huk_subkey_dervice after driver_init benefit from the HUK implementation.

@cneveux
Copy link
Copy Markdown
Contributor Author

cneveux commented Jul 24, 2019

Looking at this I doubt this is working as intended. Take tee_fs_init_key_manager as an example:

  • service_init_late runs before driver_init
  • tee_fs_init_key_manager calls huk_subkey_derive which calls tee_otp_get_hw_unique_key
  • your implementation of tee_otp_get_hw_unique_key tries to use the CAAM, but CAAM is not initialized yet (due to initcall ordering) and returns the zero key.
  • The platform runs the zero key as before wihtout the tee_otp_get_hw_unique_key implementation.

So only callers of huk_subkey_dervice after driver_init benefit from the HUK implementation.

@Emantor
This is why I submitted the commit 6840e66 in which I changed the initialization of the crypto driver (crypto_driver_init function).

  • This function is static inline if the CFG_CRYPTO_DRIVER is not defined (in other words if the Crypto Driver is not enabled). In this case the CAAM Driver HUK generation is not called and default TEE core function are used as today.
  • This function is the CAAM Driver Controller function if the Crypto Driver is enabled. And in this case the driver_init(crypto_driver_init) is not built. Hence the HUK generation is going thru the CAAM driver.

@cneveux cneveux force-pushed the feature/patch_caam_huk branch from 651596d to bcb5356 Compare July 24, 2019 12:51
   Add the CAAM driver (part of CAAM Blob) to support the
   generation of a Hardware Unique Key based on the device
   efuse.

   This is a preliminary implementation to enable the HUK generation

   Missing in this patch is the i.MX SNVS functions:
    - Check if the device is closed or not
    - Selection of the OTPMK key used to generate the HUK
   Those functions will be implemented in a separated PR
   in which the SNVS driver will be updated and functional

   Add weak function implementation in the plat-imx platform
   tee_otp_get_hw_unique_key

Signed-off-by: Cedric Neveux <[email protected]>
* If there is an error during the Master key derivation, let the device
* booting with a 0's key
*/
if (ret != TEE_SUCCESS) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe only hide errors when some sort of testing/development flag is set? If feels odd to allow the device to boot when the security module is known to be in a bad state.

My understanding of the CAAM is that this will fail if High Assurance Boot (HAB) is not enabled on the device, which is likely during development. We allow a zero key through when using CFG_RPMB_TESTKEY since that is our primary use case for tee_otp_get_hw_unique_key(), although the system PTA now also offers a key derivation function via system_derive_ta_unique_key()...

Unfortunately I don't recall having come across a good config flag for that in OP-TEE which also covers the non-RPMB path (tee_fs_init_key_manager()).

desc_add_word(desc, DESC_HEADER(0));

/* Load the key modifier */
desc_add_word(desc, LD_NOIMM(CLASS_2, REG_KEY, BLOB_KEY_MODIFIER_SIZE));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a key modifier used for the Master Key Verification Blob?
AFAICS this has no effect for the MKVB.

Copy link
Copy Markdown
Contributor

@Emantor Emantor Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing reveals that this has an effect, but the MKVB does also work without the key modifier. In theory this could be used to derive different keys, however OP-TEE already does this in software and its not really required for the MKVB.

@cneveux cneveux mentioned this pull request Jul 26, 2019
@cneveux cneveux closed this Aug 28, 2019
@cneveux cneveux deleted the feature/patch_caam_huk branch October 13, 2020 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants