mirror of https://github.com/ARMmbed/mbed-os.git
[NUC472/M487] Use interrupt signal rather than polling to check operation completion in DES alter.
This is to be consistent with PRNG/AES.pull/4925/head
parent
0c1098483f
commit
3a8c1aa687
|
|
@ -355,6 +355,8 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
|
|||
|
||||
/* Init crypto module */
|
||||
crypto_init();
|
||||
/* Enable DES interrupt */
|
||||
TDES_ENABLE_INT();
|
||||
|
||||
/* Configure TDES_CTL register
|
||||
*
|
||||
|
|
@ -407,17 +409,9 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
|
|||
|
||||
TDES_SetDMATransfer(0, (uint32_t) dmabuf_in, (uint32_t) dmabuf_out, data_len);
|
||||
|
||||
/* Ensure memory accesses above are completed before DMA is started
|
||||
*
|
||||
* Replacing __DSB() with __DMB() is also OK in this case.
|
||||
*
|
||||
* Refer to "multi-master systems" section with DMA in:
|
||||
* https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
|
||||
*/
|
||||
__DSB();
|
||||
/* Start enc/dec */
|
||||
crypto_des_prestart();
|
||||
TDES_Start(0, CRYPTO_DMA_ONE_SHOT);
|
||||
while (CRPT->TDES_STS & CRPT_TDES_STS_BUSY_Msk);
|
||||
crypto_des_wait();
|
||||
|
||||
memcpy(out_pos, dmabuf_out, data_len);
|
||||
in_pos += data_len;
|
||||
|
|
@ -457,6 +451,8 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
|
|||
}
|
||||
}
|
||||
|
||||
/* Disable DES interrupt */
|
||||
TDES_DISABLE_INT();
|
||||
/* Uninit crypto module */
|
||||
crypto_uninit();
|
||||
|
||||
|
|
|
|||
|
|
@ -355,6 +355,8 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
|
|||
|
||||
/* Init crypto module */
|
||||
crypto_init();
|
||||
/* Enable DES interrupt */
|
||||
TDES_ENABLE_INT();
|
||||
|
||||
/* Configure TDES_CTL register
|
||||
*
|
||||
|
|
@ -407,17 +409,9 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
|
|||
|
||||
TDES_SetDMATransfer(0, (uint32_t) dmabuf_in, (uint32_t) dmabuf_out, data_len);
|
||||
|
||||
/* Ensure memory accesses above are completed before DMA is started
|
||||
*
|
||||
* Replacing __DSB() with __DMB() is also OK in this case.
|
||||
*
|
||||
* Refer to "multi-master systems" section with DMA in:
|
||||
* https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
|
||||
*/
|
||||
__DSB();
|
||||
/* Start enc/dec */
|
||||
crypto_des_prestart();
|
||||
TDES_Start(0, CRYPTO_DMA_ONE_SHOT);
|
||||
while (CRPT->TDES_STS & CRPT_TDES_STS_BUSY_Msk);
|
||||
crypto_des_wait();
|
||||
|
||||
memcpy(out_pos, dmabuf_out, data_len);
|
||||
in_pos += data_len;
|
||||
|
|
@ -457,6 +451,8 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
|
|||
}
|
||||
}
|
||||
|
||||
/* Disable DES interrupt */
|
||||
TDES_DISABLE_INT();
|
||||
/* Uninit crypto module */
|
||||
crypto_uninit();
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ static void crypto_submodule_release(uint16_t *submodule_avail);
|
|||
static volatile uint16_t crypto_prng_done;
|
||||
/* Track if AES H/W operation is done */
|
||||
static volatile uint16_t crypto_aes_done;
|
||||
/* Track if DES H/W operation is done */
|
||||
static volatile uint16_t crypto_des_done;
|
||||
|
||||
static void crypto_submodule_prestart(volatile uint16_t *submodule_done);
|
||||
static bool crypto_submodule_wait(volatile uint16_t *submodule_done);
|
||||
|
|
@ -150,6 +152,16 @@ bool crypto_aes_wait(void)
|
|||
return crypto_submodule_wait(&crypto_aes_done);
|
||||
}
|
||||
|
||||
void crypto_des_prestart(void)
|
||||
{
|
||||
crypto_submodule_prestart(&crypto_des_done);
|
||||
}
|
||||
|
||||
bool crypto_des_wait(void)
|
||||
{
|
||||
return crypto_submodule_wait(&crypto_des_done);
|
||||
}
|
||||
|
||||
bool crypto_dma_buff_compat(const void *buff, size_t buff_size, size_t size_aligned_to)
|
||||
{
|
||||
uint32_t buff_ = (uint32_t) buff;
|
||||
|
|
@ -201,5 +213,8 @@ void CRYPTO_IRQHandler()
|
|||
} else if (AES_GET_INT_FLAG()) {
|
||||
crypto_aes_done = 1;
|
||||
AES_CLR_INT_FLAG();
|
||||
} else if (TDES_GET_INT_FLAG()) {
|
||||
crypto_des_done = 1;
|
||||
TDES_CLR_INT_FLAG();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ void crypto_prng_prestart(void);
|
|||
bool crypto_prng_wait(void);
|
||||
void crypto_aes_prestart(void);
|
||||
bool crypto_aes_wait(void);
|
||||
void crypto_des_prestart(void);
|
||||
bool crypto_des_wait(void);
|
||||
|
||||
|
||||
/* Check if buffer can be used for crypto DMA. It has the following requirements:
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ static void crypto_submodule_release(uint16_t *submodule_avail);
|
|||
static volatile uint16_t crypto_prng_done;
|
||||
/* Track if AES H/W operation is done */
|
||||
static volatile uint16_t crypto_aes_done;
|
||||
/* Track if DES H/W operation is done */
|
||||
static volatile uint16_t crypto_des_done;
|
||||
|
||||
static void crypto_submodule_prestart(volatile uint16_t *submodule_done);
|
||||
static bool crypto_submodule_wait(volatile uint16_t *submodule_done);
|
||||
|
|
@ -150,6 +152,16 @@ bool crypto_aes_wait(void)
|
|||
return crypto_submodule_wait(&crypto_aes_done);
|
||||
}
|
||||
|
||||
void crypto_des_prestart(void)
|
||||
{
|
||||
crypto_submodule_prestart(&crypto_des_done);
|
||||
}
|
||||
|
||||
bool crypto_des_wait(void)
|
||||
{
|
||||
return crypto_submodule_wait(&crypto_des_done);
|
||||
}
|
||||
|
||||
bool crypto_dma_buff_compat(const void *buff, size_t buff_size, size_t size_aligned_to)
|
||||
{
|
||||
uint32_t buff_ = (uint32_t) buff;
|
||||
|
|
@ -201,5 +213,8 @@ void CRYPTO_IRQHandler()
|
|||
} else if (AES_GET_INT_FLAG()) {
|
||||
crypto_aes_done = 1;
|
||||
AES_CLR_INT_FLAG();
|
||||
} else if (TDES_GET_INT_FLAG()) {
|
||||
crypto_des_done = 1;
|
||||
TDES_CLR_INT_FLAG();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ void crypto_prng_prestart(void);
|
|||
bool crypto_prng_wait(void);
|
||||
void crypto_aes_prestart(void);
|
||||
bool crypto_aes_wait(void);
|
||||
void crypto_des_prestart(void);
|
||||
bool crypto_des_wait(void);
|
||||
|
||||
|
||||
/* Check if buffer can be used for crypto DMA. It has the following requirements:
|
||||
|
|
|
|||
Loading…
Reference in New Issue