void fpe_mul_c(fpe_t rop, const fpe_t op1, const fpe_t op2) { mydouble h[24]; polymul(h,op1->v,op2->v); degred(h); coeffred_round_par(h); int i; for (i=0;i<12;i++) rop->v[i] = h[i]; }
// Square an fp2e, store result in rop: void fp2e_square_c(fp2e_t rop, const fp2e_t op) { #ifdef N_OPS sqfp2ctr += 1; #endif fpe_t a1, b1, r1, r2; mydouble ropa[24], ropb[24]; fp2e_to_2fpe(a1, b1, op); int i; /* CheckDoubles are not smart enough to recognize * binomial formula to compute b^2-a^2 */ #ifdef CHECK mydouble d1[24]; polymul(d1, a1->v, a1->v); polymul(ropb, b1->v, b1->v); polymul(ropa, b1->v, a1->v); for (i = 0; i < 23; i++) { ropb[i] -= d1[i]; ropa[i] *= 2; } #else fpe_t t1, t2, t3; for (i = 0; i < 12; i++) { t1->v[i] = a1->v[i] + b1->v[i]; t2->v[i] = b1->v[i] - a1->v[i]; t3->v[i] = 2 * b1->v[i]; } polymul(ropa, a1->v, t3->v); polymul(ropb, t1->v, t2->v); #endif degred(ropa); degred(ropb); coeffred_round_par(ropa); coeffred_round_par(ropb); fpe_set_doublearray(r1, ropa); fpe_set_doublearray(r2, ropb); _2fpe_to_fp2e(rop, r1, r2); }
// Multiply two fp2e, store result in rop: void fp2e_mul_c(fp2e_t rop, const fp2e_t op1, const fp2e_t op2) { #ifdef N_OPS mulfp2ctr += 1; #endif fpe_t a1, b1, a2, b2, r1, r2; mydouble a3[24], b3[24]; int i; mydouble t0[24], t1[24], t2[24], t3[24]; fp2e_to_2fpe(a1, b1, op1); fp2e_to_2fpe(a2, b2, op2); polymul(t1, a1->v, b2->v); // t1 = a1*b2 polymul(t2, b1->v, a2->v); // t2 = b1*a2 for (i = 0; i < 12; i++) // t3 = 1*a1 { t3[i] = 1 * a1->v[i]; } polymul(t3, t3, a2->v); // t3 = 1*a1*a2 polymul(t0, b1->v, b2->v); // t0 = b1*b2 for (i = 0; i < 23; i++) { a3[i] = t1[i] + t2[i]; // a3 = a1*b2 + b1*a2 b3[i] = t0[i] - t3[i]; // b3 = b1*b2 - 1*a1*a2 } degred(a3); degred(b3); coeffred_round_par(a3); coeffred_round_par(b3); fpe_set_doublearray(r1, a3); fpe_set_doublearray(r2, b3); _2fpe_to_fp2e(rop, r1, r2); }