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,