emlib/src/em_aes.c
void AES_DecryptKey256(uint8_t *out, const uint8_t *in)
{
  int            i;
  int            j;
  uint32_t       *_out = (uint32_t *)out;
  const uint32_t *_in  = (const uint32_t *)in;

  /* Load key */
  for (i = 3, j = 7; i >= 0; i--, j--) {
    AES->KEYLA = __REV(_in[j]);
    AES->KEYHA = __REV(_in[i]);
  }

  /* Do dummy encryption to generate decrypt key */
  AES->CTRL = AES_CTRL_AES256;
  AES->CMD  = AES_CMD_START;

  /* Wait for completion */
  while (AES->STATUS & AES_STATUS_RUNNING)
    ;

  /* Save decryption key */
  for (i = 3, j = 7; i >= 0; i--, j--) {
    _out[j] = __REV(AES->KEYLA);
    _out[i] = __REV(AES->KEYHA);
  }
}
/***************************************************************************/
/**
 * @brief
 *   Generate 256 bit decryption key from 256 bit encryption key. The decryption
 *   key is used for some cipher modes when decrypting.
 *
 * @details
 *   Please refer to general comments on layout and byte ordering of parameters.
 *
 * @param[out] out
 *   Buffer to place 256 bit decryption key. Must be at least 32 bytes long. It
 *   may be set equal to @p in, in which case the input buffer is overwritten.
 *
 * @param[in] in
 *   Buffer holding 256 bit encryption key. Must be at least 32 bytes long.
 ******************************************************************************/
@brief
Generate 256 bit decryption key from 256 bit encryption key. The decryption
key is used for some cipher modes when decrypting.

@details
Please refer to general comments on layout and byte ordering of parameters.

@param[out] out
Buffer to place 256 bit decryption key. Must be at least 32 bytes long. It
may be set equal to @p in, in which case the input buffer is overwritten.

@param[in] in
Buffer holding 256 bit encryption key. Must be at least 32 bytes long.
@brief Generate 256 bit decryption key from 256 bit encryption key . The decryption key is used for some cipher modes when decrypting . @details Please refer to general comments on layout and byte ordering of parameters . @param [ out ] out Buffer to place 256 bit decryption key . Must be at least 32 bytes long . It may be set equal to @p in in which case the input buffer is overwritten . @param [ in ] in Buffer holding 256 bit encryption key . Must be at least 32 bytes long .
void AES_DecryptKey256(uint8_t *out, const uint8_t *in)
{
  int            i;
  int            j;
  uint32_t       *_out = (uint32_t *)out;
  const uint32_t *_in  = (const uint32_t *)in;
  for (i = 3, j = 7; i >= 0; i--, j--) {
    AES->KEYLA = __REV(_in[j]);
    AES->KEYHA = __REV(_in[i]);
  }
  AES->CTRL = AES_CTRL_AES256;
  AES->CMD  = AES_CMD_START;
  while (AES->STATUS & AES_STATUS_RUNNING)
    ;
  for (i = 3, j = 7; i >= 0; i--, j--) {
    _out[j] = __REV(AES->KEYLA);
    _out[i] = __REV(AES->KEYHA);
  }
}
void AES_DecryptKey256 ( uint8_t * out , const uint8_t * in ) { int i ; int j ; uint32_t * _out = ( uint32_t * ) out ; const uint32_t * _in = ( const uint32_t * ) in ; for ( i = 3 , j = 7 ; i >= 0 ; i -- , j -- ) { AES -> KEYLA = __REV ( _in [ j ] ) ; AES -> KEYHA = __REV ( _in [ i ] ) ; } AES -> CTRL = AES_CTRL_AES256 ; AES -> CMD = AES_CMD_START ; while ( AES -> STATUS & AES_STATUS_RUNNING ) ; for ( i = 3 , j = 7 ; i >= 0 ; i -- , j -- ) { _out [ j ] = __REV ( AES -> KEYLA ) ; _out [ i ] = __REV ( AES -> KEYHA ) ; } }
@brief
   Generate 256 bit decryption key from 256 bit encryption key.
@brief Generate 256 bit decryption key from 256 bit encryption key .
/* Load key */ /* Do dummy encryption to generate decrypt key */ /* Wait for completion */ /* Save decryption key */