You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
6.6 KiB
226 lines
6.6 KiB
4 months ago
|
/*
|
||
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved.
|
||
|
* Description:Define API about key lader driver
|
||
|
* Author: Hisilicon
|
||
|
* Create: 2019-06-26
|
||
|
*/
|
||
|
|
||
|
#include "uapi_klad.h"
|
||
|
|
||
|
#include "mpi_klad_ext.h"
|
||
|
#include "mpi_klad_define.h"
|
||
|
#include "mpi_klad_func.h"
|
||
|
|
||
|
static td_s32 priv_klad_chip_info_init(td_void)
|
||
|
{
|
||
|
td_s32 ret;
|
||
|
ext_chip_info *chip = get_chip_info();
|
||
|
|
||
|
ret = uapi_sys_get_version(&chip->sys_version);
|
||
|
if (ret != TD_SUCCESS) {
|
||
|
print_err_func(uapi_sys_get_version, ret);
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
if (chip->sys_version.chip_name_id == UAPI_CHIP_NAME_RESERVED5 ||
|
||
|
chip->sys_version.chip_name_id == UAPI_CHIP_NAME_RESERVED2 ||
|
||
|
chip->sys_version.chip_name_id == UAPI_CHIP_NAME_RESERVED17 ||
|
||
|
chip->sys_version.chip_name_id == UAPI_CHIP_NAME_RESERVED19 ||
|
||
|
chip->sys_version.chip_name_id == UAPI_CHIP_NAME_HI3751V811) {
|
||
|
chip->fmw_version = EXT_KLAD_FMW_V2;
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
chip->fmw_version = EXT_KLAD_FMW_V1;
|
||
|
out:
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_init(td_void)
|
||
|
{
|
||
|
td_s32 ret;
|
||
|
|
||
|
ret = priv_klad_chip_info_init();
|
||
|
if (ret != TD_SUCCESS) {
|
||
|
print_err_func(priv_klad_chip_info_init, ret);
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
return ext_mpi_klad_init();
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_deinit(td_void)
|
||
|
{
|
||
|
return ext_mpi_klad_deinit();
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_create(td_handle *klad)
|
||
|
{
|
||
|
if (klad == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_INVALID_PARAM);
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
return ext_mpi_klad_create(klad);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_destroy(td_handle klad)
|
||
|
{
|
||
|
return ext_mpi_klad_destroy(klad);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_attach(td_handle klad, td_handle target)
|
||
|
{
|
||
|
return ext_mpi_klad_attach(klad, target);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_detach(td_handle klad, td_handle target)
|
||
|
{
|
||
|
return ext_mpi_klad_detach(klad, target);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_set_attr(td_handle klad, const uapi_klad_attr *attr)
|
||
|
{
|
||
|
if (attr == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
if (sizeof(ext_klad_attr) != sizeof(uapi_klad_attr)) {
|
||
|
print_err_hex2(sizeof(ext_klad_attr), sizeof(uapi_klad_attr));
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
|
||
|
return ext_mpi_klad_set_attr(klad, (const ext_klad_attr *)attr);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_get_attr(td_handle klad, uapi_klad_attr *attr)
|
||
|
{
|
||
|
if (attr == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
if (sizeof(ext_klad_attr) != sizeof(uapi_klad_attr)) {
|
||
|
print_err_hex2(sizeof(ext_klad_attr), sizeof(uapi_klad_attr));
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
return ext_mpi_klad_get_attr(klad, (ext_klad_attr *)attr);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_set_rootkey_attr(td_handle klad, const uapi_rootkey_attr *rootkey_attr)
|
||
|
{
|
||
|
if (rootkey_attr == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
if (sizeof(ext_rootkey_attr) != sizeof(uapi_rootkey_attr)) {
|
||
|
print_err_hex2(sizeof(ext_rootkey_attr), sizeof(uapi_rootkey_attr));
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
|
||
|
if (get_fmw_version() == EXT_KLAD_FMW_V2) {
|
||
|
return SOC_ERR_KLAD_NOT_SUPPORT;
|
||
|
}
|
||
|
|
||
|
return ext_mpi_klad_set_rootkey_attr(klad, (const ext_rootkey_attr *)rootkey_attr);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_get_rootkey_attr(td_handle klad, uapi_rootkey_attr *rootkey_attr)
|
||
|
{
|
||
|
if (rootkey_attr == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
if (sizeof(ext_rootkey_attr) != sizeof(uapi_rootkey_attr)) {
|
||
|
print_err_hex2(sizeof(ext_rootkey_attr), sizeof(uapi_rootkey_attr));
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
|
||
|
if (get_fmw_version() == EXT_KLAD_FMW_V2) {
|
||
|
return SOC_ERR_KLAD_NOT_SUPPORT;
|
||
|
}
|
||
|
|
||
|
return ext_mpi_klad_get_rootkey_attr(klad, (ext_rootkey_attr *)rootkey_attr);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_set_session_key(td_handle klad, const uapi_klad_session_key *key)
|
||
|
{
|
||
|
if (key == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
if (sizeof(ext_klad_session_key) != sizeof(uapi_klad_session_key)) {
|
||
|
print_err_hex2(sizeof(ext_klad_session_key), sizeof(uapi_klad_session_key));
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
return ext_mpi_klad_set_session_key(klad, (const ext_klad_session_key *)key);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_set_content_key(td_handle klad, const uapi_klad_content_key *key)
|
||
|
{
|
||
|
if (key == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
if (sizeof(ext_klad_content_key) != sizeof(uapi_klad_content_key)) {
|
||
|
print_err_hex2(sizeof(ext_klad_content_key), sizeof(uapi_klad_content_key));
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
return ext_mpi_klad_set_content_key(klad, (const ext_klad_content_key *)key);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_set_clear_key(td_handle klad, const uapi_klad_clear_key *key)
|
||
|
{
|
||
|
if (key == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
if (sizeof(ext_klad_clear_key) != sizeof(uapi_klad_clear_key)) {
|
||
|
print_err_hex2(sizeof(ext_klad_clear_key), sizeof(uapi_klad_clear_key));
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
|
||
|
return ext_mpi_klad_set_clear_key(klad, (ext_klad_clear_key *)key);
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_async_set_content_key(td_handle klad, const uapi_klad_content_key *key,
|
||
|
const uapi_klad_done_callback *call_back)
|
||
|
{
|
||
|
if (key == TD_NULL || call_back == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
if (sizeof(ext_klad_content_key) != sizeof(uapi_klad_content_key) ||
|
||
|
sizeof(klad_callback) != sizeof(uapi_klad_done_callback)) {
|
||
|
print_err_hex2(sizeof(ext_klad_content_key), sizeof(uapi_klad_content_key));
|
||
|
print_err_hex2(sizeof(klad_callback), sizeof(uapi_klad_done_callback));
|
||
|
return SOC_ERR_KLAD_INVALID_PARAM;
|
||
|
}
|
||
|
|
||
|
if (get_fmw_version() == EXT_KLAD_FMW_V2) {
|
||
|
return SOC_ERR_KLAD_NOT_SUPPORT;
|
||
|
}
|
||
|
|
||
|
return ext_mpi_klad_async_set_content_key(klad, (const ext_klad_content_key *)key, (klad_callback *)call_back);
|
||
|
}
|
||
|
|
||
|
|
||
|
td_s32 uapi_klad_generate_key(td_handle klad, uapi_klad_gen_key *key)
|
||
|
{
|
||
|
if (key == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
unused(klad);
|
||
|
return TD_SUCCESS;
|
||
|
}
|
||
|
|
||
|
td_s32 uapi_klad_generate_nonce(td_handle klad, uapi_klad_nonce_key *key)
|
||
|
{
|
||
|
if (key == TD_NULL) {
|
||
|
print_err_code(SOC_ERR_KLAD_NULL_PTR);
|
||
|
return SOC_ERR_KLAD_NULL_PTR;
|
||
|
}
|
||
|
unused(klad);
|
||
|
return TD_SUCCESS;
|
||
|
}
|
||
|
|