Skip to content

Commit 9fa5d88

Browse files
Merge pull request #6948 from SparkiDev/ecc_curve_koblitz
ECC double point: SECP112R2 and SEC128R2 are Koblitz curves
2 parents 7daac20 + 26a9435 commit 9fa5d88

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ enum {
337337
#endif
338338
#define ecc_oid_secp112r1_sz CODED_SECP112R1_SZ
339339
#endif /* !NO_ECC_SECP */
340-
#ifdef HAVE_ECC_SECPR2
340+
#if defined(HAVE_ECC_SECPR2) && defined(HAVE_ECC_KOBLITZ)
341341
#ifdef HAVE_OID_ENCODING
342342
#define CODED_SECP112R2 {1,3,132,0,7}
343343
#define CODED_SECP112R2_SZ 5
@@ -351,7 +351,7 @@ enum {
351351
#define ecc_oid_secp112r2 CODED_SECP112R2
352352
#endif
353353
#define ecc_oid_secp112r2_sz CODED_SECP112R2_SZ
354-
#endif /* HAVE_ECC_SECPR2 */
354+
#endif /* HAVE_ECC_SECPR2 && HAVE_ECC_KOBLITZ */
355355
#endif /* ECC112 */
356356
#ifdef ECC128
357357
#ifndef NO_ECC_SECP
@@ -369,7 +369,7 @@ enum {
369369
#endif
370370
#define ecc_oid_secp128r1_sz CODED_SECP128R1_SZ
371371
#endif /* !NO_ECC_SECP */
372-
#ifdef HAVE_ECC_SECPR2
372+
#if defined(HAVE_ECC_SECPR2) && defined(HAVE_ECC_KOBLITZ)
373373
#ifdef HAVE_OID_ENCODING
374374
#define CODED_SECP128R2 {1,3,132,0,29}
375375
#define CODED_SECP128R2_SZ 5
@@ -383,7 +383,7 @@ enum {
383383
#define ecc_oid_secp128r2 CODED_SECP128R2
384384
#endif
385385
#define ecc_oid_secp128r2_sz CODED_SECP128R2_SZ
386-
#endif /* HAVE_ECC_SECPR2 */
386+
#endif /* HAVE_ECC_SECPR2 && HAVE_ECC_KOBLITZ */
387387
#endif /* ECC128 */
388388
#ifdef ECC160
389389
#ifndef FP_ECC
@@ -790,7 +790,7 @@ const ecc_set_type ecc_sets[] = {
790790
1, /* cofactor */
791791
},
792792
#endif /* !NO_ECC_SECP */
793-
#ifdef HAVE_ECC_SECPR2
793+
#if defined(HAVE_ECC_SECPR2) && defined(HAVE_ECC_KOBLITZ)
794794
{
795795
14, /* size/bytes */
796796
ECC_SECP112R2, /* ID */
@@ -806,7 +806,7 @@ const ecc_set_type ecc_sets[] = {
806806
ECC_SECP112R2_OID, /* oid sum */
807807
4, /* cofactor */
808808
},
809-
#endif /* HAVE_ECC_SECPR2 */
809+
#endif /* HAVE_ECC_SECPR2 && HAVE_ECC_KOBLITZ */
810810
#endif /* ECC112 */
811811
#ifdef ECC128
812812
#ifndef NO_ECC_SECP
@@ -826,7 +826,7 @@ const ecc_set_type ecc_sets[] = {
826826
1, /* cofactor */
827827
},
828828
#endif /* !NO_ECC_SECP */
829-
#ifdef HAVE_ECC_SECPR2
829+
#if defined(HAVE_ECC_SECPR2) && defined(HAVE_ECC_KOBLITZ)
830830
{
831831
16, /* size/bytes */
832832
ECC_SECP128R2, /* ID */
@@ -842,7 +842,7 @@ const ecc_set_type ecc_sets[] = {
842842
ECC_SECP128R2_OID, /* oid sum */
843843
4, /* cofactor */
844844
},
845-
#endif /* HAVE_ECC_SECPR2 */
845+
#endif /* HAVE_ECC_SECPR2 && HAVE_ECC_KOBLITZ */
846846
#endif /* ECC128 */
847847
#ifdef ECC160
848848
#ifndef FP_ECC
@@ -7801,6 +7801,13 @@ int ecc_projective_dbl_point_safe(ecc_point *P, ecc_point *R, mp_int* a,
78017801
}
78027802
else {
78037803
err = _ecc_projective_dbl_point(P, R, a, modulus, mp);
7804+
if ((err == MP_OKAY) && mp_iszero(R->z)) {
7805+
err = mp_set(R->x, 0);
7806+
if (err == MP_OKAY)
7807+
err = mp_set(R->y, 0);
7808+
if (err == MP_OKAY)
7809+
err = mp_set(R->z, 1);
7810+
}
78047811
}
78057812

78067813
return err;

0 commit comments

Comments
 (0)