Unable to use AES Hardware encryption block

6 posts / 0 new
Last post
ankitdaf
Offline
Last seen:2 years 6 months ago
Joined:2015-09-03 20:14
Unable to use AES Hardware encryption block

Hi

I am trying to use AES Hardware encryption for some user data, based on BLE app barebone

I have gone through the rest of the forum documents, but it did not help.

My code is as below :

struct gapm_use_enc_block_cmd *enccmd = KE_MSG_ALLOC(GAPM_USE_ENC_BLOCK_CMD, TASK_GAPM, TASK_APP, gapm_use_enc_block_cmd);
enccmd->operation = GAPM_USE_ENC_BLOCK;
uint8_t key[16] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
uint8_t pt[16] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff};
memcpy(enccmd->operand_1,key,16);
memcpy(enccmd->operand_2,pt,16);
ke_msg_send(enccmd);

This is at the bottom of user_app_init();

---

I added this in user_catch_rest_hndl

case GAPM_USE_ENC_BLOCK_IND:
{
struct gapm_use_enc_block_ind const *msg_param = (struct gapm_use_enc_block_ind const *) (param);
uint8_t ciphertext[16];
memcpy(ciphertext,msg_param->result,16);
if(ciphertext[0] == 0x01 ) {
ciphertext[0]++;
}

if(ciphertext[0] == 0x01) {
--ciphertext[0];
}
}
break;

I added breakpoints, but it seems that the message is never caught. Can you please help me figure out what i am missing / doing wrong ?

Thanks

Keywords:
Device:
LC_Dialog
Offline
Last seen:6 days 12 hours ago
Staff
Joined:2016-09-19 23:20
Hello ankitdaf,

Hello ankitdaf,

I am currently reveiwing your query and will get back to you on this.

Regards,

LC

ankitdaf
Offline
Last seen:2 years 6 months ago
Joined:2015-09-03 20:14
Update :

Update :

I figured it out, I guess some components are not initialized before user_app_init returns, so calling the gapm_use_enc_block_cmd failed because it needed those components. Calling it on advertise start or complete works just fine.

I have a different problem now. If I wanted to encrypt an entire block of data, say 64 bytes, is there a "blocking" way to do it ? Presently, it happens with a call - callback mode, and it is rather cumbersome to keep track. Is it possible to call the hardware encryption block, then wait for the result before proceeding ?

Thanks

Joacimwe
Offline
Last seen:1 year 2 months ago
Guru
Joined:2014-01-14 06:45
Yes. See my post at https:/
ankitdaf
Offline
Last seen:2 years 6 months ago
Joined:2015-09-03 20:14
Thanks, trying this out now !

Thanks, trying this out now !

I was wondering if you could explain a few of the statements there. The exact reason you are doing a couple of things isn't clear to me..

1. Is there documentation for the lower level registers you are writing directly into ? (eg. BLE_AESKEY31_0_REG, BLE_AESCNTL_REG, etc)

2.
volatile uint8_t* plaintext_ptr = (volatile uint8_t*)0x80000 + jump_table_struct[offset_em_enc_plain];
volatile uint8_t* ciphertext_ptr = (volatile uint8_t*)0x80000 + jump_table_struct[offset_em_enc_cipher];

上面的两个指针地址的任何理由way they are ?
How are they chosen ?

I think I missing something , some documentation or understanding, and am looking to understand the system better.

Your help is much appreciated !

Thanks !

Joacimwe
Offline
Last seen:1 year 2 months ago
Guru
Joined:2014-01-14 06:45
There isn't that much

There isn't that much documentation available than what's inside datasheet.h. However the names of the fields should be almost enough as documentation. BLE_AESKEYX_X_REG holds the key, BLE_AESCNTL_REG holds only one bit called AES_START (which starts the encryption when 1 is written and reads 1 while an encryption is ongoing). The BLE_AESPTR_REG contains the memory address of the plaintext and ciphertext (consecutive in memory) which is set to (volatile uint8_t*)0x80000 + jump_table_struct[offset_em_enc_plain]. It can contain any RAM address in the 0x80000 segment, so this is just an arbitrarily selected area.