示例#1
0
/******************************************************************************
 * @fn      AesLoadKey
 *
 * @brief   Writes the key into the CC2540
 *
 * input parameters
 *
 * @param   AesKey  - Pointer to AES Key.
 *
 * @return  None
 */
void AesLoadKey( uint8 *AesKey )
{
#if (defined HAL_AES_DMA) && (HAL_AES_DMA == TRUE)
  halDMADesc_t *ch = HAL_DMA_GET_DESC1234( HAL_DMA_AES_IN );

  /* Modify descriptors for channel 1 */
  HAL_DMA_SET_SOURCE( ch, AesKey );
  HAL_DMA_SET_LEN( ch, KEY_BLENGTH );

  /* Arm DMA channel 1 */
  HAL_DMA_CLEAR_IRQ( HAL_DMA_AES_IN );
  HAL_DMA_ARM_CH( HAL_DMA_AES_IN );
  do {
    asm("NOP");
  } while (!HAL_DMA_CH_ARMED(HAL_DMA_AES_IN));

  /* Set AES mode */
  AES_SET_ENCR_DECR_KEY_IV( AES_LOAD_KEY );

  /* Kick it off, block until AES is ready */
  AES_START();
  while( !(ENCCS & 0x08) );
#else
  /* Set AES mode */
  AES_SET_ENCR_DECR_KEY_IV( AES_LOAD_KEY );

  /* Load the block */
  AesLoadBlock( AesKey );
#endif
}
//-----------------------------------------------------------------------------
// See hal.h for a description of this function.
//-----------------------------------------------------------------------------
void halAesLoadKeyOrInitVector(BYTE* pData, BOOL key){
   UINT8 i;

   // Checking whether to load a key or an initialisation vector.
   if(key){
      AES_SET_ENCR_DECR_KEY_IV(AES_LOAD_KEY);
   }
   else {
      AES_SET_ENCR_DECR_KEY_IV(AES_LOAD_IV);
   }
   // Starting loading of key or vector.
   AES_START();

   // loading the data (key or vector)
   for(i = 0; i < 16; i++){
      ENCDI = pData[i];
   }
   return;
}
示例#3
0
/******************************************************************************
 * @fn      sspAesEncryptHW
 *
 * @brief   Encrypts 16 byte block using AES encryption engine
 *
 * input parameters
 *
 * @param   AesKey  - Pointer to AES Key.
 * @param   Cstate  - Pointer to input data.
 *
 * output parameters
 *
 * @param   Cstate  - Pointer to encrypted data.
 *
 * @return  None
 *
 */
void sspAesEncryptHW( uint8 *AesKey, uint8 *Cstate )
{
  (void)AesKey;

#if (defined HAL_AES_DMA) && (HAL_AES_DMA == TRUE)
  /* Setup DMA for AES encryption */
  AesDmaSetup( Cstate, STATE_BLENGTH, Cstate, STATE_BLENGTH );
  AES_SET_ENCR_DECR_KEY_IV( AES_ENCRYPT );

  /* Kick it off, block until DMA is done */
  AES_START();
  while( !HAL_DMA_CHECK_IRQ( HAL_DMA_AES_OUT ) );
#else
  /* Set ECB mode for AES encryption */
  AES_SETMODE(ECB);
  AES_SET_ENCR_DECR_KEY_IV( AES_ENCRYPT );

  /* Load and start the block */
  AesStartBlock( Cstate, Cstate );
#endif
}