Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Power consumption cannot be reduced after using hardware encryption

Hi   

    Nordic engineer

    Power consumption cannot be reduced after using hardware encryption. Under normal conditions, the device power consumption is 30µA, but after calling aes_cbc_decrypt, it increases to 3.4mA.   SDK is nrf5 17.0.0,how can I reduce power consumption?

   

void aes_cbc_decrypt(uint8_t *in,uint32_t out_len,uint8_t *out,uint8_t *iv,uint8_t *key)
{
    int ret;
	SaSiAesUserContext_t    ContextID;
	SaSiAesUserKeyData_t    keyData;
	SaSi_LibInit();
    ret = SaSi_AesInit(&ContextID,SASI_AES_DECRYPT,SASI_AES_MODE_CBC,SASI_AES_PADDING_NONE);
    
    ret = SaSi_AesSetIv(&ContextID, iv);

    keyData.pKey = key;
    keyData.keySize = 16;
    ret = SaSi_AesSetKey(&ContextID, SASI_AES_USER_KEY, &keyData, sizeof(keyData) );
    uint16_t i=0;
	if(out_len>SASI_AES_BLOCK_SIZE_IN_BYTES)
	{
	    for(i=0 ; i<(out_len/SASI_AES_BLOCK_SIZE_IN_BYTES-1) ; i++)
	    {
	        ret = SaSi_AesBlock(&ContextID,
	   				in+i*SASI_AES_BLOCK_SIZE_IN_BYTES,
	   				SASI_AES_BLOCK_SIZE_IN_BYTES,
	   				out+i*SASI_AES_BLOCK_SIZE_IN_BYTES);
	    }
	}
    uint32_t len=out_len-i*SASI_AES_BLOCK_SIZE_IN_BYTES;
	if(len%SASI_AES_BLOCK_SIZE_IN_BYTES)
	{
		uint8_t temp[32]={0};
		uint32_t cipher_len = ((len+15)/SASI_AES_BLOCK_SIZE_IN_BYTES)*SASI_AES_BLOCK_SIZE_IN_BYTES;
		ret = SaSi_AesFinish(&ContextID,
						cipher_len,
						in+i*SASI_AES_BLOCK_SIZE_IN_BYTES,
						cipher_len,
						temp,
						&cipher_len); 
		memcpy(out+i*SASI_AES_BLOCK_SIZE_IN_BYTES,temp,len);
	}
	else
	{
		ret = SaSi_AesFinish(&ContextID,
							len,
							in+i*SASI_AES_BLOCK_SIZE_IN_BYTES,
							len,
							out+i*SASI_AES_BLOCK_SIZE_IN_BYTES,
							&len);  
	}
	SaSi_AesFree(&ContextID);
	SaSi_LibFini();	    
}

Parents Reply
  • Wr0ng order of operation in power_manage() function.

    You need to kill FPU exceptions first, and then call sd_app_evt_wait().

    Your order will wait for SD events with FPU enabled, and that may keep the MCU at high consumtion state.

    EDIT: Did not see the ble stuff before posting. But if advertizer was inactive, the sd_app_evt_wait() call might  never return.

Children
Related