49
49
#include "mbed_toolchain.h"
50
50
#include "mbed_assert.h"
51
51
#include "mbed_error.h"
52
+ #include "mbed_toolchain.h"
52
53
#include "nu_bitutil.h"
53
54
#include "crypto-misc.h"
54
55
110
111
} while(0)
111
112
112
113
/**
113
- * \brief Configure ECCOP operation and wait for its completion
114
+ * \brief Configure ECCOP operation, start it, and wait for its completion
114
115
*
115
116
* \param grp ECP group
116
117
* \param R Destination point
133
134
* \note ECC accelerator doesn't support R = 0, and we need to detect it additionally.
134
135
* For R = P + Q or R = 2*P, we can detect all R = 0 cases.
135
136
* 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.
136
140
*
137
141
*/
138
142
int mbedtls_internal_run_eccop (const mbedtls_ecp_group * grp ,
139
143
mbedtls_ecp_point * R ,
140
144
const mbedtls_mpi * m ,
141
145
const mbedtls_ecp_point * P ,
142
- const mbedtls_mpi * n ,
146
+ MBED_UNUSED const mbedtls_mpi * n ,
143
147
const mbedtls_ecp_point * Q ,
144
148
uint32_t eccop );
145
149
@@ -284,7 +288,7 @@ int mbedtls_internal_ecp_add_mixed( const mbedtls_ecp_group *grp,
284
288
MBEDTLS_MPI_CHK (mbedtls_mpi_lset (& Q_ .Z , 1 ));
285
289
}
286
290
287
- /* Run ECC point doubling : R = P + Q */
291
+ /* Run ECC point addition : R = P + Q */
288
292
MBEDTLS_MPI_CHK (mbedtls_internal_run_eccop (grp , R , NULL , & P_ , NULL , & Q_ , ECCOP_POINT_ADD ));
289
293
290
294
cleanup :
@@ -497,7 +501,7 @@ int mbedtls_internal_run_eccop(const mbedtls_ecp_group *grp,
497
501
mbedtls_ecp_point * R ,
498
502
const mbedtls_mpi * m ,
499
503
const mbedtls_ecp_point * P ,
500
- const mbedtls_mpi * n ,
504
+ MBED_UNUSED const mbedtls_mpi * n ,
501
505
const mbedtls_ecp_point * Q ,
502
506
uint32_t eccop )
503
507
{
@@ -517,6 +521,8 @@ int mbedtls_internal_run_eccop(const mbedtls_ecp_group *grp,
517
521
}
518
522
519
523
int ret ;
524
+ bool ecc_done ;
525
+
520
526
mbedtls_mpi N_ ;
521
527
const mbedtls_mpi * Np ;
522
528
@@ -658,7 +664,7 @@ int mbedtls_internal_run_eccop(const mbedtls_ecp_group *grp,
658
664
659
665
crypto_ecc_prestart ();
660
666
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 ();
662
668
663
669
/* FIXME: Better error code for ECC accelerator error */
664
670
MBEDTLS_MPI_CHK (ecc_done ? 0 : -1 );
@@ -714,7 +720,8 @@ int mbedtls_internal_run_modop(mbedtls_mpi *r,
714
720
}
715
721
716
722
int ret ;
717
-
723
+ bool ecc_done ;
724
+
718
725
mbedtls_mpi N_ ;
719
726
const mbedtls_mpi * Np ;
720
727
@@ -746,7 +753,7 @@ int mbedtls_internal_run_modop(mbedtls_mpi *r,
746
753
747
754
crypto_ecc_prestart ();
748
755
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 ();
750
757
751
758
/* FIXME: Better error code for ECC accelerator error */
752
759
MBEDTLS_MPI_CHK (ecc_done ? 0 : -1 );
0 commit comments