#### Topic: Add two ecc points?

Hi,

Do wolfssl support addition two ecc points?

Thank You!

You are not logged in. Please login or register.

Please post questions or comments you have about wolfSSL products here. It is helpful to be as descriptive as possible when asking your questions.

Stable Releases - download stable product releases.

Development Branch - latest development branch on GitHub.

wolfSSL Manual - wolfSSL (formerly CyaSSL) product manual and API reference.

wolfSSL - Embedded SSL Library → wolfCrypt → Add two ecc points?

Hi,

Do wolfssl support addition two ecc points?

Thank You!

Hi,

wolfCrypt's ECC implementation has the functionality to add two points internally, but doesn't currently expose it as part of the public API. The internal implementation is located in the ecc_projective_add_point() function of ./wolfcrypt/src/ecc.c.

Can you elaborate on your desired use case of ECC point addition?

Thanks,

Chris

Hi Chrisc,

Thank you for your answer!

I'm try to use ecc_projective_add_point() function, but the result isn't as expecting. It seems like I used it incorrectly. The following is the function which I write to add two ecc points:

```
int wc_ecc_add2point(ecc_point* P, ecc_point* Q, ecc_point* R, mp_int* modulus){
mp_digit mp;
int err;
if ((err = mp_montgomery_setup(modulus, &mp)) != MP_OKAY) {
return err;
}
if((err = ecc_projective_add_point(P, Q, R, modulus, &mp))!=MP_OKAY){
return err;
}
if((err = ecc_map(R, modulus, &mp))!=MP_OKAY) {
return err;
}
return MP_OKAY;
}
```

Is it ok if I use P and Q in affine coordinate format to put on ecc_projective_add_point() function?

Please help me how to use this function.

Thank You!

Hi hdan,

Can you tell me where the above was failing for you, and how you are calling that function? Are you initializing/importing the ecc_point's somewhere else?

Do you mind if I ask what your end goal is for adding ECC points? I just want to verify we don't already have the functionality you are looking for elsewhere.

Thanks,

Chris

Hi Chris,

I'm trying to implement "Elliptic Curve Qu-Vanstone Implicit Certificate Scheme" based on http://www.secg.org/sec4-1.0.pdf.

I tried to modify my function like this:

```
int wc_ecc_add2point(ecc_point* P, ecc_point* Q, ecc_point* R, mp_int* modulus){
mp_digit mp;
mp_int mu;
ecc_point *tP, *tQ;
int err;
/* init montgomery reduction */
if ((err = mp_montgomery_setup(modulus, &mp)) != MP_OKAY) {
return err;
}
if ((err = mp_init(&mu)) != MP_OKAY) {
return err;
}
if ((err = mp_montgomery_calc_normalization(&mu, modulus)) != MP_OKAY) {
mp_clear(&mu);
return err;
}
tP = wc_ecc_new_point();
tQ = wc_ecc_new_point();
if (err == MP_OKAY) {
if (mp_cmp_d(&mu, 1) == MP_EQ) {
err = mp_copy(P->x, tP->x);
if (err == MP_OKAY)
err = mp_copy(P->y, tP->y);
if (err == MP_OKAY)
err = mp_copy(P->z, tP->z);
} else {
err = mp_mulmod(P->x, &mu, modulus, tP->x);
if (err == MP_OKAY)
err = mp_mulmod(P->y, &mu, modulus, tP->y);
if (err == MP_OKAY)
err = mp_mulmod(P->z, &mu, modulus, tP->z);
}
}
if (err == MP_OKAY) {
if (mp_cmp_d(&mu, 1) == MP_EQ) {
err = mp_copy(Q->x, tQ->x);
if (err == MP_OKAY)
err = mp_copy(Q->y, tQ->y);
if (err == MP_OKAY)
err = mp_copy(Q->z, tQ->z);
} else {
err = mp_mulmod(Q->x, &mu, modulus, tQ->x);
if (err == MP_OKAY)
err = mp_mulmod(Q->y, &mu, modulus, tQ->y);
if (err == MP_OKAY)
err = mp_mulmod(Q->z, &mu, modulus, tQ->z);
}
}
if((err = ecc_projective_add_point(tP, tQ, R, modulus, &mp))!=MP_OKAY){
return err;
}
if((err = ecc_map(R, modulus, &mp))!=MP_OKAY) {
return err;
}
return MP_OKAY;
}
```

To expose wc_ecc_add2point as a part of public API, I added the prototype of the function on ecc.h like this:

```
WOLFSSL_API
int wc_ecc_add2point(ecc_point* P, ecc_point* Q, ecc_point* R, mp_int* modulus);
```

And then I called it in an other function in ssl.c:

```
ecc_point* base, *eccD;
const ecc_set_type* dp = &ecc_sets[curve_index];
int err;
base = wc_ecc_new_point();
/*Get domain curve parameters*/
err = mp_read_radix(&prime, (char *) dp->prime, 16);
if (err == MP_OKAY)
err = mp_read_radix(&order, (char *) dp->order, 16);
if (err == MP_OKAY)
err = mp_read_radix(base->x, (char *) dp->Gx, 16);
if (err == MP_OKAY)
err = mp_read_radix(base->y, (char *) dp->Gy, 16);
if (err == MP_OKAY)
mp_set(base->z, 1);
eccD = wc_ecc_new_point();
err = wc_ecc_add2point(base, base, eccD, &prime);
```

And the result was seem 'OK'. **eccD **point was actually double **base **point. But I still don't know whether my implement (the way I used ecc_projective_add_point function) is correct or not? And the way I use to expose the function as a part of public API of wolfSSL is right?

Can you give me advice?

Thank You,

wolfSSL - Embedded SSL Library → wolfCrypt → Add two ecc points?

Powered by PunBB, supported by Informer Technologies, Inc.