TI中文支持网
TI专业的中文技术问题搜集分享网站

CC2540 Broadcast模式下AES加密

求教CC2540 Broadcast模式下AES加密,在Broadcast使用LL_Encrypt进行加密,在Observer使用LL_EXT_Decrypt进行解密,解密数据不正确,仍然为变化的数据。是不是加密过程iv是配对绑定后确定的,而广播模式无法得到iv造成?有没有什么有效的解决方式?谢谢

Yue TANG:

这个有例子程序,请看下例子程序是否OK?

http://processors.wiki.ti.com/index.php/BLE_Encrypt_Adv_Data

This example show how to encrypt and de-crypt advertisement data using the TI CC254X AES calls. 

Broadcast encrypt.png

Download Source Files

File:BleEncryptBroadcastData.zip 

Based on RTM 1.4

SimpleBleBroadcaster.cSimpleBleCentral.c

profiles/roles/Broadcaster.cUpdated Broadcaster profile to allow constant updates to adv data without stopping.This is being fixed for next release.

static uint8 dataCount=0; uint8 key[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; uint8 plainText[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; uint8 encryptedData[16]; dataCount++; plainText[0] = dataCount; LL_Encrypt( key, plainText, encryptedData ); // GAP – Advertisement data (max size = 31 bytes, though this is // best kept short to conserve power while advertisting) uint8 advertData2[] = { // Flags; this sets the device to use limited discoverable // mode (advertises for 30 seconds at a time) instead of general // discoverable mode (advertises indefinitely) 0x02, // length of this data GAP_ADTYPE_FLAGS, GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,

// three-byte broadcast of the data "1 2 3" 0x011, // length of this data including the data type byte GAP_ADTYPE_MANUFACTURER_SPECIFIC, // manufacturer specific advertisement data type encryptedData[0], encryptedData[1], encryptedData[2], encryptedData[3], encryptedData[4], encryptedData[5], encryptedData[6], encryptedData[7], encryptedData[8], encryptedData[9], encryptedData[10], encryptedData[11], encryptedData[12], encryptedData[13], encryptedData[14], encryptedData[15] }; //update broadcast info GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData2 ), advertData2 );

case GAP_DEVICE_INFO_EVENT: { // add some way to know address we are looking for to decrypt if(pEvent->deviceInfo.dataLen==0x15) { static uint8 key[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; static uint8 encryptedData[16]; static uint8 plaintextData[16]; osal_memcpy(encryptedData,&(pEvent->deviceInfo.pEvtData[5]),16);

LL_EXT_Decrypt( key, encryptedData, plaintextData );

LCD_WRITE_STRING( bdAddr2Str( plaintextData ), HAL_LCD_LINE_2 ); } }

赞(0)
未经允许不得转载:TI中文支持网 » CC2540 Broadcast模式下AES加密
分享到: 更多 (0)