Skip to content

Commit 815a6a7

Browse files
committed
[NUC472/M487] Add parameter check for configuring DES registers in DES alter.
1 parent 1d62b91 commit 815a6a7

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,34 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
311311
static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_SIZE], int enc, uint32_t tdes_opmode, size_t length,
312312
unsigned char iv[8], const unsigned char *input, unsigned char *output)
313313
{
314+
if ((keyopt < 1) || (keyopt > 3)) {
315+
error("Key option in DES alter. requires to be 1/2/3.");
316+
}
317+
318+
if (key == NULL) {
319+
error("Meet null key pointer in DES alter.");
320+
}
321+
322+
if ((enc != 0) && (enc != 1)) {
323+
error("Enc/dec flag in DES alter. requires to be 0/1.");
324+
}
325+
326+
if ((tdes_opmode < DES_MODE_ECB) || (tdes_opmode > DES_MODE_CTR)) {
327+
error("Block cipher mode of operations in DES alter. requires to be ECB/CBC/CFB/OFB/CTR.");
328+
}
329+
314330
if (length % 8) {
315331
return MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH;
316332
}
317333

334+
if (iv == NULL) {
335+
error("Meet null IV pointer in DES alter.");
336+
}
337+
338+
if (input == NULL || output == NULL) {
339+
error("Meet null input/output pointer in DES alter.");
340+
}
341+
318342
/* DES DMA buffer has the following requirements:
319343
* (1) Word-aligned buffer base address
320344
* (2) 8-byte aligned buffer size

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,34 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
311311
static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_SIZE], int enc, uint32_t tdes_opmode, size_t length,
312312
unsigned char iv[8], const unsigned char *input, unsigned char *output)
313313
{
314+
if ((keyopt < 1) || (keyopt > 3)) {
315+
error("Key option in DES alter. requires to be 1/2/3.");
316+
}
317+
318+
if (key == NULL) {
319+
error("Meet null key pointer in DES alter.");
320+
}
321+
322+
if ((enc != 0) && (enc != 1)) {
323+
error("Enc/dec flag in DES alter. requires to be 0/1.");
324+
}
325+
326+
if ((tdes_opmode < DES_MODE_ECB) || (tdes_opmode > DES_MODE_CTR)) {
327+
error("Block cipher mode of operations in DES alter. requires to be ECB/CBC/CFB/OFB/CTR.");
328+
}
329+
314330
if (length % 8) {
315331
return MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH;
316332
}
317333

334+
if (iv == NULL) {
335+
error("Meet null IV pointer in DES alter.");
336+
}
337+
338+
if (input == NULL || output == NULL) {
339+
error("Meet null input/output pointer in DES alter.");
340+
}
341+
318342
/* DES DMA buffer has the following requirements:
319343
* (1) Word-aligned buffer base address
320344
* (2) 8-byte aligned buffer size

0 commit comments

Comments
 (0)