Example #1
0
/* SU= 600 */
void FP12_inv(FP12 *w,FP12 *x)
{
	FP4 f0,f1,f2,f3;
	FP12_norm(x);

	FP4_sqr(&f0,&(x->a));
	FP4_mul(&f1,&(x->b),&(x->c));
	FP4_times_i(&f1);
	FP4_sub(&f0,&f0,&f1);  /* y.a */

	FP4_sqr(&f1,&(x->c));
	FP4_times_i(&f1);
	FP4_mul(&f2,&(x->a),&(x->b));
	FP4_sub(&f1,&f1,&f2);  /* y.b */

	FP4_sqr(&f2,&(x->b));
	FP4_mul(&f3,&(x->a),&(x->c));
	FP4_sub(&f2,&f2,&f3);  /* y.c */

	FP4_mul(&f3,&(x->b),&f2);  
	FP4_times_i(&f3);
	FP4_mul(&(w->a),&f0,&(x->a));
	FP4_add(&f3,&(w->a),&f3);
	FP4_mul(&(w->c),&f1,&(x->c));
	FP4_times_i(&(w->c));

	FP4_add(&f3,&(w->c),&f3);
	FP4_inv(&f3,&f3);

	FP4_mul(&(w->a),&f0,&f3);
	FP4_mul(&(w->b),&f1,&f3);
	FP4_mul(&(w->c),&f2,&f3);

}
/* XTR xtr_d function */
void FP4_xtr_D(FP4 *r,FP4 *x)
{
	FP4 w;
	FP4_copy(r,x);
	FP4_conj(&w,r);
	FP4_add(&w,&w,&w);
	FP4_sqr(r,r);
	FP4_sub(r,r,&w);
	FP4_reduce(r);    /* reduce here as multiple calls trigger automatic reductions */
}
/* XTR xtr_a function */
void FP4_xtr_A(FP4 *r,FP4 *w,FP4 *x,FP4 *y,FP4 *z)
{
	FP4 t1,t2;

	FP4_copy(r,x);

	FP4_sub(&t1,w,y);

	FP4_pmul(&t1,&t1,&(r->a));
	FP4_add(&t2,w,y);
	FP4_pmul(&t2,&t2,&(r->b));
	FP4_times_i(&t2);

	FP4_add(r,&t1,&t2);
	FP4_add(r,r,z);

	FP4_norm(r);
}