Hardware Encryption not working when device is in SCAN mode
⚠️ Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
The hardware encryption worked when called after the device exits the scan(observer) mode. It also worked when the device is in broadcaster mode. This is the code snippet we use : void aes_encrypt_hw(uint8_t* data, uint8_t* key) { struct gapm_use_enc_block_cmd * cmd = ke_msg_alloc(gapm_use_enc_block_cmd,task_gapm,task_app,gapm_use_enc_block_cmd);
静态int gapm_use_enc_block_ind_handler(ke_msg_id_t msgid, struct gapm_use_enc_block_ind *param, ke_task_id_t dest_id, ke_task_id_t src_id) which is defined in app_gap_process_handlers as follows:
你好 , In the DA14580 datasheet, it is given that the chip supports hardware encryption (Screenshot enclosed herewith). So, please suggest if it is reliable to use hardware AES encryption in the DA14580 chip for prolonged period.
From the the template of the SDK 5.0.4 i did the following modifications in order to test what you ve mentioned and i can verify that the encryption message always returns an indication when the command is issued from the advertising indication callback.
After configuring the device to operate as a central user_gapm_conf.role = GAP_CENTRAL_MASTER and apply the proper configurations for the scanning procedure (the scan configurations on my setup are .code = GAPM_SCAN_PASSIVE, .addr_src = GAPM_PUBLIC_ADDR, .interval = 10, .window = 5, .mode = GAP_OBSERVER_MODE, .filt_policy = SCAN_ALLOW_ADV_ALL, .filter_duplic = SCAN_FILT_DUPLIC_DIS) i set up a scanning procedure. The scanning procedure is re-initiated as soon as it times out in the user_on_scanning_complete() function.
In order to test the encryption callback i used the below function with some dummy data
嗨Wisilica,
DA14580 does not export APIs to use the hardware encryption block. You'll probably need a software encryption.
And which API did you use and expected gapm_use_enc_block_ind_handler being called?
你好 ,
The hardware encryption worked when called after the device exits the scan(observer) mode. It also worked when the device is in broadcaster mode.
This is the code snippet we use :
void aes_encrypt_hw(uint8_t* data, uint8_t* key)
{
struct gapm_use_enc_block_cmd * cmd = ke_msg_alloc(gapm_use_enc_block_cmd,task_gapm,task_app,gapm_use_enc_block_cmd);
uint8_t rev_key[16];
uint8_t rev_data[16];
cmd->operation = GAPM_USE_ENC_BLOCK;
for(i = 0; i <16; ++ i)
{
rev_key[i] = *(key+(15-i));
rev_data [i] = *(数据+(15-i));
}
memcpy(cmd->operand_1, rev_key, 16);
memcpy(cmd->operand_2, rev_data, 16);
ke_msg_send(cmd);
}
现在,一旦加密完成,我们将对处理程序进行回调,
静态int gapm_use_enc_block_ind_handler(ke_msg_id_t msgid,
struct gapm_use_enc_block_ind *param,
ke_task_id_t dest_id,
ke_task_id_t src_id) which is defined in app_gap_process_handlers as follows:
static const struct ke_msg_handler app_gap_process_handlers [] =
{
{GAPM_DEVICE_READY_IND, (ke_msg_func_t)gapm_device_ready_ind_handler},
{GAPM_CMP_EVT, (ke_msg_func_t)gapm_cmp_evt_handler},
{GAPC_CMP_EVT, (ke_msg_func_t)gapc_cmp_evt_handler},
{GAPC_CONNECTION_REQ_IND, (ke_msg_func_t)gapc_connection_req_ind_handler},
{GAPC_DISCONNECT_IND, (ke_msg_func_t)gapc_disconnect_ind_handler},
{APP_MODULE_INIT_CMP_EVT, (ke_msg_func_t)app_module_init_cmp_evt_handler},
{gapm_adv_report_ind,(ke_msg_func_t)gapm_adv_report_ind_handler},
{GAPM_USE_ENC_BLOCK_IND, (ke_msg_func_t)gapm_use_enc_block_ind_handler},
#if (BLE_APP_SEC)
{GAPC_SECURITY_IND, gapc_se (ke_msg_func_t)curity_ind_handler},
#endif
};
除了设备处于扫描模式时,我们能够在所有情况下使用DA14580芯片获得适当的加密结果。
谢谢,
Wisilica
Hi wisillica,
我尝试了在扫描模式期间提到的内容,当发生了广告指示时,我可以举起加密功能,我可以始终在捕获休息功能中获取回调,所以请尝试在该函数而不是app_gap_process_handlers中捕获gapm_use_enc_block_ind []大批。
Thanks MT_dialog
你好 ,
In the DA14580 datasheet, it is given that the chip supports hardware encryption (Screenshot enclosed herewith). So, please suggest if it is reliable to use hardware AES encryption in the DA14580 chip for prolonged period.
谢谢,
Wisilica
嗨Wisilica,
是的芯片有一个AES-128位加密处理器,我不知道任何问题,您是否遇到了申请中的某些内容?关于扫描和加密指示,你试过上面提到的什么吗?
Thanks MT_dialog
Hi,
是的,我试图在上面提到的Catch Rest功能中包含加密的回调处理程序,但由于硬件加密完成,我无法将回调与此功能中的回调。在设备的扫描阶段调用硬件加密。
谢谢,
Wisilica
嗨Wisilica,
From the the template of the SDK 5.0.4 i did the following modifications in order to test what you ve mentioned and i can verify that the encryption message always returns an indication when the command is issued from the advertising indication callback.
void encrypt_data(void)
{
uint8_t key[16] = {15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
uint8_t plaintext[16] = {0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
struct gapm_use_enc_block_cmd * cmd = ke_msg_alloc(gapm_use_enc_block_cmd,task_gapm,task_app,gapm_use_enc_block_cmd);
cmd->operation = GAPM_USE_ENC_BLOCK;
memcpy(cmd->operand_1, key, 16);
memcpy(cmd->operand_2, plaintext, 16);
ke_msg_send(cmd);
}
void user_on_adv_report_ind(struct gapm_adv_report_ind const * param)
{
ARCH_SET_PXACT_GPIO();
ARCH_PRINTF(“连接%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%。
param-> eport.adddr.addr [5],
param-> eport.addr.addr [4],
param->report.adv_addr.addr[3],
param->report.adv_addr.addr[2],
param-> eport.addr.addr [1],
param->report.adv_addr.addr[0]);
加密_data();
}
void user_catch_rest_hndl(ke_msg_id_t const msgid,
void const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
switch(msgid)
{
case GAPM_USE_ENC_BLOCK_IND:
{
uint8_t encryted_data[16];
memset(encryted_data,0,sizeof(encryted_data));
struct gapm_use_enc_block_ind const *msg_param = (struct gapm_use_enc_block_ind const *)(param);
memcpy(encryted_data,msg_param->result,sizeof(encryted_data));
ARCH_PRINTF(“%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x \ n \ r”,
encryted_data[0],
encryted_data[1],
Encryted_data [2],
EncryTed_data [3],
encryted_data[4],
encryted_data[5],
Encryted_data [6],
encryted_data[7],
encryted_data[8],
encryted_data[9],
encryted_data[10],
encryted_data[11],
encryted_data[12],
EncryTed_data [13],
EncryTed_data [14],
encryted_data[15]
);
}休息;
如果存在打印BD地址的广告指示,并且称为encrypt_data()函数,并且加密指示尚未发生,则在终端日志上会易于发现,这是我在我的设置上没有看到的东西。即使两个广告迹象非常短暂注意到,消息也会进入队列,并且将打印两个加密响应。所以请你尝试提到的东西。
Thanks MT_dialog