Skip to content

Commit e9c5048

Browse files
a3fjarkkojs
authored andcommitted
KEYS: trusted: Introduce support for NXP CAAM-based trusted keys
The Cryptographic Acceleration and Assurance Module (CAAM) is an IP core built into many newer i.MX and QorIQ SoCs by NXP. The CAAM does crypto acceleration, hardware number generation and has a blob mechanism for encapsulation/decapsulation of sensitive material. This blob mechanism depends on a device specific random 256-bit One Time Programmable Master Key that is fused in each SoC at manufacturing time. This key is unreadable and can only be used by the CAAM for AES encryption/decryption of user data. This makes it a suitable backend (source) for kernel trusted keys. Previous commits generalized trusted keys to support multiple backends and added an API to access the CAAM blob mechanism. Based on these, provide the necessary glue to use the CAAM for trusted keys. Reviewed-by: David Gstir <[email protected]> Reviewed-by: Pankaj Gupta <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Tim Harvey <[email protected]> Tested-by: Matthias Schiffer <[email protected]> Tested-by: Pankaj Gupta <[email protected]> Tested-by: Michael Walle <[email protected]> # on ls1028a (non-E and E) Tested-by: John Ernberg <[email protected]> # iMX8QXP Signed-off-by: Ahmad Fatoum <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 007c3ff commit e9c5048

File tree

6 files changed

+109
-2
lines changed

6 files changed

+109
-2
lines changed

Documentation/admin-guide/kernel-parameters.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5958,6 +5958,7 @@
59585958
sources:
59595959
- "tpm"
59605960
- "tee"
5961+
- "caam"
59615962
If not specified then it defaults to iterating through
59625963
the trust source list starting with TPM and assigns the
59635964
first trust source as a backend which is initialized

include/keys/trusted_caam.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2021 Pengutronix, Ahmad Fatoum <[email protected]>
4+
*/
5+
6+
#ifndef __CAAM_TRUSTED_KEY_H
7+
#define __CAAM_TRUSTED_KEY_H
8+
9+
extern struct trusted_key_ops trusted_key_caam_ops;
10+
11+
#endif

security/keys/trusted-keys/Kconfig

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ config TRUSTED_KEYS_TEE
2424
Enable use of the Trusted Execution Environment (TEE) as trusted
2525
key backend.
2626

27-
if !TRUSTED_KEYS_TPM && !TRUSTED_KEYS_TEE
27+
config TRUSTED_KEYS_CAAM
28+
bool "CAAM-based trusted keys"
29+
depends on CRYPTO_DEV_FSL_CAAM_JR >= TRUSTED_KEYS
30+
select CRYPTO_DEV_FSL_CAAM_BLOB_GEN
31+
default y
32+
help
33+
Enable use of NXP's Cryptographic Accelerator and Assurance Module
34+
(CAAM) as trusted key backend.
35+
36+
if !TRUSTED_KEYS_TPM && !TRUSTED_KEYS_TEE && !TRUSTED_KEYS_CAAM
2837
comment "No trust source selected!"
2938
endif

security/keys/trusted-keys/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ trusted-$(CONFIG_TRUSTED_KEYS_TPM) += trusted_tpm2.o
1212
trusted-$(CONFIG_TRUSTED_KEYS_TPM) += tpm2key.asn1.o
1313

1414
trusted-$(CONFIG_TRUSTED_KEYS_TEE) += trusted_tee.o
15+
16+
trusted-$(CONFIG_TRUSTED_KEYS_CAAM) += trusted_caam.o
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (C) 2021 Pengutronix, Ahmad Fatoum <[email protected]>
4+
*/
5+
6+
#include <keys/trusted_caam.h>
7+
#include <keys/trusted-type.h>
8+
#include <linux/build_bug.h>
9+
#include <linux/key-type.h>
10+
#include <soc/fsl/caam-blob.h>
11+
12+
static struct caam_blob_priv *blobifier;
13+
14+
#define KEYMOD "SECURE_KEY"
15+
16+
static_assert(MAX_KEY_SIZE + CAAM_BLOB_OVERHEAD <= CAAM_BLOB_MAX_LEN);
17+
static_assert(MAX_BLOB_SIZE <= CAAM_BLOB_MAX_LEN);
18+
19+
static int trusted_caam_seal(struct trusted_key_payload *p, char *datablob)
20+
{
21+
int ret;
22+
struct caam_blob_info info = {
23+
.input = p->key, .input_len = p->key_len,
24+
.output = p->blob, .output_len = MAX_BLOB_SIZE,
25+
.key_mod = KEYMOD, .key_mod_len = sizeof(KEYMOD) - 1,
26+
};
27+
28+
ret = caam_encap_blob(blobifier, &info);
29+
if (ret)
30+
return ret;
31+
32+
p->blob_len = info.output_len;
33+
return 0;
34+
}
35+
36+
static int trusted_caam_unseal(struct trusted_key_payload *p, char *datablob)
37+
{
38+
int ret;
39+
struct caam_blob_info info = {
40+
.input = p->blob, .input_len = p->blob_len,
41+
.output = p->key, .output_len = MAX_KEY_SIZE,
42+
.key_mod = KEYMOD, .key_mod_len = sizeof(KEYMOD) - 1,
43+
};
44+
45+
ret = caam_decap_blob(blobifier, &info);
46+
if (ret)
47+
return ret;
48+
49+
p->key_len = info.output_len;
50+
return 0;
51+
}
52+
53+
static int trusted_caam_init(void)
54+
{
55+
int ret;
56+
57+
blobifier = caam_blob_gen_init();
58+
if (IS_ERR(blobifier))
59+
return PTR_ERR(blobifier);
60+
61+
ret = register_key_type(&key_type_trusted);
62+
if (ret)
63+
caam_blob_gen_exit(blobifier);
64+
65+
return ret;
66+
}
67+
68+
static void trusted_caam_exit(void)
69+
{
70+
unregister_key_type(&key_type_trusted);
71+
caam_blob_gen_exit(blobifier);
72+
}
73+
74+
struct trusted_key_ops trusted_key_caam_ops = {
75+
.migratable = 0, /* non-migratable */
76+
.init = trusted_caam_init,
77+
.seal = trusted_caam_seal,
78+
.unseal = trusted_caam_unseal,
79+
.exit = trusted_caam_exit,
80+
};

security/keys/trusted-keys/trusted_core.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <keys/user-type.h>
1010
#include <keys/trusted-type.h>
1111
#include <keys/trusted_tee.h>
12+
#include <keys/trusted_caam.h>
1213
#include <keys/trusted_tpm.h>
1314
#include <linux/capability.h>
1415
#include <linux/err.h>
@@ -29,7 +30,7 @@ MODULE_PARM_DESC(rng, "Select trusted key RNG");
2930

3031
static char *trusted_key_source;
3132
module_param_named(source, trusted_key_source, charp, 0);
32-
MODULE_PARM_DESC(source, "Select trusted keys source (tpm or tee)");
33+
MODULE_PARM_DESC(source, "Select trusted keys source (tpm, tee or caam)");
3334

3435
static const struct trusted_key_source trusted_key_sources[] = {
3536
#if defined(CONFIG_TRUSTED_KEYS_TPM)
@@ -38,6 +39,9 @@ static const struct trusted_key_source trusted_key_sources[] = {
3839
#if defined(CONFIG_TRUSTED_KEYS_TEE)
3940
{ "tee", &trusted_key_tee_ops },
4041
#endif
42+
#if defined(CONFIG_TRUSTED_KEYS_CAAM)
43+
{ "caam", &trusted_key_caam_ops },
44+
#endif
4145
};
4246

4347
DEFINE_STATIC_CALL_NULL(trusted_key_init, *trusted_key_sources[0].ops->init);

0 commit comments

Comments
 (0)