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.
60 lines
2.6 KiB
60 lines
2.6 KiB
4 months ago
|
/*
|
||
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved.
|
||
|
* Description: uapi_hdcp
|
||
|
* Author: Hisilicon
|
||
|
* Create: 2019-06-18
|
||
|
*/
|
||
|
#include "securec.h"
|
||
|
#include "uapi_cipher.h"
|
||
|
#include "crypto_ioctl_cmd.h"
|
||
|
#include "crypto_osal_user_lib.h"
|
||
|
|
||
|
#define SYMC_COMPAT_ERRNO(err_code) UAPI_COMPAT_ERRNO(ERROR_MODULE_SYMC, err_code)
|
||
|
|
||
|
td_s32 uapi_hdcp_operation(uapi_cipher_hdcp_attr *hdcp_attr,
|
||
|
const td_u8 *in, td_u8 *out, td_u32 len, td_bool is_decrypt)
|
||
|
{
|
||
|
td_s32 ret;
|
||
|
td_s32 fd = -1;
|
||
|
hdcp_encrypt_ctl_t hdcp_ctl;
|
||
|
crypto_uapi_func_enter();
|
||
|
|
||
|
crypto_chk_return(hdcp_attr == TD_NULL, SYMC_COMPAT_ERRNO(ERROR_PARAM_IS_NULL), "hdcp_attr is NULL\n");
|
||
|
crypto_chk_return(hdcp_attr->aad == TD_NULL, SYMC_COMPAT_ERRNO(ERROR_PARAM_IS_NULL), "hdcp_attr->aad is NULL\n");
|
||
|
crypto_chk_return(hdcp_attr->iv == TD_NULL, SYMC_COMPAT_ERRNO(ERROR_PARAM_IS_NULL), "hdcp_attr->iv is NULL\n");
|
||
|
crypto_chk_return(hdcp_attr->tag == TD_NULL, SYMC_COMPAT_ERRNO(ERROR_PARAM_IS_NULL), "hdcp_attr->tag is NULL\n");
|
||
|
crypto_chk_return(in == TD_NULL, SYMC_COMPAT_ERRNO(ERROR_PARAM_IS_NULL), "in is NULL\n");
|
||
|
crypto_chk_return(out == TD_NULL, SYMC_COMPAT_ERRNO(ERROR_PARAM_IS_NULL), "out is NULL\n");
|
||
|
|
||
|
(td_void)memset_s(&hdcp_ctl, sizeof(hdcp_encrypt_ctl_t), 0, sizeof(hdcp_encrypt_ctl_t));
|
||
|
|
||
|
hdcp_ctl.ram_sel = hdcp_attr->ram_sel;
|
||
|
hdcp_ctl.ram_num = hdcp_attr->ram_num;
|
||
|
hdcp_ctl.key_sel = hdcp_attr->key_sel;
|
||
|
hdcp_ctl.key_slot = hdcp_attr->key_slot;
|
||
|
hdcp_ctl.alg = (crypto_symc_alg)hdcp_attr->alg;
|
||
|
hdcp_ctl.mode = (crypto_symc_work_mode)hdcp_attr->mode;
|
||
|
ret = memcpy_s(hdcp_ctl.aad, sizeof(hdcp_ctl.aad), hdcp_attr->aad, sizeof(hdcp_attr->aad));
|
||
|
crypto_chk_return(ret != EOK, SYMC_COMPAT_ERRNO(ERROR_MEMCPY_S), "memcpy_s failed\n");
|
||
|
ret = memcpy_s(hdcp_ctl.iv, sizeof(hdcp_ctl.iv), hdcp_attr->iv, sizeof(hdcp_attr->iv));
|
||
|
crypto_chk_return(ret != EOK, SYMC_COMPAT_ERRNO(ERROR_MEMCPY_S), "memcpy_s failed\n");
|
||
|
ret = memcpy_s(hdcp_ctl.tag, sizeof(hdcp_ctl.tag), hdcp_attr->tag, sizeof(hdcp_attr->tag));
|
||
|
crypto_chk_return(ret != EOK, SYMC_COMPAT_ERRNO(ERROR_MEMCPY_S), "memcpy_s failed\n");
|
||
|
|
||
|
hdcp_ctl.in.p = (td_u8 *)in;
|
||
|
hdcp_ctl.out.p = out;
|
||
|
hdcp_ctl.len = len;
|
||
|
hdcp_ctl.is_decrypt = is_decrypt;
|
||
|
|
||
|
fd = crypto_open("/dev/" CRYPTO_CIPHER_DEV_NAME, O_RDWR, 0);
|
||
|
crypto_chk_return(fd < 0, SYMC_COMPAT_ERRNO(ERROR_DEV_OPEN_FAILED), "crypto_open failed\n");
|
||
|
|
||
|
ret = crypto_ioctl(fd, CRYPTO_CMD_HDCP_ENCRYPT, &hdcp_ctl);
|
||
|
crypto_chk_goto(ret != TD_SUCCESS, exit_close, "crypto_ioctl failed, ret = 0x%x\n", ret);
|
||
|
|
||
|
exit_close:
|
||
|
crypto_close(fd);
|
||
|
crypto_uapi_func_exit();
|
||
|
return ret;
|
||
|
}
|