@@ -24,7 +24,7 @@ int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_poi
2424 const void * ma , const void * modulus , void * mp )
2525{
2626 void * t1 , * t2 , * x , * y , * z ;
27- int err , inf ;
27+ int err , inf , x_or_y_is_zero ;
2828
2929 LTC_ARGCHK (P != NULL );
3030 LTC_ARGCHK (Q != NULL );
@@ -52,6 +52,7 @@ int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_poi
5252
5353 if ((ltc_mp_cmp (P -> x , Q -> x ) == LTC_MP_EQ ) && (ltc_mp_cmp (P -> z , Q -> z ) == LTC_MP_EQ )) {
5454 if (ltc_mp_cmp (P -> y , Q -> y ) == LTC_MP_EQ ) {
55+ dbl :
5556 /* here P = Q >> Result = 2 * P (use doubling) */
5657 ltc_mp_deinit_multi (t1 , t2 , x , y , z , LTC_NULL );
5758 return ltc_ecc_projective_dbl_point (P , R , ma , modulus , mp );
@@ -160,6 +161,7 @@ int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_poi
160161 if (ltc_mp_cmp_d (x , 0 ) == LTC_MP_LT ) {
161162 if ((err = ltc_mp_add (x , modulus , x )) != CRYPT_OK ) { goto done ; }
162163 }
164+ x_or_y_is_zero = ltc_mp_cmp_d (x , 0 ) == LTC_MP_EQ ;
163165
164166 /* T2 = T2 - X */
165167 if ((err = ltc_mp_sub (t2 , x , t2 )) != CRYPT_OK ) { goto done ; }
@@ -184,6 +186,11 @@ int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_poi
184186 if ((err = ltc_mp_add (y , modulus , y )) != CRYPT_OK ) { goto done ; }
185187 }
186188 if ((err = ltc_mp_div_2 (y , y )) != CRYPT_OK ) { goto done ; }
189+ x_or_y_is_zero |= ltc_mp_cmp_d (y , 0 ) == LTC_MP_EQ ;
190+
191+ if (x_or_y_is_zero ) {
192+ goto dbl ;
193+ }
187194
188195 if ((err = ltc_mp_copy (x , R -> x )) != CRYPT_OK ) { goto done ; }
189196 if ((err = ltc_mp_copy (y , R -> y )) != CRYPT_OK ) { goto done ; }
0 commit comments