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.

192 lines
6.0 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved.
* Description: demux descrambler iapi func impl.
* Author: Hisilicon
* Create: 2019-04-12
*/
#include "td_type.h"
#include "soc_log.h"
#include "soc_errno.h"
#include "mpi_demux_ext.h"
#include "uapi_descrambler.h"
#include "api_demux_utils.h"
typedef struct {
dmx_dsc_key_alg dsc_alg;
uapi_crypto_alg crypto_alg;
} dmx_alg_map;
static dmx_alg_map g_dmx_alg_map[] = {
{DMX_DESCRAMBLER_TYPE_CSA2, UAPI_CRYPTO_ALG_CSA2},
{DMX_DESCRAMBLER_TYPE_CSA3, UAPI_CRYPTO_ALG_CSA3},
{DMX_DESCRAMBLER_TYPE_AES_IPTV, UAPI_CRYPTO_ALG_AES_IPTV},
{DMX_DESCRAMBLER_TYPE_AES_ECB, UAPI_CRYPTO_ALG_AES_ECB_T},
{DMX_DESCRAMBLER_TYPE_AES_CI, UAPI_CRYPTO_ALG_AES_CISSA},
{DMX_DESCRAMBLER_TYPE_DES_CI, UAPI_CRYPTO_ALG_DES_CI},
{DMX_DESCRAMBLER_TYPE_DES_CBC, UAPI_CRYPTO_ALG_DES_CBC},
{DMX_DESCRAMBLER_TYPE_SMS4_IPTV, UAPI_CRYPTO_ALG_SMS4_CBC_IDSA},
{DMX_DESCRAMBLER_TYPE_SMS4_ECB, UAPI_CRYPTO_ALG_SMS4_ECB},
{DMX_DESCRAMBLER_TYPE_SMS4_CBC, UAPI_CRYPTO_ALG_SMS4_CBC},
{DMX_DESCRAMBLER_TYPE_AES_CBC, UAPI_CRYPTO_ALG_AES_CISSA},
{DMX_DESCRAMBLER_TYPE_DES_IPTV, UAPI_CRYPTO_ALG_DES_CBC_IDSA},
{DMX_DESCRAMBLER_TYPE_TDES_IPTV, UAPI_CRYPTO_ALG_TDES_CBC_IDSA},
{DMX_DESCRAMBLER_TYPE_TDES_ECB, UAPI_CRYPTO_ALG_TDES_ECB},
{DMX_DESCRAMBLER_TYPE_TDES_CBC, UAPI_CRYPTO_ALG_TDES_CBC},
{DMX_DESCRAMBLER_TYPE_AES_ECB_L, UAPI_CRYPTO_ALG_AES_ECB_L},
{DMX_DESCRAMBLER_TYPE_AES_CBC_L, UAPI_CRYPTO_ALG_AES_CBC_L},
{DMX_DESCRAMBLER_TYPE_ASA, UAPI_CRYPTO_ALG_ASA},
{DMX_DESCRAMBLER_TYPE_AES_CISSA, UAPI_CRYPTO_ALG_AES_CISSA}
};
static dmx_dsc_key_alg crypto_to_dsc_alg(uapi_crypto_alg crypto_alg)
{
td_u32 i;
dmx_dsc_key_alg dsc_alg = DMX_DESCRAMBLER_TYPE_MAX;
for (i = 0; i < sizeof(g_dmx_alg_map) / sizeof(dmx_alg_map); i++) {
if (g_dmx_alg_map[i].crypto_alg == crypto_alg) {
dsc_alg = g_dmx_alg_map[i].dsc_alg;
break;
}
}
return dsc_alg;
}
static uapi_crypto_alg dsc_to_crypto_alg(dmx_dsc_key_alg dsc_alg)
{
td_u32 i;
uapi_crypto_alg crypto_alg = UAPI_CRYPTO_ALG_MAX;
for (i = 0; i < sizeof(g_dmx_alg_map) / sizeof(dmx_alg_map); i++) {
if (g_dmx_alg_map[i].dsc_alg == dsc_alg) {
crypto_alg = g_dmx_alg_map[i].crypto_alg;
break;
}
}
return crypto_alg;
}
td_s32 uapi_dmx_desc_create(td_u32 dmx_id, const uapi_dmx_desc_attr *attr, td_handle *desc_handle)
{
dmx_dsc_attrs dsc_attr;
TD_UNUSED(dmx_id);
if (attr == TD_NULL || desc_handle == TD_NULL) {
soc_log_err("Null Pointer!\n");
return SOC_ERR_DMX_NULL_PTR;
}
dsc_attr.ca_type = DMX_CA_ADVANCE;
dsc_attr.entropy_reduction = (dmx_dsc_entropy)attr->entropy_reduction;
dsc_attr.alg = crypto_to_dsc_alg(attr->alg_type);
dsc_attr.keyslot_create_en = attr->is_create_keyslot;
return ext_mpi_dmx_dsc_create(&dsc_attr, desc_handle);
}
td_s32 uapi_dmx_desc_destroy(td_handle desc_handle)
{
return ext_mpi_dmx_dsc_destroy(desc_handle);
}
td_s32 uapi_dmx_desc_get_attr(td_handle desc_handle, uapi_dmx_desc_attr *attr)
{
td_s32 ret;
dmx_dsc_attrs dsc_attr;
if (attr == TD_NULL) {
soc_log_err("Null Pointer!\n");
return SOC_ERR_DMX_NULL_PTR;
}
ret = ext_mpi_dmx_dsc_get_attrs(desc_handle, &dsc_attr);
if (ret == TD_SUCCESS) {
attr->alg_type = dsc_to_crypto_alg(dsc_attr.alg);
attr->entropy_reduction = (uapi_dmx_ca_entropy)dsc_attr.entropy_reduction;
attr->is_create_keyslot = dsc_attr.keyslot_create_en;
}
return ret;
}
td_s32 uapi_dmx_desc_set_attr(td_handle desc_handle, const uapi_dmx_desc_attr *attr)
{
dmx_dsc_attrs dsc_attr;
if (attr == TD_NULL) {
soc_log_err("Null Pointer!\n");
return SOC_ERR_DMX_NULL_PTR;
}
dsc_attr.entropy_reduction = (dmx_dsc_entropy)attr->entropy_reduction;
dsc_attr.alg = crypto_to_dsc_alg(attr->alg_type);
dsc_attr.keyslot_create_en = attr->is_create_keyslot;
return ext_mpi_dmx_dsc_set_attrs(desc_handle, &dsc_attr);
}
td_s32 uapi_dmx_desc_set_sys_key(td_handle desc_handle, const td_u8 *sys_key, td_u32 sys_key_len)
{
return ext_mpi_dmx_dsc_set_sys_key(desc_handle, sys_key, sys_key_len);
}
td_s32 uapi_dmx_desc_set_even_iv(td_handle desc_handle, const td_u8 *even_iv, td_u32 even_iv_len)
{
return ext_mpi_dmx_dsc_set_even_iv(desc_handle, even_iv, even_iv_len);
}
td_s32 uapi_dmx_desc_set_odd_iv(td_handle desc_handle, const td_u8 *odd_iv, td_u32 odd_iv_len)
{
return ext_mpi_dmx_dsc_set_odd_iv(desc_handle, odd_iv, odd_iv_len);
}
td_s32 uapi_dmx_desc_attach_key_slot(td_handle desc_handle, td_handle key_slot)
{
return ext_mpi_dmx_dsc_attach_keyslot(desc_handle, key_slot);
}
td_s32 uapi_dmx_desc_detach_key_slot(td_handle desc_handle)
{
return ext_mpi_dmx_dsc_detach_keyslot(desc_handle);
}
td_s32 uapi_dmx_desc_get_key_slot_handle(td_handle desc_handle, td_handle *key_slot)
{
return ext_mpi_dmx_dsc_get_keyslot_handle(desc_handle, key_slot);
}
td_s32 uapi_dmx_desc_attach_pid_chan(td_handle desc_handle, td_handle pid_chan)
{
return ext_mpi_dmx_dsc_attach(desc_handle, pid_chan);
}
td_s32 uapi_dmx_desc_detach_pid_chan(td_handle desc_handle, td_handle pid_chan)
{
return ext_mpi_dmx_dsc_detach(desc_handle, pid_chan);
}
td_s32 uapi_dmx_desc_get_handle(td_handle pid_chan, td_handle *desc_handle)
{
return ext_mpi_dmx_dsc_get_dsc_key_handle(pid_chan, desc_handle);
}
td_s32 uapi_dmx_desc_get_free_count(td_u32 dmx_id, td_u32 *free_count)
{
TD_UNUSED(dmx_id);
return ext_mpi_dmx_dsc_get_free_dsc_key_cnt(free_count);
}
td_s32 uapi_dmx_desc_set_even_key(td_handle desc_handle, const td_u8 *even_key, td_u32 even_key_len)
{
return ext_mpi_dmx_dsc_set_even_key(desc_handle, even_key, even_key_len);
}
td_s32 uapi_dmx_desc_set_odd_key(td_handle desc_handle, const td_u8 *odd_key, td_u32 odd_key_len)
{
return ext_mpi_dmx_dsc_set_odd_key(desc_handle, odd_key, odd_key_len);
}