Beispiel #1
0
void ec_multiply (ec_point *p, const vl_point k)
	/* sets p := k*p */
{
	vl_point h;
	int z, hi, ki;
	word16 i;
	ec_point r;

	gf_copy (r.x, p->x); p->x[0] = 0;
	gf_copy (r.y, p->y); p->y[0] = 0;
	vl_shortmultiply (h, k, 3);
	z = vl_numbits (h) - 1; /* so vl_takebit (h, z) == 1 */
	i = 1;
	for (;;) {
		hi = vl_takebit (h, i);
		ki = vl_takebit (k, i);
		if (hi == 1 && ki == 0) {
			ec_add (p, &r);
		}
		if (hi == 0 && ki == 1) {
			ec_sub (p, &r);
		}
		if (i >= z) {
			break;
		}
		i++;
		ec_double (&r);
	}
} /* ec_multiply */
Beispiel #2
0
Datei: ec.c Projekt: tfar/sccd
void sccd_ec_sub(sccd_ec_t result, const sccd_ec_t a, const sccd_ec_t b) {
#if defined(SCCD_BACKEND_C25519)
	sccd_ec_t tmp;
	sccd_fp_neg(tmp->x, b->x);
	sccd_fp_neg(tmp->t, b->t);
	sccd_fp_copy(tmp->y, b->y);
	sccd_fp_copy(tmp->z, b->z);
	sccd_ec_add(result, a, tmp);
#elif defined(SCCD_BACKEND_RELIC)
	ec_sub(result, a, b);
#endif
}