Skip to content

Commit 1d62b91

Browse files
committed
[NUC472/M487] Refine comment with BSP driver use in DES alter.
1 parent 479cf68 commit 1d62b91

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/des/des_alt.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
332332
/* Init crypto module */
333333
crypto_init();
334334

335-
// NOTE: Don't call driver function TDES_Open in BSP because it doesn't support TDES_CTL[3KEYS] setting.
335+
/* NOTE: Don't call driver function TDES_Open in BSP because we don't want its internal multiple context (channel) support.
336+
* Multiple context (channel) support has done in the upper layer.
337+
*/
336338
CRPT->TDES_CTL = (0 << CRPT_TDES_CTL_CHANNEL_Pos) | (enc << CRPT_TDES_CTL_ENCRPT_Pos) |
337339
tdes_opmode | (TDES_IN_OUT_WHL_SWAP << CRPT_TDES_CTL_BLKSWAP_Pos);
338340

@@ -345,8 +347,10 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
345347
CRPT->TDES_CTL &= ~CRPT_TDES_CTL_3KEYS_Msk;
346348
}
347349

348-
// Set DES/TDES keys
349-
// NOTE: Don't call driver function TDES_SetKey in BSP because it doesn't support endian swap.
350+
/* Set DES/TDES keys
351+
*
352+
* NOTE: TDES_SetKey in BSP is not used because we need to make up an extra 2-dimension array to pass keys.
353+
*/
350354
uint32_t val;
351355
volatile uint32_t *tdes_key = (uint32_t *) ((uint32_t) &CRPT->TDES0_KEY1H + (0x40 * 0));
352356
val = nu_get32_be(key[0] + 0);
@@ -378,8 +382,10 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
378382

379383
TDES_SetDMATransfer(0, (uint32_t) dmabuf_in, (uint32_t) dmabuf_out, data_len);
380384

381-
// Start enc/dec.
382-
// NOTE: Don't call driver function TDES_Start in BSP because it will override TDES_CTL[3KEYS] setting.
385+
/* Start enc/dec.
386+
*
387+
* NOTE: Don't call driver function TDES_Start in BSP because of the multiple context (channel) reason as above.
388+
*/
383389
CRPT->TDES_CTL |= CRPT_TDES_CTL_START_Msk | (CRYPTO_DMA_ONE_SHOT << CRPT_TDES_CTL_DMALAST_Pos);
384390
while (CRPT->TDES_STS & CRPT_TDES_STS_BUSY_Msk);
385391

features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/des/des_alt.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
332332
/* Init crypto module */
333333
crypto_init();
334334

335-
// NOTE: Don't call driver function TDES_Open in BSP because it doesn't support TDES_CTL[3KEYS] setting.
335+
/* NOTE: Don't call driver function TDES_Open in BSP because we don't want its internal multiple context (channel) support.
336+
* Multiple context (channel) support has done in the upper layer.
337+
*/
336338
CRPT->TDES_CTL = (0 << CRPT_TDES_CTL_CHANNEL_Pos) | (enc << CRPT_TDES_CTL_ENCRPT_Pos) |
337339
tdes_opmode | (TDES_IN_OUT_WHL_SWAP << CRPT_TDES_CTL_BLKSWAP_Pos);
338340

@@ -345,8 +347,10 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
345347
CRPT->TDES_CTL &= ~CRPT_TDES_CTL_3KEYS_Msk;
346348
}
347349

348-
// Set DES/TDES keys
349-
// NOTE: Don't call driver function TDES_SetKey in BSP because it doesn't support endian swap.
350+
/* Set DES/TDES keys
351+
*
352+
* NOTE: TDES_SetKey in BSP is not used because we need to make up an extra 2-dimension array to pass keys.
353+
*/
350354
uint32_t val;
351355
volatile uint32_t *tdes_key = (uint32_t *) ((uint32_t) &CRPT->TDES0_KEY1H + (0x40 * 0));
352356
val = nu_get32_be(key[0] + 0);
@@ -378,8 +382,10 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
378382

379383
TDES_SetDMATransfer(0, (uint32_t) dmabuf_in, (uint32_t) dmabuf_out, data_len);
380384

381-
// Start enc/dec.
382-
// NOTE: Don't call driver function TDES_Start in BSP because it will override TDES_CTL[3KEYS] setting.
385+
/* Start enc/dec.
386+
*
387+
* NOTE: Don't call driver function TDES_Start in BSP because of the multiple context (channel) reason as above.
388+
*/
383389
CRPT->TDES_CTL |= CRPT_TDES_CTL_START_Msk | (CRYPTO_DMA_ONE_SHOT << CRPT_TDES_CTL_DMALAST_Pos);
384390
while (CRPT->TDES_STS & CRPT_TDES_STS_BUSY_Msk);
385391

0 commit comments

Comments
 (0)