Skip to content

Commit c9a534a

Browse files
committed
Fix issues in wc_MXC_MAA_zeroPad
1 parent 11b207e commit c9a534a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

wolfcrypt/src/port/maxim/max3266x.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ int wc_MXC_MAA_zeroPad(mp_int* multiplier, mp_int* multiplicand,
14451445
MXC_TPU_MAA_TYPE clc, unsigned int length)
14461446
{
14471447
mp_digit* zero_tmp;
1448+
unsigned int zero_size;
14481449
MAX3266X_MSG("Zero Padding Buffers for Hardware");
14491450
if (length > MXC_MAA_MAX_SIZE) {
14501451
MAX3266X_MSG("Hardware cannot exceed 2048 bit input");
@@ -1456,19 +1457,23 @@ int wc_MXC_MAA_zeroPad(mp_int* multiplier, mp_int* multiplicand,
14561457
}
14571458

14581459
/* Create an array to compare values to to check edge for error edge case */
1459-
zero_tmp = (mp_digit*)XMALLOC(multiplier->size*sizeof(mp_digit), NULL,
1460+
zero_size = mod->size;
1461+
if ((exp != NULL) && (exp->size > zero_size)) {
1462+
zero_size = exp->size;
1463+
}
1464+
zero_tmp = (mp_digit*)XMALLOC(zero_size*sizeof(mp_digit), NULL,
14601465
DYNAMIC_TYPE_TMP_BUFFER);
14611466
if (zero_tmp == NULL) {
14621467
MAX3266X_MSG("NULL pointer found after XMALLOC call");
14631468
return MEMORY_E;
14641469
}
1465-
XMEMSET(zero_tmp, 0x00, multiplier->size*sizeof(mp_digit));
1470+
XMEMSET(zero_tmp, 0x00, zero_size*sizeof(mp_digit));
14661471

14671472
/* Check for invalid arguments before padding */
14681473
switch ((char)clc) {
14691474
case MXC_TPU_MAA_EXP:
14701475
/* Cannot be 0 for a^e mod m operation */
1471-
if (XMEMCMP(zero_tmp, exp, (exp->used*sizeof(mp_digit))) == 0) {
1476+
if (XMEMCMP(zero_tmp, exp->dp, (exp->used*sizeof(mp_digit))) == 0) {
14721477
XFREE(zero_tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
14731478
MAX3266X_MSG("Cannot use Value 0 for Exp");
14741479
return BAD_FUNC_ARG;
@@ -1491,7 +1496,7 @@ int wc_MXC_MAA_zeroPad(mp_int* multiplier, mp_int* multiplicand,
14911496
case MXC_TPU_MAA_ADD:
14921497
case MXC_TPU_MAA_SUB:
14931498
/* Cannot be 0 for mod m value */
1494-
if (XMEMCMP(zero_tmp, mod, (exp->used*sizeof(mp_digit))) == 0) {
1499+
if (XMEMCMP(zero_tmp, mod->dp, (mod->used*sizeof(mp_digit))) == 0) {
14951500
XFREE(zero_tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
14961501
MAX3266X_MSG("Cannot use Value 0 for Exp");
14971502
return BAD_FUNC_ARG;

0 commit comments

Comments
 (0)