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
  • Hi,

    Generally we recommend using the nrf_crypto API on top of the cryptocell API (AES samples with cc310 can be found in /crypto/nrf_crypto/aes) which takes care of powering down the cc310 after use, but I see you ahavee SaSi_LibFini() at the end there which should have the same effect. Have you tried to debug your application to verify whether the program returns from this function and starts executing the __WFE()/__WFI() after?

    Best regards,

    Vidar 

Reply
  • Hi,

    Generally we recommend using the nrf_crypto API on top of the cryptocell API (AES samples with cc310 can be found in /crypto/nrf_crypto/aes) which takes care of powering down the cc310 after use, but I see you ahavee SaSi_LibFini() at the end there which should have the same effect. Have you tried to debug your application to verify whether the program returns from this function and starts executing the __WFE()/__WFI() after?

    Best regards,

    Vidar 

Children
Related