指定了基于硬件的 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 只能在启动时使用,以避免在 Linux 内核中 SE 驱动程序对 SE 硬件的使用造成运行时冲突。在运行时,请改用基于软件的 KDF。
以下代码展示了如何使用 API 函数的示例。
类型定义 | |
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_ctx * | tegra_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。 更多... | |
typedef struct tegra_se_cmac_context se_cmac_ctx |
定义位于 tegra_se.h 文件的 199 行。
uint32_t se_acquire | ( | void | ) |
uint32_t se_clear_aes_keyslots | ( | 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 | ||
) |
void se_release | ( | void | ) |
int se_write_keyslot | ( | uint8_t * | key_in, |
uint32_t | keylen, | ||
uint32_t | key_quad_sel, | ||
uint32_t | keyslot | ||
) |
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 | 指向导出密钥长度的指针。该函数将导出密钥的长度放置在此处。 |
void tegra_se_cmac_free | ( | se_cmac_ctx * | se_cmac | ) |
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 | 如果没有可用内存。 |
se_cmac_ctx* tegra_se_cmac_new | ( | void | ) |
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 | 如果没有可用内存。 |