Skip to content

Commit 0de10b0

Browse files
ccli8cmonr
authored andcommitted
Refine code in ECP alter.
1. Add comment for unnecessary parameter 'n' in mbedtls_internal_run_eccop 2. Fix warning message with goto which causes `bypass initialization` 3. Fix comment
1 parent 1c01ea9 commit 0de10b0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "mbed_toolchain.h"
5050
#include "mbed_assert.h"
5151
#include "mbed_error.h"
52+
#include "mbed_toolchain.h"
5253
#include "nu_bitutil.h"
5354
#include "crypto-misc.h"
5455

@@ -110,7 +111,7 @@
110111
} while(0)
111112

112113
/**
113-
* \brief Configure ECCOP operation and wait for its completion
114+
* \brief Configure ECCOP operation, start it, and wait for its completion
114115
*
115116
* \param grp ECP group
116117
* \param R Destination point
@@ -133,13 +134,16 @@
133134
* \note ECC accelerator doesn't support R = 0, and we need to detect it additionally.
134135
* For R = P + Q or R = 2*P, we can detect all R = 0 cases.
135136
* For R = m*P, we can detect all R = 0 cases only if grp->N (order) is a prime.
137+
*
138+
* \note According to ECCOP operation, n is unnecessary. But to be consistent with R = m*P + n*Q,
139+
* n is kept with unused modifier.
136140
*
137141
*/
138142
int mbedtls_internal_run_eccop(const mbedtls_ecp_group *grp,
139143
mbedtls_ecp_point *R,
140144
const mbedtls_mpi *m,
141145
const mbedtls_ecp_point *P,
142-
const mbedtls_mpi *n,
146+
MBED_UNUSED const mbedtls_mpi *n,
143147
const mbedtls_ecp_point *Q,
144148
uint32_t eccop);
145149

@@ -284,7 +288,7 @@ int mbedtls_internal_ecp_add_mixed( const mbedtls_ecp_group *grp,
284288
MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Q_.Z, 1));
285289
}
286290

287-
/* Run ECC point doubling: R = P + Q */
291+
/* Run ECC point addition: R = P + Q */
288292
MBEDTLS_MPI_CHK(mbedtls_internal_run_eccop(grp, R, NULL, &P_, NULL, &Q_, ECCOP_POINT_ADD));
289293

290294
cleanup:
@@ -497,7 +501,7 @@ int mbedtls_internal_run_eccop(const mbedtls_ecp_group *grp,
497501
mbedtls_ecp_point *R,
498502
const mbedtls_mpi *m,
499503
const mbedtls_ecp_point *P,
500-
const mbedtls_mpi *n,
504+
MBED_UNUSED const mbedtls_mpi *n,
501505
const mbedtls_ecp_point *Q,
502506
uint32_t eccop)
503507
{
@@ -517,6 +521,8 @@ int mbedtls_internal_run_eccop(const mbedtls_ecp_group *grp,
517521
}
518522

519523
int ret;
524+
bool ecc_done;
525+
520526
mbedtls_mpi N_;
521527
const mbedtls_mpi *Np;
522528

@@ -658,7 +664,7 @@ int mbedtls_internal_run_eccop(const mbedtls_ecp_group *grp,
658664

659665
crypto_ecc_prestart();
660666
CRPT->ECC_CTL = (grp->pbits << CRPT_ECC_CTL_CURVEM_Pos) | eccop | CRPT_ECC_CTL_FSEL_Msk | CRPT_ECC_CTL_START_Msk;
661-
bool ecc_done = crypto_ecc_wait();
667+
ecc_done = crypto_ecc_wait();
662668

663669
/* FIXME: Better error code for ECC accelerator error */
664670
MBEDTLS_MPI_CHK(ecc_done ? 0 : -1);
@@ -714,7 +720,8 @@ int mbedtls_internal_run_modop(mbedtls_mpi *r,
714720
}
715721

716722
int ret;
717-
723+
bool ecc_done;
724+
718725
mbedtls_mpi N_;
719726
const mbedtls_mpi *Np;
720727

@@ -746,7 +753,7 @@ int mbedtls_internal_run_modop(mbedtls_mpi *r,
746753

747754
crypto_ecc_prestart();
748755
CRPT->ECC_CTL = (pbits << CRPT_ECC_CTL_CURVEM_Pos) | (ECCOP_MODULE | modop) | CRPT_ECC_CTL_FSEL_Msk | CRPT_ECC_CTL_START_Msk;
749-
bool ecc_done = crypto_ecc_wait();
756+
ecc_done = crypto_ecc_wait();
750757

751758
/* FIXME: Better error code for ECC accelerator error */
752759
MBEDTLS_MPI_CHK(ecc_done ? 0 : -1);

0 commit comments

Comments
 (0)