Ejemplo n.º 1
0
void bn254_fp2_inv(Element z, const Element x)
{
    Element* t = field(z)->base->tmp;

    if (strcmp(x->field->field_name, "bn254_fp2a") == 0)
    {
        bn254_fp_muln(t[1], rep1(x), rep1(x)); // t1 = a1^2
        bn254_fp_addn(t[0], t[1], t[1]);
        bn254_fp_addn(t[0], t[0], t[0]);
        bn254_fp_addn(t[1], t[1], t[0]);      // t1 = 5*a1^2
        bn254_fp_muln(t[0], rep0(x), rep0(x));// t0 = a0^2
        bn254_fp_addn(t[0], t[0], t[1]);      // t0 = t0 - t1
        bn254_fp_inv(t[1], t[0]);             // t1 = t0^-1
        bn254_fp_mul(rep0(z), rep0(x), t[1]); // c0 = a0*t1
        bn254_fp_mul(rep1(z), rep1(x), t[1]); // c1 = a1*t1
        bn254_fp_neg(rep1(z), rep1(z));       // c1 = -1*a1*t1
    }

    if (strcmp(x->field->field_name, "bn254_fp2b") == 0)
    {
        bn254_fp_muln(t[1], rep1(x), rep1(x));// t1 = a1^2
        bn254_fp_muln(t[0], rep0(x), rep0(x));// t0 = a0^2
        bn254_fp_addn(t[0], t[0], t[1]);      // t0 = t0 + t1 ( beta = -1 )
        bn254_fp_inv(t[1], t[0]);             // t1 = t0^-1
        bn254_fp_mul(rep0(z), rep0(x), t[1]); // c0 = a0*t1
        bn254_fp_mul(rep1(z), rep1(x), t[1]); // c1 = a1*t1
        bn254_fp_neg(rep1(z), rep1(z));       // c1 = -1*a1*t1
    }
}
Ejemplo n.º 2
0
void bn254_fp2_inv(Element z, const Element x)
{
    Element* t = field(z)->base->tmp;

    bn254_fp_muln(t[1], rep1(x), rep1(x)); // t1 = a1^2
    bn254_fp_addn(t[0], t[1], t[1]);
    bn254_fp_addn(t[0], t[0], t[0]);
    bn254_fp_addn(t[1], t[1], t[0]);      // t1 = 5*a1^2
    bn254_fp_muln(t[0], rep0(x), rep0(x));// t0 = a0^2
    bn254_fp_addn(t[0], t[0], t[1]);      // t0 = t0 - t1
    bn254_fp_inv(t[1], t[0]);             // t1 = t0^-1
    bn254_fp_mul(rep0(z), rep0(x), t[1]); // c0 = a0*t1
    bn254_fp_mul(rep1(z), rep1(x), t[1]); // c1 = a1*t1
    bn254_fp_neg(rep1(z), rep1(z));       // c1 = -1*a1*t1
}
Ejemplo n.º 3
0
int bn254_fp2_is_sqr(const Element x)
{
    int hr = FALSE;

    Element *t = field(x)->base->tmp;

    if (element_is_zero(x)) { return FALSE; }

    bn254_fp_inv(t[0], rep1(x));
    bn254_fp_mul(t[0], t[0], rep0(x));
    bn254_fp_sqr(t[0], t[0]);
    bn254_fp_add(t[0], t[0], field(x)->irre_poly[0]);

    hr = bn254_fp_is_sqr(t[0]);

    return hr;
}