Jetson Linux API 参考

32.7.4 版本
基于硬件的 AES-CMAC 函数

详细描述

指定了基于硬件的 AES-CMAC 函数的实现,与 OpenSSL CMAC 实现非常相似,并且基于相同的概念。

如果您不熟悉 OpenSSL CMAC 的实现,上面的参考资料将帮助您理解它。每个 AES-CMAC 函数都对应于一个具有相似名称和用法的 OpenSSL CMAC 函数。要使用 AES-CMAC,请遵循与 OpenSSL CMAC 相同的操作顺序,使用 AES-CMAC 函数代替 OpenSSL CMAC 函数。密钥定义函数。

OpenSSL CMAC 函数对应的基于硬件的
AES-CMAC 函数
CMAC_CTX_new()tegra_se_cmac_new()
CMAC_Init()tegra_se_cmac_init()
CMAC_Update()tegra_se_cmac_update()
CMAC_Final()tegra_se_cmac_final()
CMAC_CTX_free()tegra_se_cmac_free()
注意
为了防止安全问题,在基于硬件的 KDF 过程完成后,必须清除 SE 密钥槽。这样,不可信的富操作系统 (Jetson Linux) 就无法在非安全世界中使用这些密钥槽。

基于硬件的 KDF 只能在启动时使用,以避免在 Linux 内核中 SE 驱动程序对 SE 硬件的使用造成运行时冲突。在运行时,请改用基于软件的 KDF。

示例

以下代码展示了如何使用 API 函数的示例。

se_cmac_ctx *se_cmac = NULL;
uint8_t test_key_256[] = {
.0x72, 0xd1, 0x1f, 0x8b, 0x1c, 0x01, 0xe1, 0x5c,
.0x49, 0x86, 0x07, 0x2a, 0xe5, 0x63, 0x42, 0x21,
.0x65, 0x3f, 0x2e, 0x7f, 0x22, 0xfd, 0x05, 0x4c,
.0x60, 0xc9, 0x76, 0xa6, 0xf4, 0x3a, 0x93, 0xfe,
};
char test_msg[] = "SE_aes_cmac_test_string";
uint8_t openssl_cmac_digest[AES_BLOCK_SIZE] = { 0 };
uint8_t se_cmac_digest[AES_BLOCK_SIZE] = {0};
size_t cmac_len;
// OpenSSL AES-CMAC
CMAC_CTX *cmac = NULL;
cmac = CMAC_CTX_new();
CMAC_Init(cmac, test_key_256, AES_KEY_256_SIZE, EVP_aes_256_cbc(), NULL);
CMAC_Update(cmac, test_msg, sizeof(test_msg));
CMAC_Final(cmac, openssl_cmac_digest, &cmac_len);
CMAC_CTX_free(cmac);
// 将密钥写入密钥槽
se_write_keyslot(test_key_256, AES_KEY_256_SIZE, AES_QUAD_KEYS_256,
SE_AES_KEYSLOT_KEK256);
// SE AES-CMAC
se_cmac = tegra_se_cmac_new();
if (se_cmac == NULL)
return;
tegra_se_cmac_init(se_cmac, SE_AES_KEYSLOT_KEK256, AES_KEY_256_SIZE);
tegra_se_cmac_update(se_cmac, test_msg, sizeof(test_msg));
tegra_se_cmac_final(se_cmac, se_cmac_digest, &cmac_len);
// 验证结果
if (memcmp(openssl_cmac_digest, se_cmac_digest, cmac_len))
TLOGE("%s: Tegra SE AES-CMAC 验证不匹配。\n", __func__);

类型定义

typedef struct tegra_se_cmac_context se_cmac_ctx
 

函数

uint32_t se_acquire (void)
 
void se_release (void)
 
uint32_t se_derive_root_key (uint8_t *root_key, size_t root_key_len, uint8_t *fv, size_t fv_len, uint32_t keyslot)
 
int se_write_keyslot (uint8_t *key_in, uint32_t keylen, uint32_t key_quad_sel, uint32_t keyslot)
 
uint32_t se_clear_aes_keyslots (void)
 
se_cmac_ctxtegra_se_cmac_new (void)
 创建 SE CMAC 上下文。 更多...
 
void tegra_se_cmac_free (se_cmac_ctx *se_cmac)
 释放 SE CMAC 上下文。 更多...
 
int tegra_se_cmac_init (se_cmac_ctx *se_cmac, se_aes_keyslot_t keyslot, uint32_t keylen)
 从用户提供的密钥初始化 SE CMAC。 更多...
 
int tegra_se_cmac_update (se_cmac_ctx *se_cmac, void *data, uint32_t dlen)
 在 SE CMAC 中缓存输入数据。 更多...
 
int tegra_se_cmac_final (se_cmac_ctx *se_cmac, uint8_t *out, uint32_t *poutlen)
 完成 SE CMAC。 更多...
 

类型定义文档

◆ se_cmac_ctx

typedef struct tegra_se_cmac_context se_cmac_ctx

定义位于 tegra_se.h 文件的 199 行。

函数文档

◆ se_acquire()

uint32_t se_acquire ( void  )

◆ se_clear_aes_keyslots()

uint32_t se_clear_aes_keyslots ( void  )

◆ se_derive_root_key()

uint32_t se_derive_root_key ( uint8_t *  root_key,
size_t  root_key_len,
uint8_t *  fv,
size_t  fv_len,
uint32_t  keyslot 
)

◆ se_release()

void se_release ( void  )

◆ se_write_keyslot()

int se_write_keyslot ( uint8_t *  key_in,
uint32_t  keylen,
uint32_t  key_quad_sel,
uint32_t  keyslot 
)

◆ tegra_se_cmac_final()

int tegra_se_cmac_final ( se_cmac_ctx se_cmac,
uint8_t *  out,
uint32_t *  poutlen 
)

完成 SE CMAC。

在输入被处理且输出已被使用后调用此函数。

参数
[in]*se_cmac指向 SE CMAC 上下文的指针。
[out]*out指向输出缓冲区的指针。该函数将导出的密钥放置在此处。
[out]*poutlen指向导出密钥长度的指针。该函数将导出密钥的长度放置在此处。
返回值
如果成功,则返回 NO_ERROR,如果任何参数无效,则返回 ERR_INVALID_ARGS。

tegra_se_cmac_self_test() 引用。

◆ tegra_se_cmac_free()

void tegra_se_cmac_free ( se_cmac_ctx se_cmac)

释放 SE CMAC 上下文。

参数
[in]*se_cmac指向 SE CMAC 上下文的指针。

tegra_se_cmac_self_test() 引用。

◆ tegra_se_cmac_init()

int tegra_se_cmac_init ( se_cmac_ctx se_cmac,
se_aes_keyslot_t  keyslot,
uint32_t  keylen 
)

从用户提供的密钥初始化 SE CMAC。

参数
[in]*se_cmac指向 SE CMAC 上下文的指针。
[in]*keyslot指向包含用户提供的密钥的 SE 密钥槽的指针。
[in]*keylen用户提供的密钥的长度。
返回值
NO_ERROR如果成功。
ERR_INVALID_ARGS如果任何参数无效。
ERR_NO_MEMORY如果没有可用内存。

tegra_se_cmac_self_test() 引用。

◆ tegra_se_cmac_new()

se_cmac_ctx* tegra_se_cmac_new ( void  )

创建 SE CMAC 上下文。

返回值
如果成功,则返回指向 SE CMAC 上下文的指针,否则返回 NULL。

tegra_se_cmac_self_test() 引用。

◆ tegra_se_cmac_update()

int tegra_se_cmac_update ( se_cmac_ctx se_cmac,
void *  data,
uint32_t  dlen 
)

在 SE CMAC 中缓存输入数据。

可以多次调用此函数以缓存更多数据。

参数
[in]*se_cmac指向 SE CMAC 上下文的指针。
[in]*data指向输入数据的指针。
[in]dlen输入数据的长度。
返回值
NO_ERROR如果成功。
ERR_INVALID_ARGS如果任何参数无效。
ERR_NO_MEMORY如果没有可用内存。

tegra_se_cmac_self_test() 引用。

tegra_se_cmac_free
void tegra_se_cmac_free(se_cmac_ctx *se_cmac)
释放 SE CMAC 上下文。
tegra_se_cmac_final
int tegra_se_cmac_final(se_cmac_ctx *se_cmac, uint8_t *out, uint32_t *poutlen)
完成 SE CMAC。
tegra_se_cmac_init
int tegra_se_cmac_init(se_cmac_ctx *se_cmac, se_aes_keyslot_t keyslot, uint32_t keylen)
从用户提供的密钥初始化 SE CMAC。
tegra_se_cmac_new
se_cmac_ctx * tegra_se_cmac_new(void)
创建 SE CMAC 上下文。
se_write_keyslot
int se_write_keyslot(uint8_t *key_in, uint32_t keylen, uint32_t key_quad_sel, uint32_t keyslot)
se_cmac_ctx
struct tegra_se_cmac_context se_cmac_ctx
定义: tegra_se.h:199
tegra_se_cmac_update
int tegra_se_cmac_update(se_cmac_ctx *se_cmac, void *data, uint32_t dlen)
在 SE CMAC 中缓存输入数据。
. All rights reserved.