static void random_gen(void) { uint8_t ciphertext[16]; AES_SETMODE(ECB); AESLoadKeyOrIV(entropy_buf, TRUE); // IV = entropy_buf AESEncDec(prng_buf, 16, ciphertext, prng_buf, FALSE, FALSE); // encrypt prng_buf with itself memcpy(prng_buf, ciphertext, 16); // prng_buf = ciphertext prng_buf_len = 16; // 16 prng bytes now available }
/****************************************************************************** * @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 }
/****************************************************************************** * @fn ssp_HW_KeyInit * * @brief Writes the key into AES engine * * input parameters * * @param AesKey - Pointer to AES Key. * * @return None */ void ssp_HW_KeyInit( uint8 *AesKey ) { AES_SETMODE(ECB); AesLoadKey( AesKey ); }