@@ -9711,27 +9711,27 @@ void wolfSSL_EC_POINT_dump(const char *msg, const WOLFSSL_EC_POINT *point)
97119711
97129712 WOLFSSL_ENTER ("wolfSSL_EC_POINT_dump" );
97139713
9714- /* Only print when debugging on and logging callback set . */
9715- if (WOLFSSL_IS_DEBUG_ON () && ( wolfSSL_GetLoggingCb () == NULL ) ) {
9714+ /* Only print when debugging on. */
9715+ if (WOLFSSL_IS_DEBUG_ON ()) {
97169716 if (point == NULL ) {
97179717 /* No point passed in so just put out "NULL". */
9718- XFPRINTF ( stderr , "%s = NULL\n" , msg );
9718+ WOLFSSL_MSG_EX ( "%s = NULL\n" , msg );
97199719 }
97209720 else {
97219721 /* Put out message and status of internal/external data set. */
9722- XFPRINTF ( stderr , "%s:\n\tinSet=%d, exSet=%d\n" , msg , point -> inSet ,
9722+ WOLFSSL_MSG_EX ( "%s:\n\tinSet=%d, exSet=%d\n" , msg , point -> inSet ,
97239723 point -> exSet );
97249724 /* Get x-ordinate as a hex string and print. */
97259725 num = wolfSSL_BN_bn2hex (point -> X );
9726- XFPRINTF ( stderr , "\tX = %s\n" , num );
9726+ WOLFSSL_MSG_EX ( "\tX = %s\n" , num );
97279727 XFREE (num , NULL , DYNAMIC_TYPE_OPENSSL );
97289728 /* Get x-ordinate as a hex string and print. */
97299729 num = wolfSSL_BN_bn2hex (point -> Y );
9730- XFPRINTF ( stderr , "\tY = %s\n" , num );
9730+ WOLFSSL_MSG_EX ( "\tY = %s\n" , num );
97319731 XFREE (num , NULL , DYNAMIC_TYPE_OPENSSL );
97329732 /* Get z-ordinate as a hex string and print. */
97339733 num = wolfSSL_BN_bn2hex (point -> Z );
9734- XFPRINTF ( stderr , "\tZ = %s\n" , num );
9734+ WOLFSSL_MSG_EX ( "\tZ = %s\n" , num );
97359735 XFREE (num , NULL , DYNAMIC_TYPE_OPENSSL );
97369736 }
97379737 }
@@ -9922,6 +9922,8 @@ int wolfSSL_ECPoint_d2i(const unsigned char *in, unsigned int len,
99229922 const WOLFSSL_EC_GROUP * group , WOLFSSL_EC_POINT * point )
99239923{
99249924 int ret = 1 ;
9925+ WOLFSSL_BIGNUM * x = NULL ;
9926+ WOLFSSL_BIGNUM * y = NULL ;
99259927
99269928 WOLFSSL_ENTER ("wolfSSL_ECPoint_d2i" );
99279929
@@ -9958,17 +9960,49 @@ int wolfSSL_ECPoint_d2i(const unsigned char *in, unsigned int len,
99589960 #endif
99599961 }
99609962
9963+ if (ret == 1 )
9964+ point -> inSet = 1 ;
9965+
99619966 /* Set new external point. */
9962- if (( ret == 1 ) && ( ec_point_external_set (point ) != 1 ) ) {
9967+ if (ret == 1 && ec_point_external_set (point ) != 1 ) {
99639968 WOLFSSL_MSG ("ec_point_external_set failed" );
99649969 ret = 0 ;
99659970 }
99669971
9972+ if (ret == 1 && !wolfSSL_BN_is_one (point -> Z )) {
9973+ #if !defined(WOLFSSL_SP_MATH ) && !defined(WOLF_CRYPTO_CB_ONLY_ECC )
9974+ x = wolfSSL_BN_new ();
9975+ y = wolfSSL_BN_new ();
9976+ if (x == NULL || y == NULL )
9977+ ret = 0 ;
9978+
9979+ if (ret == 1 && wolfSSL_EC_POINT_get_affine_coordinates_GFp (group ,
9980+ point , x , y , NULL ) != 1 ) {
9981+ WOLFSSL_MSG ("wolfSSL_EC_POINT_get_affine_coordinates_GFp failed" );
9982+ ret = 0 ;
9983+ }
9984+
9985+ /* wolfSSL_EC_POINT_set_affine_coordinates_GFp check that the point is
9986+ * on the curve. */
9987+ if (ret == 1 && wolfSSL_EC_POINT_set_affine_coordinates_GFp (group ,
9988+ point , x , y , NULL ) != 1 ) {
9989+ WOLFSSL_MSG ("wolfSSL_EC_POINT_set_affine_coordinates_GFp failed" );
9990+ ret = 0 ;
9991+ }
9992+ #else
9993+ WOLFSSL_MSG ("Importing non-affine point. This may cause issues in math "
9994+ "operations later on." );
9995+ #endif
9996+ }
9997+
99679998 if (ret == 1 ) {
99689999 /* Dump new point. */
996910000 wolfSSL_EC_POINT_dump ("d2i p" , point );
997010001 }
997110002
10003+ wolfSSL_BN_free (x );
10004+ wolfSSL_BN_free (y );
10005+
997210006 return ret ;
997310007}
997410008
@@ -10060,6 +10094,14 @@ size_t wolfSSL_EC_POINT_point2oct(const WOLFSSL_EC_GROUP *group,
1006010094 }
1006110095 }
1006210096
10097+ #if defined(DEBUG_WOLFSSL )
10098+ if (!err ) {
10099+ wolfSSL_EC_POINT_dump ("wolfSSL_EC_POINT_point2oct point" , point );
10100+ WOLFSSL_MSG ("\twolfSSL_EC_POINT_point2oct output:" );
10101+ WOLFSSL_BUFFER (buf , enc_len );
10102+ }
10103+ #endif
10104+
1006310105 /* On error, return encoding length of 0. */
1006410106 if (err ) {
1006510107 enc_len = 0 ;
@@ -10209,7 +10251,7 @@ int wolfSSL_EC_POINT_is_on_curve(const WOLFSSL_EC_GROUP *group,
1020910251 * @return 1 on success.
1021010252 * @return 0 on error.
1021110253 */
10212- static int ec_point_convert_to_affine (const WOLFSSL_EC_GROUP * group ,
10254+ int ec_point_convert_to_affine (const WOLFSSL_EC_GROUP * group ,
1021310255 WOLFSSL_EC_POINT * point )
1021410256{
1021510257 int err = 0 ;
@@ -10606,6 +10648,20 @@ int wolfSSL_EC_POINT_add(const WOLFSSL_EC_GROUP* group, WOLFSSL_EC_POINT* r,
1060610648 ret = 0 ;
1060710649 }
1060810650
10651+ #ifdef DEBUG_WOLFSSL
10652+ if (ret == 1 ) {
10653+ int nid = wolfSSL_EC_GROUP_get_curve_name (group );
10654+ const char * curve = wolfSSL_OBJ_nid2ln (nid );
10655+ const char * nistName = wolfSSL_EC_curve_nid2nist (nid );
10656+ wolfSSL_EC_POINT_dump ("wolfSSL_EC_POINT_add p1" , p1 );
10657+ wolfSSL_EC_POINT_dump ("wolfSSL_EC_POINT_add p2" , p2 );
10658+ if (curve != NULL )
10659+ WOLFSSL_MSG_EX ("curve name: %s" , curve );
10660+ if (nistName != NULL )
10661+ WOLFSSL_MSG_EX ("nist curve name: %s" , nistName );
10662+ }
10663+ #endif
10664+
1060910665 if (ret == 1 ) {
1061010666 /* Add points using wolfCrypt objects. */
1061110667 ret = wolfssl_ec_point_add (group -> curve_idx , (ecc_point * )r -> internal ,
@@ -10618,6 +10674,12 @@ int wolfSSL_EC_POINT_add(const WOLFSSL_EC_GROUP* group, WOLFSSL_EC_POINT* r,
1061810674 ret = 0 ;
1061910675 }
1062010676
10677+ #ifdef DEBUG_WOLFSSL
10678+ if (ret == 1 ) {
10679+ wolfSSL_EC_POINT_dump ("wolfSSL_EC_POINT_add result" , r );
10680+ }
10681+ #endif
10682+
1062110683 return ret ;
1062210684}
1062310685
@@ -10779,7 +10841,7 @@ static int wolfssl_ec_point_mul(int curveIdx, ecc_point* r, mp_int* n,
1077910841
1078010842 if ((ret == 1 ) && (n != NULL ) && (q != NULL ) && (m != NULL )) {
1078110843 /* r = base point * n + q * m */
10782- ec_mul2add (r , r , m , q , n , a , prime );
10844+ ret = ec_mul2add (r , r , n , q , m , a , prime );
1078310845 }
1078410846 /* Not all values present, see if we are only doing base point * n. */
1078510847 else if ((ret == 1 ) && (n != NULL )) {
@@ -10852,6 +10914,26 @@ int wolfSSL_EC_POINT_mul(const WOLFSSL_EC_GROUP *group, WOLFSSL_EC_POINT *r,
1085210914 ret = 0 ;
1085310915 }
1085410916
10917+ #ifdef DEBUG_WOLFSSL
10918+ if (ret == 1 ) {
10919+ int nid = wolfSSL_EC_GROUP_get_curve_name (group );
10920+ const char * curve = wolfSSL_OBJ_nid2ln (nid );
10921+ const char * nistName = wolfSSL_EC_curve_nid2nist (nid );
10922+ char * num ;
10923+ wolfSSL_EC_POINT_dump ("wolfSSL_EC_POINT_mul input q" , q );
10924+ num = wolfSSL_BN_bn2hex (n );
10925+ WOLFSSL_MSG_EX ("\tn = %s" , num );
10926+ XFREE (num , NULL , DYNAMIC_TYPE_OPENSSL );
10927+ num = wolfSSL_BN_bn2hex (m );
10928+ WOLFSSL_MSG_EX ("\tm = %s" , num );
10929+ XFREE (num , NULL , DYNAMIC_TYPE_OPENSSL );
10930+ if (curve != NULL )
10931+ WOLFSSL_MSG_EX ("curve name: %s" , curve );
10932+ if (nistName != NULL )
10933+ WOLFSSL_MSG_EX ("nist curve name: %s" , nistName );
10934+ }
10935+ #endif
10936+
1085510937 if (ret == 1 ) {
1085610938 mp_int * ni = (n != NULL ) ? (mp_int * )n -> internal : NULL ;
1085710939 ecc_point * qi = (q != NULL ) ? (ecc_point * )q -> internal : NULL ;
@@ -10872,6 +10954,12 @@ int wolfSSL_EC_POINT_mul(const WOLFSSL_EC_GROUP *group, WOLFSSL_EC_POINT *r,
1087210954 ret = 0 ;
1087310955 }
1087410956
10957+ #ifdef DEBUG_WOLFSSL
10958+ if (ret == 1 ) {
10959+ wolfSSL_EC_POINT_dump ("wolfSSL_EC_POINT_mul result" , r );
10960+ }
10961+ #endif
10962+
1087510963 return ret ;
1087610964}
1087710965#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A && !HAVE_SELFTEST &&
@@ -10960,6 +11048,30 @@ int wolfSSL_EC_POINT_invert(const WOLFSSL_EC_GROUP *group,
1096011048 ret = 0 ;
1096111049 }
1096211050
11051+ #ifdef DEBUG_WOLFSSL
11052+ if (ret == 1 ) {
11053+ int nid = wolfSSL_EC_GROUP_get_curve_name (group );
11054+ const char * curve = wolfSSL_OBJ_nid2ln (nid );
11055+ const char * nistName = wolfSSL_EC_curve_nid2nist (nid );
11056+ wolfSSL_EC_POINT_dump ("wolfSSL_EC_POINT_invert input" , point );
11057+ if (curve != NULL )
11058+ WOLFSSL_MSG_EX ("curve name: %s" , curve );
11059+ if (nistName != NULL )
11060+ WOLFSSL_MSG_EX ("nist curve name: %s" , nistName );
11061+
11062+ }
11063+ #endif
11064+
11065+ if (ret == 1 && !wolfSSL_BN_is_one (point -> Z )) {
11066+ #if !defined(WOLFSSL_SP_MATH ) && !defined(WOLF_CRYPTO_CB_ONLY_ECC )
11067+ if (ec_point_convert_to_affine (group , point ) != 0 )
11068+ ret = 0 ;
11069+ #else
11070+ WOLFSSL_MSG ("wolfSSL_EC_POINT_invert called on non-affine point" );
11071+ ret = 0 ;
11072+ #endif
11073+ }
11074+
1096311075 if (ret == 1 ) {
1096411076 /* Perform inversion using wolfCrypt objects. */
1096511077 ret = wolfssl_ec_point_invert (group -> curve_idx ,
@@ -10972,6 +11084,12 @@ int wolfSSL_EC_POINT_invert(const WOLFSSL_EC_GROUP *group,
1097211084 ret = 0 ;
1097311085 }
1097411086
11087+ #ifdef DEBUG_WOLFSSL
11088+ if (ret == 1 ) {
11089+ wolfSSL_EC_POINT_dump ("wolfSSL_EC_POINT_invert result" , point );
11090+ }
11091+ #endif
11092+
1097511093 return ret ;
1097611094}
1097711095
0 commit comments